touch_sensor: fix touch_sensor_v1 filter issue

This commit is contained in:
wangyuanze 2022-08-18 16:55:24 +08:00 committed by Wang Yuan Ze
parent dfbebccf91
commit 6ca1db3ef2
7 changed files with 38 additions and 13 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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('*')

View File

@ -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

View File

@ -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('*')

View File

@ -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