ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
pca9554.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
7
8namespace esphome {
9namespace pca9554 {
10
12 public i2c::I2CDevice,
13 public gpio_expander::CachedGpioExpander<uint16_t, 16> {
14 public:
15 PCA9554Component() = 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 void set_pin_count(size_t pin_count) { this->pin_count_ = pin_count; }
29
30 protected:
31 static void IRAM_ATTR gpio_intr(PCA9554Component *arg);
32
33 bool read_inputs_();
34 bool write_register_(uint8_t reg, uint16_t value);
35
36 // Virtual methods from CachedGpioExpander
37 bool digital_read_hw(uint8_t pin) override;
38 bool digital_read_cache(uint8_t pin) override;
39 void digital_write_hw(uint8_t pin, bool value) override;
40
42 size_t pin_count_{8};
44 size_t reg_width_{1};
46 uint16_t config_mask_{0x00};
48 uint16_t output_mask_{0x00};
50 uint16_t input_mask_{0x00};
54};
55
57class PCA9554GPIOPin : public GPIOPin {
58 public:
59 void setup() override;
60 void pin_mode(gpio::Flags flags) override;
61 bool digital_read() override;
62 void digital_write(bool value) override;
63 size_t dump_summary(char *buffer, size_t len) const override;
64
65 void set_parent(PCA9554Component *parent) { parent_ = parent; }
66 void set_pin(uint8_t pin) { pin_ = pin; }
67 void set_inverted(bool inverted) { inverted_ = inverted; }
69
70 gpio::Flags get_flags() const override { return this->flags_; }
71
72 protected:
74 uint8_t pin_;
77};
78
79} // namespace pca9554
80} // 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
float get_setup_priority() const override
Definition pca9554.cpp:143
size_t pin_count_
number of bits the expander has
Definition pca9554.h:42
bool digital_read_cache(uint8_t pin) override
Definition pca9554.cpp:76
void set_interrupt_pin(InternalGPIOPin *pin)
Definition pca9554.h:28
InternalGPIOPin * interrupt_pin_
Definition pca9554.h:53
bool write_register_(uint8_t reg, uint16_t value)
Definition pca9554.cpp:128
void set_pin_count(size_t pin_count)
Definition pca9554.h:27
static void IRAM_ATTR gpio_intr(PCA9554Component *arg)
Definition pca9554.cpp:49
uint16_t output_mask_
The mask to write as output state - 1 means HIGH, 0 means LOW.
Definition pca9554.h:48
size_t reg_width_
width of registers
Definition pca9554.h:44
void digital_write_hw(uint8_t pin, bool value) override
Definition pca9554.cpp:81
bool digital_read_hw(uint8_t pin) override
Definition pca9554.cpp:71
uint16_t input_mask_
The state of the actual input pin states - 1 means HIGH, 0 means LOW.
Definition pca9554.h:50
void pin_mode(uint8_t pin, gpio::Flags flags)
Helper function to set the pin mode of a pin.
Definition pca9554.cpp:90
uint16_t config_mask_
Mask for the pin config - 1 means OUTPUT, 0 means INPUT.
Definition pca9554.h:46
void setup() override
Check i2c availability and setup masks.
Definition pca9554.cpp:15
esphome::i2c::ErrorCode last_error_
Storage for last I2C error seen.
Definition pca9554.h:52
Helper class to expose a PCA9554 pin as an internal input GPIO pin.
Definition pca9554.h:57
gpio::Flags get_flags() const override
Definition pca9554.h:70
void set_pin(uint8_t pin)
Definition pca9554.h:66
void pin_mode(gpio::Flags flags) override
Definition pca9554.cpp:146
PCA9554Component * parent_
Definition pca9554.h:73
void set_parent(PCA9554Component *parent)
Definition pca9554.h:65
void set_inverted(bool inverted)
Definition pca9554.h:67
void set_flags(gpio::Flags flags)
Definition pca9554.h:68
void digital_write(bool value) override
Definition pca9554.cpp:148
size_t dump_summary(char *buffer, size_t len) const override
Definition pca9554.cpp:149
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