From d8592f7a0354bc92f2d14342eff1f6fd2da94822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hermann=20Bj=C3=B6rgvin=20Haraldsson?= Date: Mon, 11 May 2026 02:21:20 +0000 Subject: [PATCH] Gate touch_read on ISR flag instead of double-polling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit touch_read() had two branches that both called getPoint() unconditionally — the touch_data_ready flag served no purpose. Gate the I2C transaction on the flag so the ISR finally pulls its weight: idle loops no longer hit I2C, getPoint() runs only when the CST9220 actually raised the TP_INT line. Also scope touch_pressed/x/y to file-static (no cross-TU users) and drop the stale 'permanent while we work on it' comment by the default boot screen — splash-on-boot is documented in CLAUDE.md. --- firmware/src/main.cpp | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index 37c6f15..df99d7d 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -30,28 +30,17 @@ SensorQMI8658 imu; static UsageData usage = {}; // ---- Touch interrupt + shared state ---- -volatile bool touch_pressed = false; -volatile uint16_t touch_x = 0; -volatile uint16_t touch_y = 0; -static volatile bool touch_data_ready = false; +static volatile bool touch_pressed = false; +static volatile uint16_t touch_x = 0; +static volatile uint16_t touch_y = 0; +static volatile bool touch_data_ready = false; static void IRAM_ATTR touch_isr(void) { touch_data_ready = true; } static void touch_read() { - if (!touch_data_ready) { - int16_t tx[5], ty[5]; - uint8_t n = touch.getPoint(tx, ty, touch.getSupportTouchPoint()); - if (n > 0) { - touch_pressed = true; - touch_x = (uint16_t)tx[0]; - touch_y = (uint16_t)ty[0]; - } else { - touch_pressed = false; - } - return; - } + if (!touch_data_ready) return; touch_data_ready = false; int16_t tx[5], ty[5]; @@ -305,7 +294,6 @@ void setup() { // Show initial battery status ui_update_battery(power_battery_pct(), power_is_charging()); - // Default to splash screen (permanent while we work on it) ui_show_screen(SCREEN_SPLASH); Serial.println("Dashboard ready, waiting for data on BLE...");