Skip to content

Commit cd3e7aa

Browse files
committed
Merge branch 'feat/led_indicator_add_ledc_sleep_mode' into 'master'
feat(led_indicator): ledc/rgb indicators support config ledc sleep mode Closes AEGHB-1079 See merge request ae_group/esp-iot-solution!1354
2 parents 9d660a7 + dde1e10 commit cd3e7aa

File tree

6 files changed

+31
-1
lines changed

6 files changed

+31
-1
lines changed

components/led/led_indicator/CHANGELOG.md

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

3+
## v2.1.0 - 2025-11-5
4+
5+
## Improve:
6+
7+
* LED controlled by the LEDC driver supports [sleep_mode](https://docs.espressif.com/projects/esp-idf/en/v5.5.1/esp32/api-reference/peripherals/ledc.html#power-management) configuration
8+
39
## v2.0.2 - 2025-10-08
410

511
### Bugfix

components/led/led_indicator/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "2.0.2"
1+
version: "2.1.0"
22
description: LED indicator driver
33
url: https://github.com/espressif/esp-iot-solution/tree/master/components/led/led_indicator
44
dependencies:

components/led/led_indicator/include/led_indicator_ledc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#pragma once
88

99
#include "driver/ledc.h"
10+
#include "esp_idf_version.h"
1011
#include "led_indicator.h"
1112

1213
#ifdef __cplusplus
@@ -19,6 +20,9 @@ typedef struct {
1920
ledc_timer_t timer_num; /*!< The timer source of channel */
2021
int32_t gpio_num; /*!< num of gpio */
2122
ledc_channel_t channel; /*!< LEDC channel */
23+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
24+
ledc_sleep_mode_t sleep_mode; /*!< LEDC sleep mode */
25+
#endif
2226
} led_indicator_ledc_config_t;
2327

2428
/**

components/led/led_indicator/include/led_indicator_rgb.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#pragma once
77

88
#include "driver/ledc.h"
9+
#include "esp_idf_version.h"
910
#include "led_indicator.h"
1011

1112
#ifdef __cplusplus
@@ -26,6 +27,9 @@ typedef struct {
2627
ledc_channel_t red_channel; /*!< Red LED LEDC channel */
2728
ledc_channel_t green_channel; /*!< Green LED LEDC channel */
2829
ledc_channel_t blue_channel; /*!< Blue LED LEDC channel */
30+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
31+
ledc_sleep_mode_t sleep_mode; /*!< LEDC sleep mode */
32+
#endif
2933
} led_indicator_rgb_config_t;
3034

3135
/**

components/led/led_indicator/src/led_indicator_ledc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ static esp_err_t led_indicator_ledc_init(void *param)
5858
LED_LEDC_CHECK(!s_ledc->ledc_channel[ch].is_init, "LEDC channel is already initialized!", goto EXIT);
5959
ledc_channel_config_t ledc_ch_cfg = LEDC_CHANNEL_CONFIG(cfg->timer_num, cfg->channel, cfg->gpio_num);
6060
ledc_ch_cfg.flags.output_invert = cfg->is_active_level_high ? false : true;
61+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
62+
LED_LEDC_CHECK(cfg->sleep_mode < LEDC_SLEEP_MODE_INVALID, "invalid sleep mode", return ESP_ERR_INVALID_ARG);
63+
ledc_ch_cfg.sleep_mode = cfg->sleep_mode;
64+
#endif
6165
ret = ledc_channel_config(&ledc_ch_cfg);
6266
LED_LEDC_CHECK(ESP_OK == ret, "ledc_channel_config fail!", goto EXIT);
6367
s_ledc->ledc_channel[ch].channel = ch;

components/led/led_indicator/src/led_indicator_rgb.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,28 @@ static esp_err_t led_indicator_rgb_init(void *param, void **ret_rgb)
4242
rgb->max_duty = pow(2, ledc_timer_cfg.duty_resolution) - 1;
4343
}
4444

45+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
46+
LED_RGB_CHECK(cfg->sleep_mode < LEDC_SLEEP_MODE_INVALID, "invalid sleep mode", return ESP_ERR_INVALID_ARG);
47+
#endif
4548
ledc_channel_config_t red_ch_cfg = LEDC_CHANNEL_CONFIG(cfg->timer_num, cfg->red_channel, cfg->red_gpio_num);
4649
red_ch_cfg.flags.output_invert = cfg->is_active_level_high ? false : true;
50+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
51+
red_ch_cfg.sleep_mode = cfg->sleep_mode;
52+
#endif
4753
ret = ledc_channel_config(&red_ch_cfg);
4854
LED_RGB_CHECK(ESP_OK == ret, "red ledc_channel_config fail!", goto EXIT);
4955
ledc_channel_config_t green_ch_cfg = LEDC_CHANNEL_CONFIG(cfg->timer_num, cfg->green_channel, cfg->green_gpio_num);
5056
green_ch_cfg.flags.output_invert = cfg->is_active_level_high ? false : true;
57+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
58+
green_ch_cfg.sleep_mode = cfg->sleep_mode;
59+
#endif
5160
ret = ledc_channel_config(&green_ch_cfg);
5261
LED_RGB_CHECK(ESP_OK == ret, "green ledc_channel_config fail!", goto EXIT);
5362
ledc_channel_config_t blue_ch_cfg = LEDC_CHANNEL_CONFIG(cfg->timer_num, cfg->blue_channel, cfg->blue_gpio_num);
5463
blue_ch_cfg.flags.output_invert = cfg->is_active_level_high ? false : true;
64+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
65+
blue_ch_cfg.sleep_mode = cfg->sleep_mode;
66+
#endif
5567
ret = ledc_channel_config(&blue_ch_cfg);
5668
LED_RGB_CHECK(ESP_OK == ret, "blud ledc_channel_config fail!", goto EXIT);
5769
rgb->rgb_channel[0] = cfg->red_channel;

0 commit comments

Comments
 (0)