ESPHome  2024.11.0
pca6416a.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
6 
7 namespace esphome {
8 namespace pca6416a {
9 
10 class PCA6416AComponent : public Component, public i2c::I2CDevice {
11  public:
12  PCA6416AComponent() = default;
13 
15  void setup() override;
17  bool digital_read(uint8_t pin);
19  void digital_write(uint8_t pin, bool value);
21  void pin_mode(uint8_t pin, gpio::Flags flags);
22 
23  float get_setup_priority() const override;
24 
25  void dump_config() override;
26 
27  protected:
28  bool read_register_(uint8_t reg, uint8_t *value);
29  bool write_register_(uint8_t reg, uint8_t value);
30  void update_register_(uint8_t pin, bool pin_value, uint8_t reg_addr);
31 
33  uint8_t output_0_{0x00};
34  uint8_t output_1_{0x00};
38  bool has_pullup_{false};
39 };
40 
42 class PCA6416AGPIOPin : public GPIOPin {
43  public:
44  void setup() override;
45  void pin_mode(gpio::Flags flags) override;
46  bool digital_read() override;
47  void digital_write(bool value) override;
48  std::string dump_summary() const override;
49 
50  void set_parent(PCA6416AComponent *parent) { parent_ = parent; }
51  void set_pin(uint8_t pin) { pin_ = pin; }
52  void set_inverted(bool inverted) { inverted_ = inverted; }
53  void set_flags(gpio::Flags flags) { flags_ = flags; }
54 
55  protected:
57  uint8_t pin_;
58  bool inverted_;
60 };
61 
62 } // namespace pca6416a
63 } // namespace esphome
bool digital_read(uint8_t pin)
Helper function to read the value of a pin.
Definition: pca6416a.cpp:67
void set_flags(gpio::Flags flags)
Definition: pca6416a.h:53
void set_inverted(bool inverted)
Definition: pca6416a.h:52
bool write_register_(uint8_t reg, uint8_t value)
Definition: pca6416a.cpp:119
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition: i2c.h:149
esphome::i2c::ErrorCode last_error_
Storage for last I2C error seen.
Definition: pca6416a.h:36
void digital_write(uint8_t pin, bool value)
Helper function to write the value of a pin.
Definition: pca6416a.cpp:75
bool has_pullup_
Only the PCAL6416A has pull-up resistors.
Definition: pca6416a.h:38
void update_register_(uint8_t pin, bool pin_value, uint8_t reg_addr)
Definition: pca6416a.cpp:135
void pin_mode(uint8_t pin, gpio::Flags flags)
Helper function to set the pin mode of a pin.
Definition: pca6416a.cpp:80
void set_parent(PCA6416AComponent *parent)
Definition: pca6416a.h:50
bool read_register_(uint8_t reg, uint8_t *value)
Definition: pca6416a.cpp:103
void setup() override
Check i2c availability and setup masks.
Definition: pca6416a.cpp:26
const uint32_t flags
Definition: stm32flash.h:85
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
PCA6416AComponent * parent_
Definition: pca6416a.h:56
Helper class to expose a PCA6416A pin as an internal input GPIO pin.
Definition: pca6416a.h:42
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition: i2c_bus.h:11
float get_setup_priority() const override
Definition: pca6416a.cpp:161
uint8_t output_0_
The mask to write as output state - 1 means HIGH, 0 means LOW.
Definition: pca6416a.h:33
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133