ESPHome  2021.10.2
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(float frequency, uint8_t mode = PCA9685_MODE_OUTPUT_ONACK | PCA9685_MODE_OUTPUT_TOTEM_POLE)
41  : frequency_(frequency), mode_(mode) {}
42 
43  void register_channel(PCA9685Channel *channel);
44 
45  void setup() override;
46  void dump_config() override;
47  float get_setup_priority() const override { return setup_priority::HARDWARE; }
48  void loop() override;
49 
50  protected:
52 
53  void set_channel_value_(uint8_t channel, uint16_t value) {
54  if (this->pwm_amounts_[channel] != value)
55  this->update_ = true;
56  this->pwm_amounts_[channel] = value;
57  }
58 
59  float frequency_;
60  uint8_t mode_;
61 
62  uint8_t min_channel_{0xFF};
63  uint8_t max_channel_{0x00};
64  uint16_t pwm_amounts_[16] = {
65  0,
66  };
67  bool update_{true};
68 };
69 
70 } // namespace pca9685
71 } // 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.
void set_channel_value_(uint8_t channel, uint16_t value)
PCA9685Output(float frequency, 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:17
ClimateMode mode
Definition: climate.h:534
Library based on https://github.com/miguelbalboa/rfid and adapted to ESPHome by . ...
Definition: a4988.cpp:4
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.
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.