rp2040_pwm frequency is per pair of pins (#4061)

This commit is contained in:
Jesse Hills 2022-11-22 21:12:33 +13:00 committed by GitHub
parent c1f696c32a
commit 7258a82875
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 5 deletions

View File

@ -42,9 +42,9 @@ void HOT RP2040PWM::write_state(float state) {
state = 1.0f - state;
}
if (frequency_changed_) {
if (this->frequency_changed_) {
this->setup_pwm_();
frequency_changed_ = false;
this->frequency_changed_ = false;
}
gpio_set_function(this->pin_->get_pin(), GPIO_FUNC_PWM);

View File

@ -10,8 +10,6 @@
namespace esphome {
namespace rp2040_pwm {
static bool frequency_changed_ = false;
class RP2040PWM : public output::FloatOutput, public Component {
public:
void set_pin(InternalGPIOPin *pin) { pin_ = pin; }
@ -19,7 +17,7 @@ class RP2040PWM : public output::FloatOutput, public Component {
/// Dynamically update frequency
void update_frequency(float frequency) override {
this->set_frequency(frequency);
frequency_changed_ = true;
this->frequency_changed_ = true;
this->write_state(this->last_output_);
}
@ -38,6 +36,7 @@ class RP2040PWM : public output::FloatOutput, public Component {
float frequency_{1000.0};
/// Cache last output level for dynamic frequency updating
float last_output_{0.0};
bool frequency_changed_{false};
};
template<typename... Ts> class SetFrequencyAction : public Action<Ts...> {