Skip to main content

ledc_set_fade_with_time

Function ledc_set_fade_with_time 

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

@brief 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 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.

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