Gate touch_read on ISR flag instead of double-polling

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.
This commit is contained in:
Hermann Björgvin Haraldsson
2026-05-11 02:21:20 +00:00
parent f1feacb3dc
commit d8592f7a03
+5 -17
View File
@@ -30,28 +30,17 @@ SensorQMI8658 imu;
static UsageData usage = {}; static UsageData usage = {};
// ---- Touch interrupt + shared state ---- // ---- Touch interrupt + shared state ----
volatile bool touch_pressed = false; static volatile bool touch_pressed = false;
volatile uint16_t touch_x = 0; static volatile uint16_t touch_x = 0;
volatile uint16_t touch_y = 0; static volatile uint16_t touch_y = 0;
static volatile bool touch_data_ready = false; static volatile bool touch_data_ready = false;
static void IRAM_ATTR touch_isr(void) { static void IRAM_ATTR touch_isr(void) {
touch_data_ready = true; touch_data_ready = true;
} }
static void touch_read() { static void touch_read() {
if (!touch_data_ready) { if (!touch_data_ready) return;
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;
}
touch_data_ready = false; touch_data_ready = false;
int16_t tx[5], ty[5]; int16_t tx[5], ty[5];
@@ -305,7 +294,6 @@ void setup() {
// Show initial battery status // Show initial battery status
ui_update_battery(power_battery_pct(), power_is_charging()); ui_update_battery(power_battery_pct(), power_is_charging());
// Default to splash screen (permanent while we work on it)
ui_show_screen(SCREEN_SPLASH); ui_show_screen(SCREEN_SPLASH);
Serial.println("Dashboard ready, waiting for data on BLE..."); Serial.println("Dashboard ready, waiting for data on BLE...");