From ba21af7254488cc4f2f87ec37c2d62fa686f13a5 Mon Sep 17 00:00:00 2001 From: Yang Jiyun Date: Fri, 20 Mar 2026 10:42:53 +0800 Subject: [PATCH] fw/drivers/touch/cst816: do a reset cycle when the touch IC cannot communicate with MCU CST816 may hung up by ESD, so reset it when it cannot communicate with MCU. Signed-off-by: Yang Jiyun --- src/fw/drivers/touch/cst816/cst816.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/fw/drivers/touch/cst816/cst816.c b/src/fw/drivers/touch/cst816/cst816.c index a7c72b3412..3cc99611e6 100644 --- a/src/fw/drivers/touch/cst816/cst816.c +++ b/src/fw/drivers/touch/cst816/cst816.c @@ -51,6 +51,7 @@ static PebbleMutex *s_i2c_lock; static void prv_exti_cb(bool *should_context_switch); static void cst816_hw_reset(void); +void touch_sensor_set_enabled(bool enabled); static bool prv_read_data(uint16_t register_address, uint8_t *result, uint16_t size, bool is_work_mode) { mutex_lock(s_i2c_lock); @@ -251,14 +252,17 @@ void touch_sensor_init(void) { static void prv_process_pending_messages(void* context) { s_callback_scheduled = false; + const uint64_t current_time_ms = ticks_to_milliseconds(rtc_get_ticks()); uint8_t data[CST816_TOUCH_DATA_SIZE] = {0}; bool rv = prv_read_data(CST816_TOUCH_DATA_REG, data, CST816_TOUCH_DATA_SIZE, 1); if (!rv) { - PBL_LOG_ERR("Failed to read touch data, dropping event"); + PBL_LOG_ERR("Failed to read touch data, trying to recover"); + touch_handle_update(0, TouchState_FingerUp, NULL, 0, current_time_ms); + exti_disable(CST816->int_exti); + touch_sensor_set_enabled(true); return; } - const uint64_t current_time_ms = ticks_to_milliseconds(rtc_get_ticks()); uint8_t press = data[0] & 0x0F; GPoint point = { .x = (((uint16_t)(data[1] & 0x0F)) << 8) | data[2],