ESPHome 2025.5.0
Loading...
Searching...
No Matches
esphome::gpio_expander::CachedGpioExpander< T, N > Class Template Referenceabstract

A class to cache the read state of a GPIO expander. More...

#include <cached_gpio.h>

Public Member Functions

bool digital_read (T 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

const uint8_t cache_byte_size_ = N / (sizeof(T) * BITS_PER_BYTE)
 
std::array< bool, N/(sizeof(T) *BITS_PER_BYTE)> read_cache_invalidated_ {}
 

Static Protected Attributes

static const uint8_t BITS_PER_BYTE = 8
 

Detailed Description

template<typename T, T N>
class esphome::gpio_expander::CachedGpioExpander< T, N >

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 18 of file cached_gpio.h.

Member Function Documentation

◆ digital_read()

template<typename T , T N>
bool esphome::gpio_expander::CachedGpioExpander< T, N >::digital_read ( T pin)
inline

Definition at line 20 of file cached_gpio.h.

◆ digital_read_cache()

template<typename T , T N>
virtual bool esphome::gpio_expander::CachedGpioExpander< T, N >::digital_read_cache ( T pin)
protectedpure virtual

Call component read function from internal cache.

Implemented in esphome::tca9555::TCA9555Component.

◆ digital_read_hw()

template<typename T , T N>
virtual bool esphome::gpio_expander::CachedGpioExpander< T, N >::digital_read_hw ( T pin)
protectedpure virtual

Call component low level function to read GPIO state from device.

Implemented in esphome::tca9555::TCA9555Component.

◆ digital_write()

template<typename T , T N>
void esphome::gpio_expander::CachedGpioExpander< T, N >::digital_write ( T pin,
bool value )
inline

Definition at line 30 of file cached_gpio.h.

◆ digital_write_hw()

template<typename T , T N>
virtual void esphome::gpio_expander::CachedGpioExpander< T, N >::digital_write_hw ( T pin,
bool value )
protectedpure virtual

Call component low level function to write GPIO state to device.

Implemented in esphome::tca9555::TCA9555Component.

◆ reset_pin_cache_()

template<typename T , T N>
void esphome::gpio_expander::CachedGpioExpander< T, N >::reset_pin_cache_ ( )
inlineprotected

Invalidate cache. This function should be called in component loop().

Definition at line 42 of file cached_gpio.h.

Field Documentation

◆ BITS_PER_BYTE

template<typename T , T N>
const uint8_t esphome::gpio_expander::CachedGpioExpander< T, N >::BITS_PER_BYTE = 8
staticprotected

Definition at line 48 of file cached_gpio.h.

◆ cache_byte_size_

template<typename T , T N>
const uint8_t esphome::gpio_expander::CachedGpioExpander< T, N >::cache_byte_size_ = N / (sizeof(T) * BITS_PER_BYTE)
protected

Definition at line 39 of file cached_gpio.h.

◆ read_cache_invalidated_

template<typename T , T N>
std::array<bool, N / (sizeof(T) * BITS_PER_BYTE)> esphome::gpio_expander::CachedGpioExpander< T, N >::read_cache_invalidated_ {}
protected

Definition at line 49 of file cached_gpio.h.


The documentation for this class was generated from the following file: