Skip to content

Commit b25f3fa

Browse files
committed
fix(touch): fixed channel offset issue in touch v2
1 parent c10d3ac commit b25f3fa

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

components/esp_driver_touch_sens/common/touch_sens_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern "C" {
3030
/* Helper macros */
3131
#define TOUCH_NULL_POINTER_CHECK(p) ESP_RETURN_ON_FALSE((p), ESP_ERR_INVALID_ARG, TAG, "input parameter '"#p"' is NULL")
3232
#define TOUCH_NULL_POINTER_CHECK_ISR(p) ESP_RETURN_ON_FALSE_ISR((p), ESP_ERR_INVALID_ARG, TAG, "input parameter '"#p"' is NULL")
33-
#define FOR_EACH_TOUCH_CHANNEL(i) for (int i = 0; i < SOC_TOUCH_SENSOR_NUM; i++)
33+
#define FOR_EACH_TOUCH_CHANNEL(i) for (int i = 0; i < TOUCH_TOTAL_CHAN_NUM; i++)
3434
#define TOUCH_IRAM_CHECK(cb) (!(cb) || esp_ptr_in_iram(cb))
3535

3636
/* IRAM safe caps */

components/esp_driver_touch_sens/hw_ver2/touch_version_specific.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ void IRAM_ATTR touch_priv_default_intr_handler(void *arg)
6464
touch_base_event_data_t data;
6565
touch_ll_get_active_channel_mask(&data.status_mask);
6666
uint32_t curr_chan = touch_ll_get_current_meas_channel();
67+
if (curr_chan == 0) {
68+
return;
69+
}
6770
/* It actually won't be out of range in the real environment, but limit the range to pass the coverity check */
68-
curr_chan = curr_chan >= SOC_TOUCH_SENSOR_NUM ? SOC_TOUCH_SENSOR_NUM - 1 : curr_chan;
69-
data.chan = g_touch->ch[curr_chan];
71+
uint32_t curr_chan_offset = (curr_chan >= SOC_TOUCH_SENSOR_NUM ? SOC_TOUCH_SENSOR_NUM - 1 : curr_chan) - TOUCH_MIN_CHAN_ID;
72+
data.chan = g_touch->ch[curr_chan_offset];
7073
/* If the channel is not registered, return directly */
7174
if (!data.chan) {
7275
return;

components/esp_driver_touch_sens/include/driver/touch_sens_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
extern "C" {
1717
#endif
1818

19-
#define TOUCH_TOTAL_CHAN_NUM SOC_TOUCH_SENSOR_NUM /*!< The total channel number of the touch sensor */
2019
#define TOUCH_SAMPLE_CFG_NUM SOC_TOUCH_SAMPLE_CFG_NUM /*!< The supported max sample configuration number */
2120
#if SOC_TOUCH_SUPPORT_PROX_SENSING
2221
#define TOUCH_PROXIMITY_CHAN_NUM SOC_TOUCH_PROXIMITY_CHANNEL_NUM /*!< The supported proximity channel number in proximity sensing mode */
2322
#endif
2423

2524
#define TOUCH_MIN_CHAN_ID SOC_TOUCH_MIN_CHAN_ID /*!< The minimum available channel id of the touch pad */
2625
#define TOUCH_MAX_CHAN_ID SOC_TOUCH_MAX_CHAN_ID /*!< The maximum available channel id of the touch pad */
26+
#define TOUCH_TOTAL_CHAN_NUM (TOUCH_MAX_CHAN_ID - TOUCH_MIN_CHAN_ID + 1) /*!< The total channel number of the touch sensor */
2727

2828
/**
2929
* @brief The chip sleep level that allows the touch sensor to wake-up

0 commit comments

Comments
 (0)