[ledc] Tweak fix in #6997 (#7336)

This commit is contained in:
Keith Burzinski 2024-08-24 02:32:08 -05:00 committed by GitHub
parent 43f8f2fd2e
commit a01fea54a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,6 +8,8 @@
#endif #endif
#include <driver/ledc.h> #include <driver/ledc.h>
#include <cinttypes>
#define CLOCK_FREQUENCY 80e6f #define CLOCK_FREQUENCY 80e6f
#ifdef USE_ARDUINO #ifdef USE_ARDUINO
@ -120,13 +122,17 @@ void LEDCOutput::write_state(float state) {
ledcWrite(this->channel_, duty); ledcWrite(this->channel_, duty);
#endif #endif
#ifdef USE_ESP_IDF #ifdef USE_ESP_IDF
#if !defined(USE_ESP32_VARIANT_ESP32C3) || (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0))
// ensure that 100% on is not 99.975% on // ensure that 100% on is not 99.975% on
// note: on the C3, this tweak will result in the outputs turning off at 100%, so it has been omitted
if ((duty == max_duty) && (max_duty != 1)) { if ((duty == max_duty) && (max_duty != 1)) {
duty = max_duty + 1; duty = max_duty + 1;
} }
#endif
auto speed_mode = get_speed_mode(channel_); auto speed_mode = get_speed_mode(channel_);
auto chan_num = static_cast<ledc_channel_t>(channel_ % 8); auto chan_num = static_cast<ledc_channel_t>(channel_ % 8);
int hpoint = ledc_angle_to_htop(this->phase_angle_, this->bit_depth_); int hpoint = ledc_angle_to_htop(this->phase_angle_, this->bit_depth_);
ESP_LOGV(TAG, "Setting duty: %" PRIu32 " on channel %u", duty, this->channel_);
ledc_set_duty_with_hpoint(speed_mode, chan_num, duty, hpoint); ledc_set_duty_with_hpoint(speed_mode, chan_num, duty, hpoint);
ledc_update_duty(speed_mode, chan_num); ledc_update_duty(speed_mode, chan_num);
#endif #endif