Skip to main content

ledc_set_fade_time_and_start

Function ledc_set_fade_time_and_start 

Source
pub unsafe extern "C" fn ledc_set_fade_time_and_start(
    speed_mode: ledc_mode_t,
    channel: ledc_channel_t,
    target_duty: u32,
    desired_fade_time_ms: u32,
    fade_mode: ledc_fade_mode_t,
) -> esp_err_t
Expand description

@brief A thread-safe API to set and start LEDC fade function, with a limited time.

@note Call ledc_fade_func_install() once, before calling this function. @note For ESP32, hardware does not support any duty change while a fade operation is running in progress on that channel. Other duty operations will have to wait until the fade operation has finished.

@param speed_mode Select the LEDC channel group with specified speed mode. Note that not all targets support high speed mode. @param channel LEDC channel index (0 - LEDC_CHANNEL_MAX-1), select from ledc_channel_t @param target_duty Target duty of fading [0, (2**duty_resolution)] @param desired_fade_time_ms The intended time of the fading ( ms ). Note that the actual time it takes to complete the fade could vary by a factor of up to 2x shorter or longer than the expected time due to internal rounding errors in calculations. Specifically: * The total number of cycles (total_cycle_num = desired_fade_time_ms * freq / 1000) * The difference in duty cycle (duty_delta = |target_duty - current_duty|) The fade may complete faster than expected if total_cycle_num larger than duty_delta. Conversely, it may take longer than expected if total_cycle_num is less than duty_delta. The closer the ratio of total_cycle_num/duty_delta (or its inverse) is to a whole number (the floor value), the more accurately the actual fade duration will match the intended time. If an exact fade time is expected, please consider to split the entire fade into several smaller linear fades. The split should make each fade step has a divisible total_cycle_num/duty_delta (or its inverse) ratio. @param fade_mode choose blocking or non-blocking mode

@return - ESP_OK Success - ESP_ERR_INVALID_ARG Parameter error - ESP_ERR_INVALID_STATE Channel not initialized - ESP_FAIL Fade function init error