diff --git a/components/driver/esp32/touch_sensor.c b/components/driver/esp32/touch_sensor.c index 1980cb40f8..b7781a4780 100644 --- a/components/driver/esp32/touch_sensor.c +++ b/components/driver/esp32/touch_sensor.c @@ -21,6 +21,7 @@ #include "driver/touch_pad.h" #include "driver/rtc_cntl.h" #include "driver/gpio.h" +#include "esp_check.h" #ifndef NDEBUG // Enable built-in checks in queue.h in debug builds @@ -49,13 +50,9 @@ static SemaphoreHandle_t rtc_touch_mux = NULL; #define TOUCH_PAD_SHIFT_ROUND_DEFAULT (8) // ROUND = 2^(n-1); rounding off for fractional. static const char *TOUCH_TAG = "TOUCH_SENSOR"; -#define TOUCH_CHECK(a, str, ret_val) ({ \ - if (!(a)) { \ - ESP_LOGE(TOUCH_TAG,"%s(%d): %s", __FUNCTION__, __LINE__, str); \ - return (ret_val); \ - } \ -}) -#define TOUCH_CHANNEL_CHECK(channel) TOUCH_CHECK(channel < SOC_TOUCH_SENSOR_NUM, "Touch channel error", ESP_ERR_INVALID_ARG) + +#define TOUCH_CHANNEL_CHECK(channel) ESP_RETURN_ON_FALSE(channel < SOC_TOUCH_SENSOR_NUM, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch channel error"); +#define TOUCH_NULL_POINTER_CHECK(p, name) ESP_RETURN_ON_FALSE((p), ESP_ERR_INVALID_ARG, TOUCH_TAG, "input param '"name"' is NULL") #define TOUCH_PARAM_CHECK_STR(s) ""s" parameter error" extern portMUX_TYPE rtc_spinlock; //TODO: Will be placed in the appropriate position after the rtc module is finished. @@ -72,13 +69,13 @@ static esp_err_t _touch_pad_read(touch_pad_t touch_num, uint16_t *touch_value, t esp_err_t touch_pad_isr_handler_register(void (*fn)(void *), void *arg, int no_use, intr_handle_t *handle_no_use) { - TOUCH_CHECK(fn, "Touch_Pad ISR null", ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE(fn, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch_Pad ISR null"); return rtc_isr_register(fn, arg, RTC_CNTL_TOUCH_INT_ST_M); } esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg) { - TOUCH_CHECK(fn, "Touch_Pad ISR null", ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE(fn, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch_Pad ISR null"); return rtc_isr_register(fn, arg, RTC_CNTL_TOUCH_INT_ST_M); } @@ -121,7 +118,7 @@ static void touch_pad_filter_cb(void *arg) } xTimerReset(s_touch_pad_filter->timer, portMAX_DELAY); xSemaphoreGive(rtc_touch_mux); - if (s_filter_cb != NULL) { + if (s_filter_cb) { //return the raw data and filtered data. s_filter_cb(s_touch_pad_filter->raw_val, s_touch_pad_filter->filtered_val); } @@ -139,6 +136,8 @@ esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_cycle) esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_cycle) { + TOUCH_NULL_POINTER_CHECK(sleep_cycle, "sleep_cycle"); + TOUCH_NULL_POINTER_CHECK(meas_cycle, "meas_cycle"); TOUCH_ENTER_CRITICAL(); touch_hal_get_meas_time(meas_cycle); touch_hal_get_sleep_time(sleep_cycle); @@ -149,7 +148,7 @@ esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_cycle) esp_err_t touch_pad_set_trigger_mode(touch_trigger_mode_t mode) { - TOUCH_CHECK((mode < TOUCH_TRIGGER_MAX), TOUCH_PARAM_CHECK_STR("mode"), ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE((mode < TOUCH_TRIGGER_MAX), ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("mode")); TOUCH_ENTER_CRITICAL(); touch_hal_set_trigger_mode(mode); TOUCH_EXIT_CRITICAL(); @@ -158,13 +157,14 @@ esp_err_t touch_pad_set_trigger_mode(touch_trigger_mode_t mode) esp_err_t touch_pad_get_trigger_mode(touch_trigger_mode_t *mode) { + TOUCH_NULL_POINTER_CHECK(mode, "mode"); touch_hal_get_trigger_mode(mode); return ESP_OK; } esp_err_t touch_pad_set_trigger_source(touch_trigger_src_t src) { - TOUCH_CHECK((src < TOUCH_TRIGGER_SOURCE_MAX), TOUCH_PARAM_CHECK_STR("src"), ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE((src < TOUCH_TRIGGER_SOURCE_MAX), ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("src")); TOUCH_ENTER_CRITICAL(); touch_hal_set_trigger_source(src); TOUCH_EXIT_CRITICAL(); @@ -173,15 +173,16 @@ esp_err_t touch_pad_set_trigger_source(touch_trigger_src_t src) esp_err_t touch_pad_get_trigger_source(touch_trigger_src_t *src) { + TOUCH_NULL_POINTER_CHECK(src, "src"); touch_hal_get_trigger_source(src); return ESP_OK; } esp_err_t touch_pad_set_group_mask(uint16_t set1_mask, uint16_t set2_mask, uint16_t en_mask) { - TOUCH_CHECK((set1_mask <= TOUCH_PAD_BIT_MASK_ALL), "touch set1 bitmask error", ESP_ERR_INVALID_ARG); - TOUCH_CHECK((set2_mask <= TOUCH_PAD_BIT_MASK_ALL), "touch set2 bitmask error", ESP_ERR_INVALID_ARG); - TOUCH_CHECK((en_mask <= TOUCH_PAD_BIT_MASK_ALL), "touch work_en bitmask error", ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE((set1_mask <= TOUCH_PAD_BIT_MASK_ALL), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch set1 bitmask error"); + ESP_RETURN_ON_FALSE((set2_mask <= TOUCH_PAD_BIT_MASK_ALL), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch set2 bitmask error"); + ESP_RETURN_ON_FALSE((en_mask <= TOUCH_PAD_BIT_MASK_ALL), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch work_en bitmask error"); TOUCH_ENTER_CRITICAL(); touch_hal_set_group_mask(set1_mask, set2_mask); @@ -193,6 +194,9 @@ esp_err_t touch_pad_set_group_mask(uint16_t set1_mask, uint16_t set2_mask, uint1 esp_err_t touch_pad_get_group_mask(uint16_t *set1_mask, uint16_t *set2_mask, uint16_t *en_mask) { + TOUCH_NULL_POINTER_CHECK(set1_mask, "set1_mask"); + TOUCH_NULL_POINTER_CHECK(set2_mask, "set2_mask"); + TOUCH_NULL_POINTER_CHECK(en_mask, "en_mask"); TOUCH_ENTER_CRITICAL(); touch_hal_get_channel_mask(en_mask); touch_hal_get_group_mask(set1_mask, set2_mask); @@ -203,9 +207,9 @@ esp_err_t touch_pad_get_group_mask(uint16_t *set1_mask, uint16_t *set2_mask, uin esp_err_t touch_pad_clear_group_mask(uint16_t set1_mask, uint16_t set2_mask, uint16_t en_mask) { - TOUCH_CHECK((set1_mask <= TOUCH_PAD_BIT_MASK_ALL), "touch set1 bitmask error", ESP_ERR_INVALID_ARG); - TOUCH_CHECK((set2_mask <= TOUCH_PAD_BIT_MASK_ALL), "touch set2 bitmask error", ESP_ERR_INVALID_ARG); - TOUCH_CHECK((en_mask <= TOUCH_PAD_BIT_MASK_ALL), "touch work_en bitmask error", ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE((set1_mask <= TOUCH_PAD_BIT_MASK_ALL), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch set1 bitmask error"); + ESP_RETURN_ON_FALSE((set2_mask <= TOUCH_PAD_BIT_MASK_ALL), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch set2 bitmask error"); + ESP_RETURN_ON_FALSE((en_mask <= TOUCH_PAD_BIT_MASK_ALL), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch work_en bitmask error"); TOUCH_ENTER_CRITICAL(); touch_hal_clear_channel_mask(en_mask); @@ -245,7 +249,7 @@ bool touch_pad_meas_is_done(void) esp_err_t touch_pad_config(touch_pad_t touch_num, uint16_t threshold) { - TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); + ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_FAIL, TOUCH_TAG, "Touch pad not initialized"); TOUCH_CHANNEL_CHECK(touch_num); touch_fsm_mode_t mode; touch_pad_io_init(touch_num); @@ -297,8 +301,8 @@ esp_err_t touch_pad_init(void) esp_err_t touch_pad_deinit(void) { - TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); - if (s_touch_pad_filter != NULL) { + ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_FAIL, TOUCH_TAG, "Touch pad not initialized"); + if (s_touch_pad_filter) { touch_pad_filter_stop(); touch_pad_filter_delete(); } @@ -337,8 +341,8 @@ static esp_err_t _touch_pad_read(touch_pad_t touch_num, uint16_t *touch_value, t esp_err_t touch_pad_read(touch_pad_t touch_num, uint16_t *touch_value) { TOUCH_CHANNEL_CHECK(touch_num); - TOUCH_CHECK(touch_value != NULL, "touch_value", ESP_ERR_INVALID_ARG); - TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); + TOUCH_NULL_POINTER_CHECK(touch_value, "touch_value"); + ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_FAIL, TOUCH_TAG, "Touch pad not initialized"); esp_err_t res = ESP_OK; touch_fsm_mode_t mode; @@ -351,10 +355,10 @@ esp_err_t touch_pad_read(touch_pad_t touch_num, uint16_t *touch_value) IRAM_ATTR esp_err_t touch_pad_read_raw_data(touch_pad_t touch_num, uint16_t *touch_value) { - TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); + ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_FAIL, TOUCH_TAG, "Touch pad not initialized"); TOUCH_CHANNEL_CHECK(touch_num); - TOUCH_CHECK(touch_value != NULL, "touch_value", ESP_ERR_INVALID_ARG); - TOUCH_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_FAIL); + TOUCH_NULL_POINTER_CHECK(touch_value, "touch_value"); + ESP_RETURN_ON_FALSE(s_touch_pad_filter, ESP_FAIL, TOUCH_TAG, "Touch pad filter not initialized"); *touch_value = s_touch_pad_filter->raw_val[touch_num]; if (*touch_value == 0) { return ESP_ERR_INVALID_STATE; @@ -364,10 +368,10 @@ IRAM_ATTR esp_err_t touch_pad_read_raw_data(touch_pad_t touch_num, uint16_t *tou IRAM_ATTR esp_err_t touch_pad_read_filtered(touch_pad_t touch_num, uint16_t *touch_value) { - TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); + ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_FAIL, TOUCH_TAG, "Touch pad not initialized"); TOUCH_CHANNEL_CHECK(touch_num); - TOUCH_CHECK(touch_value != NULL, "touch_value", ESP_ERR_INVALID_ARG); - TOUCH_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_FAIL); + TOUCH_NULL_POINTER_CHECK(touch_value, "touch_value"); + ESP_RETURN_ON_FALSE(s_touch_pad_filter, ESP_FAIL, TOUCH_TAG, "Touch pad filter not initialized"); *touch_value = (s_touch_pad_filter->filtered_val[touch_num]); if (*touch_value == 0) { return ESP_ERR_INVALID_STATE; @@ -377,13 +381,13 @@ IRAM_ATTR esp_err_t touch_pad_read_filtered(touch_pad_t touch_num, uint16_t *tou esp_err_t touch_pad_set_filter_period(uint32_t new_period_ms) { - TOUCH_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE); - TOUCH_CHECK(new_period_ms > 0, "Touch pad filter period error", ESP_ERR_INVALID_ARG); - TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_ERR_INVALID_STATE); + ESP_RETURN_ON_FALSE(s_touch_pad_filter, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad filter not initialized"); + ESP_RETURN_ON_FALSE(new_period_ms > 0, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch pad filter period error"); + ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad not initialized"); esp_err_t ret = ESP_OK; xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); - if (s_touch_pad_filter != NULL) { + if (s_touch_pad_filter) { xTimerChangePeriod(s_touch_pad_filter->timer, new_period_ms / portTICK_PERIOD_MS, portMAX_DELAY); s_touch_pad_filter->period = new_period_ms; } else { @@ -396,13 +400,13 @@ esp_err_t touch_pad_set_filter_period(uint32_t new_period_ms) esp_err_t touch_pad_get_filter_period(uint32_t *p_period_ms) { - TOUCH_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE); - TOUCH_CHECK(p_period_ms != NULL, "Touch pad period pointer error", ESP_ERR_INVALID_ARG); - TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_ERR_INVALID_STATE); + ESP_RETURN_ON_FALSE(s_touch_pad_filter, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad filter not initialized"); + TOUCH_NULL_POINTER_CHECK(p_period_ms, "p_period_ms"); + ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad not initialized"); esp_err_t ret = ESP_OK; xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); - if (s_touch_pad_filter != NULL) { + if (s_touch_pad_filter) { *p_period_ms = s_touch_pad_filter->period; } else { ESP_LOGE(TOUCH_TAG, "Touch pad filter deleted"); @@ -414,8 +418,8 @@ esp_err_t touch_pad_get_filter_period(uint32_t *p_period_ms) esp_err_t touch_pad_filter_start(uint32_t filter_period_ms) { - TOUCH_CHECK(filter_period_ms >= portTICK_PERIOD_MS, "Touch pad filter period error", ESP_ERR_INVALID_ARG); - TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_ERR_INVALID_STATE); + ESP_RETURN_ON_FALSE(filter_period_ms >= portTICK_PERIOD_MS, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch pad filter period error"); + ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad not initialized"); xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); if (s_touch_pad_filter == NULL) { @@ -445,11 +449,11 @@ err_no_mem: esp_err_t touch_pad_filter_stop(void) { - TOUCH_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE); - TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_ERR_INVALID_STATE); + ESP_RETURN_ON_FALSE(s_touch_pad_filter, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad filter not initialized"); + ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad not initialized"); esp_err_t ret = ESP_OK; xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); - if (s_touch_pad_filter != NULL) { + if (s_touch_pad_filter) { xTimerStop(s_touch_pad_filter->timer, portMAX_DELAY); } else { ESP_LOGE(TOUCH_TAG, "Touch pad filter deleted"); @@ -461,11 +465,11 @@ esp_err_t touch_pad_filter_stop(void) esp_err_t touch_pad_filter_delete(void) { - TOUCH_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE); - TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_ERR_INVALID_STATE); + ESP_RETURN_ON_FALSE(s_touch_pad_filter, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad filter not initialized"); + ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad not initialized"); xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); - if (s_touch_pad_filter != NULL) { - if (s_touch_pad_filter->timer != NULL) { + if (s_touch_pad_filter) { + if (s_touch_pad_filter->timer) { xTimerStop(s_touch_pad_filter->timer, portMAX_DELAY); xTimerDelete(s_touch_pad_filter->timer, portMAX_DELAY); s_touch_pad_filter->timer = NULL; diff --git a/components/driver/esp32s2/include/driver/touch_sensor.h b/components/driver/esp32s2/include/driver/touch_sensor.h index 178e3b1a9d..d90a56e992 100644 --- a/components/driver/esp32s2/include/driver/touch_sensor.h +++ b/components/driver/esp32s2/include/driver/touch_sensor.h @@ -293,7 +293,7 @@ esp_err_t touch_pad_reset_benchmark(touch_pad_t touch_num); * @return * - ESP_OK Success */ -esp_err_t touch_pad_filter_set_config(touch_filter_config_t *filter_info); +esp_err_t touch_pad_filter_set_config(const touch_filter_config_t *filter_info); /** * @brief get parameter of touch sensor filter and detection algorithm. @@ -331,7 +331,7 @@ esp_err_t touch_pad_filter_disable(void); * @return * - ESP_OK Success */ -esp_err_t touch_pad_denoise_set_config(touch_pad_denoise_t *denoise); +esp_err_t touch_pad_denoise_set_config(const touch_pad_denoise_t *denoise); /** * @brief get parameter of denoise pad (TOUCH_PAD_NUM0). @@ -380,7 +380,7 @@ esp_err_t touch_pad_denoise_read_data(uint32_t *data); * @return * - ESP_OK Success */ -esp_err_t touch_pad_waterproof_set_config(touch_pad_waterproof_t *waterproof); +esp_err_t touch_pad_waterproof_set_config(const touch_pad_waterproof_t *waterproof); /** * @brief get parameter of waterproof function. diff --git a/components/driver/esp32s2/touch_sensor.c b/components/driver/esp32s2/touch_sensor.c index 98e390704b..5b6203c9e4 100644 --- a/components/driver/esp32s2/touch_sensor.c +++ b/components/driver/esp32s2/touch_sensor.c @@ -20,6 +20,7 @@ #include "driver/rtc_cntl.h" #include "driver/gpio.h" #include "sdkconfig.h" +#include "esp_check.h" #include "hal/touch_sensor_types.h" #include "hal/touch_sensor_hal.h" @@ -36,18 +37,14 @@ #define TOUCH_PAD_MEASURE_WAIT_DEFAULT (0xFF) // The timer frequency is 8Mhz, the max value is 0xff static const char *TOUCH_TAG = "TOUCH_SENSOR"; -#define TOUCH_CHECK(a, str, ret_val) ({ \ - if (!(a)) { \ - ESP_LOGE(TOUCH_TAG,"%s(%d): %s", __FUNCTION__, __LINE__, str); \ - return (ret_val); \ - } \ -}) + #define TOUCH_CHANNEL_CHECK(channel) do { \ - TOUCH_CHECK(channel < SOC_TOUCH_SENSOR_NUM && channel >= 0, "Touch channel error", ESP_ERR_INVALID_ARG); \ - TOUCH_CHECK(channel != SOC_TOUCH_DENOISE_CHANNEL, "TOUCH0 is internal denoise channel", ESP_ERR_INVALID_ARG); \ + ESP_RETURN_ON_FALSE(channel < SOC_TOUCH_SENSOR_NUM && channel >= 0, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch channel error"); \ + ESP_RETURN_ON_FALSE(channel != SOC_TOUCH_DENOISE_CHANNEL, ESP_ERR_INVALID_ARG, TOUCH_TAG, "TOUCH0 is internal denoise channel"); \ } while (0); -#define TOUCH_CH_MASK_CHECK(mask) TOUCH_CHECK((mask <= TOUCH_PAD_BIT_MASK_ALL), "touch channel bitmask error", ESP_ERR_INVALID_ARG) -#define TOUCH_INTR_MASK_CHECK(mask) TOUCH_CHECK(mask & TOUCH_PAD_INTR_MASK_ALL, "intr mask error", ESP_ERR_INVALID_ARG) +#define TOUCH_CH_MASK_CHECK(mask) ESP_RETURN_ON_FALSE((mask <= TOUCH_PAD_BIT_MASK_ALL), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch channel bitmask error"); +#define TOUCH_INTR_MASK_CHECK(mask) ESP_RETURN_ON_FALSE(mask & TOUCH_PAD_INTR_MASK_ALL, ESP_ERR_INVALID_ARG, TOUCH_TAG, "intr mask error"); +#define TOUCH_NULL_POINTER_CHECK(p, name) ESP_RETURN_ON_FALSE((p), ESP_ERR_INVALID_ARG, TOUCH_TAG, "input param '"name"' is NULL") #define TOUCH_PARAM_CHECK_STR(s) ""s" parameter error" extern portMUX_TYPE rtc_spinlock; //TODO: Will be placed in the appropriate position after the rtc module is finished. @@ -85,7 +82,7 @@ static void touch_pad_workaround_isr_internal(void *arg) esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_mask_t intr_mask) { static bool reg_flag = false; - TOUCH_CHECK(fn != NULL, TOUCH_PARAM_CHECK_STR("intr_mask"), ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE(fn, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("intr_mask")); TOUCH_INTR_MASK_CHECK(intr_mask); uint32_t en_msk = 0; @@ -141,7 +138,7 @@ esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_times) esp_err_t touch_pad_set_idle_channel_connect(touch_pad_conn_type_t type) { - TOUCH_CHECK(type < TOUCH_PAD_CONN_MAX, TOUCH_PARAM_CHECK_STR("type"), ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE(type < TOUCH_PAD_CONN_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("type")); TOUCH_ENTER_CRITICAL(); touch_hal_set_idle_channel_connect(type); TOUCH_EXIT_CRITICAL(); @@ -150,6 +147,7 @@ esp_err_t touch_pad_set_idle_channel_connect(touch_pad_conn_type_t type) esp_err_t touch_pad_get_idle_channel_connect(touch_pad_conn_type_t *type) { + TOUCH_NULL_POINTER_CHECK(type, "type"); touch_hal_get_idle_channel_connect(type); return ESP_OK; } @@ -171,6 +169,7 @@ esp_err_t touch_pad_set_channel_mask(uint16_t enable_mask) esp_err_t touch_pad_get_channel_mask(uint16_t *enable_mask) { + TOUCH_NULL_POINTER_CHECK(enable_mask, "enable_mask"); TOUCH_ENTER_CRITICAL(); touch_hal_get_channel_mask(enable_mask); TOUCH_EXIT_CRITICAL(); @@ -243,6 +242,7 @@ esp_err_t touch_pad_timeout_set(bool enable, uint32_t threshold) esp_err_t touch_pad_timeout_get_threshold(uint32_t *threshold) { + TOUCH_NULL_POINTER_CHECK(threshold, "threshold"); TOUCH_ENTER_CRITICAL(); touch_hal_timeout_get_threshold(threshold); TOUCH_EXIT_CRITICAL(); @@ -286,7 +286,7 @@ esp_err_t touch_pad_init(void) esp_err_t touch_pad_deinit(void) { - TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); + ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_FAIL, TOUCH_TAG, "Touch pad not initialized"); xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); TOUCH_ENTER_CRITICAL(); touch_hal_deinit(); @@ -307,7 +307,8 @@ esp_err_t touch_pad_reset(void) esp_err_t IRAM_ATTR touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data) { - TOUCH_CHECK(touch_num < TOUCH_PAD_MAX && touch_num >= 0, "Touch channel error", ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE(touch_num < TOUCH_PAD_MAX && touch_num >= 0, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch channel error"); + TOUCH_NULL_POINTER_CHECK(raw_data, "raw_data"); TOUCH_ENTER_CRITICAL_SAFE(); *raw_data = touch_hal_read_raw_data(touch_num); TOUCH_EXIT_CRITICAL_SAFE(); @@ -316,6 +317,7 @@ esp_err_t IRAM_ATTR touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw esp_err_t IRAM_ATTR touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth_data) { + TOUCH_NULL_POINTER_CHECK(smooth_data, "smooth_data"); TOUCH_CHANNEL_CHECK(touch_num); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_filter_read_smooth(touch_num, smooth_data); @@ -325,6 +327,7 @@ esp_err_t IRAM_ATTR touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t esp_err_t IRAM_ATTR touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark) { + TOUCH_NULL_POINTER_CHECK(benchmark, "benchmark"); TOUCH_CHANNEL_CHECK(touch_num); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_read_benchmark(touch_num, benchmark); @@ -335,20 +338,21 @@ esp_err_t IRAM_ATTR touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *be /* Should be call after clk enable and filter enable. */ esp_err_t touch_pad_reset_benchmark(touch_pad_t touch_num) { - TOUCH_CHECK(touch_num <= TOUCH_PAD_MAX && touch_num >= 0, "Touch channel error", ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE(touch_num <= TOUCH_PAD_MAX && touch_num >= 0, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch channel error"); TOUCH_ENTER_CRITICAL(); touch_hal_reset_benchmark(touch_num); TOUCH_EXIT_CRITICAL(); return ESP_OK; } -esp_err_t touch_pad_filter_set_config(touch_filter_config_t *filter_info) +esp_err_t touch_pad_filter_set_config(const touch_filter_config_t *filter_info) { - TOUCH_CHECK(filter_info->mode < TOUCH_PAD_FILTER_MAX, TOUCH_PARAM_CHECK_STR("mode"), ESP_ERR_INVALID_ARG); - TOUCH_CHECK(filter_info->debounce_cnt <= TOUCH_DEBOUNCE_CNT_MAX, TOUCH_PARAM_CHECK_STR("debounce"), ESP_ERR_INVALID_ARG); - TOUCH_CHECK(filter_info->noise_thr <= TOUCH_NOISE_THR_MAX, TOUCH_PARAM_CHECK_STR("noise"), ESP_ERR_INVALID_ARG); - TOUCH_CHECK(filter_info->jitter_step <= TOUCH_JITTER_STEP_MAX, TOUCH_PARAM_CHECK_STR("jitter_step"), ESP_ERR_INVALID_ARG); - TOUCH_CHECK(filter_info->smh_lvl < TOUCH_PAD_SMOOTH_MAX, TOUCH_PARAM_CHECK_STR("smooth level"), ESP_ERR_INVALID_ARG); + TOUCH_NULL_POINTER_CHECK(filter_info, "filter_info"); + ESP_RETURN_ON_FALSE(filter_info->mode < TOUCH_PAD_FILTER_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("mode")); + ESP_RETURN_ON_FALSE(filter_info->debounce_cnt <= TOUCH_DEBOUNCE_CNT_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("debounce")); + ESP_RETURN_ON_FALSE(filter_info->noise_thr <= TOUCH_NOISE_THR_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("noise")); + ESP_RETURN_ON_FALSE(filter_info->jitter_step <= TOUCH_JITTER_STEP_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("jitter_step")); + ESP_RETURN_ON_FALSE(filter_info->smh_lvl < TOUCH_PAD_SMOOTH_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("smooth level")); TOUCH_ENTER_CRITICAL(); touch_hal_filter_set_config(filter_info); @@ -359,6 +363,7 @@ esp_err_t touch_pad_filter_set_config(touch_filter_config_t *filter_info) esp_err_t touch_pad_filter_get_config(touch_filter_config_t *filter_info) { + TOUCH_NULL_POINTER_CHECK(filter_info, "filter_info"); TOUCH_ENTER_CRITICAL(); touch_hal_filter_get_config(filter_info); TOUCH_EXIT_CRITICAL(); @@ -398,10 +403,11 @@ esp_err_t touch_pad_denoise_disable(void) return ESP_OK; } -esp_err_t touch_pad_denoise_set_config(touch_pad_denoise_t *denoise) +esp_err_t touch_pad_denoise_set_config(const touch_pad_denoise_t *denoise) { - TOUCH_CHECK(denoise->grade < TOUCH_PAD_DENOISE_MAX, TOUCH_PARAM_CHECK_STR("grade"), ESP_ERR_INVALID_ARG); - TOUCH_CHECK(denoise->cap_level < TOUCH_PAD_DENOISE_CAP_MAX, TOUCH_PARAM_CHECK_STR("cap_level"), ESP_ERR_INVALID_ARG); + TOUCH_NULL_POINTER_CHECK(denoise, "denoise"); + ESP_RETURN_ON_FALSE(denoise->grade < TOUCH_PAD_DENOISE_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("grade")); + ESP_RETURN_ON_FALSE(denoise->cap_level < TOUCH_PAD_DENOISE_CAP_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("cap_level")); const touch_hal_meas_mode_t meas = { .slope = TOUCH_PAD_SLOPE_DEFAULT, @@ -417,6 +423,7 @@ esp_err_t touch_pad_denoise_set_config(touch_pad_denoise_t *denoise) esp_err_t touch_pad_denoise_get_config(touch_pad_denoise_t *denoise) { + TOUCH_NULL_POINTER_CHECK(denoise, "denoise"); TOUCH_ENTER_CRITICAL(); touch_hal_denoise_get_config(denoise); TOUCH_EXIT_CRITICAL(); @@ -425,14 +432,16 @@ esp_err_t touch_pad_denoise_get_config(touch_pad_denoise_t *denoise) esp_err_t touch_pad_denoise_read_data(uint32_t *data) { + TOUCH_NULL_POINTER_CHECK(data, "data"); touch_hal_denoise_read_data(data); return ESP_OK; } -esp_err_t touch_pad_waterproof_set_config(touch_pad_waterproof_t *waterproof) +esp_err_t touch_pad_waterproof_set_config(const touch_pad_waterproof_t *waterproof) { - TOUCH_CHECK(waterproof->guard_ring_pad < SOC_TOUCH_SENSOR_NUM, TOUCH_PARAM_CHECK_STR("pad"), ESP_ERR_INVALID_ARG); - TOUCH_CHECK(waterproof->shield_driver < TOUCH_PAD_SHIELD_DRV_MAX, TOUCH_PARAM_CHECK_STR("shield_driver"), ESP_ERR_INVALID_ARG); + TOUCH_NULL_POINTER_CHECK(waterproof, "waterproof"); + ESP_RETURN_ON_FALSE(waterproof->guard_ring_pad < SOC_TOUCH_SENSOR_NUM, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("pad")); + ESP_RETURN_ON_FALSE(waterproof->shield_driver < TOUCH_PAD_SHIELD_DRV_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("shield_driver")); TOUCH_ENTER_CRITICAL(); touch_hal_waterproof_set_config(waterproof); @@ -442,6 +451,7 @@ esp_err_t touch_pad_waterproof_set_config(touch_pad_waterproof_t *waterproof) esp_err_t touch_pad_waterproof_get_config(touch_pad_waterproof_t *waterproof) { + TOUCH_NULL_POINTER_CHECK(waterproof, "waterproof"); TOUCH_ENTER_CRITICAL(); touch_hal_waterproof_get_config(waterproof); TOUCH_EXIT_CRITICAL(); @@ -468,7 +478,7 @@ esp_err_t touch_pad_waterproof_disable(void) esp_err_t touch_pad_proximity_enable(touch_pad_t touch_num, bool enabled) { esp_err_t ret = ESP_OK; - TOUCH_CHECK(touch_num < TOUCH_PAD_MAX, "Touch channel error", ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE(touch_num < TOUCH_PAD_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch channel error"); TOUCH_ENTER_CRITICAL(); if (!touch_hal_enable_proximity(touch_num, enabled)) { @@ -480,7 +490,7 @@ esp_err_t touch_pad_proximity_enable(touch_pad_t touch_num, bool enabled) esp_err_t touch_pad_proximity_set_count(touch_pad_t touch_num, uint32_t count) { - TOUCH_CHECK(count <= TOUCH_PROXIMITY_MEAS_NUM_MAX, TOUCH_PARAM_CHECK_STR("measure count"), ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE(count <= TOUCH_PROXIMITY_MEAS_NUM_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("measure count")); TOUCH_ENTER_CRITICAL(); touch_hal_proximity_set_meas_times(count); @@ -490,7 +500,7 @@ esp_err_t touch_pad_proximity_set_count(touch_pad_t touch_num, uint32_t count) esp_err_t touch_pad_proximity_get_count(touch_pad_t touch_num, uint32_t *count) { - TOUCH_CHECK(count != NULL, TOUCH_PARAM_CHECK_STR("measure count"), ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE(count, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("measure count")); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_proximity_get_meas_times(count); @@ -509,7 +519,8 @@ esp_err_t touch_pad_proximity_get_count(touch_pad_t touch_num, uint32_t *count) */ esp_err_t touch_pad_proximity_read_meas_cnt(touch_pad_t touch_num, uint32_t *cnt) { - TOUCH_CHECK(touch_hal_proximity_pad_check(touch_num), "touch num is not proximity", ESP_ERR_INVALID_ARG); + TOUCH_NULL_POINTER_CHECK(cnt, "cnt"); + ESP_RETURN_ON_FALSE(touch_hal_proximity_pad_check(touch_num), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch num is not proximity"); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_proximity_read_meas_cnt(touch_num, cnt); TOUCH_EXIT_CRITICAL_SAFE(); @@ -518,7 +529,8 @@ esp_err_t touch_pad_proximity_read_meas_cnt(touch_pad_t touch_num, uint32_t *cnt esp_err_t touch_pad_proximity_get_data(touch_pad_t touch_num, uint32_t *measure_out) { - TOUCH_CHECK(touch_hal_proximity_pad_check(touch_num), "touch num is not proximity", ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE(touch_hal_proximity_pad_check(touch_num), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch num is not proximity"); + TOUCH_NULL_POINTER_CHECK(measure_out, "measure_out"); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_read_benchmark(touch_num, measure_out); TOUCH_EXIT_CRITICAL_SAFE(); @@ -529,6 +541,7 @@ esp_err_t touch_pad_proximity_get_data(touch_pad_t touch_num, uint32_t *measure_ esp_err_t touch_pad_sleep_channel_get_info(touch_pad_sleep_channel_t *slp_config) { + TOUCH_NULL_POINTER_CHECK(slp_config, "slp_config"); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_sleep_channel_get_config(slp_config); TOUCH_EXIT_CRITICAL_SAFE(); @@ -561,6 +574,7 @@ esp_err_t touch_pad_sleep_channel_enable_proximity(touch_pad_t pad_num, bool ena esp_err_t touch_pad_sleep_get_channel_num(touch_pad_t *pad_num) { + TOUCH_NULL_POINTER_CHECK(pad_num, "pad_num"); TOUCH_ENTER_CRITICAL(); touch_hal_sleep_get_channel_num(pad_num); TOUCH_EXIT_CRITICAL(); @@ -577,6 +591,7 @@ esp_err_t touch_pad_sleep_set_threshold(touch_pad_t pad_num, uint32_t touch_thre esp_err_t touch_pad_sleep_get_threshold(touch_pad_t pad_num, uint32_t *touch_thres) { + TOUCH_NULL_POINTER_CHECK(touch_thres, "touch_thres"); TOUCH_ENTER_CRITICAL(); touch_hal_sleep_get_threshold(touch_thres); TOUCH_EXIT_CRITICAL(); @@ -585,6 +600,7 @@ esp_err_t touch_pad_sleep_get_threshold(touch_pad_t pad_num, uint32_t *touch_thr esp_err_t touch_pad_sleep_channel_read_benchmark(touch_pad_t pad_num, uint32_t *benchmark) { + TOUCH_NULL_POINTER_CHECK(benchmark, "benchmark"); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_sleep_read_benchmark(benchmark); TOUCH_EXIT_CRITICAL_SAFE(); @@ -593,6 +609,7 @@ esp_err_t touch_pad_sleep_channel_read_benchmark(touch_pad_t pad_num, uint32_t * esp_err_t touch_pad_sleep_channel_read_smooth(touch_pad_t pad_num, uint32_t *smooth_data) { + TOUCH_NULL_POINTER_CHECK(smooth_data, "smooth_data"); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_sleep_read_smooth(smooth_data); TOUCH_EXIT_CRITICAL_SAFE(); @@ -601,6 +618,7 @@ esp_err_t touch_pad_sleep_channel_read_smooth(touch_pad_t pad_num, uint32_t *smo esp_err_t touch_pad_sleep_channel_read_data(touch_pad_t pad_num, uint32_t *raw_data) { + TOUCH_NULL_POINTER_CHECK(raw_data, "raw_data"); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_sleep_read_data(raw_data); TOUCH_EXIT_CRITICAL_SAFE(); @@ -617,12 +635,14 @@ esp_err_t touch_pad_sleep_channel_reset_benchmark(void) esp_err_t touch_pad_sleep_channel_read_debounce(touch_pad_t pad_num, uint32_t *debounce) { + TOUCH_NULL_POINTER_CHECK(debounce, "debounce"); touch_hal_sleep_read_debounce(debounce); return ESP_OK; } esp_err_t touch_pad_sleep_channel_read_proximity_cnt(touch_pad_t pad_num, uint32_t *approach_cnt) { + TOUCH_NULL_POINTER_CHECK(approach_cnt, "approach_cnt"); touch_hal_sleep_read_proximity_cnt(approach_cnt); return ESP_OK; } diff --git a/components/driver/esp32s3/include/driver/touch_sensor.h b/components/driver/esp32s3/include/driver/touch_sensor.h index 178e3b1a9d..d90a56e992 100644 --- a/components/driver/esp32s3/include/driver/touch_sensor.h +++ b/components/driver/esp32s3/include/driver/touch_sensor.h @@ -293,7 +293,7 @@ esp_err_t touch_pad_reset_benchmark(touch_pad_t touch_num); * @return * - ESP_OK Success */ -esp_err_t touch_pad_filter_set_config(touch_filter_config_t *filter_info); +esp_err_t touch_pad_filter_set_config(const touch_filter_config_t *filter_info); /** * @brief get parameter of touch sensor filter and detection algorithm. @@ -331,7 +331,7 @@ esp_err_t touch_pad_filter_disable(void); * @return * - ESP_OK Success */ -esp_err_t touch_pad_denoise_set_config(touch_pad_denoise_t *denoise); +esp_err_t touch_pad_denoise_set_config(const touch_pad_denoise_t *denoise); /** * @brief get parameter of denoise pad (TOUCH_PAD_NUM0). @@ -380,7 +380,7 @@ esp_err_t touch_pad_denoise_read_data(uint32_t *data); * @return * - ESP_OK Success */ -esp_err_t touch_pad_waterproof_set_config(touch_pad_waterproof_t *waterproof); +esp_err_t touch_pad_waterproof_set_config(const touch_pad_waterproof_t *waterproof); /** * @brief get parameter of waterproof function. diff --git a/components/driver/esp32s3/touch_sensor.c b/components/driver/esp32s3/touch_sensor.c index 9a224d78b2..c120a1c580 100644 --- a/components/driver/esp32s3/touch_sensor.c +++ b/components/driver/esp32s3/touch_sensor.c @@ -20,6 +20,7 @@ #include "driver/rtc_cntl.h" #include "driver/gpio.h" #include "sdkconfig.h" +#include "esp_check.h" #include "hal/touch_sensor_types.h" #include "hal/touch_sensor_hal.h" @@ -36,18 +37,14 @@ #define TOUCH_PAD_MEASURE_WAIT_DEFAULT (0xFF) // The timer frequency is 8Mhz, the max value is 0xff static const char *TOUCH_TAG = "TOUCH_SENSOR"; -#define TOUCH_CHECK(a, str, ret_val) ({ \ - if (!(a)) { \ - ESP_LOGE(TOUCH_TAG,"%s(%d): %s", __FUNCTION__, __LINE__, str); \ - return (ret_val); \ - } \ -}) + #define TOUCH_CHANNEL_CHECK(channel) do { \ - TOUCH_CHECK(channel < SOC_TOUCH_SENSOR_NUM && channel >= 0, "Touch channel error", ESP_ERR_INVALID_ARG); \ - TOUCH_CHECK(channel != SOC_TOUCH_DENOISE_CHANNEL, "TOUCH0 is internal denoise channel", ESP_ERR_INVALID_ARG); \ + ESP_RETURN_ON_FALSE(channel < SOC_TOUCH_SENSOR_NUM && channel >= 0, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch channel error"); \ + ESP_RETURN_ON_FALSE(channel != SOC_TOUCH_DENOISE_CHANNEL, ESP_ERR_INVALID_ARG, TOUCH_TAG, "TOUCH0 is internal denoise channel"); \ } while (0); -#define TOUCH_CH_MASK_CHECK(mask) TOUCH_CHECK((mask <= TOUCH_PAD_BIT_MASK_ALL), "touch channel bitmask error", ESP_ERR_INVALID_ARG) -#define TOUCH_INTR_MASK_CHECK(mask) TOUCH_CHECK(mask & TOUCH_PAD_INTR_MASK_ALL, "intr mask error", ESP_ERR_INVALID_ARG) +#define TOUCH_CH_MASK_CHECK(mask) ESP_RETURN_ON_FALSE((mask <= TOUCH_PAD_BIT_MASK_ALL), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch channel bitmask error"); +#define TOUCH_INTR_MASK_CHECK(mask) ESP_RETURN_ON_FALSE(mask & TOUCH_PAD_INTR_MASK_ALL, ESP_ERR_INVALID_ARG, TOUCH_TAG, "intr mask error"); +#define TOUCH_NULL_POINTER_CHECK(p, name) ESP_RETURN_ON_FALSE((p), ESP_ERR_INVALID_ARG, TOUCH_TAG, "input param '"name"' is NULL") #define TOUCH_PARAM_CHECK_STR(s) ""s" parameter error" extern portMUX_TYPE rtc_spinlock; //TODO: Will be placed in the appropriate position after the rtc module is finished. @@ -64,7 +61,7 @@ static SemaphoreHandle_t rtc_touch_mux = NULL; esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_mask_t intr_mask) { - TOUCH_CHECK(fn != NULL, TOUCH_PARAM_CHECK_STR("intr_mask"), ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE(fn, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("intr_mask")); TOUCH_INTR_MASK_CHECK(intr_mask); uint32_t en_msk = 0; @@ -105,6 +102,8 @@ esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_times) esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_times) { + TOUCH_NULL_POINTER_CHECK(sleep_cycle, "sleep_cycle"); + TOUCH_NULL_POINTER_CHECK(meas_times, "meas_times"); TOUCH_ENTER_CRITICAL(); touch_hal_get_measure_times(meas_times); touch_hal_get_sleep_time(sleep_cycle); @@ -115,7 +114,7 @@ esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_times) esp_err_t touch_pad_set_idle_channel_connect(touch_pad_conn_type_t type) { - TOUCH_CHECK(type < TOUCH_PAD_CONN_MAX, TOUCH_PARAM_CHECK_STR("type"), ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE(type < TOUCH_PAD_CONN_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("type")); TOUCH_ENTER_CRITICAL(); touch_hal_set_idle_channel_connect(type); TOUCH_EXIT_CRITICAL(); @@ -124,6 +123,7 @@ esp_err_t touch_pad_set_idle_channel_connect(touch_pad_conn_type_t type) esp_err_t touch_pad_get_idle_channel_connect(touch_pad_conn_type_t *type) { + TOUCH_NULL_POINTER_CHECK(type, "type"); touch_hal_get_idle_channel_connect(type); return ESP_OK; } @@ -145,6 +145,7 @@ esp_err_t touch_pad_set_channel_mask(uint16_t enable_mask) esp_err_t touch_pad_get_channel_mask(uint16_t *enable_mask) { + TOUCH_NULL_POINTER_CHECK(enable_mask, "enable_mask"); TOUCH_ENTER_CRITICAL(); touch_hal_get_channel_mask(enable_mask); TOUCH_EXIT_CRITICAL(); @@ -217,6 +218,7 @@ esp_err_t touch_pad_timeout_set(bool enable, uint32_t threshold) esp_err_t touch_pad_timeout_get_threshold(uint32_t *threshold) { + TOUCH_NULL_POINTER_CHECK(threshold, "threshold"); TOUCH_ENTER_CRITICAL(); touch_hal_timeout_get_threshold(threshold); TOUCH_EXIT_CRITICAL(); @@ -260,7 +262,7 @@ esp_err_t touch_pad_init(void) esp_err_t touch_pad_deinit(void) { - TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); + ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_FAIL, TOUCH_TAG, "Touch pad not initialized"); xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); TOUCH_ENTER_CRITICAL(); touch_hal_deinit(); @@ -281,7 +283,8 @@ esp_err_t touch_pad_reset(void) esp_err_t IRAM_ATTR touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data) { - TOUCH_CHECK(touch_num < TOUCH_PAD_MAX && touch_num >= 0, "Touch channel error", ESP_ERR_INVALID_ARG); + TOUCH_CHANNEL_CHECK(touch_num); + TOUCH_NULL_POINTER_CHECK(raw_data, "raw_data"); TOUCH_ENTER_CRITICAL_SAFE(); *raw_data = touch_hal_read_raw_data(touch_num); TOUCH_EXIT_CRITICAL_SAFE(); @@ -291,6 +294,7 @@ esp_err_t IRAM_ATTR touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw esp_err_t IRAM_ATTR touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth_data) { TOUCH_CHANNEL_CHECK(touch_num); + TOUCH_NULL_POINTER_CHECK(smooth_data, "smooth_data"); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_filter_read_smooth(touch_num, smooth_data); TOUCH_EXIT_CRITICAL_SAFE(); @@ -300,6 +304,7 @@ esp_err_t IRAM_ATTR touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t esp_err_t IRAM_ATTR touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark) { TOUCH_CHANNEL_CHECK(touch_num); + TOUCH_NULL_POINTER_CHECK(benchmark, "benchmark"); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_read_benchmark(touch_num, benchmark); TOUCH_EXIT_CRITICAL_SAFE(); @@ -309,20 +314,21 @@ esp_err_t IRAM_ATTR touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *be /* Should be call after clk enable and filter enable. */ esp_err_t touch_pad_reset_benchmark(touch_pad_t touch_num) { - TOUCH_CHECK(touch_num <= TOUCH_PAD_MAX && touch_num >= 0, "Touch channel error", ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE(touch_num <= TOUCH_PAD_MAX && touch_num >= 0, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch channel error"); TOUCH_ENTER_CRITICAL(); touch_hal_reset_benchmark(touch_num); TOUCH_EXIT_CRITICAL(); return ESP_OK; } -esp_err_t touch_pad_filter_set_config(touch_filter_config_t *filter_info) +esp_err_t touch_pad_filter_set_config(const touch_filter_config_t *filter_info) { - TOUCH_CHECK(filter_info->mode < TOUCH_PAD_FILTER_MAX, TOUCH_PARAM_CHECK_STR("mode"), ESP_ERR_INVALID_ARG); - TOUCH_CHECK(filter_info->debounce_cnt <= TOUCH_DEBOUNCE_CNT_MAX, TOUCH_PARAM_CHECK_STR("debounce"), ESP_ERR_INVALID_ARG); - TOUCH_CHECK(filter_info->noise_thr <= TOUCH_NOISE_THR_MAX, TOUCH_PARAM_CHECK_STR("noise"), ESP_ERR_INVALID_ARG); - TOUCH_CHECK(filter_info->jitter_step <= TOUCH_JITTER_STEP_MAX, TOUCH_PARAM_CHECK_STR("jitter_step"), ESP_ERR_INVALID_ARG); - TOUCH_CHECK(filter_info->smh_lvl < TOUCH_PAD_SMOOTH_MAX, TOUCH_PARAM_CHECK_STR("smooth level"), ESP_ERR_INVALID_ARG); + TOUCH_NULL_POINTER_CHECK(filter_info, "filter_info"); + ESP_RETURN_ON_FALSE(filter_info->mode < TOUCH_PAD_FILTER_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("mode")); + ESP_RETURN_ON_FALSE(filter_info->debounce_cnt <= TOUCH_DEBOUNCE_CNT_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("debounce")); + ESP_RETURN_ON_FALSE(filter_info->noise_thr <= TOUCH_NOISE_THR_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("noise")); + ESP_RETURN_ON_FALSE(filter_info->jitter_step <= TOUCH_JITTER_STEP_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("jitter_step")); + ESP_RETURN_ON_FALSE(filter_info->smh_lvl < TOUCH_PAD_SMOOTH_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("smooth level")); TOUCH_ENTER_CRITICAL(); touch_hal_filter_set_config(filter_info); @@ -333,6 +339,7 @@ esp_err_t touch_pad_filter_set_config(touch_filter_config_t *filter_info) esp_err_t touch_pad_filter_get_config(touch_filter_config_t *filter_info) { + TOUCH_NULL_POINTER_CHECK(filter_info, "filter_info"); TOUCH_ENTER_CRITICAL(); touch_hal_filter_get_config(filter_info); TOUCH_EXIT_CRITICAL(); @@ -372,10 +379,11 @@ esp_err_t touch_pad_denoise_disable(void) return ESP_OK; } -esp_err_t touch_pad_denoise_set_config(touch_pad_denoise_t *denoise) +esp_err_t touch_pad_denoise_set_config(const touch_pad_denoise_t *denoise) { - TOUCH_CHECK(denoise->grade < TOUCH_PAD_DENOISE_MAX, TOUCH_PARAM_CHECK_STR("grade"), ESP_ERR_INVALID_ARG); - TOUCH_CHECK(denoise->cap_level < TOUCH_PAD_DENOISE_CAP_MAX, TOUCH_PARAM_CHECK_STR("cap_level"), ESP_ERR_INVALID_ARG); + TOUCH_NULL_POINTER_CHECK(denoise, "denoise"); + ESP_RETURN_ON_FALSE(denoise->grade < TOUCH_PAD_DENOISE_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("grade")); + ESP_RETURN_ON_FALSE(denoise->cap_level < TOUCH_PAD_DENOISE_CAP_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("cap_level")); const touch_hal_meas_mode_t meas = { .slope = TOUCH_PAD_SLOPE_DEFAULT, @@ -391,6 +399,7 @@ esp_err_t touch_pad_denoise_set_config(touch_pad_denoise_t *denoise) esp_err_t touch_pad_denoise_get_config(touch_pad_denoise_t *denoise) { + TOUCH_NULL_POINTER_CHECK(denoise, "denoise"); TOUCH_ENTER_CRITICAL(); touch_hal_denoise_get_config(denoise); TOUCH_EXIT_CRITICAL(); @@ -403,10 +412,11 @@ esp_err_t touch_pad_denoise_read_data(uint32_t *data) return ESP_OK; } -esp_err_t touch_pad_waterproof_set_config(touch_pad_waterproof_t *waterproof) +esp_err_t touch_pad_waterproof_set_config(const touch_pad_waterproof_t *waterproof) { - TOUCH_CHECK(waterproof->guard_ring_pad < SOC_TOUCH_SENSOR_NUM, TOUCH_PARAM_CHECK_STR("pad"), ESP_ERR_INVALID_ARG); - TOUCH_CHECK(waterproof->shield_driver < TOUCH_PAD_SHIELD_DRV_MAX, TOUCH_PARAM_CHECK_STR("shield_driver"), ESP_ERR_INVALID_ARG); + TOUCH_NULL_POINTER_CHECK(waterproof, "waterproof"); + ESP_RETURN_ON_FALSE(waterproof->guard_ring_pad < SOC_TOUCH_SENSOR_NUM, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("pad")); + ESP_RETURN_ON_FALSE(waterproof->shield_driver < TOUCH_PAD_SHIELD_DRV_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("shield_driver")); TOUCH_ENTER_CRITICAL(); touch_hal_waterproof_set_config(waterproof); @@ -416,6 +426,7 @@ esp_err_t touch_pad_waterproof_set_config(touch_pad_waterproof_t *waterproof) esp_err_t touch_pad_waterproof_get_config(touch_pad_waterproof_t *waterproof) { + TOUCH_NULL_POINTER_CHECK(waterproof, "waterproof"); TOUCH_ENTER_CRITICAL(); touch_hal_waterproof_get_config(waterproof); TOUCH_EXIT_CRITICAL(); @@ -442,7 +453,7 @@ esp_err_t touch_pad_waterproof_disable(void) esp_err_t touch_pad_proximity_enable(touch_pad_t touch_num, bool enabled) { esp_err_t ret = ESP_OK; - TOUCH_CHECK(touch_num < TOUCH_PAD_MAX, "Touch channel error", ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE(touch_num < TOUCH_PAD_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch channel error"); TOUCH_ENTER_CRITICAL(); if (!touch_hal_enable_proximity(touch_num, enabled)) { @@ -454,7 +465,7 @@ esp_err_t touch_pad_proximity_enable(touch_pad_t touch_num, bool enabled) esp_err_t touch_pad_proximity_set_count(touch_pad_t touch_num, uint32_t count) { - TOUCH_CHECK(count <= TOUCH_PROXIMITY_MEAS_NUM_MAX, TOUCH_PARAM_CHECK_STR("measure count"), ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE(count <= TOUCH_PROXIMITY_MEAS_NUM_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("measure count")); TOUCH_ENTER_CRITICAL(); touch_hal_proximity_set_meas_times(count); @@ -464,7 +475,7 @@ esp_err_t touch_pad_proximity_set_count(touch_pad_t touch_num, uint32_t count) esp_err_t touch_pad_proximity_get_count(touch_pad_t touch_num, uint32_t *count) { - TOUCH_CHECK(count != NULL, TOUCH_PARAM_CHECK_STR("measure count"), ESP_ERR_INVALID_ARG); + ESP_RETURN_ON_FALSE(count, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("measure count")); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_proximity_get_meas_times(count); @@ -483,7 +494,8 @@ esp_err_t touch_pad_proximity_get_count(touch_pad_t touch_num, uint32_t *count) */ esp_err_t touch_pad_proximity_read_meas_cnt(touch_pad_t touch_num, uint32_t *cnt) { - TOUCH_CHECK(touch_hal_proximity_pad_check(touch_num), "touch num is not proximity", ESP_ERR_INVALID_ARG); + TOUCH_NULL_POINTER_CHECK(cnt, "cnt"); + ESP_RETURN_ON_FALSE(touch_hal_proximity_pad_check(touch_num), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch num is not proximity"); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_proximity_read_meas_cnt(touch_num, cnt); TOUCH_EXIT_CRITICAL_SAFE(); @@ -492,7 +504,8 @@ esp_err_t touch_pad_proximity_read_meas_cnt(touch_pad_t touch_num, uint32_t *cnt esp_err_t touch_pad_proximity_get_data(touch_pad_t touch_num, uint32_t *measure_out) { - TOUCH_CHECK(touch_hal_proximity_pad_check(touch_num), "touch num is not proximity", ESP_ERR_INVALID_ARG); + TOUCH_NULL_POINTER_CHECK(measure_out, "measure_out"); + ESP_RETURN_ON_FALSE(touch_hal_proximity_pad_check(touch_num), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch num is not proximity"); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_read_benchmark(touch_num, measure_out); TOUCH_EXIT_CRITICAL_SAFE(); @@ -503,6 +516,7 @@ esp_err_t touch_pad_proximity_get_data(touch_pad_t touch_num, uint32_t *measure_ esp_err_t touch_pad_sleep_channel_get_info(touch_pad_sleep_channel_t *slp_config) { + TOUCH_NULL_POINTER_CHECK(slp_config, "slp_config"); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_sleep_channel_get_config(slp_config); TOUCH_EXIT_CRITICAL_SAFE(); @@ -535,6 +549,7 @@ esp_err_t touch_pad_sleep_channel_enable_proximity(touch_pad_t pad_num, bool ena esp_err_t touch_pad_sleep_get_channel_num(touch_pad_t *pad_num) { + TOUCH_NULL_POINTER_CHECK(pad_num, "pad_num"); TOUCH_ENTER_CRITICAL(); touch_hal_sleep_get_channel_num(pad_num); TOUCH_EXIT_CRITICAL(); @@ -559,6 +574,7 @@ esp_err_t touch_pad_sleep_get_threshold(touch_pad_t pad_num, uint32_t *touch_thr esp_err_t touch_pad_sleep_channel_read_benchmark(touch_pad_t pad_num, uint32_t *benchmark) { + TOUCH_NULL_POINTER_CHECK(benchmark, "benchmark"); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_sleep_read_benchmark(benchmark); TOUCH_EXIT_CRITICAL_SAFE(); @@ -567,6 +583,7 @@ esp_err_t touch_pad_sleep_channel_read_benchmark(touch_pad_t pad_num, uint32_t * esp_err_t touch_pad_sleep_channel_read_smooth(touch_pad_t pad_num, uint32_t *smooth_data) { + TOUCH_NULL_POINTER_CHECK(smooth_data, "smooth_data"); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_sleep_read_smooth(smooth_data); TOUCH_EXIT_CRITICAL_SAFE(); @@ -575,6 +592,7 @@ esp_err_t touch_pad_sleep_channel_read_smooth(touch_pad_t pad_num, uint32_t *smo esp_err_t touch_pad_sleep_channel_read_data(touch_pad_t pad_num, uint32_t *raw_data) { + TOUCH_NULL_POINTER_CHECK(raw_data, "raw_data"); TOUCH_ENTER_CRITICAL_SAFE(); touch_hal_sleep_read_data(raw_data); TOUCH_EXIT_CRITICAL_SAFE(); @@ -591,12 +609,14 @@ esp_err_t touch_pad_sleep_channel_reset_benchmark(void) esp_err_t touch_pad_sleep_channel_read_debounce(touch_pad_t pad_num, uint32_t *debounce) { + TOUCH_NULL_POINTER_CHECK(debounce, "debounce"); touch_hal_sleep_read_debounce(debounce); return ESP_OK; } esp_err_t touch_pad_sleep_channel_read_proximity_cnt(touch_pad_t pad_num, uint32_t *approach_cnt) { + TOUCH_NULL_POINTER_CHECK(approach_cnt, "approach_cnt"); touch_hal_sleep_read_proximity_cnt(approach_cnt); return ESP_OK; } diff --git a/components/driver/test/touch_sensor_test/test_esp32.c b/components/driver/test/touch_sensor_test/test_touch_v1.c similarity index 100% rename from components/driver/test/touch_sensor_test/test_esp32.c rename to components/driver/test/touch_sensor_test/test_touch_v1.c diff --git a/components/driver/test/touch_sensor_test/test_esp32s2.c b/components/driver/test/touch_sensor_test/test_touch_v2.c similarity index 99% rename from components/driver/test/touch_sensor_test/test_esp32s2.c rename to components/driver/test/touch_sensor_test/test_touch_v2.c index 9d9d9fbb14..0085e1b337 100644 --- a/components/driver/test/touch_sensor_test/test_esp32s2.c +++ b/components/driver/test/touch_sensor_test/test_touch_v2.c @@ -5,7 +5,7 @@ */ /* - Tests for the touch sensor device driver for ESP32-S2 only + Tests for the touch sensor device driver for ESP32-S2 & ESP32-S3 */ #include "sdkconfig.h" #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 @@ -1157,25 +1157,32 @@ esp_err_t test_touch_filter_parameter_reset(int reset_cnt) } printf_touch_hw_read("[raw ] cnt:"); printf_touch_benchmark_read("[base] cnt:"); + + /*The benchmark on S2 will track the raw data in real time while the channel is not active. + But on S3, it track the smooth data. And due to the latency of the smooth data, + the benchmark will be updated to the last smooth data. Thus we have to read smooth data here + but read benchmark after one measurement step. */ #if CONFIG_IDF_TARGET_ESP32S3 uint32_t smooth_data[TEST_TOUCH_CHANNEL] = {0}; for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &(smooth_data[i])) ); } #endif + /* Run 1 time measurement, the benchmark will update after finishing the channel scan*/ test_touch_measure_step(1); printf_touch_hw_read("[raw ] cnt+1:"); printf_touch_smooth_read("[smooth]cnt+1:"); printf_touch_benchmark_read("[base] cnt+1:"); - /* ESP32S2 reset benchmark to smooth data */ for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &base_value) ); #if CONFIG_IDF_TARGET_ESP32S2 - /* In ESP32S3, reset to raw data. */ + /* In ESP32S3, benchmark will update to the raw data. */ TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_value) ); + /* Here we compare the benchmark with raw data directly */ TEST_ASSERT_EQUAL_UINT32(base_value, touch_value); #elif CONFIG_IDF_TARGET_ESP32S3 - /* In ESP32S3, reset to smooth data, smooth data filtered from raw data by IIR. */ + /* In ESP32S3, benchmark will update to the smooth data. Smooth data is filtered from raw data by IIR. + Here we compare the benchmark with the previous smooth data*/ TEST_ASSERT_EQUAL_UINT32(base_value, smooth_data[i]); #endif } diff --git a/components/hal/esp32s3/touch_sensor_hal.c b/components/hal/esp32s3/touch_sensor_hal.c index 99d5a3699d..6ec7fc7308 100644 --- a/components/hal/esp32s3/touch_sensor_hal.c +++ b/components/hal/esp32s3/touch_sensor_hal.c @@ -1,16 +1,8 @@ -// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ // The HAL layer for Touch Sensor (common part) diff --git a/components/soc/esp32/include/soc/soc_caps.h b/components/soc/esp32/include/soc/soc_caps.h index 02e4b1acc7..c640df1286 100644 --- a/components/soc/esp32/include/soc/soc_caps.h +++ b/components/soc/esp32/include/soc/soc_caps.h @@ -239,6 +239,7 @@ #define SOC_TIMER_GROUP_TOTAL_TIMERS (SOC_TIMER_GROUPS * SOC_TIMER_GROUP_TIMERS_PER_GROUP) /*-------------------------- TOUCH SENSOR CAPS -------------------------------*/ +#define SOC_TOUCH_VERSION_1 (1) /*!`_. -.. only:: esp32 +.. only:: SOC_TOUCH_VERSION_1 For more information about testing touch sensors in various configurations, please check the `Guide for ESP32-Sense-Kit `_. @@ -61,7 +61,7 @@ Use the function :cpp:func:`touch_pad_set_fsm_mode` to select if touch pad measu Touch State Measurements ^^^^^^^^^^^^^^^^^^^^^^^^ -.. only:: esp32 +.. only:: SOC_TOUCH_VERSION_1 The following two functions come in handy to read raw or filtered measurements from the sensor: @@ -74,7 +74,7 @@ Touch State Measurements Before using :cpp:func:`touch_pad_read_filtered`, you need to initialize and configure the filter by calling specific filter functions described in Section `Filtering of Measurements`_. -.. only:: esp32s2 or esp32s3 +.. only:: SOC_TOUCH_VERSION_2 The following function come in handy to read raw measurements from the sensor: @@ -117,7 +117,7 @@ All functions are provided in pairs to *set* a specific parameter and to *get* t Filtering of Measurements ^^^^^^^^^^^^^^^^^^^^^^^^^ -.. only:: esp32 +.. only:: SOC_TOUCH_VERSION_1 If measurements are noisy, you can filter them with provided API functions. Before using the filter, please start it by calling :cpp:func:`touch_pad_filter_start`. @@ -125,7 +125,7 @@ Filtering of Measurements You can stop the filter with :cpp:func:`touch_pad_filter_stop`. If not required anymore, the filter can be deleted by invoking :cpp:func:`touch_pad_filter_delete`. -.. only:: esp32s2 or esp32s3 +.. only:: SOC_TOUCH_VERSION_2 If measurements are noisy, you can filter them with provided API functions. The {IDF_TARGET_NAME}'s touch functionality provide two sets of APIs for doing this. @@ -150,7 +150,7 @@ Before enabling an interrupt on a touch detection, you should establish a touch Once a detection threshold is established, it can be set during initialization with :cpp:func:`touch_pad_config` or at the runtime with :cpp:func:`touch_pad_set_thresh`. -.. only:: esp32 +.. only:: SOC_TOUCH_VERSION_1 In the next step, configure how interrupts are triggered. They can be triggered below or above the threshold, which is set with the function :cpp:func:`touch_pad_set_trigger_mode`. @@ -161,13 +161,13 @@ Finally, configure and manage interrupt calls using the following functions: When interrupts are operational, you can obtain the information from which particular pad an interrupt came by invoking :cpp:func:`touch_pad_get_status` and clear the pad status with :cpp:func:`touch_pad_clear_status`. -.. only:: esp32 +.. only:: SOC_TOUCH_VERSION_1 .. note:: Interrupts on touch detection operate on raw / unfiltered measurements checked against user established threshold and are implemented in hardware. Enabling the software filtering API (see :ref:`touch_pad-api-filtering-of-measurements`) does not affect this process. -.. only:: esp32 +.. only:: SOC_TOUCH_VERSION_1 Wakeup from Sleep Mode ^^^^^^^^^^^^^^^^^^^^^^ @@ -184,8 +184,8 @@ When interrupts are operational, you can obtain the information from which parti Application Examples -------------------- - - Touch sensor read example: :example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_read`. - - Touch sensor interrupt example: :example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_interrupt`. +- Touch sensor read example: :example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_read`. +- Touch sensor interrupt example: :example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_interrupt`. .. _touch_pad-api-reference: diff --git a/docs/zh_CN/api-reference/peripherals/touch_pad.rst b/docs/zh_CN/api-reference/peripherals/touch_pad.rst index 515b361051..17658dc8f9 100644 --- a/docs/zh_CN/api-reference/peripherals/touch_pad.rst +++ b/docs/zh_CN/api-reference/peripherals/touch_pad.rst @@ -9,13 +9,13 @@ 触摸传感器系统由保护覆盖层、触摸电极、绝缘基板和走线组成,保护覆盖层位于最上层,绝缘基板上设有电极及走线。用户触摸覆盖层将产生电容变化,根据电容变化判断此次触摸是否为有效触摸行为。 -.. only:: esp32 +.. only:: SOC_TOUCH_VERSION_1 - ESP32 上的触摸传感器硬件版本为V1.0,可最多支持 10 个电容式触摸传感器通道/GPIO。 + ESP32 最多可支持 10 个电容式触摸传感器通道/GPIO。 -.. only:: esp32s2 or esp32s3 +.. only:: SOC_TOUCH_VERSION_2 - {IDF_TARGET_NAME} 上的触摸传感器硬件版本为V2.0,可最多支持 14 个电容式触摸传感器通道/GPIO。 + {IDF_TARGET_NAME} 最多可支持 14 个电容式触摸传感器通道/GPIO。 触摸传感器可以以矩阵或滑条等方式组合使用,从而覆盖更大触感区域及更多触感点。触摸传感由软件或专用硬件计时器发起,由有限状态机 (FSM) 硬件控制。 @@ -23,7 +23,7 @@ 请参考 `触摸传感器应用方案简介 `_,查看触摸传感器设计详情和固件开发指南。 -.. only:: esp32 +.. only:: SOC_TOUCH_VERSION_1 如果想评估触摸传感器的多种应用场景,请查看 `ESP32 触摸功能开发套件 `_。 @@ -61,7 +61,7 @@ 触摸状态测量 ^^^^^^^^^^^^^^^^^^^^^^^^ -.. only:: esp32 +.. only:: SOC_TOUCH_VERSION_1 借助以下两个函数从传感器读取原始数据和滤波后的数据: @@ -74,7 +74,7 @@ 使用 :cpp:func:`touch_pad_read_filtered` 之前,需要先调用 `滤波采样`_ 中特定的滤波器函数来初始化并配置该滤波器。 -.. only:: esp32s2 or esp32s3 +.. only:: SOC_TOUCH_VERSION_2 借助以下函数从传感器读取原始数据: @@ -117,7 +117,7 @@ 滤波采样 ^^^^^^^^^^^^^^^^^^^^^^^^^ -.. only:: esp32 +.. only:: SOC_TOUCH_VERSION_1 如果测量中存在噪声,可以使用提供的 API 函数对采样进行滤波。使用滤波器之前,请先调用 :cpp:func:`touch_pad_filter_start` 启动该滤波器。 @@ -125,7 +125,7 @@ 如需停止滤波器,请调用 :cpp:func:`touch_pad_filter_stop` 函数。如果不再使用该滤波器,请调用 :cpp:func:`touch_pad_filter_delete` 删除此滤波器。 -.. only:: esp32s2 or esp32s3 +.. only:: SOC_TOUCH_VERSION_2 如果测量中存在噪声,可以使用提供的 API 函数对采样进行滤波。{IDF_TARGET_NAME} 的触摸功能提供了两套 API 可实现此功能。 @@ -150,7 +150,7 @@ 确定监测阈值后就可以在初始化时调用 :cpp:func:`touch_pad_config` 设置此阈值,或在运行时调用 :cpp:func:`touch_pad_set_thresh` 设置此阈值。 -.. only:: esp32 +.. only:: SOC_TOUCH_VERSION_1 下一步就是设置如何触发中断。用户可以设置在阈值以下或以上触发中断,具体触发模式由函数 :cpp:func:`touch_pad_set_trigger_mode` 设置。 @@ -161,13 +161,13 @@ 中断配置完成后,用户可以调用 :cpp:func:`touch_pad_get_status` 查看中断信号来自哪个触摸传感器,也可以调用 :cpp:func:`touch_pad_clear_status` 清除触摸传感器状态信息。 -.. only:: esp32 +.. only:: SOC_TOUCH_VERSION_1 .. note:: 触摸监测中的中断信号基于原始/未经滤波的采样(对比用户设置的阈值),并在硬件中实现。启用软件滤波 API (请参考 :ref:`touch_pad-api-filtering-of-measurements`)并不会影响这一过程。 -.. only:: esp32 +.. only:: SOC_TOUCH_VERSION_1 从睡眠模式唤醒 ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/examples/peripherals/touch_sensor/touch_sensor_v2/touch_pad_interrupt/main/tp_interrupt_main.c b/examples/peripherals/touch_sensor/touch_sensor_v2/touch_pad_interrupt/main/tp_interrupt_main.c index 226210a142..b3e743ab8d 100644 --- a/examples/peripherals/touch_sensor/touch_sensor_v2/touch_pad_interrupt/main/tp_interrupt_main.c +++ b/examples/peripherals/touch_sensor/touch_sensor_v2/touch_pad_interrupt/main/tp_interrupt_main.c @@ -165,7 +165,7 @@ void app_main(void) touch_pad_set_voltage(TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD); touch_pad_set_idle_channel_connect(TOUCH_PAD_IDLE_CH_CONNECT_DEFAULT); for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { - touch_pad_set_cnt_mode(i, TOUCH_PAD_SLOPE_DEFAULT, TOUCH_PAD_TIE_OPT_DEFAULT); + touch_pad_set_cnt_mode(button[i], TOUCH_PAD_SLOPE_DEFAULT, TOUCH_PAD_TIE_OPT_DEFAULT); } #endif diff --git a/examples/peripherals/touch_sensor/touch_sensor_v2/touch_pad_read/main/tp_read_main.c b/examples/peripherals/touch_sensor/touch_sensor_v2/touch_pad_read/main/tp_read_main.c index 66b7eacb68..16d2b712fb 100644 --- a/examples/peripherals/touch_sensor/touch_sensor_v2/touch_pad_read/main/tp_read_main.c +++ b/examples/peripherals/touch_sensor/touch_sensor_v2/touch_pad_read/main/tp_read_main.c @@ -68,7 +68,7 @@ void app_main(void) touch_pad_set_voltage(TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD); touch_pad_set_idle_channel_connect(TOUCH_PAD_IDLE_CH_CONNECT_DEFAULT); for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { - touch_pad_set_cnt_mode(i, TOUCH_PAD_SLOPE_DEFAULT, TOUCH_PAD_TIE_OPT_DEFAULT); + touch_pad_set_cnt_mode(button[i], TOUCH_PAD_SLOPE_DEFAULT, TOUCH_PAD_TIE_OPT_DEFAULT); } #endif /* Denoise setting at TouchSensor 0. */ diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index fedac54bb7..6146abb8a3 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -1644,7 +1644,6 @@ components/hal/esp32s3/include/hal/mpu_ll.h components/hal/esp32s3/include/hal/mwdt_ll.h components/hal/esp32s3/include/hal/pcnt_ll.h components/hal/esp32s3/include/hal/rtc_cntl_ll.h -components/hal/esp32s3/include/hal/rtc_io_ll.h components/hal/esp32s3/include/hal/rwdt_ll.h components/hal/esp32s3/include/hal/sha_ll.h components/hal/esp32s3/include/hal/sigmadelta_ll.h @@ -1655,8 +1654,6 @@ components/hal/esp32s3/include/hal/spi_ll.h components/hal/esp32s3/include/hal/spimem_flash_ll.h components/hal/esp32s3/include/hal/systimer_ll.h components/hal/esp32s3/include/hal/timer_ll.h -components/hal/esp32s3/include/hal/touch_sensor_hal.h -components/hal/esp32s3/include/hal/touch_sensor_ll.h components/hal/esp32s3/include/hal/trace_ll.h components/hal/esp32s3/include/hal/twai_ll.h components/hal/esp32s3/include/hal/uart_ll.h @@ -1664,7 +1661,6 @@ components/hal/esp32s3/include/hal/uhci_ll.h components/hal/esp32s3/include/hal/usb_ll.h components/hal/esp32s3/include/hal/usb_serial_jtag_ll.h components/hal/esp32s3/interrupt_descriptor_table.c -components/hal/esp32s3/touch_sensor_hal.c components/hal/gdma_hal.c components/hal/gpio_hal.c components/hal/i2c_hal.c @@ -1729,7 +1725,6 @@ components/hal/include/hal/systimer_types.h components/hal/include/hal/timer_hal.h components/hal/include/hal/timer_types.h components/hal/include/hal/touch_sensor_hal.h -components/hal/include/hal/touch_sensor_types.h components/hal/include/hal/twai_hal.h components/hal/include/hal/twai_types.h components/hal/include/hal/uart_hal.h @@ -2280,7 +2275,6 @@ components/soc/esp32/include/soc/sens_struct.h components/soc/esp32/include/soc/slc_reg.h components/soc/esp32/include/soc/slc_struct.h components/soc/esp32/include/soc/soc.h -components/soc/esp32/include/soc/soc_caps.h components/soc/esp32/include/soc/soc_pins.h components/soc/esp32/include/soc/soc_ulp.h components/soc/esp32/include/soc/spi_pins.h @@ -2665,9 +2659,6 @@ components/soc/esp32s3/include/soc/periph_defs.h components/soc/esp32s3/include/soc/reset_reasons.h components/soc/esp32s3/include/soc/rmt_reg.h components/soc/esp32s3/include/soc/rmt_struct.h -components/soc/esp32s3/include/soc/rtc.h -components/soc/esp32s3/include/soc/rtc_cntl_reg.h -components/soc/esp32s3/include/soc/rtc_cntl_struct.h components/soc/esp32s3/include/soc/rtc_gpio_channel.h components/soc/esp32s3/include/soc/rtc_i2c_reg.h components/soc/esp32s3/include/soc/rtc_i2c_struct.h @@ -2680,13 +2671,11 @@ components/soc/esp32s3/include/soc/sdmmc_pins.h components/soc/esp32s3/include/soc/sdmmc_reg.h components/soc/esp32s3/include/soc/sdmmc_struct.h components/soc/esp32s3/include/soc/sens_reg.h -components/soc/esp32s3/include/soc/sens_struct.h components/soc/esp32s3/include/soc/sensitive_reg.h components/soc/esp32s3/include/soc/sensitive_struct.h components/soc/esp32s3/include/soc/sigmadelta_caps.h components/soc/esp32s3/include/soc/soc.h components/soc/esp32s3/include/soc/soc_caps.h -components/soc/esp32s3/include/soc/soc_pins.h components/soc/esp32s3/include/soc/soc_ulp.h components/soc/esp32s3/include/soc/spi_mem_reg.h components/soc/esp32s3/include/soc/spi_mem_struct.h @@ -2703,7 +2692,6 @@ components/soc/esp32s3/include/soc/timer_group_reg.h components/soc/esp32s3/include/soc/timer_group_struct.h components/soc/esp32s3/include/soc/touch_channel.h components/soc/esp32s3/include/soc/touch_sensor_caps.h -components/soc/esp32s3/include/soc/touch_sensor_channel.h components/soc/esp32s3/include/soc/twai_caps.h components/soc/esp32s3/include/soc/twai_struct.h components/soc/esp32s3/include/soc/uart_caps.h @@ -2739,7 +2727,6 @@ components/soc/esp32s3/sdmmc_periph.c components/soc/esp32s3/sigmadelta_periph.c components/soc/esp32s3/spi_periph.c components/soc/esp32s3/timer_periph.c -components/soc/esp32s3/touch_sensor_periph.c components/soc/esp32s3/uart_periph.c components/soc/esp32s3/usb_periph.c components/soc/esp32s3/usb_periph.h