ESPHome 2025.10.0-dev
Loading...
Searching...
No Matches
pca6416a.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
7
8namespace esphome {
9namespace pca6416a {
10
12 public i2c::I2CDevice,
13 public gpio_expander::CachedGpioExpander<uint8_t, 16> {
14 public:
15 PCA6416AComponent() = default;
16
18 void setup() override;
19 void loop() override;
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 // Virtual methods from CachedGpioExpander
29 bool digital_read_hw(uint8_t pin) override;
30 bool digital_read_cache(uint8_t pin) override;
31 void digital_write_hw(uint8_t pin, bool value) override;
32
33 bool read_register_(uint8_t reg, uint8_t *value);
34 bool write_register_(uint8_t reg, uint8_t value);
35 void update_register_(uint8_t pin, bool pin_value, uint8_t reg_addr);
36
38 uint8_t output_0_{0x00};
39 uint8_t output_1_{0x00};
41 uint16_t input_mask_{0x00};
45 bool has_pullup_{false};
46};
47
49class PCA6416AGPIOPin : public GPIOPin {
50 public:
51 void setup() override;
52 void pin_mode(gpio::Flags flags) override;
53 bool digital_read() override;
54 void digital_write(bool value) override;
55 std::string dump_summary() const override;
56
57 void set_parent(PCA6416AComponent *parent) { parent_ = parent; }
58 void set_pin(uint8_t pin) { pin_ = pin; }
59 void set_inverted(bool inverted) { inverted_ = inverted; }
61
62 gpio::Flags get_flags() const override { return this->flags_; }
63
64 protected:
66 uint8_t pin_;
69};
70
71} // namespace pca6416a
72} // namespace esphome
A class to cache the read state of a GPIO expander.
Definition cached_gpio.h:29
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:133
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition i2c.h:153
void digital_write_hw(uint8_t pin, bool value) override
Definition pca6416a.cpp:89
bool write_register_(uint8_t reg, uint8_t value)
Definition pca6416a.cpp:134
bool read_register_(uint8_t reg, uint8_t *value)
Definition pca6416a.cpp:117
esphome::i2c::ErrorCode last_error_
Storage for last I2C error seen.
Definition pca6416a.h:43
void update_register_(uint8_t pin, bool pin_value, uint8_t reg_addr)
Definition pca6416a.cpp:151
uint16_t input_mask_
Cache for input values (16-bit combined for both banks)
Definition pca6416a.h:41
bool has_pullup_
Only the PCAL6416A has pull-up resistors.
Definition pca6416a.h:45
void pin_mode(uint8_t pin, gpio::Flags flags)
Helper function to set the pin mode of a pin.
Definition pca6416a.cpp:94
void setup() override
Check i2c availability and setup masks.
Definition pca6416a.cpp:26
float get_setup_priority() const override
Definition pca6416a.cpp:177
bool digital_read_hw(uint8_t pin) override
Definition pca6416a.cpp:71
bool digital_read_cache(uint8_t pin) override
Definition pca6416a.cpp:87
uint8_t output_0_
The mask to write as output state - 1 means HIGH, 0 means LOW.
Definition pca6416a.h:38
Helper class to expose a PCA6416A pin as an internal input GPIO pin.
Definition pca6416a.h:49
gpio::Flags get_flags() const override
Definition pca6416a.h:62
void digital_write(bool value) override
Definition pca6416a.cpp:182
void set_flags(gpio::Flags flags)
Definition pca6416a.h:60
PCA6416AComponent * parent_
Definition pca6416a.h:65
void set_inverted(bool inverted)
Definition pca6416a.h:59
std::string dump_summary() const override
Definition pca6416a.cpp:183
void set_parent(PCA6416AComponent *parent)
Definition pca6416a.h:57
void pin_mode(gpio::Flags flags) override
Definition pca6416a.cpp:180
uint16_t flags
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition i2c_bus.h:31
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7