ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
pca9685_output.h
Go to the documentation of this file.
1#pragma once
2
6
7namespace esphome::pca9685 {
8
9enum class PhaseBalancer {
10 NONE = 0x00,
11 LINEAR = 0x01,
12};
13
15inline constexpr uint8_t PCA9685_MODE_INVERTED = 0x10;
17inline constexpr uint8_t PCA9685_MODE_OUTPUT_ONACK = 0x08;
19inline constexpr uint8_t PCA9685_MODE_OUTPUT_TOTEM_POLE = 0x04;
21inline constexpr uint8_t PCA9685_MODE_OUTNE_HIGHZ = 0x02;
23inline constexpr uint8_t PCA9685_MODE_OUTNE_LOW = 0x01;
24
25class PCA9685Output;
26
28 public:
29 void set_channel(uint8_t channel) { channel_ = channel; }
30 void set_parent(PCA9685Output *parent) { parent_ = parent; }
31
32 protected:
33 friend class PCA9685Output;
34
35 void write_state(float state) override;
36
37 uint8_t channel_;
39};
40
42class PCA9685Output : public Component, public i2c::I2CDevice {
43 public:
45
46 void register_channel(PCA9685Channel *channel);
47
48 void setup() override;
49 void dump_config() override;
50 float get_setup_priority() const override { return setup_priority::HARDWARE; }
51 void loop() override;
52 void set_extclk(bool extclk) { this->extclk_ = extclk; }
54 void set_phase_balancer(PhaseBalancer balancer) { this->balancer_ = balancer; }
55
56 protected:
58
59 void set_channel_value_(uint8_t channel, uint16_t value) {
60 if (this->pwm_amounts_[channel] != value)
61 this->update_ = true;
62 this->pwm_amounts_[channel] = value;
63 }
64
66 uint8_t mode_;
67 bool extclk_ = false;
69
70 uint8_t min_channel_{0xFF};
71 uint8_t max_channel_{0x00};
72 uint16_t pwm_amounts_[16] = {
73 0,
74 };
75 bool update_{true};
76};
77
78} // namespace esphome::pca9685
BedjetMode mode
BedJet operating mode.
uint16_le_t frequency
Definition bl0942.h:6
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:132
Base class for all output components that can output a variable level, like PWM.
void write_state(float state) override
void set_parent(PCA9685Output *parent)
void set_channel(uint8_t channel)
PCA9685 float output component.
PCA9685Output(uint8_t mode=PCA9685_MODE_OUTPUT_ONACK|PCA9685_MODE_OUTPUT_TOTEM_POLE)
void set_channel_value_(uint8_t channel, uint16_t value)
void set_frequency(float frequency)
void register_channel(PCA9685Channel *channel)
float get_setup_priority() const override
void set_phase_balancer(PhaseBalancer balancer)
bool state
Definition fan.h:2
constexpr uint8_t PCA9685_MODE_INVERTED
Inverts polarity of channel output signal.
constexpr uint8_t PCA9685_MODE_OUTPUT_TOTEM_POLE
Use a totem-pole (push-pull) style output rather than an open-drain structure.
constexpr uint8_t PCA9685_MODE_OUTNE_LOW
Similarly, sets channel output to high if in totem-pole mode, otherwise.
constexpr uint8_t PCA9685_MODE_OUTNE_HIGHZ
For active low output enable, sets channel output to high-impedance state.
constexpr uint8_t PCA9685_MODE_OUTPUT_ONACK
Channel update happens upon ACK (post-set) rather than on STOP (endTransmission)
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.h:41