10static constexpr uint32_t POLL_INTERVAL_MS = 50;
16 LOG_STR(
"Failed to read from device - check wiring / address")))
19 if (!this->
setup_check(this->configure_pins_(), LOG_STR(
"Failed to configure pins")))
23 if (!this->
setup_check(this->
write_byte(TCA8418_REG_CFG, TCA8418_CFG_KEY_INT_EN | TCA8418_CFG_INT_CFG),
24 LOG_STR(
"Failed to write the configuration register")))
41bool TCA8418Component::configure_pins_() {
43 uint8_t matrix[3] = {0, 0, 0};
44 if (this->
rows_ > 0) {
45 matrix[0] =
static_cast<uint8_t
>((1U << this->
rows_) - 1U);
47 matrix[1] =
static_cast<uint8_t
>((1U << low_columns) - 1U);
49 matrix[2] =
static_cast<uint8_t
>((1U << (this->
columns_ - 8U)) - 1U);
54 const uint8_t gpi[3] = {
55 static_cast<uint8_t
>(this->
gpi_events_ ? ~matrix[0] : 0),
56 static_cast<uint8_t
>(this->
gpi_events_ ? ~matrix[1] : 0),
57 static_cast<uint8_t
>(this->
gpi_events_ ? (0x03 & ~matrix[2]) : 0),
60 for (uint8_t i = 0; i < 3; i++) {
63 if (!this->
write_byte(TCA8418_REG_GPIO_PULL1 + i, 0x00) || !this->
write_byte(TCA8418_REG_KP_GPIO1 + i, matrix[i]) ||
64 !this->
write_byte(TCA8418_REG_GPI_EM1 + i, gpi[i]) || !this->
write_byte(TCA8418_REG_GPIO_INT_EN1 + i, gpi[i])) {
89 count &= TCA8418_EVENT_COUNT_MASK;
94 if (dispatch &&
count >= TCA8418_FIFO_DEPTH) {
95 ESP_LOGW(TAG,
"Event queue is full - some key presses may have been lost");
99 for (uint8_t i = 0; i <
count; i++) {
100 if (!this->
read_byte(TCA8418_REG_KEY_EVENT_A, &event))
103 this->
dispatch_(event & TCA8418_KEY_CODE_MASK, (event & TCA8418_KEY_PRESSED) != 0);
105 return this->
write_byte(TCA8418_REG_INT_STAT, TCA8418_INT_STAT_ALL);
115 ESP_LOGV(TAG,
"Key %u %s",
key, pressed ? LOG_STR_LITERAL(
"pressed") : LOG_STR_LITERAL(
"released"));
117#ifdef USE_TCA8418_KEY_PUBLISHER
118 if (this->key_publisher_ !=
nullptr)
119 this->key_publisher_(
key, pressed);
127 const uint8_t key_char = this->
key_char_(key);
134 " Individual inputs: %s",
136 if (this->
rows_ > 0) {
137 ESP_LOGCONFIG(TAG,
" Key matrix: %u rows x %u columns", this->
rows_, this->
columns_);
140 LOG_I2C_DEVICE(
this);
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
bool status_comm_result(bool ok)
Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
bool ESPHOME_ALWAYS_INLINE setup_check(bool ok)
Marks the component failed with message (default "Communication failed") unless ok; returns ok.
void disable_loop()
Disable this component's loop.
bool digital_read() override
bool write_byte(uint8_t a_register, uint8_t data) const
bool read_byte(uint8_t a_register, uint8_t *data)
void send_key_(uint8_t key)
InternalGPIOPin * interrupt_pin_
HUB_PUBLISHER(key, uint8_t, bool) protected bool drain_events_(bool dispatch)
Read every queued key event, dispatching them if asked, then clear the interrupt flags.
uint8_t key_char_(uint8_t key) const
The character mapped to a matrix key, or 0 when it has none.
void dispatch_(uint8_t key, bool pressed)
void dump_config() override
ESPHOME_LOG_TAG(TAG, "tca8418")
bool setup_wake_interrupt(GPIOPin *pin, Component *component, gpio::InterruptType type)
Set up pin and attach the wake interrupt when it is a GPIO of the chip itself.
Application App
Global storage of Application pointer - only one Application can exist.
uint8_t progmem_read_byte(const uint8_t *addr)