From deb061943a66a39307758eaa279d6c0db1ff07b2 Mon Sep 17 00:00:00 2001 From: GlassOnTin Date: Fri, 27 Mar 2026 18:48:07 +0000 Subject: [PATCH] Add CST9217 touch panel with touch-to-wake display blanking Touch driver via SensorLib TouchDrvCST92xx on I2C 0x1A with interrupt on GPIO 12. Touch events unblank the display and reset the blanking timer. Display blanks after 10 seconds of inactivity. XL9555 TOUCH_RST now explicitly released at boot. Touch init runs with explicit I2C_SDA/I2C_SCL pins (same fix as XPowersLib). --- Display.h | 5 +++-- RNode_Firmware.ino | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Display.h b/Display.h index 7caee7b..5dcc87f 100644 --- a/Display.h +++ b/Display.h @@ -52,8 +52,9 @@ if (!co5300_init()) return false; co5300_set_brightness(128); - // Disable blanking until button wake is implemented - display_blanking_enabled = false; + // Enable blanking — touch input now available to unblank + display_blanking_enabled = true; + display_blanking_timeout = 10000; // 10 seconds // Allocate partial framebuffer for clock region (PSRAM preferred for large buffers) clock_fb = (uint16_t *)heap_caps_malloc(CLOCK_FB_W * CLOCK_FB_H * 2, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index e199dc6..978f5a0 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -28,6 +28,14 @@ #include SensorBHI260AP *bhi260 = NULL; bool bhi260_ready = false; + + // CST9217 capacitive touch panel + #include + TouchDrvCST92xx touch; + bool touch_ready = false; + volatile bool touch_irq = false; + #define TP_INT 12 + void IRAM_ATTR touch_isr() { touch_irq = true; } #endif #define CHANNEL_FIFO_SIZE (CONFIG_UART_BUFFER_SIZE / NUM_CHANNELS) @@ -284,10 +292,18 @@ void setup() { xl9555_enable_lora_antenna(); xl9555_set(EXPANDS_DRV_EN, true); // Enable haptic motor driver xl9555_set(EXPANDS_DISP_EN, true); // Enable display power gate - delay(10); + xl9555_set(EXPANDS_TOUCH_RST, true); // Release touch reset + delay(100); drv2605_init(); if (drv2605_ready) drv2605_play(HAPTIC_SHARP_CLICK); // Boot feedback + // Init touch panel + touch.setPins(-1, TP_INT); // No reset pin (handled by XL9555), INT on GPIO 12 + if (touch.begin(Wire, 0x1A, I2C_SDA, I2C_SCL)) { + touch_ready = true; + attachInterrupt(TP_INT, touch_isr, FALLING); + } + // BHI260AP init deferred — firmware upload takes ~10s at 1MHz I2C // and blocks serial communication during boot. Will be initialized // lazily from the main loop after radio is up. @@ -1997,6 +2013,21 @@ void loop() { input_read(); #endif + // Touch panel event handling + #if BOARD_MODEL == BOARD_TWATCH_ULT + if (touch_ready && touch_irq) { + touch_irq = false; + int16_t tx, ty; + if (touch.getPoint(&tx, &ty, 1) > 0) { + // Touch detected — unblank display and update activity + #if HAS_DISPLAY + display_unblank(); + #endif + last_unblank_event = millis(); + } + } + #endif + // Deferred BHI260AP init — runs once after boot is complete // Firmware upload takes ~10s and blocks, so we do it after radio is up #if BOARD_MODEL == BOARD_TWATCH_ULT