Skip to content

Commit c876df7

Browse files
YanKE01zhongchaoesp
andcommitted
Merge branch 'led_factory' into 'master'
Refactor the components into the Factory Pattern Closes AEG-2071 and AEGHB-989 Closes #532 Closes #472 See merge request ae_group/esp-iot-solution!1330 Co-authored-by: zhongchaoesp <[email protected]>
2 parents 568869a + b754058 commit c876df7

40 files changed

+1096
-956
lines changed

.gitlab/ci/build.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -587,10 +587,7 @@ build_example_indicator:
587587
extends:
588588
- .build_examples_template
589589
- .rules:build:example_indicator
590-
parallel:
591-
matrix:
592-
- IMAGE: espressif/idf:release-v5.1
593-
- IMAGE: espressif/idf:release-v4.4
590+
- .build_idf_version_greater_equal_v5_0
594591
variables:
595592
EXAMPLE_DIR: examples/indicator
596593

@@ -1417,10 +1414,7 @@ build_components_led_led_indicator_test_apps:
14171414
extends:
14181415
- .build_examples_template
14191416
- .rules:build:components_led_led_indicator_test_apps
1420-
parallel:
1421-
matrix:
1422-
- IMAGE: espressif/idf:release-v4.4
1423-
- IMAGE: espressif/idf:release-v5.0
1417+
- .build_idf_version_greater_equal_v5_0
14241418
variables:
14251419
EXAMPLE_DIR: components/led/led_indicator/test_apps
14261420

.gitlab/ci/target_test.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,6 @@ components_test_led_indicator:
300300
optional: true
301301
parallel:
302302
matrix:
303-
- IDF_VERSION: "4.4"
304-
IDF_TARGET: esp32s3
305-
ENV_TAG: "led_indicator"
306303
- IDF_VERSION: "5.0"
307304
IDF_TARGET: esp32s3
308305
ENV_TAG: "led_indicator"

components/led/led_indicator/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# ChangeLog
22

3+
## v2.0.0 - 2025-7-30
4+
5+
### Improve:
6+
7+
* Refactor with Factory Pattern
8+
* Update the version of `led_strip` to v3.0
9+
* Add Xiaomi Blink support
10+
311
## v1.1.1 - 2025-03-11
412

513
### Bugfix

components/led/led_indicator/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
set(srcs "src/led_ledc.c"
1+
set(srcs "src/led_indicator_ledc.c"
22
"src/led_gamma.c"
3-
"src/led_gpio.c"
3+
"src/led_indicator_gpio.c"
44
"src/led_indicator.c"
55
"src/led_indicator_blink_default.c"
6-
"src/led_rgb.c"
7-
"src/led_strips.c"
6+
"src/led_indicator_rgb.c"
7+
"src/led_indicator_strips.c"
88
"src/led_convert.c"
99
)
1010

components/led/led_indicator/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ menu "LED Indicator"
99
bool "Enable gamma correction"
1010
default "y"
1111

12+
config USE_MI_RGB_BLINK_DEFAULT
13+
bool "Use Xiaomi rgb blink default"
14+
default "n"
15+
1216
menu "LEDC Config"
1317

1418
choice LEDC_SPEED_MODE

components/led/led_indicator/idf_component.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
version: "1.1.1"
1+
version: "2.0.0"
22
description: LED indicator driver
33
url: https://github.com/espressif/esp-iot-solution/tree/master/components/led/led_indicator
44
dependencies:
5-
idf: ">=4.0"
5+
idf: ">=5.0"
66
led_strip:
7-
version: "2.5.5"
7+
version: "3.*"
88
public: true
99
cmake_utilities: "*"
1010
examples:

components/led/led_indicator/include/led_convert.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/

components/led/led_indicator/include/led_custom.h

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

components/led/led_indicator/include/led_gpio.h

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

components/led/led_indicator/include/led_indicator.h

Lines changed: 10 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -13,89 +13,18 @@ extern "C" {
1313
#include <stdint.h>
1414
#include <stdbool.h>
1515
#include "esp_err.h"
16-
#include "led_gpio.h"
17-
#include "led_ledc.h"
18-
#include "led_rgb.h"
19-
#include "led_strips.h"
2016
#include "led_convert.h"
21-
#include "led_custom.h"
17+
#include "led_types.h"
2218

23-
/**
24-
* @brief LED state: 0-100, only hardware that supports to set brightness can adjust brightness.
25-
*
26-
*/
27-
enum {
28-
LED_STATE_OFF = 0, /*!< turn off the LED */
29-
LED_STATE_25_PERCENT = 64, /*!< 25% brightness, must support to set brightness */
30-
LED_STATE_50_PERCENT = 128, /*!< 50% brightness, must support to set brightness */
31-
LED_STATE_75_PERCENT = 191, /*!< 75% brightness, must support to set brightness */
32-
LED_STATE_ON = UINT8_MAX, /*!< turn on the LED */
33-
};
34-
35-
/**
36-
* @brief actions in this type
37-
*
38-
*/
39-
typedef enum {
40-
LED_BLINK_STOP = -1, /*!< stop the blink */
41-
LED_BLINK_HOLD, /*!< hold the on-off state */
42-
LED_BLINK_BREATHE, /*!< breathe state */
43-
LED_BLINK_BRIGHTNESS, /*!< set the brightness, it will transition from the old brightness to the new brightness */
44-
LED_BLINK_RGB, /*!< color change with R(0-255) G(0-255) B(0-255) */
45-
LED_BLINK_RGB_RING, /*!< Gradual color transition from old color to new color in a color ring */
46-
LED_BLINK_HSV, /*!< color change with H(0-360) S(0-255) V(0-255) */
47-
LED_BLINK_HSV_RING, /*!< Gradual color transition from old color to new color in a color ring */
48-
LED_BLINK_LOOP, /*!< loop from first step */
49-
} blink_step_type_t;
50-
51-
/**
52-
* @brief one blink step, a meaningful signal consists of a group of steps
53-
*
54-
*/
55-
typedef struct {
56-
blink_step_type_t type; /*!< action type in this step */
57-
uint32_t value; /*!< hold on or off, set 0 if LED_BLINK_STOP() or LED_BLINK_LOOP */
58-
uint32_t hold_time_ms; /*!< hold time(ms), set 0 if not LED_BLINK_HOLD */
59-
} blink_step_t;
19+
#define LED_INDICATOR_CHECK(a, str, action) if(!(a)) { \
20+
ESP_LOGE(TAG,"%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, str); \
21+
action; \
22+
}
6023

61-
/**
62-
* @brief LED indicator blink mode, as a member of led_indicator_config_t
63-
*
64-
*/
65-
typedef enum {
66-
LED_GPIO_MODE, /*!< blink with max brightness */
67-
LED_LEDC_MODE, /*!< blink with LEDC driver */
68-
LED_RGB_MODE, /*!< blink with RGB driver */
69-
LED_STRIPS_MODE, /*!< blink with LEDC strips driver */
70-
LED_CUSTOM_MODE, /*!< blink with custom driver */
71-
} led_indicator_mode_t;
72-
73-
/**
74-
* @brief LED indicator specified configurations, as a arg when create a new indicator
75-
*
76-
*/
77-
typedef struct {
78-
led_indicator_mode_t mode; /*!< LED work mode, eg. GPIO or pwm mode */
79-
union {
80-
led_indicator_gpio_config_t *led_indicator_gpio_config; /*!< LED GPIO configuration */
81-
led_indicator_ledc_config_t *led_indicator_ledc_config; /*!< LED LEDC configuration */
82-
led_indicator_rgb_config_t *led_indicator_rgb_config; /*!< LED RGB configuration */
83-
led_indicator_strips_config_t *led_indicator_strips_config; /*!< LED LEDC rgb configuration */
84-
led_indicator_custom_config_t *led_indicator_custom_config; /*!< LED custom configuration */
85-
}; /**< LED configuration */
86-
blink_step_t const **blink_lists; /*!< user defined LED blink lists */
87-
uint16_t blink_list_num; /*!< number of blink lists */
88-
} led_indicator_config_t;
89-
90-
typedef void *led_indicator_handle_t; /*!< LED indicator operation handle */
91-
92-
/**
93-
* @brief create a LED indicator instance with GPIO number and configuration
94-
*
95-
* @param config configuration of the LED, eg. GPIO level when LED off
96-
* @return led_indicator_handle_t handle of the LED indicator, NULL if create failed.
97-
*/
98-
led_indicator_handle_t led_indicator_create(const led_indicator_config_t *config);
24+
#define LED_INDICATOR_CHECK_WARNING(a, str, action) if(!(a)) { \
25+
ESP_LOGW(TAG,"%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, str); \
26+
action; \
27+
}
9928

10029
/**
10130
* @brief delete the LED indicator and release resource

0 commit comments

Comments
 (0)