diff --git a/components/esp_driver_touch_sens/test_apps/touch_sens/main/test_touch_sens_common.c b/components/esp_driver_touch_sens/test_apps/touch_sens/main/test_touch_sens_common.c index 64481e6972..b3d4b28126 100644 --- a/components/esp_driver_touch_sens/test_apps/touch_sens/main/test_touch_sens_common.c +++ b/components/esp_driver_touch_sens/test_apps/touch_sens/main/test_touch_sens_common.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -10,12 +10,13 @@ #include "unity.h" #include "driver/touch_sens.h" #include "hal/touch_sensor_ll.h" -#include "esp_private/touch_sens_helper.h" #include "esp_log.h" #include "esp_attr.h" static touch_sensor_sample_config_t s_sample_cfg[TOUCH_SAMPLE_CFG_NUM] = { -#if SOC_TOUCH_SENSOR_VERSION == 2 +#if SOC_TOUCH_SENSOR_VERSION == 1 + TOUCH_SENSOR_V1_DEFAULT_SAMPLE_CONFIG(5.0, TOUCH_VOLT_LIM_L_0V5, TOUCH_VOLT_LIM_H_1V7), +#elif SOC_TOUCH_SENSOR_VERSION == 2 TOUCH_SENSOR_V2_DEFAULT_SAMPLE_CONFIG(500, TOUCH_VOLT_LIM_L_0V5, TOUCH_VOLT_LIM_H_2V2), #elif SOC_TOUCH_SENSOR_VERSION == 3 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] = { }; static touch_channel_config_t s_chan_cfg = { -#if SOC_TOUCH_SENSOR_VERSION == 2 +#if SOC_TOUCH_SENSOR_VERSION == 1 + .abs_active_thresh = {1000}, + .charge_speed = TOUCH_CHARGE_SPEED_7, + .init_charge_volt = TOUCH_INIT_CHARGE_VOLT_LOW, + .group = TOUCH_CHAN_TRIG_GROUP_BOTH, +#elif SOC_TOUCH_SENSOR_VERSION == 2 .active_thresh = { 2000, }, @@ -77,15 +83,24 @@ TEST_CASE("touch_sens_install_uninstall_test", "[touch]") typedef struct { int active_count; int inactive_count; +#if SOC_TOUCH_SENSOR_VERSION == 1 + int hw_active_count; +#endif } test_touch_cb_data_t; static touch_channel_config_t s_test_get_chan_cfg_by_benchmark(uint32_t benchmark[], uint32_t num, float coeff) { - touch_channel_config_t chan_cfg = {}; + touch_channel_config_t chan_cfg = s_chan_cfg; for (int i = 0; i < num; i++) { +#if SOC_TOUCH_SENSOR_VERSION == 1 + chan_cfg.abs_active_thresh[i] = benchmark[i] * (1 - coeff); + printf("[Sampler %d] benchmark %5"PRIu32" abs thresh %4"PRIu32"\n", + i, benchmark[i], chan_cfg.abs_active_thresh[i]); +#else chan_cfg.active_thresh[i] = benchmark[i] * coeff; printf("[Sampler %d] benchmark %5"PRIu32" thresh %4"PRIu32"\n", i, benchmark[i], chan_cfg.active_thresh[i]); +#endif } return chan_cfg; } @@ -108,6 +123,15 @@ static void s_test_touch_do_initial_scanning(touch_sensor_handle_t touch, int sc #define TEST_TCH_IRAM_ATTR #endif +#if SOC_TOUCH_SENSOR_VERSION == 1 +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) +{ + test_touch_cb_data_t *cb_data = (test_touch_cb_data_t *)user_ctx; + cb_data->hw_active_count++; + return false; +} +#endif + 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) { 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 static void s_test_touch_simulate_touch(touch_sensor_handle_t touch, touch_channel_handle_t touch_chan, bool active) { -#if SOC_TOUCH_SENSOR_VERSION == 2 +#if SOC_TOUCH_SENSOR_VERSION <= 2 touch_chan_info_t chan_info = {}; touch_sensor_get_channel_info(touch_chan, &chan_info); touch_ll_set_charge_speed(chan_info.chan_id, active ? TOUCH_CHARGE_SPEED_4 : TOUCH_CHARGE_SPEED_7); @@ -169,7 +193,12 @@ TEST_CASE("touch_sens_active_inactive_test", "[touch]") /* Read benchmark */ uint32_t benchmark[TOUCH_SAMPLE_CFG_NUM] = {0}; - TEST_ESP_OK(touch_channel_read_data(touch_chan, TOUCH_CHAN_DATA_TYPE_BENCHMARK, benchmark)); +#if SOC_TOUCH_SUPPORT_BENCHMARK + touch_chan_data_type_t data_type = TOUCH_CHAN_DATA_TYPE_BENCHMARK; +#else + touch_chan_data_type_t data_type = TOUCH_CHAN_DATA_TYPE_SMOOTH; +#endif // SOC_TOUCH_SUPPORT_BENCHMARK + TEST_ESP_OK(touch_channel_read_data(touch_chan, data_type, benchmark)); /* Test whether success to finish the initial scanning */ for (int i = 0; i < TOUCH_SAMPLE_CFG_NUM; i++) { TEST_ASSERT_GREATER_THAN(0, benchmark[i]); @@ -177,10 +206,12 @@ TEST_CASE("touch_sens_active_inactive_test", "[touch]") /* Re-configure the threshold according to the benchmark */ touch_channel_config_t chan_cfg = s_test_get_chan_cfg_by_benchmark(benchmark, TOUCH_SAMPLE_CFG_NUM, TEST_ACTIVE_THRESH_RATIO); TEST_ESP_OK(touch_sensor_reconfig_channel(touch_chan, &chan_cfg)); - touch_event_callbacks_t callbacks = { .on_active = s_test_touch_on_active_callback, .on_inactive = s_test_touch_on_inactive_callback, +#if SOC_TOUCH_SENSOR_VERSION == 1 + .on_hw_active = s_test_touch_on_hw_active_callback, +#endif }; test_touch_cb_data_t cb_data = {}; TEST_ESP_OK(touch_sensor_register_callbacks(touch, &callbacks, &cb_data)); @@ -196,13 +227,13 @@ TEST_CASE("touch_sens_active_inactive_test", "[touch]") s_test_touch_log_data(touch_chan, TOUCH_SAMPLE_CFG_NUM, "Data Before"); // Simulate touch s_test_touch_simulate_touch(touch, touch_chan, true); - vTaskDelay(pdMS_TO_TICKS(50)); + vTaskDelay(pdMS_TO_TICKS(100)); // Read data after touched s_test_touch_log_data(touch_chan, TOUCH_SAMPLE_CFG_NUM, "Data After "); // Simulate release s_test_touch_simulate_touch(touch, touch_chan, false); - vTaskDelay(pdMS_TO_TICKS(50)); + vTaskDelay(pdMS_TO_TICKS(100)); } printf("\n"); @@ -212,6 +243,12 @@ TEST_CASE("touch_sens_active_inactive_test", "[touch]") TEST_ESP_OK(touch_sensor_del_controller(touch)); /* Check the callback count */ +#if SOC_TOUCH_SENSOR_VERSION == 1 + // The Touch V1 interrupt will keep triggering as long as the channel data is below the threshold + // So it might be greater than the touch count + printf("hardware active interrupt count: %d\n", cb_data.hw_active_count); + TEST_ASSERT_GREATER_OR_EQUAL_UINT32(touch_cnt, cb_data.hw_active_count); +#endif // SOC_TOUCH_SENSOR_VERSION == 1 TEST_ASSERT_EQUAL_INT32(touch_cnt, cb_data.active_count); TEST_ASSERT_EQUAL_INT32(touch_cnt, cb_data.inactive_count); } diff --git a/components/esp_driver_touch_sens/test_apps/touch_sens/sdkconfig.defaults b/components/esp_driver_touch_sens/test_apps/touch_sens/sdkconfig.defaults index b308cb2ddd..8e326e32e1 100644 --- a/components/esp_driver_touch_sens/test_apps/touch_sens/sdkconfig.defaults +++ b/components/esp_driver_touch_sens/test_apps/touch_sens/sdkconfig.defaults @@ -1,2 +1,2 @@ CONFIG_FREERTOS_HZ=1000 -CONFIG_ESP_TASK_WDT=n +CONFIG_ESP_TASK_WDT_INIT=n