9#include <core_esp8266_waveform.h>
12namespace esp8266_pwm {
14static const char *
const TAG =
"esp8266_pwm";
17 ESP_LOGCONFIG(TAG,
"Setting up ESP8266 PWM Output...");
22 ESP_LOGCONFIG(TAG,
"ESP8266 PWM:");
23 LOG_PIN(
" Pin: ", this->
pin_);
24 ESP_LOGCONFIG(TAG,
" Frequency: %.1f Hz", this->
frequency_);
25 LOG_FLOAT_OUTPUT(
this);
35 auto total_time_us =
static_cast<uint32_t
>(roundf(1e6f / this->
frequency_));
36 auto duty_on =
static_cast<uint32_t
>(roundf(total_time_us *
state));
37 uint32_t duty_off = total_time_us - duty_on;
42 if (this->
pin_->
digital_read() && 50 <= this->frequency_ && this->frequency_ <= 300) {
47 }
else if (duty_off == 0) {
51 startWaveform(this->
pin_->
get_pin(), duty_on, duty_off, 0);
virtual void digital_write(bool value)=0
virtual bool digital_read()=0
virtual uint8_t get_pin() const =0
virtual bool is_inverted() const =0
void dump_config() override
float last_output_
Cache last output level for dynamic frequency updating.
void write_state(float state) override
void setup() override
Initialize pin.
virtual void turn_off()
Disable this binary output.
Providing packet encoding functions for exchanging data with a remote host.
void IRAM_ATTR HOT delay(uint32_t ms)