ESPHome 2025.5.0
Loading...
Searching...
No Matches
pca9554.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
6
7namespace esphome {
8namespace pca9554 {
9
11 public:
12 PCA9554Component() = default;
13
15 void setup() override;
17 void loop() override;
19 bool digital_read(uint8_t pin);
21 void digital_write(uint8_t pin, bool value);
23 void pin_mode(uint8_t pin, gpio::Flags flags);
24
25 float get_setup_priority() const override;
26
27 float get_loop_priority() const override;
28
29 void dump_config() override;
30
31 void set_pin_count(size_t pin_count) { this->pin_count_ = pin_count; }
32
33 protected:
34 bool read_inputs_();
35
36 bool write_register_(uint8_t reg, uint16_t value);
37
39 size_t pin_count_{8};
41 size_t reg_width_{1};
43 uint16_t config_mask_{0x00};
45 uint16_t output_mask_{0x00};
47 uint16_t input_mask_{0x00};
49 uint16_t was_previously_read_ = {0x00};
52};
53
55class PCA9554GPIOPin : public GPIOPin {
56 public:
57 void setup() override;
58 void pin_mode(gpio::Flags flags) override;
59 bool digital_read() override;
60 void digital_write(bool value) override;
61 std::string dump_summary() const override;
62
63 void set_parent(PCA9554Component *parent) { parent_ = parent; }
64 void set_pin(uint8_t pin) { pin_ = pin; }
65 void set_inverted(bool inverted) { inverted_ = inverted; }
66 void set_flags(gpio::Flags flags) { flags_ = flags; }
67
68 gpio::Flags get_flags() const override { return this->flags_; }
69
70 protected:
72 uint8_t pin_;
75};
76
77} // namespace pca9554
78} // namespace esphome
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:127
size_t pin_count_
number of bits the expander has
Definition pca9554.h:39
bool write_register_(uint8_t reg, uint16_t value)
Definition pca9554.cpp:112
uint16_t was_previously_read_
Flags to check if read previously during this loop.
Definition pca9554.h:49
void set_pin_count(size_t pin_count)
Definition pca9554.h:31
void digital_write(uint8_t pin, bool value)
Helper function to write the value of a pin.
Definition pca9554.cpp:70
uint16_t output_mask_
The mask to write as output state - 1 means HIGH, 0 means LOW.
Definition pca9554.h:45
size_t reg_width_
width of registers
Definition pca9554.h:41
float get_loop_priority() const override
Definition pca9554.cpp:131
uint16_t input_mask_
The state of the actual input pin states - 1 means HIGH, 0 means LOW.
Definition pca9554.h:47
void pin_mode(uint8_t pin, gpio::Flags flags)
Helper function to set the pin mode of a pin.
Definition pca9554.cpp:79
uint16_t config_mask_
Mask for the pin config - 1 means OUTPUT, 0 means INPUT.
Definition pca9554.h:43
void loop() override
Poll for input changes periodically.
Definition pca9554.cpp:40
void setup() override
Check i2c availability and setup masks.
Definition pca9554.cpp:15
bool digital_read(uint8_t pin)
Helper function to read the value of a pin.
Definition pca9554.cpp:56
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:55
gpio::Flags get_flags() const override
Definition pca9554.h:68
void set_pin(uint8_t pin)
Definition pca9554.h:64
void pin_mode(gpio::Flags flags) override
Definition pca9554.cpp:134
std::string dump_summary() const override
Definition pca9554.cpp:137
PCA9554Component * parent_
Definition pca9554.h:71
void set_parent(PCA9554Component *parent)
Definition pca9554.h:63
void set_inverted(bool inverted)
Definition pca9554.h:65
void set_flags(gpio::Flags flags)
Definition pca9554.h:66
void digital_write(bool value) override
Definition pca9554.cpp:136
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition i2c_bus.h:11
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7