ESPHome  2024.3.1
pca9685_output.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace pca9685 {
9 
11 extern const uint8_t PCA9685_MODE_INVERTED;
13 extern const uint8_t PCA9685_MODE_OUTPUT_ONACK;
15 extern const uint8_t PCA9685_MODE_OUTPUT_TOTEM_POLE;
17 extern const uint8_t PCA9685_MODE_OUTNE_HIGHZ;
19 extern const uint8_t PCA9685_MODE_OUTNE_LOW;
20 
21 class PCA9685Output;
22 
24  public:
25  void set_channel(uint8_t channel) { channel_ = channel; }
26  void set_parent(PCA9685Output *parent) { parent_ = parent; }
27 
28  protected:
29  friend class PCA9685Output;
30 
31  void write_state(float state) override;
32 
33  uint8_t channel_;
35 };
36 
38 class PCA9685Output : public Component, public i2c::I2CDevice {
39  public:
40  PCA9685Output(uint8_t mode = PCA9685_MODE_OUTPUT_ONACK | PCA9685_MODE_OUTPUT_TOTEM_POLE) : mode_(mode) {}
41 
42  void register_channel(PCA9685Channel *channel);
43 
44  void setup() override;
45  void dump_config() override;
46  float get_setup_priority() const override { return setup_priority::HARDWARE; }
47  void loop() override;
48  void set_extclk(bool extclk) { this->extclk_ = extclk; }
49  void set_frequency(float frequency) { this->frequency_ = frequency; }
50 
51  protected:
53 
54  void set_channel_value_(uint8_t channel, uint16_t value) {
55  if (this->pwm_amounts_[channel] != value)
56  this->update_ = true;
57  this->pwm_amounts_[channel] = value;
58  }
59 
60  float frequency_;
61  uint8_t mode_;
62  bool extclk_ = false;
63 
64  uint8_t min_channel_{0xFF};
65  uint8_t max_channel_{0x00};
66  uint16_t pwm_amounts_[16] = {
67  0,
68  };
69  bool update_{true};
70 };
71 
72 } // namespace pca9685
73 } // namespace esphome
void setup()
void loop()
const uint8_t PCA9685_MODE_OUTPUT_ONACK
Channel update happens upon ACK (post-set) rather than on STOP (endTransmission)
float get_setup_priority() const override
Base class for all output components that can output a variable level, like PWM.
Definition: float_output.h:31
const uint8_t PCA9685_MODE_INVERTED
Inverts polarity of channel output signal.
void set_parent(PCA9685Output *parent)
PCA9685 float output component.
BedjetMode mode
BedJet operating mode.
Definition: bedjet_codec.h:151
void set_channel_value_(uint8_t channel, uint16_t value)
void set_frequency(float frequency)
uint16_le_t frequency
Definition: bl0942.h:21
PCA9685Output(uint8_t mode=PCA9685_MODE_OUTPUT_ONACK|PCA9685_MODE_OUTPUT_TOTEM_POLE)
void write_state(float state) override
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition: component.cpp:18
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
const uint8_t PCA9685_MODE_OUTPUT_TOTEM_POLE
Use a totem-pole (push-pull) style output rather than an open-drain structure.
const uint8_t PCA9685_MODE_OUTNE_HIGHZ
For active low output enable, sets channel output to high-impedance state.
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133
bool state
Definition: fan.h:34
void set_channel(uint8_t channel)
const uint8_t PCA9685_MODE_OUTNE_LOW
Similarly, sets channel output to high if in totem-pole mode, otherwise.