ESPHome 2026.3.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;
20 void loop() override;
22 void pin_mode(uint8_t pin, gpio::Flags flags);
23
24 float get_setup_priority() const override;
25
26#ifdef USE_LOOP_PRIORITY
27 float get_loop_priority() const override;
28#endif
29
30 void dump_config() override;
31
32 void set_pin_count(size_t pin_count) { this->pin_count_ = pin_count; }
33
34 protected:
35 bool read_inputs_();
36 bool write_register_(uint8_t reg, uint16_t value);
37
38 // Virtual methods from CachedGpioExpander
39 bool digital_read_hw(uint8_t pin) override;
40 bool digital_read_cache(uint8_t pin) override;
41 void digital_write_hw(uint8_t pin, bool value) override;
42
44 size_t pin_count_{8};
46 size_t reg_width_{1};
48 uint16_t config_mask_{0x00};
50 uint16_t output_mask_{0x00};
52 uint16_t input_mask_{0x00};
55};
56
58class PCA9554GPIOPin : public GPIOPin {
59 public:
60 void setup() override;
61 void pin_mode(gpio::Flags flags) override;
62 bool digital_read() override;
63 void digital_write(bool value) override;
64 size_t dump_summary(char *buffer, size_t len) const override;
65
66 void set_parent(PCA9554Component *parent) { parent_ = parent; }
67 void set_pin(uint8_t pin) { pin_ = pin; }
68 void set_inverted(bool inverted) { inverted_ = inverted; }
70
71 gpio::Flags get_flags() const override { return this->flags_; }
72
73 protected:
75 uint8_t pin_;
78};
79
80} // namespace pca9554
81} // 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:123
size_t pin_count_
number of bits the expander has
Definition pca9554.h:44
bool digital_read_cache(uint8_t pin) override
Definition pca9554.cpp:61
bool write_register_(uint8_t reg, uint16_t value)
Definition pca9554.cpp:108
void set_pin_count(size_t pin_count)
Definition pca9554.h:32
uint16_t output_mask_
The mask to write as output state - 1 means HIGH, 0 means LOW.
Definition pca9554.h:50
size_t reg_width_
width of registers
Definition pca9554.h:46
void digital_write_hw(uint8_t pin, bool value) override
Definition pca9554.cpp:66
bool digital_read_hw(uint8_t pin) override
Definition pca9554.cpp:56
float get_loop_priority() const override
Definition pca9554.cpp:127
uint16_t input_mask_
The state of the actual input pin states - 1 means HIGH, 0 means LOW.
Definition pca9554.h:52
void pin_mode(uint8_t pin, gpio::Flags flags)
Helper function to set the pin mode of a pin.
Definition pca9554.cpp:75
uint16_t config_mask_
Mask for the pin config - 1 means OUTPUT, 0 means INPUT.
Definition pca9554.h:48
void loop() override
Invalidate cache at start of each loop.
Definition pca9554.cpp:39
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:54
Helper class to expose a PCA9554 pin as an internal input GPIO pin.
Definition pca9554.h:58
gpio::Flags get_flags() const override
Definition pca9554.h:71
void set_pin(uint8_t pin)
Definition pca9554.h:67
void pin_mode(gpio::Flags flags) override
Definition pca9554.cpp:131
PCA9554Component * parent_
Definition pca9554.h:74
void set_parent(PCA9554Component *parent)
Definition pca9554.h:66
void set_inverted(bool inverted)
Definition pca9554.h:68
void set_flags(gpio::Flags flags)
Definition pca9554.h:69
void digital_write(bool value) override
Definition pca9554.cpp:133
size_t dump_summary(char *buffer, size_t len) const override
Definition pca9554.cpp:134
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:817