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

A02

2

N

A04

0

1

A13

2

N

当优先通道被占用,将自动尝试选择次选通道,若两个通道均被占用,则会被作为通用 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

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

#include <wq_ledc.h>

LED blink config.

Public Members

GPIO pull mode, down for high active and up for low active

When LED is flickering, first step is on

LED on duration, 0 for always on

LED off duration, 0 for always on

Delay between loops

Repeat times for ON/OFF at one loop, 0 for infinite

Repeat times total loops, 0 for infinite

Brightness percentage 1-100

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