From 7adc84467f29be83a4a4ee31147a1a2f3fb8a07d Mon Sep 17 00:00:00 2001 From: Pete Kabaragoya Date: Tue, 21 Oct 2025 21:11:13 -0400 Subject: [PATCH] fix(esp32p4): P4 touch channel 14 failure fix Merges https://github.com/espressif/esp-idf/pull/17759 Core dump when using all touch channels on a P4 unless curr_chan is allowed to be 14 --- .../esp_driver_touch_sens/hw_ver3/touch_version_specific.c | 4 ++++ components/hal/esp32p4/include/hal/touch_sensor_ll.h | 6 +----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/esp_driver_touch_sens/hw_ver3/touch_version_specific.c b/components/esp_driver_touch_sens/hw_ver3/touch_version_specific.c index d00e0df8b7..ce4c5f1cc4 100644 --- a/components/esp_driver_touch_sens/hw_ver3/touch_version_specific.c +++ b/components/esp_driver_touch_sens/hw_ver3/touch_version_specific.c @@ -63,6 +63,10 @@ void IRAM_ATTR touch_priv_default_intr_handler(void *arg) touch_base_event_data_t data; touch_ll_get_active_channel_mask(&data.status_mask); int ch_offset = touch_ll_get_current_meas_channel() - TOUCH_MIN_CHAN_ID; + if (ch_offset < 0 || ch_offset >= (int)SOC_MODULE_ATTR(TOUCH, CHAN_NUM)) { + /* Not a valid channel */ + return; + } data.chan = g_touch->ch[ch_offset]; /* If the channel is not registered, return directly */ if (!data.chan) { diff --git a/components/hal/esp32p4/include/hal/touch_sensor_ll.h b/components/hal/esp32p4/include/hal/touch_sensor_ll.h index 8ee210efb9..4ea8d62d4a 100644 --- a/components/hal/esp32p4/include/hal/touch_sensor_ll.h +++ b/components/hal/esp32p4/include/hal/touch_sensor_ll.h @@ -492,11 +492,7 @@ static inline void touch_ll_set_idle_channel_connect(touch_idle_conn_t type) __attribute__((always_inline)) static inline uint32_t touch_ll_get_current_meas_channel(void) { - uint32_t curr_chan = LP_TOUCH.chn_status.scan_curr; - HAL_ASSERT(curr_chan < 14); - // Workaround: the curr channel read 0 when the actual channel is 14 - curr_chan = curr_chan == 0 ? 14 : curr_chan; - return curr_chan; + return LP_TOUCH.chn_status.scan_curr; } /**