Skip to content

Commit

Permalink
Merge branch 'bugfix/led_indicator_fix_rgb' into 'master'
Browse files Browse the repository at this point in the history
bugfix: rgb's is_active_level_high

See merge request ae_group/esp-iot-solution!901
  • Loading branch information
leeebo committed Nov 30, 2023
2 parents e60b439 + 9415bd6 commit a972d4a
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 213 deletions.
12 changes: 12 additions & 0 deletions components/led/led_indicator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@

# ChangeLog

## v0.9.0 - 2023-11-28

### BUG FIX

* Resolve the error with 'is_active_level_high' in LEDC RGB type.

### Break Change

* Remove `led_indicator_strips_config_t:is_active_level_high`

* Remove `led_indicator_get_handle`, the query of 'led_indicator handle' through GPIO number and LEDC channel is no longer supported.

## v0.8.0 -2023-11-21

### Enhancements:
Expand Down
2 changes: 1 addition & 1 deletion components/led/led_indicator/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "0.8.0"
version: "0.9.0"
description: LED indicator driver
url: https://github.com/espressif/esp-iot-solution/tree/master/components/led/led_indicator
dependencies:
Expand Down
24 changes: 12 additions & 12 deletions components/led/led_indicator/include/led_convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ extern "C" {
#define INSERT_INDEX(index, brightness) \
((((index) & 0x7F) << 25) | ((brightness) & 0xFF))

#define SET_INDEX(variable, value) \
variable = (variable & 0x1FFFFFF) | (((value) & 0x7F) << 25)

#define SET_HUE(variable, value) \
variable = (variable & 0xFE00FFFF) | (((value) & 0x1FF) << 16)

#define SET_SATURATION(variable, value) \
variable = (variable & 0xFFFF00FF) | (((value) & 0xFF) << 8)

#define SET_BRIGHTNESS(variable, value) \
variable = (variable & 0xFFFFFF00) | ((value) & 0xFF)

#define GET_INDEX(variable) \
((variable >> 25) & 0x7F)

Expand All @@ -64,6 +52,18 @@ extern "C" {
#define GET_BLUE(variable) \
(variable & 0xFF)

typedef struct {
union {
struct {
uint32_t v:8; /*!< Brightness/Value of the LED. 0-255 */
uint32_t s:8; /*!< Saturation of the LED. 0-255 */
uint32_t h:9; /*!< Hue of the LED. 0-360 */
uint32_t i:7; /*!< Index of the LED. 0-126, set 127 to control all */
};
uint32_t value; /*!< IHSV value of the LED. */
};
} led_indicator_ihsv_t;

/**
* @brief Convert an RGB color value to an HSV color value.
*
Expand Down
2 changes: 1 addition & 1 deletion components/led/led_indicator/include/led_custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typedef enum {
*
*/
typedef struct {
bool is_active_level_high; /*!< Set true if GPIO level is high when light is ON, otherwise false. */
bool is_active_level_high; /*!< Set true if GPIO level is high when light is ON, otherwise false, values should be modified based on the actual scenario.*/
led_indicator_duty_t duty_resolution; /*!< Resolution of duty setting in number of bits. The range of duty values is [0, (2**duty_resolution) -1]. If the brightness cannot be set, set this as 1. */
esp_err_t (*hal_indicator_init)(void *hardware_data ); /*!< pointer functions for initialization*/
esp_err_t (*hal_indicator_set_on_off)(void *hardware_data, bool on_off); /*!< pointer functions for setting on or off */
Expand Down
13 changes: 7 additions & 6 deletions components/led/led_indicator/include/led_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,35 @@ typedef struct {
/**
* @brief Initialize the specific GPIO to work as a LED indicator
*
* @param io_num GPIO number of the LED
* @param param led_indicator_gpio_config_t
* @param ret_handle gpio_handle
* @return esp_err_t
* - ESP_OK success
* - ESP_ERR_INVALID_ARG Parameter error
*/
esp_err_t led_indicator_gpio_init(void *io_num);
esp_err_t led_indicator_gpio_init(void *param, void **ret_handle);

/**
* @brief Deinitialize the specific GPIO that works as a LED indicator
*
* @param io_num GPIO number of the LED
* @param handle GPIO handle
* @return esp_err_t
* - ESP_OK success
*/
esp_err_t led_indicator_gpio_deinit(void *io_num);
esp_err_t led_indicator_gpio_deinit(void *handle);

/**
* @brief Set the specific GPIO's level to make the LED indicator ON or OFF
*
* @param io_num GPIO number of the LED
* @param handle GPIO handle
* @param on_off Set number to control the GPIO's level. If the LED's positive side is connected to this GPIO, then setting number greater than 0 will make the LED OFF,
* and setting 0 will make the LED ON. If the LED's negative side is connected to this GPIO, then setting 0 will make the LED OFF, and
* setting number greater than 0 will make the LED ON.
* @return esp_err_t
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG GPIO number error
*/
esp_err_t led_indicator_gpio_set_on_off(void *io_num, bool on_off);
esp_err_t led_indicator_gpio_set_on_off(void *handle, bool on_off);

#ifdef __cplusplus
}
Expand Down
8 changes: 0 additions & 8 deletions components/led/led_indicator/include/led_indicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ typedef void *led_indicator_handle_t; /*!< LED indicator operation handle */
*/
led_indicator_handle_t led_indicator_create(const led_indicator_config_t *config);

/**
* @brief get the handle of created led_indicator with hardware data
*
* @param hardware_data user hardware data for LED
* @return led_indicator_handle_t handle of the created LED indicator, NULL if not created.
*/
led_indicator_handle_t led_indicator_get_handle(void *hardware_data);

/**
* @brief delete the LED indicator and release resource
*
Expand Down
1 change: 0 additions & 1 deletion components/led/led_indicator/include/led_strips.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ typedef enum {
} led_strip_driver_t;

typedef struct {
bool is_active_level_high; /*!< Set true if GPIO level is high when light is ON, otherwise false. */
led_strip_config_t led_strip_cfg; /*!< LED Strip Configuration. */
led_strip_driver_t led_strip_driver; /*!< led strip control type */
union {
Expand Down
4 changes: 2 additions & 2 deletions components/led/led_indicator/src/led_convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ uint32_t led_indicator_rgb2hsv(uint32_t rgb_value)

void led_indicator_hsv2rgb(uint32_t hsv, uint32_t *r, uint32_t *g, uint32_t *b)
{
uint8_t h = (hsv >> 16) & 0x1FF;
uint16_t h = (hsv >> 16) & 0x1FF;
uint8_t s = (hsv >> 8) & 0xFF;
uint16_t v = hsv & 0xFF;
uint8_t v = hsv & 0xFF;

uint8_t rgb_max = v;
uint8_t rgb_min = rgb_max * (255 - s) / 255.0f;
Expand Down
36 changes: 29 additions & 7 deletions components/led/led_indicator/src/led_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,63 @@
#include "esp_log.h"
#include "led_gpio.h"

esp_err_t led_indicator_gpio_init(void *io_num)
typedef struct {
bool is_active_level_high; /*!< Set true if GPIO level is high when light is ON, otherwise false. */
uint32_t io_num;
} led_gpio_t;

esp_err_t led_indicator_gpio_init(void *param, void **ret_handle)
{
const led_indicator_gpio_config_t *cfg = (const led_indicator_gpio_config_t *)param;

gpio_config_t io_conf = {0};
//disable interrupt
io_conf.intr_type = GPIO_INTR_DISABLE;
//set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
//bit mask of the pins that you want to set
io_conf.pin_bit_mask = 1ULL << (uint32_t)io_num;
io_conf.pin_bit_mask = 1ULL << (uint32_t)cfg->gpio_num;
//disable pull-down mode
io_conf.pull_down_en = 0;
//disable pull-up mode
io_conf.pull_up_en = 0;
//configure GPIO with the given settings
esp_err_t ret = gpio_config(&io_conf);

if (ret != ESP_OK) {
return ret;
}

led_gpio_t *handle = calloc(1, sizeof(led_gpio_t));
handle->is_active_level_high = cfg->is_active_level_high;
handle->io_num = cfg->gpio_num;
*ret_handle = (void *)handle;
return ESP_OK;
}

esp_err_t led_indicator_gpio_deinit(void *io_num)
esp_err_t led_indicator_gpio_deinit(void *handle)
{
esp_err_t ret = gpio_reset_pin((uint32_t)io_num);
if (handle == NULL) {
return ESP_ERR_INVALID_ARG;
}
led_gpio_t *p_gpio = (led_gpio_t *)handle;
esp_err_t ret = gpio_reset_pin(p_gpio->io_num);

if (ret != ESP_OK) {
return ret;
}
free(p_gpio);

return ESP_OK;
}

esp_err_t led_indicator_gpio_set_on_off(void *io_num, bool on_off)
esp_err_t led_indicator_gpio_set_on_off(void *handle, bool on_off)
{
return gpio_set_level((uint32_t)io_num, on_off);
if (handle == NULL) {
return ESP_ERR_INVALID_ARG;
}
led_gpio_t *p_gpio = (led_gpio_t *)handle;
if (!p_gpio->is_active_level_high) {
on_off = !on_off;
}
return gpio_set_level(p_gpio->io_num, on_off);
}
Loading

0 comments on commit a972d4a

Please sign in to comment.