mirror of
https://github.com/esphome/esphome.git
synced 2025-10-30 06:33:51 +00:00
Add tca9555 GPIO driver (#7146)
Co-authored-by: Michal Obrembski <michal@obrembski.com> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
0
esphome/components/gpio_expander/__init__.py
Normal file
0
esphome/components/gpio_expander/__init__.py
Normal file
38
esphome/components/gpio_expander/cached_gpio.h
Normal file
38
esphome/components/gpio_expander/cached_gpio.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include "esphome/core/hal.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace gpio_expander {
|
||||
|
||||
/// @brief A class to cache the read state of a GPIO expander.
|
||||
template<typename T, T N> class CachedGpioExpander {
|
||||
public:
|
||||
bool digital_read(T pin) {
|
||||
if (!this->read_cache_invalidated_[pin]) {
|
||||
this->read_cache_invalidated_[pin] = true;
|
||||
return this->digital_read_cache(pin);
|
||||
}
|
||||
return this->digital_read_hw(pin);
|
||||
}
|
||||
|
||||
void digital_write(T pin, bool value) { this->digital_write_hw(pin, value); }
|
||||
|
||||
protected:
|
||||
virtual bool digital_read_hw(T pin) = 0;
|
||||
virtual bool digital_read_cache(T pin) = 0;
|
||||
virtual void digital_write_hw(T pin, bool value) = 0;
|
||||
|
||||
void reset_pin_cache_() {
|
||||
for (T i = 0; i < N; i++) {
|
||||
this->read_cache_invalidated_[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
std::array<bool, N> read_cache_invalidated_{};
|
||||
};
|
||||
|
||||
} // namespace gpio_expander
|
||||
} // namespace esphome
|
||||
Reference in New Issue
Block a user