mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 02:37:19 +02:00
ledc: Simplify the procedure to perform a one-time duty update
Avoid adding one extra fade cycle when performing a one-time duty update.
Add some notes to ledc_get_duty and ledc_update_duty APIs, so that users
are aware of when the new duty will be effective.
Closes https://github.com/espressif/esp-idf/issues/7288
(cherry picked from commit e175086226
)
This commit is contained in:
@ -61,6 +61,7 @@ esp_err_t ledc_timer_config(const ledc_timer_config_t* timer_conf);
|
||||
* @brief LEDC update channel parameters
|
||||
* @note Call this function to activate the LEDC updated parameters.
|
||||
* After ledc_set_duty, we need to call this function to update the settings.
|
||||
* And the new LEDC parameters don't take effect until the next PWM cycle.
|
||||
* @note ledc_set_duty, ledc_set_duty_with_hpoint and ledc_update_duty 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_duty_and_update
|
||||
@ -178,6 +179,9 @@ esp_err_t ledc_set_duty(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t
|
||||
|
||||
/**
|
||||
* @brief LEDC get duty
|
||||
* This function returns the duty at the present PWM cycle.
|
||||
* You shouldn't expect the function to return the new duty in the same cycle of calling ledc_update_duty,
|
||||
* because duty update doesn't take effect until the next cycle.
|
||||
*
|
||||
* @param speed_mode Select the LEDC speed_mode, high-speed mode and low-speed mode
|
||||
* @param channel LEDC channel (0-7), select from ledc_channel_t
|
||||
|
@ -472,8 +472,8 @@ esp_err_t ledc_set_duty_with_hpoint(ledc_mode_t speed_mode, ledc_channel_t chann
|
||||
hpoint, //uint32_t hpoint_val,
|
||||
duty, //uint32_t duty_val,
|
||||
1, //uint32_t increase,
|
||||
1, //uint32_t duty_num,
|
||||
1, //uint32_t duty_cycle,
|
||||
0, //uint32_t duty_num,
|
||||
0, //uint32_t duty_cycle,
|
||||
0 //uint32_t duty_scale
|
||||
);
|
||||
_ledc_fade_hw_release(speed_mode, channel);
|
||||
@ -492,8 +492,8 @@ esp_err_t ledc_set_duty(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t
|
||||
LEDC_VAL_NO_CHANGE,
|
||||
duty, //uint32_t duty_val,
|
||||
1, //uint32_t increase,
|
||||
1, //uint32_t duty_num,
|
||||
1, //uint32_t duty_cycle,
|
||||
0, //uint32_t duty_num,
|
||||
0, //uint32_t duty_cycle,
|
||||
0 //uint32_t duty_scale
|
||||
);
|
||||
_ledc_fade_hw_release(speed_mode, channel);
|
||||
@ -842,12 +842,13 @@ esp_err_t ledc_set_duty_and_update(ledc_mode_t speed_mode, ledc_channel_t channe
|
||||
LEDC_ARG_CHECK(speed_mode < LEDC_SPEED_MODE_MAX, "speed_mode");
|
||||
LEDC_ARG_CHECK(channel < LEDC_CHANNEL_MAX, "channel");
|
||||
LEDC_ARG_CHECK(duty <= ledc_get_max_duty(speed_mode, channel), "target_duty");
|
||||
LEDC_ARG_CHECK(hpoint <= LEDC_HPOINT_VAL_MAX, "hpoint");
|
||||
LEDC_CHECK(p_ledc_obj[speed_mode] != NULL, LEDC_NOT_INIT, ESP_ERR_INVALID_STATE);
|
||||
LEDC_CHECK(ledc_fade_channel_init_check(speed_mode, channel) == ESP_OK , LEDC_FADE_INIT_ERROR_STR, ESP_FAIL);
|
||||
_ledc_op_lock_acquire(speed_mode, channel);
|
||||
_ledc_fade_hw_acquire(speed_mode, channel);
|
||||
_ledc_set_fade_with_step(speed_mode, channel, duty, 0, 1);
|
||||
_ledc_fade_start(speed_mode, channel, LEDC_FADE_WAIT_DONE);
|
||||
ledc_duty_config(speed_mode, channel, hpoint, duty, 1, 0, 0, 0);
|
||||
ledc_update_duty(speed_mode, channel);
|
||||
_ledc_fade_hw_release(speed_mode, channel);
|
||||
_ledc_op_lock_release(speed_mode, channel);
|
||||
return ESP_OK;
|
||||
|
Reference in New Issue
Block a user