ESPHome 2026.6.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::pca9554 {
9
11 public i2c::I2CDevice,
12 public gpio_expander::CachedGpioExpander<uint16_t, 16> {
13 public:
14 PCA9554Component() = default;
15
17 void setup() override;
18 void loop() override;
20 void pin_mode(uint8_t pin, gpio::Flags flags);
21
22 float get_setup_priority() const override;
23
24 void dump_config() override;
25
26 void set_pin_count(size_t pin_count) { this->pin_count_ = pin_count; }
28
29 protected:
30 static void IRAM_ATTR gpio_intr(PCA9554Component *arg);
31
32 bool read_inputs_();
33 bool write_register_(uint8_t reg, uint16_t value);
34
35 // Virtual methods from CachedGpioExpander
36 bool digital_read_hw(uint8_t pin) override;
37 bool digital_read_cache(uint8_t pin) override;
38 void digital_write_hw(uint8_t pin, bool value) override;
39
41 size_t pin_count_{8};
43 size_t reg_width_{1};
45 uint16_t config_mask_{0x00};
47 uint16_t output_mask_{0x00};
49 uint16_t input_mask_{0x00};
53};
54
56class PCA9554GPIOPin : public GPIOPin {
57 public:
58 void setup() override;
59 void pin_mode(gpio::Flags flags) override;
60 bool digital_read() override;
61 void digital_write(bool value) override;
62 size_t dump_summary(char *buffer, size_t len) const override;
63
64 void set_parent(PCA9554Component *parent) { parent_ = parent; }
65 void set_pin(uint8_t pin) { pin_ = pin; }
66 void set_inverted(bool inverted) { inverted_ = inverted; }
68
69 gpio::Flags get_flags() const override { return this->flags_; }
70
71 protected:
73 uint8_t pin_;
76};
77
78} // namespace esphome::pca9554
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:144
size_t pin_count_
number of bits the expander has
Definition pca9554.h:41
bool digital_read_cache(uint8_t pin) override
Definition pca9554.cpp:77
void set_interrupt_pin(InternalGPIOPin *pin)
Definition pca9554.h:27
InternalGPIOPin * interrupt_pin_
Definition pca9554.h:52
bool write_register_(uint8_t reg, uint16_t value)
Definition pca9554.cpp:129
void set_pin_count(size_t pin_count)
Definition pca9554.h:26
static void IRAM_ATTR gpio_intr(PCA9554Component *arg)
Definition pca9554.cpp:48
uint16_t output_mask_
The mask to write as output state - 1 means HIGH, 0 means LOW.
Definition pca9554.h:47
size_t reg_width_
width of registers
Definition pca9554.h:43
void digital_write_hw(uint8_t pin, bool value) override
Definition pca9554.cpp:82
bool digital_read_hw(uint8_t pin) override
Definition pca9554.cpp:72
uint16_t input_mask_
The state of the actual input pin states - 1 means HIGH, 0 means LOW.
Definition pca9554.h:49
void pin_mode(uint8_t pin, gpio::Flags flags)
Helper function to set the pin mode of a pin.
Definition pca9554.cpp:91
uint16_t config_mask_
Mask for the pin config - 1 means OUTPUT, 0 means INPUT.
Definition pca9554.h:45
void setup() override
Check i2c availability and setup masks.
Definition pca9554.cpp:14
esphome::i2c::ErrorCode last_error_
Storage for last I2C error seen.
Definition pca9554.h:51
Helper class to expose a PCA9554 pin as an internal input GPIO pin.
Definition pca9554.h:56
gpio::Flags get_flags() const override
Definition pca9554.h:69
void set_pin(uint8_t pin)
Definition pca9554.h:65
void pin_mode(gpio::Flags flags) override
Definition pca9554.cpp:147
PCA9554Component * parent_
Definition pca9554.h:72
void set_parent(PCA9554Component *parent)
Definition pca9554.h:64
void set_inverted(bool inverted)
Definition pca9554.h:66
void set_flags(gpio::Flags flags)
Definition pca9554.h:67
void digital_write(bool value) override
Definition pca9554.cpp:149
size_t dump_summary(char *buffer, size_t len) const override
Definition pca9554.cpp:150
uint16_t flags
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition i2c_bus.h:12
const void size_t len
Definition hal.h:64