Module ledc
LED Controller low-level APIs.
Description
The functions in this module broadly reflect the ESP IDF-SDK LED Controller API.
See the IDF-SDK LEDC documentation for more information about these APIs.
Data Types
channel()
channel() = 0..7
channel_cfg()
channel_cfg() = {channel, channel()}
channel_config()
channel_config() = [channel_cfg() | duty_cfg() | gpio_num_cfg() | speed_mode_cfg() | hpoint_cfg() | timer_sel_cfg()]
duty()
duty() = non_neg_integer()
duty_cfg()
duty_cfg() = {duty, duty()}
duty_resolution()
duty_resolution() = non_neg_integer()
duty_resolution_cfg()
duty_resolution_cfg() = {duty_resolution, duty_resolution()}
fade_mode()
fade_mode() = non_neg_integer()
freq_hz()
freq_hz() = non_neg_integer()
freq_hz_cfg()
freq_hz_cfg() = {freq_hz, freq_hz()}
gpio_num()
gpio_num() = non_neg_integer()
gpio_num_cfg()
gpio_num_cfg() = {gpio_num, gpio_num()}
hpoint()
hpoint() = non_neg_integer()
hpoint_cfg()
hpoint_cfg() = {hpoint, hpoint()}
ledc_error_code()
ledc_error_code() = non_neg_integer()
speed_mode()
speed_mode() = ?LEDC_LOW_SPEED_MODE | ?LEDC_HIGH_SPEED_MODE
speed_mode_cfg()
speed_mode_cfg() = {speed_mode, speed_mode()}
timer_config()
timer_config() = [duty_resolution_cfg() | freq_hz_cfg() | speed_mode_cfg() | timer_num_cfg()]
timer_num()
timer_num() = 0..3
timer_num_cfg()
timer_num_cfg() = {timer_num, timer_num()}
timer_sel()
timer_sel() = non_neg_integer()
timer_sel_cfg()
timer_sel_cfg() = {timer_sel, timer_sel()}
Function Index
channel_config/1 | LEDC channel configuration. |
fade_func_install/1 | Install LEDC fade function. |
fade_func_uninstall/0 | Uninstall LEDC fade function. |
fade_start/3 | Start LEDC fading. |
get_duty/2 | LEDC get duty. |
get_freq/2 | LEDC get channel frequency (Hz). |
set_duty/3 | LEDC set duty. |
set_fade_with_step/5 | Set LEDC fade function. |
set_fade_with_time/4 | Set LEDC fade function, with a limited time. |
set_freq/3 | LEDC set channel frequency (Hz). |
stop/3 | LEDC stop. |
timer_config/1 | LEDC timer configuration. |
update_duty/2 | LEDC update channel parameters. |
Function Details
channel_config/1
channel_config(Config::channel_config()) -> ok | {error, ledc_error_code()}
Config
: channel configuration
returns: ok | {error, ledc_error_code()}
LEDC channel configuration.
Configure LEDC timer with the given source timer/frequency(Hz)/duty_resolution.
fade_func_install/1
fade_func_install(Flags::non_neg_integer()) -> ok | {error, ledc_error_code()}
Flags
: Flags used to allocate the interrupt. One (or multiple, using
an ORred mask) ESP_INTR_FLAG_* values. See esp_intr_alloc.h
for more info.
returns: ok | {error, ledc_error_code()}
Install LEDC fade function.
This function will occupy interrupt of LEDC module.
fade_func_uninstall/0
fade_func_uninstall() -> ok
returns: ok
Uninstall LEDC fade function.
fade_start/3
fade_start(SpeedMode::speed_mode(), Channel::channel(), FadeMode::fade_mode()) -> ok | {error, ledc_error_code()}
SpeedMode
: Select the LEDC channel group with specified speed mode.
Note that not all targets support high speed mode.Channel
: LEDC channel index (0-7).FadeMode
: Whether to block until fading done.
returns: ok | {error, ledc_error_code()}
Start LEDC fading.
Note. Call ledc:fade_func_install() once before calling this function. Call ledc:fade_start() after this to start fading.
get_duty/2
get_duty(SpeedMode::speed_mode(), Channel::channel()) -> ok | {error, ledc_error_code()}
SpeedMode
: Select the LEDC channel group with specified speed mode.
Note that not all targets support high speed mode.Channel
: LEDC channel index (0-7).
returns: ok | {error, ledc_error_code()}
LEDC get duty.
get_freq/2
get_freq(SpeedMode::speed_mode(), TimerNum::timer_num()) -> ok | {error, ledc_error_code()}
SpeedMode
: Select the LEDC channel group with specified speed mode.TimerNum
: LEDC timer index (0-3).
returns: ok | {error, ledc_error_code()}
LEDC get channel frequency (Hz)
set_duty/3
set_duty(SpeedMode::speed_mode(), Channel::channel(), Duty::non_neg_integer()) -> ok | {error, ledc_error_code()}
SpeedMode
: Select the LEDC channel group with specified speed mode.
Note that not all targets support high speed mode.Channel
: LEDC channel index (0-7).Duty
: Set the LEDC duty, the range of setting is [0, (2^duty_resolution)-1].
returns: ok | {error, ledc_error_code()}
LEDC set duty.
set_fade_with_step/5
set_fade_with_step(SpeedMode::speed_mode(), Channel::channel(), TargetDuty::non_neg_integer(), Scale::non_neg_integer(), CycleNum::non_neg_integer()) -> ok | {error, ledc_error_code()}
SpeedMode
: Select the LEDC channel group with specified speed mode.
Note that not all targets support high speed mode.Channel
: LEDC channel index (0-7).TargetDuty
: Target duty of fading. (0..(2^duty_resolution)-1)Scale
: Controls the increase or decrease step scale.CycleNum
: increase or decrease the duty every cycle_num cycles
returns: ok | {error, ledc_error_code()}
Set LEDC fade function
Note. Call ledc:fade_func_install() once before calling this function. Call ledc:fade_start() after this to start fading.
set_fade_with_time/4
set_fade_with_time(SpeedMode::speed_mode(), Channel::channel(), TargetDuty::non_neg_integer(), MaxFadeTimeMs::non_neg_integer()) -> ok | {error, ledc_error_code()}
SpeedMode
: Select the LEDC channel group with specified speed mode.
Note that not all targets support high speed mode.Channel
: LEDC channel index (0-7).TargetDuty
: Target duty of fading. (0..(2^duty_resolution)-1)MaxFadeTimeMs
: The maximum time of the fading (ms).
returns: ok | {error, ledc_error_code()}
Set LEDC fade function, with a limited time.
Note. Call ledc:fade_func_install() once before calling this function. Call ledc:fade_start() after this to start fading.
set_freq/3
set_freq(SpeedMode::speed_mode(), TimerNum::timer_num(), FreqHz::non_neg_integer()) -> ok | {error, ledc_error_code()}
SpeedMode
: Select the LEDC channel group with specified speed mode.TimerNum
: LEDC timer index (0-3).FreqHz
: Set the LEDC frequency.
returns: ok | {error, ledc_error_code()}
LEDC set channel frequency (Hz)
stop/3
stop(SpeedMode::speed_mode(), Channel::channel(), IdleLevel::non_neg_integer()) -> ok | {error, ledc_error_code()}
SpeedMode
: Select the LEDC channel group with specified speed mode.
Note that not all targets support high speed mode.Channel
: LEDC channel index (0-7).IdleLevel
: Set output idle level after LEDC stops.
returns: ok | {error, ledc_error_code()}
LEDC stop. Disable LEDC output, and set idle level.
timer_config/1
timer_config(Config::timer_config()) -> ok | {error, ledc_error_code()}
Config
: timer configuration
returns: ok | {error, Reason}
LEDC timer configuration.
Configure LEDC timer with the given source timer/frequency(Hz)/duty_resolution.
update_duty/2
update_duty(SpeedMode::speed_mode(), Channel::channel()) -> ok | {error, ledc_error_code()}
SpeedMode
: Select the LEDC channel group with specified speed mode.
Note that not all targets support high speed mode.Channel
: LEDC channel index (0-7).
returns: ok | {error, ledc_error_code()}
LEDC update channel parameters.