LEDC
概述
LEDC 模块是一个波形发生器,主要用于控制 led 工作状态,支持闪烁和呼吸灯模式。
功能特性
支持最多8路GPIO
支持最多4路AON-GPIO
支持配置闪烁呼吸循环次数
支持配置占空比和周期
资源依赖
LEDC
GPIO
功能说明
引脚说明
任意最多 8 路 GPIO 可配置,普通 GPIO 无法在低功耗模式下继续产生波形 AON-GPIO 最多支持 4 通道同时开启,每个 AON-GPIO 有两个可选通道,驱动将依据以下顺序选择
AON-GPIO |
优先通道 |
次选通道 |
|---|---|---|
A00 |
0 |
1 |
A01 |
0 |
1 |
A13 |
2 |
0 |
A14 |
3 |
1 |
A15 |
0 |
2 |
A16 |
1 |
3 |
当优先通道被占用,将自动尝试选择次选通道,若两个通道均被占用,则会被作为通用 GPIO 开启。
闪烁模式
闪烁模式有以下几个主要参数
参数 |
意义 |
|---|---|
pull |
配置 io 空闲状态的上下拉模式 |
start_from_on |
配置闪烁模式是否以亮状态开始 |
ton_ms |
配置单次闪烁时,亮状态持续的时间,次项配置为 0 时,保持常亮 |
toff_ms |
配置单次闪烁时,暗状态的持续时间,次项配置为 0 时,保持常亮 |
cycle |
配置单个 loop 内的亮暗循环次数 |
tnop_ms |
配置单个 loop 后的等待时间 |
loop |
配置整体循环次数 |
duty |
配置亮度百分比,可配置 1-100 |
警告
常亮 永久阻止系统进入低功耗状态,需主动调用 wq_ledc_close() 后可正常进入低功耗状态。
呼吸模式
呼吸模式时 gpio 占空比连续变化的 pwm 波形,控制 LED 产生渐亮渐暗的显示效果
呼吸模式有以下几个主要参数
参数 |
意义 |
|---|---|
pull |
配置 io 空闲状态的上下拉模式 |
tdim_up_ms |
配置由暗到亮的渐变过程的持续时间 |
tdum_down_ms |
配置由亮到暗的渐变过程的持续时间 |
ton_ms |
配置全亮状态的持续时间 |
toff_ms |
配置全暗状态的持续时间 |
cycle |
配置单个 loop 内的亮暗循环次数 |
tnop_ms |
配置单个 loop 后的等待时间 |
loop |
配置整体循环次数 |
参考示例
examples\testsuite\acore\cmds\ledc
API 介绍
Functions
-
WQ_RET wq_ledc_init(void)
This function is to init ledc ctrl clk&output mapping.
- 返回:
WQ_RET WQ_RET_OK for success else error.
-
WQ_RET wq_ledc_deinit(void)
This function is to deinit ledc ctrl clk&output mapping.
- 返回:
WQ_RET WQ_RET_OK for success else error.
-
WQ_RET wq_ledc_close(WQ_GPIO_ID gpio)
Stop a LED flash process and release the gpio.
- 参数:
gpio -- [in] GPIO ID need be release
- 返回:
WQ_RET_OK success
WQ_RET_INVAL invalid gpio param
WQ_RET_NOT_EXIST gpio not opened as led
-
WQ_RET wq_ledc_blink(WQ_GPIO_ID gpio, const wq_ledc_blink_config_t *cfg)
Start a LED blink process.
- 参数:
gpio -- [in] GPIO ID that led connect
cfg -- [in]
- 返回:
WQ_RET_OK success
WQ_RET_FAIL can't open gpio as ledc
WQ_RET_INVAL invalid gpio param
-
WQ_RET wq_ledc_breath(WQ_GPIO_ID gpio, const wq_ledc_breath_config_t *cfg)
Start a LED breath process.
- 参数:
gpio -- [in] GPIO ID that led connect
cfg -- [in]
- 返回:
WQ_RET_OK success
WQ_RET_FAIL can't open gpio as ledc
WQ_RET_INVAL invalid gpio param
-
struct wq_ledc_blink_config_t
- #include <wq_ledc.h>
LED blink config.
Public Members
-
WQ_GPIO_PULL_MODE pull
GPIO pull mode, down for high active and up for low active
-
bool start_from_on
When LED is flickering, first step is on
-
uint16_t ton_ms
LED on duration, 0 for always on
-
uint16_t toff_ms
LED off duration, 0 for always on
-
uint16_t tnop_ms
Delay between loops
-
uint8_t cycle
Repeat times for ON/OFF at one loop, 0 for infinite
-
uint8_t loop
Repeat times total loops, 0 for infinite
-
uint8_t duty
Brightness percentage 1-100
-
WQ_GPIO_PULL_MODE pull
-
struct wq_ledc_breath_config_t
- #include <wq_ledc.h>
LED breath config.
Public Members
-
WQ_GPIO_PULL_MODE pull
GPIO pull mode, down for high active and up for low active
-
uint16_t tdim_up_ms
The duration millisecond of gradually brightening
-
uint16_t tdim_down_ms
The duration millisecond of gradually darkening
-
uint16_t ton_ms
LED on duration
-
uint16_t toff_ms
LED off duration
-
uint16_t tnop_ms
Delay between loops
-
uint8_t cycle
Repeat times for ON/OFF at one loop, 0 for infinite
-
uint8_t loop
Repeat times total loops, 0 for infinite
-
WQ_GPIO_PULL_MODE pull