ESPHome 2025.9.0-dev
|
A class to cache the read state of a GPIO expander. More...
#include <cached_gpio.h>
Public Member Functions | |
bool | digital_read (T pin) |
Read the state of the given pin. | |
void | digital_write (T pin, bool value) |
Protected Member Functions | |
virtual bool | digital_read_hw (T pin)=0 |
Call component low level function to read GPIO state from device. | |
virtual bool | digital_read_cache (T pin)=0 |
Call component read function from internal cache. | |
virtual void | digital_write_hw (T pin, bool value)=0 |
Call component low level function to write GPIO state to device. | |
void | reset_pin_cache_ () |
Invalidate cache. This function should be called in component loop(). | |
Protected Attributes | |
T | read_cache_valid_ [BANKS] {0} |
Static Protected Attributes | |
static constexpr uint8_t | BITS_PER_BYTE = 8 |
static constexpr uint8_t | BANK_SIZE = sizeof(T) * BITS_PER_BYTE |
static constexpr size_t | BANKS = N / BANK_SIZE |
static constexpr size_t | CACHE_SIZE_BYTES = BANKS * sizeof(T) |
A class to cache the read state of a GPIO expander.
This class caches reads between GPIO Pins which are on the same bank. This means that for reading whole Port (ex. 8 pins) component needs only one I2C/SPI read per main loop call. It assumes, that one bit in byte identifies one GPIO pin Template parameters: T - Type which represents internal register. Could be uint8_t or uint16_t. Adjust to match size of your internal GPIO bank register. N - Number of pins
Definition at line 19 of file cached_gpio.h.
|
inline |
Read the state of the given pin.
This will invalidate the cache for the given pin number.
pin | Pin number to read |
Definition at line 24 of file cached_gpio.h.
|
protectedpure virtual |
Call component read function from internal cache.
Implemented in esphome::mcp23x08_base::MCP23X08Base, esphome::mcp23x17_base::MCP23X17Base, esphome::pi4ioe5v6408::PI4IOE5V6408Component, and esphome::tca9555::TCA9555Component.
|
protectedpure virtual |
Call component low level function to read GPIO state from device.
Implemented in esphome::mcp23x08_base::MCP23X08Base, esphome::mcp23x17_base::MCP23X17Base, esphome::pi4ioe5v6408::PI4IOE5V6408Component, and esphome::tca9555::TCA9555Component.
|
inline |
Definition at line 41 of file cached_gpio.h.
|
protectedpure virtual |
Call component low level function to write GPIO state to device.
Implemented in esphome::mcp23x08_base::MCP23X08Base, esphome::mcp23x17_base::MCP23X17Base, esphome::pi4ioe5v6408::PI4IOE5V6408Component, and esphome::tca9555::TCA9555Component.
|
inlineprotected |
Invalidate cache. This function should be called in component loop().
Definition at line 52 of file cached_gpio.h.
|
staticconstexprprotected |
Definition at line 55 of file cached_gpio.h.
|
staticconstexprprotected |
Definition at line 56 of file cached_gpio.h.
|
staticconstexprprotected |
Definition at line 54 of file cached_gpio.h.
|
staticconstexprprotected |
Definition at line 57 of file cached_gpio.h.
|
protected |
Definition at line 59 of file cached_gpio.h.