mirror of
https://github.com/esphome/esphome.git
synced 2024-12-23 22:14:54 +01:00
rp2040_pwm frequency is per pair of pins (#4061)
This commit is contained in:
parent
2bfaf9dce3
commit
7623f63846
2 changed files with 4 additions and 5 deletions
|
@ -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);
|
||||
|
|
|
@ -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...> {
|
||||
|
|
Loading…
Reference in a new issue