ESPHome
2026.8.0b4
Loading...
Searching...
No Matches
esphome
components
zephyr_pwm
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
7
namespace
esphome::zephyr_pwm
{
8
9
static
const
char
*
const
TAG =
"zephyr_pwm"
;
10
11
void
ZephyrPWMChannel::setup
() {
12
if
(!device_is_ready(this->
device_
)) {
13
ESP_LOGE(TAG,
"PWM is not ready."
);
14
this->
mark_failed
();
15
return
;
16
}
17
}
18
19
void
ZephyrPWMChannel::dump_config
() {
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
}
27
void
HOT
ZephyrPWMChannel::write_state
(
float
state
) {
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
esphome::Component::mark_failed
void mark_failed()
Mark this component as failed.
Definition
component.cpp:203
esphome::zephyr_pwm::ZephyrPWMChannel::dump_config
void dump_config() override
Definition
zephyr_pwm.cpp:19
esphome::zephyr_pwm::ZephyrPWMChannel::channel_
uint8_t channel_
Definition
zephyr_pwm.h:25
esphome::zephyr_pwm::ZephyrPWMChannel::period_ns_
uint32_t period_ns_
Definition
zephyr_pwm.h:27
esphome::zephyr_pwm::ZephyrPWMChannel::device_
const struct device * device_
Definition
zephyr_pwm.h:24
esphome::zephyr_pwm::ZephyrPWMChannel::setup
void setup() override
Definition
zephyr_pwm.cpp:11
esphome::zephyr_pwm::ZephyrPWMChannel::pin_inverted_
bool pin_inverted_
Definition
zephyr_pwm.h:26
esphome::zephyr_pwm::ZephyrPWMChannel::write_state
void write_state(float state) override
Definition
zephyr_pwm.cpp:27
flags
uint16_t flags
Definition
dns_server_esp32_idf.cpp:1
state
bool state
Definition
fan.h:2
esphome::zephyr_pwm
Definition
zephyr_pwm.cpp:7
uint32_t
static void uint32_t
Definition
crash_handler.cpp:141
zephyr_pwm.h
Generated by
1.12.0