ESPHome 2025.10.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 float get_loop_priority() const override;
27
28 void dump_config() override;
29
30 void set_pin_count(size_t pin_count) { this->pin_count_ = pin_count; }
31
32 protected:
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};
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 std::string dump_summary() 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 pca9554
79} // 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
float get_setup_priority() const override
Definition pca9554.cpp:123
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: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:30
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:66
bool digital_read_hw(uint8_t pin) override
Definition pca9554.cpp:56
float get_loop_priority() const override
Definition pca9554.cpp:126
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:75
uint16_t config_mask_
Mask for the pin config - 1 means OUTPUT, 0 means INPUT.
Definition pca9554.h:46
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:52
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:129
std::string dump_summary() const override
Definition pca9554.cpp:132
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:131
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