Skip to content

Commit ef75607

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'bugfix/fix_touch_curr_scan_workaround_on_p4_v5.5' into 'release/v5.5'
fix(esp32p4): P4 touch channel 14 failure fix (v5.5) See merge request espressif/esp-idf!42922
2 parents 443bbf5 + 0ee40ef commit ef75607

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

components/esp_driver_touch_sens/hw_ver3/touch_version_specific.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ void IRAM_ATTR touch_priv_default_intr_handler(void *arg)
6363
touch_base_event_data_t data;
6464
touch_ll_get_active_channel_mask(&data.status_mask);
6565
int ch_offset = touch_ll_get_current_meas_channel() - TOUCH_MIN_CHAN_ID;
66+
if (ch_offset < 0 || ch_offset >= (int)SOC_TOUCH_SENSOR_NUM) {
67+
/* Not a valid channel */
68+
return;
69+
}
6670
data.chan = g_touch->ch[ch_offset];
6771
/* If the channel is not registered, return directly */
6872
if (!data.chan) {

components/esp_driver_touch_sens/test_apps/touch_sens/main/test_touch_sens_common.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,53 @@ TEST_CASE("touch_sens_active_inactive_test", "[touch]")
252252
TEST_ASSERT_EQUAL_INT32(touch_cnt, cb_data.active_count);
253253
TEST_ASSERT_EQUAL_INT32(touch_cnt, cb_data.inactive_count);
254254
}
255+
256+
#if SOC_TOUCH_SENSOR_VERSION > 1
257+
TEST_CASE("touch_sens_current_meas_channel_test", "[touch]")
258+
{
259+
touch_sensor_handle_t touch = NULL;
260+
touch_channel_handle_t touch_chan = NULL;
261+
262+
touch_sensor_config_t sens_cfg = TOUCH_SENSOR_DEFAULT_BASIC_CONFIG(TOUCH_SAMPLE_CFG_NUM, s_sample_cfg);
263+
TEST_ESP_OK(touch_sensor_new_controller(&sens_cfg, &touch));
264+
265+
/* Configuring the filter */
266+
touch_sensor_filter_config_t filter_cfg = TOUCH_SENSOR_DEFAULT_FILTER_CONFIG();
267+
TEST_ESP_OK(touch_sensor_config_filter(touch, &filter_cfg));
268+
269+
int err_chan[TOUCH_MAX_CHAN_ID - TOUCH_MIN_CHAN_ID + 1] = {[0 ...(TOUCH_MAX_CHAN_ID - TOUCH_MIN_CHAN_ID)] = -1};
270+
int scan_times = 100;
271+
uint32_t curr_chan[scan_times];
272+
/* Loop all channels */
273+
for (int ch_id = TOUCH_MIN_CHAN_ID; ch_id <= TOUCH_MAX_CHAN_ID; ch_id++) {
274+
/* New a channel */
275+
TEST_ESP_OK(touch_sensor_new_channel(touch, ch_id, &s_chan_cfg, &touch_chan));
276+
TEST_ESP_OK(touch_sensor_enable(touch));
277+
/* Trigger one-shot scanning to update the current measuring channel */
278+
touch_sensor_trigger_oneshot_scanning(touch, 2000);
279+
280+
/* Read the current measuring channel for several times */
281+
for (int i = 0; i < scan_times; i++) {
282+
curr_chan[i] = touch_ll_get_current_meas_channel();
283+
/* Check if the current measuring channel is the same as the channel id */
284+
if (curr_chan[i] != ch_id) {
285+
err_chan[ch_id - TOUCH_MIN_CHAN_ID] = curr_chan[i];
286+
}
287+
}
288+
/* Check if there is any error */
289+
TEST_ESP_OK(touch_sensor_disable(touch));
290+
TEST_ESP_OK(touch_sensor_del_channel(touch_chan));
291+
}
292+
TEST_ESP_OK(touch_sensor_del_controller(touch));
293+
294+
/* Check if there is any error in the current measuring channel from any channel */
295+
bool has_error = false;
296+
for (int i = 0; i < TOUCH_MAX_CHAN_ID - TOUCH_MIN_CHAN_ID + 1; i++) {
297+
if (err_chan[i] >= 0) {
298+
ESP_LOGE("TOUCH_TEST", "actual channel is %d, but current measuring channel reads %d", i + TOUCH_MIN_CHAN_ID, err_chan[i]);
299+
has_error = true;
300+
}
301+
}
302+
TEST_ASSERT_FALSE(has_error);
303+
}
304+
#endif // SOC_TOUCH_SENSOR_VERSION > 1

components/hal/esp32p4/include/hal/touch_sensor_ll.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,7 @@ static inline void touch_ll_set_idle_channel_connect(touch_idle_conn_t type)
489489
__attribute__((always_inline))
490490
static inline uint32_t touch_ll_get_current_meas_channel(void)
491491
{
492-
uint32_t curr_chan = LP_TOUCH.chn_status.scan_curr;
493-
HAL_ASSERT(curr_chan < 14);
494-
// Workaround: the curr channel read 0 when the actual channel is 14
495-
curr_chan = curr_chan == 0 ? 14 : curr_chan;
496-
return curr_chan;
492+
return LP_TOUCH.chn_status.scan_curr;
497493
}
498494

499495
/**

0 commit comments

Comments
 (0)