ESPHome 2026.8.0b4
Loading...
Searching...
No Matches
zephyr_pwm.cpp
Go to the documentation of this file.
1#ifdef USE_ZEPHYR
2
3#include "zephyr_pwm.h"
4
5#include <zephyr/drivers/pwm.h>
6
8
9static const char *const TAG = "zephyr_pwm";
10
12 if (!device_is_ready(this->device_)) {
13 ESP_LOGE(TAG, "PWM is not ready.");
14 this->mark_failed();
15 return;
16 }
17}
18
20 ESP_LOGCONFIG(TAG,
21 "Zephyr PWM:\n"
22 " Channel: %u\n"
23 " Period: %u ns",
24 this->channel_, this->period_ns_);
25 LOG_FLOAT_OUTPUT(this);
26}
28 uint32_t pulse_width_ns = state * this->period_ns_;
29 pwm_flags_t flags = this->pin_inverted_ ? PWM_POLARITY_INVERTED : PWM_POLARITY_NORMAL;
30 int err = pwm_set(this->device_, this->channel_, this->period_ns_, pulse_width_ns, flags);
31 if (err != 0) {
32 ESP_LOGE(TAG, "Failed to set PWM output: channel=%u, period=%u ns, pulse_width=%u ns, error=%d", this->channel_,
33 this->period_ns_, pulse_width_ns, err);
34 }
35}
36
37} // namespace esphome::zephyr_pwm
38
39#endif // USE_ZEPHYR
void mark_failed()
Mark this component as failed.
void write_state(float state) override
uint16_t flags
bool state
Definition fan.h:2
static void uint32_t