mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(touch_sens): add missing user_filter_ctx initializer for C++
- Add .user_filter_ctx = NULL to TOUCH_SENSOR_DEFAULT_FILTER_CONFIG macro - Rename test_touch_sens_common.c to .cpp for C++ compatibility - Fix C++ compile issues: add spaces between string literals and PRIu32 - Replace VLAs with dynamic memory allocation Merges https://github.com/espressif/esp-idf/pull/17655
This commit is contained in:
@@ -55,6 +55,7 @@ extern "C" {
|
|||||||
#define TOUCH_SENSOR_DEFAULT_FILTER_CONFIG() { \
|
#define TOUCH_SENSOR_DEFAULT_FILTER_CONFIG() { \
|
||||||
.interval_ms = 10, \
|
.interval_ms = 10, \
|
||||||
.data_filter_fn = NULL, /* Set NULL to use default software filter */ \
|
.data_filter_fn = NULL, /* Set NULL to use default software filter */ \
|
||||||
|
.user_filter_ctx = NULL, \
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
set(srcs "test_app_main.c" "test_touch_sens_common.c")
|
set(srcs "test_app_main.c" "test_touch_sens_common.cpp")
|
||||||
|
|
||||||
idf_component_register(SRCS ${srcs}
|
idf_component_register(SRCS ${srcs}
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
|
|||||||
+22
-7
@@ -12,6 +12,7 @@
|
|||||||
#include "hal/touch_sensor_ll.h"
|
#include "hal/touch_sensor_ll.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_attr.h"
|
#include "esp_attr.h"
|
||||||
|
#include "esp_heap_caps.h"
|
||||||
|
|
||||||
static touch_sensor_sample_config_t s_sample_cfg[TOUCH_SAMPLE_CFG_NUM] = {
|
static touch_sensor_sample_config_t s_sample_cfg[TOUCH_SAMPLE_CFG_NUM] = {
|
||||||
#if SOC_TOUCH_SENSOR_VERSION == 1
|
#if SOC_TOUCH_SENSOR_VERSION == 1
|
||||||
@@ -94,11 +95,11 @@ static touch_channel_config_t s_test_get_chan_cfg_by_benchmark(uint32_t benchmar
|
|||||||
for (int i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
#if SOC_TOUCH_SENSOR_VERSION == 1
|
#if SOC_TOUCH_SENSOR_VERSION == 1
|
||||||
chan_cfg.abs_active_thresh[i] = benchmark[i] * (1 - coeff);
|
chan_cfg.abs_active_thresh[i] = benchmark[i] * (1 - coeff);
|
||||||
printf("[Sampler %d] benchmark %5"PRIu32" abs thresh %4"PRIu32"\n",
|
printf("[Sampler %d] benchmark %5" PRIu32 " abs thresh %4" PRIu32 "\n",
|
||||||
i, benchmark[i], chan_cfg.abs_active_thresh[i]);
|
i, benchmark[i], chan_cfg.abs_active_thresh[i]);
|
||||||
#else
|
#else
|
||||||
chan_cfg.active_thresh[i] = benchmark[i] * coeff;
|
chan_cfg.active_thresh[i] = benchmark[i] * coeff;
|
||||||
printf("[Sampler %d] benchmark %5"PRIu32" thresh %4"PRIu32"\n",
|
printf("[Sampler %d] benchmark %5" PRIu32 " thresh %4" PRIu32 "\n",
|
||||||
i, benchmark[i], chan_cfg.active_thresh[i]);
|
i, benchmark[i], chan_cfg.active_thresh[i]);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -161,13 +162,14 @@ static void s_test_touch_simulate_touch(touch_sensor_handle_t touch, touch_chann
|
|||||||
|
|
||||||
static void s_test_touch_log_data(touch_channel_handle_t touch_chan, uint32_t sample_cfg_num, const char *tag)
|
static void s_test_touch_log_data(touch_channel_handle_t touch_chan, uint32_t sample_cfg_num, const char *tag)
|
||||||
{
|
{
|
||||||
uint32_t data[sample_cfg_num];
|
uint32_t *data = (uint32_t *)heap_caps_malloc(sample_cfg_num * sizeof(uint32_t), MALLOC_CAP_INTERNAL);
|
||||||
TEST_ESP_OK(touch_channel_read_data(touch_chan, TOUCH_CHAN_DATA_TYPE_SMOOTH, data));
|
TEST_ESP_OK(touch_channel_read_data(touch_chan, TOUCH_CHAN_DATA_TYPE_SMOOTH, data));
|
||||||
printf("%s:", tag);
|
printf("%s:", tag);
|
||||||
for (int i = 0; i < sample_cfg_num; i++) {
|
for (int i = 0; i < sample_cfg_num; i++) {
|
||||||
printf(" %"PRIu32, data[i]);
|
printf(" %" PRIu32, data[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TEST_ACTIVE_THRESH_RATIO (0.01f)
|
#define TEST_ACTIVE_THRESH_RATIO (0.01f)
|
||||||
@@ -211,6 +213,12 @@ TEST_CASE("touch_sens_active_inactive_test", "[touch]")
|
|||||||
.on_inactive = s_test_touch_on_inactive_callback,
|
.on_inactive = s_test_touch_on_inactive_callback,
|
||||||
#if SOC_TOUCH_SENSOR_VERSION == 1
|
#if SOC_TOUCH_SENSOR_VERSION == 1
|
||||||
.on_hw_active = s_test_touch_on_hw_active_callback,
|
.on_hw_active = s_test_touch_on_hw_active_callback,
|
||||||
|
#endif
|
||||||
|
#if SOC_TOUCH_SENSOR_VERSION > 1
|
||||||
|
.on_measure_done = NULL,
|
||||||
|
.on_scan_done = NULL,
|
||||||
|
.on_timeout = NULL,
|
||||||
|
.on_proximity_meas_done = NULL,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
test_touch_cb_data_t cb_data = {};
|
test_touch_cb_data_t cb_data = {};
|
||||||
@@ -266,9 +274,13 @@ TEST_CASE("touch_sens_current_meas_channel_test", "[touch]")
|
|||||||
touch_sensor_filter_config_t filter_cfg = TOUCH_SENSOR_DEFAULT_FILTER_CONFIG();
|
touch_sensor_filter_config_t filter_cfg = TOUCH_SENSOR_DEFAULT_FILTER_CONFIG();
|
||||||
TEST_ESP_OK(touch_sensor_config_filter(touch, &filter_cfg));
|
TEST_ESP_OK(touch_sensor_config_filter(touch, &filter_cfg));
|
||||||
|
|
||||||
int err_chan[TOUCH_MAX_CHAN_ID - TOUCH_MIN_CHAN_ID + 1] = {[0 ...(TOUCH_MAX_CHAN_ID - TOUCH_MIN_CHAN_ID)] = -1};
|
int err_chan_num = TOUCH_MAX_CHAN_ID - TOUCH_MIN_CHAN_ID + 1;
|
||||||
|
int *err_chan = (int *)malloc(err_chan_num * sizeof(int));
|
||||||
|
for (int i = 0; i < err_chan_num; i++) {
|
||||||
|
err_chan[i] = -1;
|
||||||
|
}
|
||||||
int scan_times = 100;
|
int scan_times = 100;
|
||||||
uint32_t curr_chan[scan_times];
|
uint32_t *curr_chan = (uint32_t *)malloc(scan_times * sizeof(uint32_t));
|
||||||
/* Loop all channels */
|
/* Loop all channels */
|
||||||
for (int ch_id = TOUCH_MIN_CHAN_ID; ch_id <= TOUCH_MAX_CHAN_ID; ch_id++) {
|
for (int ch_id = TOUCH_MIN_CHAN_ID; ch_id <= TOUCH_MAX_CHAN_ID; ch_id++) {
|
||||||
/* New a channel */
|
/* New a channel */
|
||||||
@@ -293,12 +305,15 @@ TEST_CASE("touch_sens_current_meas_channel_test", "[touch]")
|
|||||||
|
|
||||||
/* Check if there is any error in the current measuring channel from any channel */
|
/* Check if there is any error in the current measuring channel from any channel */
|
||||||
bool has_error = false;
|
bool has_error = false;
|
||||||
for (int i = 0; i < TOUCH_MAX_CHAN_ID - TOUCH_MIN_CHAN_ID + 1; i++) {
|
for (int i = 0; i < err_chan_num; i++) {
|
||||||
if (err_chan[i] >= 0) {
|
if (err_chan[i] >= 0) {
|
||||||
ESP_LOGE("TOUCH_TEST", "actual channel is %d, but current measuring channel reads %d", i + TOUCH_MIN_CHAN_ID, err_chan[i]);
|
ESP_LOGE("TOUCH_TEST", "actual channel is %d, but current measuring channel reads %d", i + TOUCH_MIN_CHAN_ID, err_chan[i]);
|
||||||
has_error = true;
|
has_error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TEST_ASSERT_FALSE(has_error);
|
TEST_ASSERT_FALSE(has_error);
|
||||||
|
|
||||||
|
free(err_chan);
|
||||||
|
free(curr_chan);
|
||||||
}
|
}
|
||||||
#endif // SOC_TOUCH_SENSOR_VERSION > 1
|
#endif // SOC_TOUCH_SENSOR_VERSION > 1
|
||||||
Reference in New Issue
Block a user