ESPHome 2026.5.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
28
29 protected:
30 static void IRAM_ATTR gpio_intr(PCA6416AComponent *arg);
31 // Virtual methods from CachedGpioExpander
32 bool digital_read_hw(uint8_t pin) override;
33 bool digital_read_cache(uint8_t pin) override;
34 void digital_write_hw(uint8_t pin, bool value) override;
35
36 bool read_register_(uint8_t reg, uint8_t *value);
37 bool write_register_(uint8_t reg, uint8_t value);
38 void update_register_(uint8_t pin, bool pin_value, uint8_t reg_addr);
39
41 uint8_t output_0_{0x00};
42 uint8_t output_1_{0x00};
44 uint16_t input_mask_{0x00};
48 bool has_pullup_{false};
50};
51
53class PCA6416AGPIOPin : public GPIOPin {
54 public:
55 void setup() override;
56 void pin_mode(gpio::Flags flags) override;
57 bool digital_read() override;
58 void digital_write(bool value) override;
59 size_t dump_summary(char *buffer, size_t len) const override;
60
61 void set_parent(PCA6416AComponent *parent) { parent_ = parent; }
62 void set_pin(uint8_t pin) { pin_ = pin; }
63 void set_inverted(bool inverted) { inverted_ = inverted; }
65
66 gpio::Flags get_flags() const override { return this->flags_; }
67
68 protected:
70 uint8_t pin_;
73};
74
75} // namespace pca6416a
76} // 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:132
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition i2c.h:152
void digital_write_hw(uint8_t pin, bool value) override
Definition pca6416a.cpp:101
bool write_register_(uint8_t reg, uint8_t value)
Definition pca6416a.cpp:152
static void IRAM_ATTR gpio_intr(PCA6416AComponent *arg)
Definition pca6416a.cpp:61
bool read_register_(uint8_t reg, uint8_t *value)
Definition pca6416a.cpp:135
esphome::i2c::ErrorCode last_error_
Storage for last I2C error seen.
Definition pca6416a.h:46
void update_register_(uint8_t pin, bool pin_value, uint8_t reg_addr)
Definition pca6416a.cpp:169
uint16_t input_mask_
Cache for input values (16-bit combined for both banks)
Definition pca6416a.h:44
bool has_pullup_
Only the PCAL6416A has pull-up resistors.
Definition pca6416a.h:48
void set_interrupt_pin(InternalGPIOPin *pin)
Definition pca6416a.h:27
void pin_mode(uint8_t pin, gpio::Flags flags)
Helper function to set the pin mode of a pin.
Definition pca6416a.cpp:106
void setup() override
Check i2c availability and setup masks.
Definition pca6416a.cpp:26
float get_setup_priority() const override
Definition pca6416a.cpp:195
bool digital_read_hw(uint8_t pin) override
Definition pca6416a.cpp:83
bool digital_read_cache(uint8_t pin) override
Definition pca6416a.cpp:99
uint8_t output_0_
The mask to write as output state - 1 means HIGH, 0 means LOW.
Definition pca6416a.h:41
Helper class to expose a PCA6416A pin as an internal input GPIO pin.
Definition pca6416a.h:53
size_t dump_summary(char *buffer, size_t len) const override
Definition pca6416a.cpp:201
gpio::Flags get_flags() const override
Definition pca6416a.h:66
void digital_write(bool value) override
Definition pca6416a.cpp:200
void set_flags(gpio::Flags flags)
Definition pca6416a.h:64
PCA6416AComponent * parent_
Definition pca6416a.h:69
void set_inverted(bool inverted)
Definition pca6416a.h:63
void set_parent(PCA6416AComponent *parent)
Definition pca6416a.h:61
void pin_mode(gpio::Flags flags) override
Definition pca6416a.cpp:198
uint16_t flags
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition i2c_bus.h:12
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:1045