mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 15:38:11 +01:00
Fix ledc can't find bit_depth (#786)
Fixes https://github.com/esphome/issues/issues/759
This commit is contained in:
parent
eca3685ea0
commit
31aa3c55ca
1 changed files with 3 additions and 3 deletions
|
@ -42,8 +42,8 @@ float ledc_min_frequency_for_bit_depth(uint8_t bit_depth) {
|
||||||
}
|
}
|
||||||
optional<uint8_t> ledc_bit_depth_for_frequency(float frequency) {
|
optional<uint8_t> ledc_bit_depth_for_frequency(float frequency) {
|
||||||
for (int i = 20; i >= 1; i--) {
|
for (int i = 20; i >= 1; i--) {
|
||||||
const float min_frequency = ledc_min_frequency_for_bit_depth(frequency);
|
const float min_frequency = ledc_min_frequency_for_bit_depth(i);
|
||||||
const float max_frequency = ledc_max_frequency_for_bit_depth(frequency);
|
const float max_frequency = ledc_max_frequency_for_bit_depth(i);
|
||||||
if (min_frequency <= frequency && frequency <= max_frequency)
|
if (min_frequency <= frequency && frequency <= max_frequency)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ void LEDCOutput::apply_frequency(float frequency) {
|
||||||
ESP_LOGW(TAG, "Frequency %f can't be achieved with any bit depth", frequency);
|
ESP_LOGW(TAG, "Frequency %f can't be achieved with any bit depth", frequency);
|
||||||
this->status_set_warning();
|
this->status_set_warning();
|
||||||
}
|
}
|
||||||
this->bit_depth_ = *bit_depth_opt;
|
this->bit_depth_ = bit_depth_opt.value_or(8);
|
||||||
this->frequency_ = frequency;
|
this->frequency_ = frequency;
|
||||||
ledcSetup(this->channel_, frequency, this->bit_depth_);
|
ledcSetup(this->channel_, frequency, this->bit_depth_);
|
||||||
// re-apply duty
|
// re-apply duty
|
||||||
|
|
Loading…
Reference in a new issue