From 6ca1db3ef2b4e89bd441da4dbeb0a1fcbbc9c607 Mon Sep 17 00:00:00 2001 From: wangyuanze Date: Thu, 18 Aug 2022 16:55:24 +0800 Subject: [PATCH] touch_sensor: fix touch_sensor_v1 filter issue --- components/driver/esp32/touch_sensor.c | 15 ++++++++------- .../touch_sensor_v1/main/test_app_main.c | 2 +- .../touch_sensor_v1/main/test_touch_v1.c | 10 +++++----- .../touch_sensor_v1/pytest_touch_sensor_v1.py | 7 +++++++ .../touch_sensor_v1/sdkconfig.ci.release | 5 +++++ .../touch_sensor_v2/pytest_touch_sensor_v2.py | 7 +++++++ .../touch_sensor_v2/sdkconfig.ci.release | 5 +++++ 7 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 components/driver/test_apps/touch_sensor_v1/sdkconfig.ci.release create mode 100644 components/driver/test_apps/touch_sensor_v2/sdkconfig.ci.release diff --git a/components/driver/esp32/touch_sensor.c b/components/driver/esp32/touch_sensor.c index 52f2219da3..6548c94487 100644 --- a/components/driver/esp32/touch_sensor.c +++ b/components/driver/esp32/touch_sensor.c @@ -34,6 +34,7 @@ typedef struct { TimerHandle_t timer; uint16_t filtered_val[TOUCH_PAD_MAX]; + uint32_t filter_last_val[TOUCH_PAD_MAX]; uint16_t raw_val[TOUCH_PAD_MAX]; uint32_t filter_period; uint32_t period; @@ -97,9 +98,7 @@ esp_err_t touch_pad_set_filter_read_cb(filter_cb_t read_cb) static void touch_pad_filter_cb(void *arg) { - static uint32_t s_filtered_temp[TOUCH_PAD_MAX] = {0}; - - if (s_touch_pad_filter == NULL || rtc_touch_mux == NULL) { + if (s_touch_pad_filter == NULL) { return; } uint16_t val = 0; @@ -110,10 +109,12 @@ static void touch_pad_filter_cb(void *arg) if ((s_touch_pad_init_bit >> i) & 0x1) { _touch_pad_read(i, &val, mode); s_touch_pad_filter->raw_val[i] = val; - s_filtered_temp[i] = s_filtered_temp[i] == 0 ? ((uint32_t)val << TOUCH_PAD_SHIFT_DEFAULT) : s_filtered_temp[i]; - s_filtered_temp[i] = _touch_filter_iir((val << TOUCH_PAD_SHIFT_DEFAULT), - s_filtered_temp[i], TOUCH_PAD_FILTER_FACTOR_DEFAULT); - s_touch_pad_filter->filtered_val[i] = (s_filtered_temp[i] + TOUCH_PAD_SHIFT_ROUND_DEFAULT) >> TOUCH_PAD_SHIFT_DEFAULT; + s_touch_pad_filter->filter_last_val[i] = s_touch_pad_filter->filter_last_val[i] == 0 ? + ((uint32_t)val << TOUCH_PAD_SHIFT_DEFAULT) : s_touch_pad_filter->filter_last_val[i]; + s_touch_pad_filter->filter_last_val[i] = _touch_filter_iir((val << TOUCH_PAD_SHIFT_DEFAULT), + s_touch_pad_filter->filter_last_val[i], TOUCH_PAD_FILTER_FACTOR_DEFAULT); + s_touch_pad_filter->filtered_val[i] = + (s_touch_pad_filter->filter_last_val[i] + TOUCH_PAD_SHIFT_ROUND_DEFAULT) >> TOUCH_PAD_SHIFT_DEFAULT; } } xTimerReset(s_touch_pad_filter->timer, portMAX_DELAY); diff --git a/components/driver/test_apps/touch_sensor_v1/main/test_app_main.c b/components/driver/test_apps/touch_sensor_v1/main/test_app_main.c index 896caa3200..027d2b69c0 100644 --- a/components/driver/test_apps/touch_sensor_v1/main/test_app_main.c +++ b/components/driver/test_apps/touch_sensor_v1/main/test_app_main.c @@ -8,7 +8,7 @@ #include "unity_test_runner.h" #include "esp_heap_caps.h" -#define TEST_MEMORY_LEAK_THRESHOLD (-200) +#define TEST_MEMORY_LEAK_THRESHOLD (-300) static size_t before_free_8bit; static size_t before_free_32bit; diff --git a/components/driver/test_apps/touch_sensor_v1/main/test_touch_v1.c b/components/driver/test_apps/touch_sensor_v1/main/test_touch_v1.c index 350c550b47..6c16c7def3 100644 --- a/components/driver/test_apps/touch_sensor_v1/main/test_touch_v1.c +++ b/components/driver/test_apps/touch_sensor_v1/main/test_touch_v1.c @@ -209,8 +209,8 @@ TEST_CASE("Touch Sensor all channel read test", "[touch]") { #if CONFIG_PM_ENABLE esp_pm_lock_handle_t pm_lock; - esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "test_touch", &pm_lock); - esp_pm_lock_acquire(pm_lock); + TEST_ESP_OK(esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "test_touch", &pm_lock)); + TEST_ESP_OK(esp_pm_lock_acquire(pm_lock)); #endif TOUCH_REG_BASE_TEST(); test_touch_sw_read_test_runner(); @@ -218,8 +218,8 @@ TEST_CASE("Touch Sensor all channel read test", "[touch]") TEST_ESP_OK( test_touch_timer_read() ); TEST_ESP_OK( test_touch_filtered_read() ); #if CONFIG_PM_ENABLE - esp_pm_lock_release(pm_lock); - esp_pm_lock_delete(pm_lock); + TEST_ESP_OK(esp_pm_lock_release(pm_lock)); + TEST_ESP_OK(esp_pm_lock_delete(pm_lock)); #endif } @@ -267,7 +267,7 @@ TEST_CASE("Touch Sensor parameters test", "[touch]") touch_val[1] = test_touch_parameter(touch_list[2], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_HVOLT_2V5, TOUCH_LVOLT_0V6, TOUCH_HVOLT_ATTEN_1V, TOUCH_PAD_SLOPE_DEFAULT); - touch_val[2] = test_touch_parameter(touch_list[0], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, + touch_val[2] = test_touch_parameter(touch_list[2], TOUCH_PAD_MEASURE_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_HVOLT_2V4, TOUCH_LVOLT_0V8, TOUCH_HVOLT_ATTEN_1V5, TOUCH_PAD_SLOPE_DEFAULT); diff --git a/components/driver/test_apps/touch_sensor_v1/pytest_touch_sensor_v1.py b/components/driver/test_apps/touch_sensor_v1/pytest_touch_sensor_v1.py index 86edab8560..5d1c07e26c 100644 --- a/components/driver/test_apps/touch_sensor_v1/pytest_touch_sensor_v1.py +++ b/components/driver/test_apps/touch_sensor_v1/pytest_touch_sensor_v1.py @@ -6,6 +6,13 @@ from pytest_embedded import Dut @pytest.mark.esp32 @pytest.mark.generic +@pytest.mark.parametrize( + 'config', + [ + 'release', + ], + indirect=True, +) def test_touch_sensor_v1(dut: Dut) -> None: dut.expect_exact('Press ENTER to see the list of tests') dut.write('*') diff --git a/components/driver/test_apps/touch_sensor_v1/sdkconfig.ci.release b/components/driver/test_apps/touch_sensor_v1/sdkconfig.ci.release new file mode 100644 index 0000000000..91d93f163e --- /dev/null +++ b/components/driver/test_apps/touch_sensor_v1/sdkconfig.ci.release @@ -0,0 +1,5 @@ +CONFIG_PM_ENABLE=y +CONFIG_FREERTOS_USE_TICKLESS_IDLE=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y diff --git a/components/driver/test_apps/touch_sensor_v2/pytest_touch_sensor_v2.py b/components/driver/test_apps/touch_sensor_v2/pytest_touch_sensor_v2.py index f21311808c..18abe96fa7 100644 --- a/components/driver/test_apps/touch_sensor_v2/pytest_touch_sensor_v2.py +++ b/components/driver/test_apps/touch_sensor_v2/pytest_touch_sensor_v2.py @@ -7,6 +7,13 @@ from pytest_embedded import Dut @pytest.mark.esp32s2 @pytest.mark.esp32s3 @pytest.mark.generic +@pytest.mark.parametrize( + 'config', + [ + 'release', + ], + indirect=True, +) def test_touch_sensor_v2(dut: Dut) -> None: dut.expect_exact('Press ENTER to see the list of tests') dut.write('*') diff --git a/components/driver/test_apps/touch_sensor_v2/sdkconfig.ci.release b/components/driver/test_apps/touch_sensor_v2/sdkconfig.ci.release new file mode 100644 index 0000000000..91d93f163e --- /dev/null +++ b/components/driver/test_apps/touch_sensor_v2/sdkconfig.ci.release @@ -0,0 +1,5 @@ +CONFIG_PM_ENABLE=y +CONFIG_FREERTOS_USE_TICKLESS_IDLE=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y