template<typename T, uint16_t N, typename P = typename std::conditional<(N > 256), uint16_t, uint8_t>::type>
class esphome::gpio_expander::CachedGpioExpander< T, N, P >
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:
- uint8_t: For chips that read banks separately (8 pins at a time) Examples: MCP23017 (2x8-bit banks), TCA9555 (2x8-bit banks)
- uint16_t: For chips that read all pins at once (up to 16 pins) Examples: PCF8574/8575 (8/16 pins), PCA9554/9555 (8/16 pins) N - Total number of pins (maximum 65535) P - Type for pin number parameters (automatically selected based on N: uint8_t for N<=256, uint16_t for N>256). Can be explicitly specified if needed (e.g., for components like SN74HC165 with >256 pins)
Definition at line 29 of file cached_gpio.h.
template<typename T , uint16_t N, typename P = typename std::conditional<(N > 256), uint16_t, uint8_t>::type>
Read the state of the given pin.
This will invalidate the cache for the given pin number.
- Parameters
-
- Returns
- Pin state
Definition at line 34 of file cached_gpio.h.