|
ESPHome 2026.12.0-dev
|
A class to cache the read state of a GPIO expander. More...
#include <cached_gpio.h>
Public Member Functions | |
| void | digital_write (P pin, bool value) |
Protected Types | |
| using | bank_t = T |
| using | pin_t = P |
Protected Member Functions | |
| bool | cached_read_ (P pin, bool invalidate_on_read) |
| Read pin through the bank cache. | |
| virtual bool | digital_read_hw (P pin)=0 |
| Read GPIO bank from hardware into internal state. | |
| virtual bool | digital_read_cache (P pin)=0 |
| Get cached pin value from internal state. | |
| virtual void | digital_write_hw (P pin, bool value)=0 |
| Write GPIO state to hardware. | |
| 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 uint16_t | BITS_PER_BYTE = 8 |
| static constexpr uint16_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 bank register. Could be uint8_t or uint16_t. Choose based on how your I/O expander reads pins:
CachedGpioExpanderBase holds the cache; CachedGpioExpander adds the invalidate-on-read flag, and CachedGpioExpanderComponent takes it from the interrupt pin instead.
Definition at line 34 of file cached_gpio.h.
|
protected |
Definition at line 39 of file cached_gpio.h.
|
protected |
Definition at line 40 of file cached_gpio.h.
|
inlineprotected |
Read pin through the bank cache.
With invalidate_on_read the pin is read from hardware again next time; otherwise the bank stays cached until reset_pin_cache_().
Definition at line 44 of file cached_gpio.h.
|
protectedpure virtual |
Get cached pin value from internal state.
| pin | Pin number to read |
Implemented in esphome::gpio_expander::GpioExpanderInputs< CachedGpioExpanderBase< T, N > >, and esphome::gpio_expander::GpioExpanderInputs< gpio_expander::CachedGpioExpander< uint8_t, 8 > >.
|
protectedpure virtual |
Read GPIO bank from hardware into internal state.
| pin | Pin number (used to determine which bank to read) |
|
inline |
Definition at line 36 of file cached_gpio.h.
|
protectedpure virtual |
Write GPIO state to hardware.
| pin | Pin number to write |
| value | Pin state to write (true = HIGH, false = LOW) |
|
inlineprotected |
Invalidate cache. This function should be called in component loop().
Definition at line 82 of file cached_gpio.h.
|
staticconstexprprotected |
Definition at line 85 of file cached_gpio.h.
|
staticconstexprprotected |
Definition at line 86 of file cached_gpio.h.
|
staticconstexprprotected |
Definition at line 84 of file cached_gpio.h.
|
staticconstexprprotected |
Definition at line 87 of file cached_gpio.h.
|
protected |
Definition at line 89 of file cached_gpio.h.