From 5de3f74f5eaa1f9b07f14fc4708621b9467c4f0f 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 | 4 ++-- .../touch_sensor_v1/main/test_touch_v1.c | 12 ++++++------ .../touch_sensor_v1/pytest_touch_sensor_v1.py | 9 ++++++++- .../touch_sensor_v1/sdkconfig.ci.release | 5 +++++ .../touch_sensor_v2/main/test_app_main.c | 2 +- .../touch_sensor_v2/main/test_touch_v2.c | 2 +- .../test_apps/touch_sensor_v2/main/touch_scope.c | 2 +- .../test_apps/touch_sensor_v2/main/touch_scope.h | 2 +- .../touch_sensor_v2/pytest_touch_sensor_v2.py | 9 ++++++++- .../touch_sensor_v2/sdkconfig.ci.release | 5 +++++ .../touch_element/test_apps/main/test_app_main.c | 2 +- .../test_apps/main/test_touch_button.c | 2 +- .../test_apps/main/test_touch_element.c | 2 +- .../test_apps/main/test_touch_matrix.c | 2 +- .../test_apps/main/test_touch_slider.c | 2 +- .../test_apps/pytest_touch_element.py | 2 +- 17 files changed, 52 insertions(+), 27 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 6099769ffd..3e65a7fcf2 100644 --- a/components/driver/esp32/touch_sensor.c +++ b/components/driver/esp32/touch_sensor.c @@ -34,6 +34,7 @@ typedef struct { esp_timer_handle_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; @@ -109,10 +108,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; } } if (s_filter_cb) { 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..f18acf5d6c 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 @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -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 fe0b03709d..00abc7e4b6 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 @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -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..4bc80342ec 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 @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Unlicense OR CC0-1.0 import pytest from pytest_embedded import Dut @@ -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/main/test_app_main.c b/components/driver/test_apps/touch_sensor_v2/main/test_app_main.c index 0ea01c452c..97a766e408 100644 --- a/components/driver/test_apps/touch_sensor_v2/main/test_app_main.c +++ b/components/driver/test_apps/touch_sensor_v2/main/test_app_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/components/driver/test_apps/touch_sensor_v2/main/test_touch_v2.c b/components/driver/test_apps/touch_sensor_v2/main/test_touch_v2.c index 928cb09971..699969fecc 100644 --- a/components/driver/test_apps/touch_sensor_v2/main/test_touch_v2.c +++ b/components/driver/test_apps/touch_sensor_v2/main/test_touch_v2.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/components/driver/test_apps/touch_sensor_v2/main/touch_scope.c b/components/driver/test_apps/touch_sensor_v2/main/touch_scope.c index 94e30a131e..4ff25e6eaf 100644 --- a/components/driver/test_apps/touch_sensor_v2/main/touch_scope.c +++ b/components/driver/test_apps/touch_sensor_v2/main/touch_scope.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/components/driver/test_apps/touch_sensor_v2/main/touch_scope.h b/components/driver/test_apps/touch_sensor_v2/main/touch_scope.h index 79993ea470..cd97761337 100644 --- a/components/driver/test_apps/touch_sensor_v2/main/touch_scope.h +++ b/components/driver/test_apps/touch_sensor_v2/main/touch_scope.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ 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..31d2de4845 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 @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Unlicense OR CC0-1.0 import pytest from pytest_embedded import Dut @@ -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 diff --git a/components/touch_element/test_apps/main/test_app_main.c b/components/touch_element/test_apps/main/test_app_main.c index e6429bb6b2..5b4eb52599 100644 --- a/components/touch_element/test_apps/main/test_app_main.c +++ b/components/touch_element/test_apps/main/test_app_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/components/touch_element/test_apps/main/test_touch_button.c b/components/touch_element/test_apps/main/test_touch_button.c index 24ae89e406..5dc8a65036 100644 --- a/components/touch_element/test_apps/main/test_touch_button.c +++ b/components/touch_element/test_apps/main/test_touch_button.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ diff --git a/components/touch_element/test_apps/main/test_touch_element.c b/components/touch_element/test_apps/main/test_touch_element.c index 6fee84bdde..3d730c4f15 100644 --- a/components/touch_element/test_apps/main/test_touch_element.c +++ b/components/touch_element/test_apps/main/test_touch_element.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ diff --git a/components/touch_element/test_apps/main/test_touch_matrix.c b/components/touch_element/test_apps/main/test_touch_matrix.c index da1f3abd1a..c1272432ed 100644 --- a/components/touch_element/test_apps/main/test_touch_matrix.c +++ b/components/touch_element/test_apps/main/test_touch_matrix.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ diff --git a/components/touch_element/test_apps/main/test_touch_slider.c b/components/touch_element/test_apps/main/test_touch_slider.c index effd3ba068..6c02b2dd3d 100644 --- a/components/touch_element/test_apps/main/test_touch_slider.c +++ b/components/touch_element/test_apps/main/test_touch_slider.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ diff --git a/components/touch_element/test_apps/pytest_touch_element.py b/components/touch_element/test_apps/pytest_touch_element.py index e5651438df..1d3861b406 100644 --- a/components/touch_element/test_apps/pytest_touch_element.py +++ b/components/touch_element/test_apps/pytest_touch_element.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Unlicense OR CC0-1.0 import pytest from pytest_embedded import Dut