diff --git a/components/esp_driver_touch_sens/common/touch_sens_private.h b/components/esp_driver_touch_sens/common/touch_sens_private.h index d8f47fc148..aaa0328ef1 100644 --- a/components/esp_driver_touch_sens/common/touch_sens_private.h +++ b/components/esp_driver_touch_sens/common/touch_sens_private.h @@ -30,7 +30,7 @@ extern "C" { /* Helper macros */ #define TOUCH_NULL_POINTER_CHECK(p) ESP_RETURN_ON_FALSE((p), ESP_ERR_INVALID_ARG, TAG, "input parameter '"#p"' is NULL") #define TOUCH_NULL_POINTER_CHECK_ISR(p) ESP_RETURN_ON_FALSE_ISR((p), ESP_ERR_INVALID_ARG, TAG, "input parameter '"#p"' is NULL") -#define FOR_EACH_TOUCH_CHANNEL(i) for (int i = 0; i < SOC_TOUCH_SENSOR_NUM; i++) +#define FOR_EACH_TOUCH_CHANNEL(i) for (int i = 0; i < TOUCH_TOTAL_CHAN_NUM; i++) #define TOUCH_IRAM_CHECK(cb) (!(cb) || esp_ptr_in_iram(cb)) /* IRAM safe caps */ diff --git a/components/esp_driver_touch_sens/hw_ver2/touch_version_specific.c b/components/esp_driver_touch_sens/hw_ver2/touch_version_specific.c index c3eacb5bc6..99d2e29f59 100644 --- a/components/esp_driver_touch_sens/hw_ver2/touch_version_specific.c +++ b/components/esp_driver_touch_sens/hw_ver2/touch_version_specific.c @@ -64,9 +64,12 @@ 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); uint32_t curr_chan = touch_ll_get_current_meas_channel(); + if (curr_chan == 0) { + return; + } /* It actually won't be out of range in the real environment, but limit the range to pass the coverity check */ - curr_chan = curr_chan >= SOC_TOUCH_SENSOR_NUM ? SOC_TOUCH_SENSOR_NUM - 1 : curr_chan; - data.chan = g_touch->ch[curr_chan]; + uint32_t curr_chan_offset = (curr_chan >= SOC_TOUCH_SENSOR_NUM ? SOC_TOUCH_SENSOR_NUM - 1 : curr_chan) - TOUCH_MIN_CHAN_ID; + data.chan = g_touch->ch[curr_chan_offset]; /* If the channel is not registered, return directly */ if (!data.chan) { return; diff --git a/components/esp_driver_touch_sens/include/driver/touch_sens_types.h b/components/esp_driver_touch_sens/include/driver/touch_sens_types.h index 5d7e2d548d..7c1dac34c5 100644 --- a/components/esp_driver_touch_sens/include/driver/touch_sens_types.h +++ b/components/esp_driver_touch_sens/include/driver/touch_sens_types.h @@ -16,7 +16,6 @@ extern "C" { #endif -#define TOUCH_TOTAL_CHAN_NUM SOC_TOUCH_SENSOR_NUM /*!< The total channel number of the touch sensor */ #define TOUCH_SAMPLE_CFG_NUM SOC_TOUCH_SAMPLE_CFG_NUM /*!< The supported max sample configuration number */ #if SOC_TOUCH_SUPPORT_PROX_SENSING #define TOUCH_PROXIMITY_CHAN_NUM SOC_TOUCH_PROXIMITY_CHANNEL_NUM /*!< The supported proximity channel number in proximity sensing mode */ @@ -24,6 +23,7 @@ extern "C" { #define TOUCH_MIN_CHAN_ID SOC_TOUCH_MIN_CHAN_ID /*!< The minimum available channel id of the touch pad */ #define TOUCH_MAX_CHAN_ID SOC_TOUCH_MAX_CHAN_ID /*!< The maximum available channel id of the touch pad */ +#define TOUCH_TOTAL_CHAN_NUM (TOUCH_MAX_CHAN_ID - TOUCH_MIN_CHAN_ID + 1) /*!< The total channel number of the touch sensor */ /** * @brief The chip sleep level that allows the touch sensor to wake-up