Chapter 2. API Reference
• scale: Controls the increase or decrease step scale.
• cycle_num: increase or decrease the duty every cycle_num cycles
esp_err_t ledc_set_fade_with_time(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t
target_duty, int max_fade_time_ms)
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.
Note ledc_set_fade_with_step, ledc_set_fade_with_time and ledc_fade_start are not thread-safe, do not call
these functions to control one LEDC channel in different tasks at the same time. A thread-safe version
of API is ledc_set_fade_step_and_start
Note If a fade operation is running in progress on that channel, the driver would not allow it to be stopped.
Other duty operations will have to wait until the fade operation has finished.
Return
• ESP_ERR_INVALID_ARG Parameter error
• ESP_OK Success
• ESP_ERR_INVALID_STATE Fade function not installed.
• ESP_FAIL Fade function init error
Parameters
• speed_mode: Select the LEDC channel group with specified speed mode. Note that not all targets
support high speed mode. ,
• channel: LEDC channel index (0 - LEDC_CHANNEL_MAX-1), select from ledc_channel_t
• target_duty: Target duty of fading [0, (2**duty_resolution) - 1]
• max_fade_time_ms: The maximum time of the fading ( ms ).
esp_err_t ledc_fade_func_install(int intr_alloc_flags)
Install LEDC fade function. This function will occupy interrupt of LEDC module.
Return
• ESP_OK Success
• ESP_ERR_INVALID_STATE Fade function already installed.
Parameters
• intr_alloc_flags: Flags used to allocate the interrupt. One or multiple (ORred)
ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info.
void ledc_fade_func_uninstall(void)
Uninstall LEDC fade function.
esp_err_t ledc_fade_start(ledc_mode_t speed_mode, ledc_channel_t channel, ledc_fade_mode_t
fade_mode)
Start LEDC fading.
Note Call ledc_fade_func_install() once before calling this function. Call this API right after
ledc_set_fade_with_time or ledc_set_fade_with_step before to start fading.
Note If a fade operation is running in progress on that channel, the driver would not allow it to be stopped.
Other duty operations will have to wait until the fade operation has finished.
Return
• ESP_OK Success
• ESP_ERR_INVALID_STATE Fade function not installed.
• ESP_ERR_INVALID_ARG Parameter error.
Parameters
• speed_mode: Select the LEDC channel group with specified speed mode. Note that not all targets
support high speed mode.
• channel: LEDC channel number
• fade_mode: Whether to block until fading done.
esp_err_t ledc_set_duty_and_update(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t
duty, uint32_t hpoint)
A thread-safe API to set duty for LEDC channel and return when duty updated.
Note If a fade operation is running in progress on that channel, the driver would not allow it to be stopped.
Other duty operations will have to wait until the fade operation has finished.
Espressif Systems 323
Submit Document Feedback
Release v4.4