From b0f74b101a4b2895315aaf3eaf58fca12b12dc92 Mon Sep 17 00:00:00 2001 From: pelgraine <140762863+pelgraine@users.noreply.github.com> Date: Mon, 23 Mar 2026 13:33:23 +1100 Subject: [PATCH] tdpro - update firmware build date; improve keyboard responsiveness after boot --- examples/companion_radio/MyMesh.h | 2 +- variants/lilygo_tdeck_pro/Tca8418keyboard.h | 39 ++++++++++++++++----- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/examples/companion_radio/MyMesh.h b/examples/companion_radio/MyMesh.h index 40f0043..3b609f1 100644 --- a/examples/companion_radio/MyMesh.h +++ b/examples/companion_radio/MyMesh.h @@ -8,7 +8,7 @@ #define FIRMWARE_VER_CODE 10 #ifndef FIRMWARE_BUILD_DATE -#define FIRMWARE_BUILD_DATE "22 March 2026" +#define FIRMWARE_BUILD_DATE "23 March 2026" #endif #ifndef FIRMWARE_VERSION diff --git a/variants/lilygo_tdeck_pro/Tca8418keyboard.h b/variants/lilygo_tdeck_pro/Tca8418keyboard.h index 8fa25eb..fb0cfef 100644 --- a/variants/lilygo_tdeck_pro/Tca8418keyboard.h +++ b/variants/lilygo_tdeck_pro/Tca8418keyboard.h @@ -161,24 +161,47 @@ public: return false; } - // Configure keyboard matrix (8 rows x 10 cols) + // --- Warm-reboot safe init sequence --- + // The TCA8418 stays powered across ESP32 resets (no dedicated RST pin), + // so the scanner may still be active from the previous session. + // We must disable it before reconfiguring the matrix. + + // 1. Disable scanner — stop all scanning before touching config + writeReg(TCA8418_REG_CFG, 0x00); + + // 2. Drain any stale events from the previous session + for (int i = 0; i < 16; i++) { + if ((readReg(TCA8418_REG_KEY_LCK_EC) & 0x0F) == 0) break; + readReg(TCA8418_REG_KEY_EVENT_A); + } + writeReg(TCA8418_REG_INT_STAT, 0x1F); // Clear all interrupt flags + + // 3. Explicitly clear GPI event masks (prevent phantom GPI events) + writeReg(TCA8418_REG_GPI_EM1, 0x00); + writeReg(TCA8418_REG_GPI_EM2, 0x00); + writeReg(TCA8418_REG_GPI_EM3, 0x00); + + // 4. Configure keyboard matrix (8 rows x 10 cols) writeReg(TCA8418_REG_KP_GPIO1, 0xFF); // Rows 0-7 as keypad writeReg(TCA8418_REG_KP_GPIO2, 0xFF); // Cols 0-7 as keypad writeReg(TCA8418_REG_KP_GPIO3, 0x03); // Cols 8-9 as keypad - // Enable keypad with FIFO overflow detection - writeReg(TCA8418_REG_CFG, 0x11); // KE_IEN + INT_CFG - - // Set debounce + // 5. Set debounce writeReg(TCA8418_REG_DEBOUNCE, 0x03); - // Clear any pending interrupts + // 6. Final pre-enable cleanup writeReg(TCA8418_REG_INT_STAT, 0x1F); - // Flush the FIFO - while (readReg(TCA8418_REG_KEY_LCK_EC) & 0x0F) { + // 7. Enable scanner — matrix config is stable, safe to start scanning + writeReg(TCA8418_REG_CFG, 0x11); // KE_IEN + INT_CFG + + // 8. Let scanner stabilise, then flush any spurious first-scan events + delay(5); + for (int i = 0; i < 16; i++) { + if ((readReg(TCA8418_REG_KEY_LCK_EC) & 0x0F) == 0) break; readReg(TCA8418_REG_KEY_EVENT_A); } + writeReg(TCA8418_REG_INT_STAT, 0x1F); _initialized = true; Serial.println("TCA8418: Keyboard initialized OK");