Skip to content

Commit 32d23f9

Browse files
committed
feat(touch): support touch v1 test cases
1 parent fd7b808 commit 32d23f9

File tree

2 files changed

+48
-11
lines changed

2 files changed

+48
-11
lines changed

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

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -10,12 +10,13 @@
1010
#include "unity.h"
1111
#include "driver/touch_sens.h"
1212
#include "hal/touch_sensor_ll.h"
13-
#include "esp_private/touch_sens_helper.h"
1413
#include "esp_log.h"
1514
#include "esp_attr.h"
1615

1716
static touch_sensor_sample_config_t s_sample_cfg[TOUCH_SAMPLE_CFG_NUM] = {
18-
#if SOC_TOUCH_SENSOR_VERSION == 2
17+
#if SOC_TOUCH_SENSOR_VERSION == 1
18+
TOUCH_SENSOR_V1_DEFAULT_SAMPLE_CONFIG(5.0, TOUCH_VOLT_LIM_L_0V5, TOUCH_VOLT_LIM_H_1V7),
19+
#elif SOC_TOUCH_SENSOR_VERSION == 2
1920
TOUCH_SENSOR_V2_DEFAULT_SAMPLE_CONFIG(500, TOUCH_VOLT_LIM_L_0V5, TOUCH_VOLT_LIM_H_2V2),
2021
#elif SOC_TOUCH_SENSOR_VERSION == 3
2122
TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG(1, 1, 1),
@@ -27,7 +28,12 @@ static touch_sensor_sample_config_t s_sample_cfg[TOUCH_SAMPLE_CFG_NUM] = {
2728
};
2829

2930
static touch_channel_config_t s_chan_cfg = {
30-
#if SOC_TOUCH_SENSOR_VERSION == 2
31+
#if SOC_TOUCH_SENSOR_VERSION == 1
32+
.abs_active_thresh = {1000},
33+
.charge_speed = TOUCH_CHARGE_SPEED_7,
34+
.init_charge_volt = TOUCH_INIT_CHARGE_VOLT_LOW,
35+
.group = TOUCH_CHAN_TRIG_GROUP_BOTH,
36+
#elif SOC_TOUCH_SENSOR_VERSION == 2
3137
.active_thresh = {
3238
2000,
3339
},
@@ -77,15 +83,24 @@ TEST_CASE("touch_sens_install_uninstall_test", "[touch]")
7783
typedef struct {
7884
int active_count;
7985
int inactive_count;
86+
#if SOC_TOUCH_SENSOR_VERSION == 1
87+
int hw_active_count;
88+
#endif
8089
} test_touch_cb_data_t;
8190

8291
static touch_channel_config_t s_test_get_chan_cfg_by_benchmark(uint32_t benchmark[], uint32_t num, float coeff)
8392
{
84-
touch_channel_config_t chan_cfg = {};
93+
touch_channel_config_t chan_cfg = s_chan_cfg;
8594
for (int i = 0; i < num; i++) {
95+
#if SOC_TOUCH_SENSOR_VERSION == 1
96+
chan_cfg.abs_active_thresh[i] = benchmark[i] * (1 - coeff);
97+
printf("[Sampler %d] benchmark %5"PRIu32" abs thresh %4"PRIu32"\n",
98+
i, benchmark[i], chan_cfg.abs_active_thresh[i]);
99+
#else
86100
chan_cfg.active_thresh[i] = benchmark[i] * coeff;
87101
printf("[Sampler %d] benchmark %5"PRIu32" thresh %4"PRIu32"\n",
88102
i, benchmark[i], chan_cfg.active_thresh[i]);
103+
#endif
89104
}
90105
return chan_cfg;
91106
}
@@ -108,6 +123,15 @@ static void s_test_touch_do_initial_scanning(touch_sensor_handle_t touch, int sc
108123
#define TEST_TCH_IRAM_ATTR
109124
#endif
110125

126+
#if SOC_TOUCH_SENSOR_VERSION == 1
127+
static bool TEST_TCH_IRAM_ATTR s_test_touch_on_hw_active_callback(touch_sensor_handle_t sens_handle, const touch_hw_active_event_data_t *event, void *user_ctx)
128+
{
129+
test_touch_cb_data_t *cb_data = (test_touch_cb_data_t *)user_ctx;
130+
cb_data->hw_active_count++;
131+
return false;
132+
}
133+
#endif
134+
111135
static bool TEST_TCH_IRAM_ATTR s_test_touch_on_active_callback(touch_sensor_handle_t sens_handle, const touch_active_event_data_t *event, void *user_ctx)
112136
{
113137
ESP_EARLY_LOGI("touch_callback", "[CH %d] active", (int)event->chan_id);
@@ -126,7 +150,7 @@ static bool TEST_TCH_IRAM_ATTR s_test_touch_on_inactive_callback(touch_sensor_ha
126150

127151
static void s_test_touch_simulate_touch(touch_sensor_handle_t touch, touch_channel_handle_t touch_chan, bool active)
128152
{
129-
#if SOC_TOUCH_SENSOR_VERSION == 2
153+
#if SOC_TOUCH_SENSOR_VERSION <= 2
130154
touch_chan_info_t chan_info = {};
131155
touch_sensor_get_channel_info(touch_chan, &chan_info);
132156
touch_ll_set_charge_speed(chan_info.chan_id, active ? TOUCH_CHARGE_SPEED_4 : TOUCH_CHARGE_SPEED_7);
@@ -169,18 +193,25 @@ TEST_CASE("touch_sens_active_inactive_test", "[touch]")
169193

170194
/* Read benchmark */
171195
uint32_t benchmark[TOUCH_SAMPLE_CFG_NUM] = {0};
172-
TEST_ESP_OK(touch_channel_read_data(touch_chan, TOUCH_CHAN_DATA_TYPE_BENCHMARK, benchmark));
196+
#if SOC_TOUCH_SUPPORT_BENCHMARK
197+
touch_chan_data_type_t data_type = TOUCH_CHAN_DATA_TYPE_BENCHMARK;
198+
#else
199+
touch_chan_data_type_t data_type = TOUCH_CHAN_DATA_TYPE_SMOOTH;
200+
#endif // SOC_TOUCH_SUPPORT_BENCHMARK
201+
TEST_ESP_OK(touch_channel_read_data(touch_chan, data_type, benchmark));
173202
/* Test whether success to finish the initial scanning */
174203
for (int i = 0; i < TOUCH_SAMPLE_CFG_NUM; i++) {
175204
TEST_ASSERT_GREATER_THAN(0, benchmark[i]);
176205
}
177206
/* Re-configure the threshold according to the benchmark */
178207
touch_channel_config_t chan_cfg = s_test_get_chan_cfg_by_benchmark(benchmark, TOUCH_SAMPLE_CFG_NUM, TEST_ACTIVE_THRESH_RATIO);
179208
TEST_ESP_OK(touch_sensor_reconfig_channel(touch_chan, &chan_cfg));
180-
181209
touch_event_callbacks_t callbacks = {
182210
.on_active = s_test_touch_on_active_callback,
183211
.on_inactive = s_test_touch_on_inactive_callback,
212+
#if SOC_TOUCH_SENSOR_VERSION == 1
213+
.on_hw_active = s_test_touch_on_hw_active_callback,
214+
#endif
184215
};
185216
test_touch_cb_data_t cb_data = {};
186217
TEST_ESP_OK(touch_sensor_register_callbacks(touch, &callbacks, &cb_data));
@@ -196,13 +227,13 @@ TEST_CASE("touch_sens_active_inactive_test", "[touch]")
196227
s_test_touch_log_data(touch_chan, TOUCH_SAMPLE_CFG_NUM, "Data Before");
197228
// Simulate touch
198229
s_test_touch_simulate_touch(touch, touch_chan, true);
199-
vTaskDelay(pdMS_TO_TICKS(50));
230+
vTaskDelay(pdMS_TO_TICKS(100));
200231

201232
// Read data after touched
202233
s_test_touch_log_data(touch_chan, TOUCH_SAMPLE_CFG_NUM, "Data After ");
203234
// Simulate release
204235
s_test_touch_simulate_touch(touch, touch_chan, false);
205-
vTaskDelay(pdMS_TO_TICKS(50));
236+
vTaskDelay(pdMS_TO_TICKS(100));
206237
}
207238
printf("\n");
208239

@@ -212,6 +243,12 @@ TEST_CASE("touch_sens_active_inactive_test", "[touch]")
212243
TEST_ESP_OK(touch_sensor_del_controller(touch));
213244

214245
/* Check the callback count */
246+
#if SOC_TOUCH_SENSOR_VERSION == 1
247+
// The Touch V1 interrupt will keep triggering as long as the channel data is below the threshold
248+
// So it might be greater than the touch count
249+
printf("hardware active interrupt count: %d\n", cb_data.hw_active_count);
250+
TEST_ASSERT_GREATER_OR_EQUAL_UINT32(touch_cnt, cb_data.hw_active_count);
251+
#endif // SOC_TOUCH_SENSOR_VERSION == 1
215252
TEST_ASSERT_EQUAL_INT32(touch_cnt, cb_data.active_count);
216253
TEST_ASSERT_EQUAL_INT32(touch_cnt, cb_data.inactive_count);
217254
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
CONFIG_FREERTOS_HZ=1000
2-
CONFIG_ESP_TASK_WDT=n
2+
CONFIG_ESP_TASK_WDT_INIT=n

0 commit comments

Comments
 (0)