ESPHome  2024.12.2
libretiny_pwm.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
7 
8 #ifdef USE_LIBRETINY
9 
10 namespace esphome {
11 namespace libretiny_pwm {
12 
13 class LibreTinyPWM : public output::FloatOutput, public Component {
14  public:
15  explicit LibreTinyPWM(InternalGPIOPin *pin) : pin_(pin) {}
16 
17  void set_frequency(float frequency) { this->frequency_ = frequency; }
19  void update_frequency(float frequency) override;
20 
22  void setup() override;
23  void dump_config() override;
25  float get_setup_priority() const override { return setup_priority::HARDWARE; }
26 
28  void write_state(float state) override;
29 
30  protected:
32  uint8_t bit_depth_{10};
33  float frequency_{};
34  float duty_{0.0f};
35  bool initialized_ = false;
36 };
37 
38 template<typename... Ts> class SetFrequencyAction : public Action<Ts...> {
39  public:
40  SetFrequencyAction(LibreTinyPWM *parent) : parent_(parent) {}
41  TEMPLATABLE_VALUE(float, frequency);
42 
43  void play(Ts... x) {
44  float freq = this->frequency_.value(x...);
45  this->parent_->update_frequency(freq);
46  }
47 
48  protected:
50 };
51 
52 } // namespace libretiny_pwm
53 } // namespace esphome
54 
55 #endif
void setup() override
Setup LibreTinyPWM.
float get_setup_priority() const override
HARDWARE setup priority.
Definition: libretiny_pwm.h:25
LibreTinyPWM(InternalGPIOPin *pin)
Definition: libretiny_pwm.h:15
Base class for all output components that can output a variable level, like PWM.
Definition: float_output.h:31
uint16_t x
Definition: tt21100.cpp:17
void update_frequency(float frequency) override
Dynamically change frequency at runtime.
uint16_le_t frequency
Definition: bl0942.h:72
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition: component.cpp:18
void write_state(float state) override
Override FloatOutput&#39;s write_state.
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_frequency(float frequency)
Definition: libretiny_pwm.h:17
bool state
Definition: fan.h:34