ESPHome 2025.5.0
Loading...
Searching...
No Matches
ledc_output.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
7
8#ifdef USE_ESP32
9
10namespace esphome {
11namespace ledc {
12
13// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
14extern uint8_t next_ledc_channel;
15
17 public:
18 explicit LEDCOutput(InternalGPIOPin *pin) : pin_(pin) { this->channel_ = next_ledc_channel++; }
19
20 void set_channel(uint8_t channel) { this->channel_ = channel; }
22 void set_phase_angle(float angle) { this->phase_angle_ = angle; }
24 void update_frequency(float frequency) override;
25
27 void setup() override;
28 void dump_config() override;
30 float get_setup_priority() const override { return setup_priority::HARDWARE; }
31
33 void write_state(float state) override;
34
35 protected:
37 uint8_t channel_{};
38 uint8_t bit_depth_{};
39 float phase_angle_{0.0f};
40 float frequency_{};
41 float duty_{0.0f};
42 bool initialized_ = false;
43};
44
45template<typename... Ts> class SetFrequencyAction : public Action<Ts...> {
46 public:
49
50 void play(Ts... x) {
51 float freq = this->frequency_.value(x...);
52 this->parent_->update_frequency(freq);
53 }
54
55 protected:
57};
58
59} // namespace ledc
60} // namespace esphome
61
62#endif
uint16_le_t frequency
Definition bl0942.h:6
void update_frequency(float frequency) override
Dynamically change frequency at runtime.
float get_setup_priority() const override
HARDWARE setup priority.
Definition ledc_output.h:30
void set_phase_angle(float angle)
Definition ledc_output.h:22
void set_frequency(float frequency)
Definition ledc_output.h:21
void setup() override
Setup LEDC.
void write_state(float state) override
Override FloatOutput's write_state.
LEDCOutput(InternalGPIOPin *pin)
Definition ledc_output.h:18
void set_channel(uint8_t channel)
Definition ledc_output.h:20
void dump_config() override
InternalGPIOPin * pin_
Definition ledc_output.h:36
TEMPLATABLE_VALUE(float, frequency)
SetFrequencyAction(LEDCOutput *parent)
Definition ledc_output.h:47
Base class for all output components that can output a variable level, like PWM.
bool state
Definition fan.h:0
uint8_t next_ledc_channel
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.cpp:18
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t x
Definition tt21100.cpp:5