Skip to content

Commit 76df7be

Browse files
committed
feat(led_indicator): Remove LED custom mode, hide user-irrelevant APIs, add esp_types.h
1 parent 7a71099 commit 76df7be

File tree

16 files changed

+148
-517
lines changed

16 files changed

+148
-517
lines changed

components/led/led_indicator/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ set(srcs "src/led_ledc.c"
66
"src/led_rgb.c"
77
"src/led_strips.c"
88
"src/led_convert.c"
9-
"src/led_custom.c"
109
)
1110

1211
idf_component_register( SRCS ${srcs}

components/led/led_indicator/include/led_convert.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,6 @@ extern "C" {
1616
#define MAX_BRIGHTNESS 255
1717
#define MAX_INDEX 127
1818

19-
/**
20-
* @brief LED duty should be consistent with the physical resolution of the indicator.
21-
* eg. LED_GPIO_MODE should with LED_DUTY_1_BIT
22-
*
23-
*/
24-
typedef enum {
25-
LED_DUTY_1_BIT = 1, /*!< LED duty resolution of 1 bits */
26-
LED_DUTY_2_BIT, /*!< LED duty resolution of 2 bits */
27-
LED_DUTY_3_BIT, /*!< LED duty resolution of 3 bits */
28-
LED_DUTY_4_BIT, /*!< LED duty resolution of 4 bits */
29-
LED_DUTY_5_BIT, /*!< LED duty resolution of 5 bits */
30-
LED_DUTY_6_BIT, /*!< LED duty resolution of 6 bits */
31-
LED_DUTY_7_BIT, /*!< LED duty resolution of 7 bits */
32-
LED_DUTY_8_BIT, /*!< LED duty resolution of 8 bits */
33-
LED_DUTY_9_BIT, /*!< LED duty resolution of 9 bits */
34-
LED_DUTY_10_BIT, /*!< LED duty resolution of 10 bits */
35-
LED_DUTY_11_BIT, /*!< LED duty resolution of 11 bits */
36-
LED_DUTY_12_BIT, /*!< LED duty resolution of 12 bits */
37-
LED_DUTY_13_BIT, /*!< LED duty resolution of 13 bits */
38-
LED_DUTY_14_BIT, /*!< LED duty resolution of 14 bits */
39-
LED_DUTY_15_BIT, /*!< LED duty resolution of 15 bits */
40-
} led_indicator_duty_t;
41-
4219
#define SET_RGB(r, g, b) \
4320
((((r) & 0xFF) << 16) | (((g) & 0xFF) << 8) | ((b) & 0xFF))
4421

components/led/led_indicator/include/led_custom.h

Lines changed: 0 additions & 49 deletions
This file was deleted.

components/led/led_indicator/include/led_gpio.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,6 @@ typedef struct {
2222
int32_t gpio_num; /*!< num of GPIO */
2323
} led_indicator_gpio_config_t;
2424

25-
/**
26-
* @brief Initialize the specific GPIO to work as a LED indicator
27-
*
28-
* @param param led_indicator_gpio_config_t
29-
* @param ret_handle gpio_handle
30-
* @return esp_err_t
31-
* - ESP_OK success
32-
* - ESP_ERR_INVALID_ARG Parameter error
33-
*/
34-
esp_err_t led_indicator_gpio_init(void *param, void **ret_handle);
35-
36-
/**
37-
* @brief Deinitialize the specific GPIO that works as a LED indicator
38-
*
39-
* @param handle GPIO handle
40-
* @return esp_err_t
41-
* - ESP_OK success
42-
*/
43-
esp_err_t led_indicator_gpio_deinit(void *handle);
44-
45-
/**
46-
* @brief Set the specific GPIO's level to make the LED indicator ON or OFF
47-
*
48-
* @param handle GPIO handle
49-
* @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,
50-
* 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
51-
* setting number greater than 0 will make the LED ON.
52-
* @return esp_err_t
53-
* - ESP_OK Success
54-
* - ESP_ERR_INVALID_ARG GPIO number error
55-
*/
56-
esp_err_t led_indicator_gpio_set_on_off(void *handle, bool on_off);
57-
5825
/**
5926
* @brief Create a new LED indicator device using a GPIO pin.
6027
*

components/led/led_indicator/include/led_indicator.h

Lines changed: 13 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern "C" {
1717
#include "freertos/semphr.h"
1818
#include "esp_err.h"
1919
#include "led_convert.h"
20+
#include "led_types.h"
2021

2122
#define LED_INDICATOR_CHECK(a, str, action) if(!(a)) { \
2223
ESP_LOGE(TAG,"%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, str); \
@@ -27,108 +28,28 @@ extern "C" {
2728
ESP_LOGW(TAG,"%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, str); \
2829
action; \
2930
}
30-
/**
31-
* @brief LED state: 0-100, only hardware that supports to set brightness can adjust brightness.
32-
*
33-
*/
34-
enum {
35-
LED_STATE_OFF = 0, /*!< turn off the LED */
36-
LED_STATE_25_PERCENT = 64, /*!< 25% brightness, must support to set brightness */
37-
LED_STATE_50_PERCENT = 128, /*!< 50% brightness, must support to set brightness */
38-
LED_STATE_75_PERCENT = 191, /*!< 75% brightness, must support to set brightness */
39-
LED_STATE_ON = UINT8_MAX, /*!< turn on the LED */
40-
};
41-
42-
/**
43-
* @brief actions in this type
44-
*
45-
*/
46-
typedef enum {
47-
LED_BLINK_STOP = -1, /*!< stop the blink */
48-
LED_BLINK_HOLD, /*!< hold the on-off state */
49-
LED_BLINK_BREATHE, /*!< breathe state */
50-
LED_BLINK_BRIGHTNESS, /*!< set the brightness, it will transition from the old brightness to the new brightness */
51-
LED_BLINK_RGB, /*!< color change with R(0-255) G(0-255) B(0-255) */
52-
LED_BLINK_RGB_RING, /*!< Gradual color transition from old color to new color in a color ring */
53-
LED_BLINK_HSV, /*!< color change with H(0-360) S(0-255) V(0-255) */
54-
LED_BLINK_HSV_RING, /*!< Gradual color transition from old color to new color in a color ring */
55-
LED_BLINK_LOOP, /*!< loop from first step */
56-
} blink_step_type_t;
5731

5832
/**
59-
* @brief one blink step, a meaningful signal consists of a group of steps
33+
* @brief Creates a new LED indicator instance with the specified configuration.
6034
*
61-
*/
62-
typedef struct {
63-
blink_step_type_t type; /*!< action type in this step */
64-
uint32_t value; /*!< hold on or off, set 0 if LED_BLINK_STOP() or LED_BLINK_LOOP */
65-
uint32_t hold_time_ms; /*!< hold time(ms), set 0 if not LED_BLINK_HOLD */
66-
} blink_step_t;
67-
68-
/**
69-
* @brief LED indicator blink mode, as a member of led_indicator_config_t
35+
* @param cfg Pointer to a configuration structure of type _led_indicator_com_config_t
36+
* containing initialization parameters for the LED indicator.
7037
*
38+
* @return Pointer to the created _led_indicator_t instance on success, or NULL on failure.
7139
*/
72-
typedef enum {
73-
LED_GPIO_MODE, /*!< blink with max brightness */
74-
LED_LEDC_MODE, /*!< blink with LEDC driver */
75-
LED_RGB_MODE, /*!< blink with RGB driver */
76-
LED_STRIPS_MODE, /*!< blink with LEDC strips driver */
77-
LED_CUSTOM_MODE, /*!< blink with custom driver */
78-
} led_indicator_mode_t;
79-
80-
typedef struct {
81-
esp_err_t (*hal_indicator_set_on_off)(void *hardware_data, bool on_off); /*!< Pointer function for setting on or off */
82-
esp_err_t (*hal_indicator_deinit)(void *hardware_data); /*!< Pointer function for Deinitialization */
83-
esp_err_t (*hal_indicator_set_brightness)(void *hardware_data, uint32_t brightness); /*!< Pointer function for setting brightness, must be supported by hardware */
84-
esp_err_t (*hal_indicator_set_rgb)(void *hardware, uint32_t rgb_value); /*!< Pointer function for setting rgb, must be supported by hardware */
85-
esp_err_t (*hal_indicator_set_hsv)(void *hardware, uint32_t hsv_value); /*!< Pointer function for setting hsv, must be supported by hardware */
86-
void *hardware_data; /*!< Hardware data of the LED indicator */
87-
led_indicator_mode_t mode; /*!< LED work mode, eg. GPIO or pwm mode */
88-
int active_blink; /*!< Active blink list*/
89-
int preempt_blink; /*!< Highest priority blink list*/
90-
int *p_blink_steps; /*!< Stage of each blink list */
91-
led_indicator_ihsv_t current_fade_value; /*!< Current fade value */
92-
led_indicator_ihsv_t last_fade_value; /*!< Save the last value. */
93-
uint16_t fade_value_count; /*!< Count the number of fade */
94-
uint16_t fade_step; /*!< Step of fade */
95-
uint16_t fade_total_step; /*!< Total step of fade */
96-
uint32_t max_duty; /*!< Max duty cycle from duty_resolution : 2^duty_resolution -1 */
97-
SemaphoreHandle_t mutex; /*!< Mutex to achieve thread-safe */
98-
TimerHandle_t h_timer; /*!< LED timer handle, invalid if works in pwm mode */
99-
blink_step_t const **blink_lists; /*!< User defined LED blink lists */
100-
uint16_t blink_list_num; /*!< Number of blink lists */
101-
} _led_indicator_t;
102-
103-
typedef struct _led_indicator_com_config {
104-
esp_err_t (*hal_indicator_set_on_off)(void *hardware_data, bool on_off); /*!< Pointer function for setting on or off */
105-
esp_err_t (*hal_indicator_deinit)(void *hardware_data); /*!< Pointer function for Deinitialization */
106-
esp_err_t (*hal_indicator_set_brightness)(void *hardware_data, uint32_t brightness); /*!< Pointer function for setting brightness, must be supported by hardware */
107-
esp_err_t (*hal_indicator_set_rgb)(void *hardware, uint32_t rgb_value); /*!< Pointer function for setting rgb, must be supported by hardware */
108-
esp_err_t (*hal_indicator_set_hsv)(void *hardware, uint32_t hsv_value); /*!< Pointer function for setting hsv, must be supported by hardware */
109-
void *hardware_data; /*!< GPIO number of the LED indicator */
110-
blink_step_t const **blink_lists; /*!< User defined LED blink lists */
111-
uint16_t blink_list_num; /*!< Number of blink lists */
112-
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. */
113-
} _led_indicator_com_config_t;
114-
115-
typedef struct {
116-
blink_step_t const **blink_lists; /*!< user defined LED blink lists */
117-
uint16_t blink_list_num; /*!< number of blink lists */
118-
} led_config_t;
119-
120-
typedef void *led_indicator_handle_t; /*!< LED indicator operation handle */
121-
12240
_led_indicator_t *_led_indicator_create_com(_led_indicator_com_config_t *cfg);
12341

124-
esp_err_t _led_indicator_add_node(_led_indicator_t *p_led_indicator);
125-
12642
/**
127-
* @brief create a LED indicator instance with GPIO number and configuration
43+
* @brief Add a new node to the LED indicator instance.
44+
*
45+
* @param[in,out] p_led_indicator Pointer to the LED indicator instance to which the node will be added.
12846
*
129-
* @param config configuration of the LED, eg. GPIO level when LED off
130-
* @return led_indicator_handle_t handle of the LED indicator, NULL if create failed.
47+
* @return esp_err_t
48+
* - ESP_ERR_INVALID_ARG if parameter is invalid
49+
* - ESP_ERR_NOT_FOUND no predefined blink_type found
50+
* - ESP_OK Success
13151
*/
52+
esp_err_t _led_indicator_add_node(_led_indicator_t *p_led_indicator);
13253

13354
/**
13455
* @brief delete the LED indicator and release resource

components/led/led_indicator/include/led_ledc.h

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,51 +21,6 @@ typedef struct {
2121
ledc_channel_t channel; /*!< LEDC channel */
2222
} led_indicator_ledc_config_t;
2323

24-
/**
25-
* @brief Initialize LEDC-related configurations for this LED indicator.
26-
*
27-
* @param param LEDC config: ledc_timer_config & ledc_channel_config
28-
* @return esp_err_t
29-
* - ESP_OK Success
30-
* - ESP_FAIL Deinit fail
31-
* - ESP_ERR_NO_MEM failed to request memory
32-
*/
33-
esp_err_t led_indicator_ledc_init(void *param);
34-
35-
/**
36-
* @brief Deinitialize LEDC which is used by the LED indicator.
37-
*
38-
* @param ledc_handle LED indicator LEDC operation handle
39-
* @return esp_err_t
40-
* - ESP_OK Success
41-
* - ESP_FAIL Deinit fail
42-
*/
43-
esp_err_t led_indicator_ledc_deinit(void *ledc_handle);
44-
45-
/**
46-
* @brief Set the specific LEDC's level to make the LED indicator ON or OFF
47-
*
48-
* @param ledc_handle LED indicator LEDC operation handle
49-
* @param on_off Set 0 to control the LEDC's output level low, while values greater than 0 set the LEDC's output level high..
50-
* @return esp_err_t
51-
* - ESP_OK Success
52-
* - ESP_ERR_INVALID_ARG Parameter error
53-
* - ESP_FAIL LEDC channel doesn't init
54-
*/
55-
esp_err_t led_indicator_ledc_set_on_off(void *ledc_handle, bool on_off);
56-
57-
/**
58-
* @brief Set LEDC duty cycle
59-
*
60-
* @param ledc_handle LED indicator LEDC operation handle
61-
* @param brightness duty cycle of LEDC [0-255]
62-
* @return esp_err_t
63-
* - ESP_OK Success
64-
* - ESP_ERR_INVALID_ARG Parameter error
65-
* - ESP_FAIL Set brightness fail
66-
*/
67-
esp_err_t led_indicator_ledc_set_brightness(void *ledc_handle, uint32_t brightness);
68-
6924
/**
7025
* @brief Create a new LED indicator device using the LEDC (LED Controller) peripheral.
7126
*

components/led/led_indicator/include/led_rgb.h

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -28,76 +28,6 @@ typedef struct {
2828
ledc_channel_t blue_channel; /*!< Blue LED LEDC channel */
2929
} led_indicator_rgb_config_t;
3030

31-
/**
32-
* @brief Initialize the RGB LED indicator (WS2812 SK6812).
33-
*
34-
* @param param Pointer to initialization parameters.
35-
* @param ret_rgb Pointer to a variable that will hold the LED RGB instance.
36-
* @return esp_err_t
37-
* - ESP_OK: Success
38-
* - ESP_FAIL: Initialization failed
39-
* - ESP_ERR_INVALID_ARG: Invalid argument provided
40-
* - ESP_ERR_NO_MEM: Memory allocation failed
41-
*/
42-
esp_err_t led_indicator_rgb_init(void *param, void **ret_rgb);
43-
44-
/**
45-
* @brief Deinitialize led RGB which is used by the LED indicator.
46-
*
47-
* @param rgb_handle LED indicator LED RGB operation handle
48-
* @return esp_err_t
49-
* - ESP_OK Success
50-
* - ESP_FAIL Deinit fail
51-
*/
52-
esp_err_t led_indicator_rgb_deinit(void *rgb_handle);
53-
54-
/**
55-
* @brief Turn the LED indicator on or off.
56-
*
57-
* @param rgb_handle LED indicator LED RGB operation handle.
58-
* @param on_off Set to 0 or 1 to control the LED (0 for off, 1 for on).
59-
* @return esp_err_t
60-
* - ESP_OK: Success
61-
* - ESP_ERR_INVALID_ARG: Invalid argument provided
62-
* - ESP_FAIL: LEDC channel initialization failed
63-
*/
64-
esp_err_t led_indicator_rgb_set_on_off(void *rgb_handle, bool on_off);
65-
66-
/**
67-
* @brief Set the RGB color for the LED indicator.
68-
*
69-
* @param rgb_handle LED indicator LED RGB operation handle.
70-
* @param rgb_value RGB color value to set. (R: 0-255, G: 0-255, B: 0-255)
71-
* @return esp_err_t
72-
* - ESP_OK: Success
73-
* - ESP_ERR_INVALID_ARG: Invalid argument provided
74-
* - ESP_FAIL: Failed to set brightness
75-
*/
76-
esp_err_t led_indicator_rgb_set_rgb(void *rgb_handle, uint32_t rgb_value);
77-
78-
/**
79-
* @brief Set the HSV color for the LED indicator.
80-
*
81-
* @param rgb_handle LED indicator LED RGB operation handle.
82-
* @param hsv_value HSV color value to set. (H: 0-360, S: 0-255, V: 0-255)
83-
* @return esp_err_t
84-
* - ESP_OK: Success
85-
* - ESP_ERR_INVALID_ARG: Invalid argument provided
86-
* - ESP_FAIL: Failed to set brightness
87-
*/
88-
esp_err_t led_indicator_rgb_set_hsv(void *rgb_handle, uint32_t hsv_value);
89-
90-
/**
91-
* @brief Set the brightness for the LED indicator.
92-
*
93-
* @param rgb_handle Pointer to the LED indicator handle.
94-
* @param brightness Brightness value to set.
95-
* @return esp_err_t
96-
* - ESP_OK: Success
97-
* - ESP_FAIL: Failed to set brightness
98-
*/
99-
esp_err_t led_indicator_rgb_set_brightness(void *rgb_handle, uint32_t brightness);
100-
10131
/**
10232
* @brief Create a new RGB LED device instance.
10333
*

0 commit comments

Comments
 (0)