From 057b9d61b56e42e27ba26290b19d3f5c786f7a44 Mon Sep 17 00:00:00 2001 From: fuzhibo Date: Tue, 22 Jun 2021 21:53:16 +0800 Subject: [PATCH 1/6] driver(touch): support touch sensor for esp32s3 platform --- components/driver/CMakeLists.txt | 4 +- .../esp32s3/include/driver/touch_sensor.h | 6 +- components/driver/esp32s3/touch_sensor.c | 4 + .../test/touch_sensor_test/test_esp32s2.c | 34 ++- components/esp_hw_support/sleep_modes.c | 10 +- .../hal/esp32s3/include/hal/rtc_io_ll.h | 5 +- .../esp32s3/include/hal/touch_sensor_hal.h | 2 +- .../hal/esp32s3/include/hal/touch_sensor_ll.h | 76 ++++-- components/hal/esp32s3/touch_sensor_hal.c | 3 +- .../hal/include/hal/touch_sensor_types.h | 11 + components/soc/esp32/include/soc/soc_caps.h | 2 +- components/soc/esp32s2/include/soc/soc_caps.h | 2 +- components/soc/esp32s3/include/soc/rtc.h | 3 + .../soc/esp32s3/include/soc/rtc_cntl_reg.h | 48 ++-- .../soc/esp32s3/include/soc/rtc_cntl_struct.h | 6 +- .../soc/esp32s3/include/soc/sens_struct.h | 2 +- components/soc/esp32s3/include/soc/soc_caps.h | 8 +- components/soc/esp32s3/include/soc/soc_pins.h | 1 + .../include/soc/touch_sensor_channel.h | 47 ++-- ...ouch_sensor_caps.h => touch_sensor_pins.h} | 15 +- components/soc/esp32s3/touch_sensor_periph.c | 8 +- docs/en/api-reference/system/sleep_modes.rst | 2 +- .../main/esp32s2/tp_interrupt_main.c | 4 +- .../main/esp32s3/tp_interrupt_main.c | 240 ++++++++++++++++++ .../main/esp32s3/tp_read_main.c | 90 +++++++ .../deep_sleep/main/deep_sleep_example_main.c | 2 +- 26 files changed, 531 insertions(+), 104 deletions(-) create mode 100644 components/driver/esp32s3/touch_sensor.c rename components/soc/esp32s3/include/soc/{touch_sensor_caps.h => touch_sensor_pins.h} (53%) create mode 100644 examples/peripherals/touch_pad_interrupt/main/esp32s3/tp_interrupt_main.c create mode 100644 examples/peripherals/touch_pad_read/main/esp32s3/tp_read_main.c diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index 093e321823..c9026b268c 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -60,7 +60,9 @@ if(${target} STREQUAL "esp32s3") "mcpwm.c" "usb_serial_jtag.c" "spi_slave_hd.c" - "touch_sensor_common.c") + "touch_sensor_common.c" + "esp32s2/touch_sensor.c" # The touch sensor function is the same as the esp32s2 platform. + ) endif() if(IDF_TARGET STREQUAL "esp32c3") diff --git a/components/driver/esp32s3/include/driver/touch_sensor.h b/components/driver/esp32s3/include/driver/touch_sensor.h index 7240590e27..178e3b1a9d 100644 --- a/components/driver/esp32s3/include/driver/touch_sensor.h +++ b/components/driver/esp32s3/include/driver/touch_sensor.h @@ -6,12 +6,12 @@ #pragma once +#include "driver/touch_sensor_common.h" + #ifdef __cplusplus extern "C" { #endif -#include "driver/touch_sensor_common.h" - /** * @brief Set touch sensor FSM start * @note Start FSM after the touch sensor FSM mode is set. @@ -180,6 +180,7 @@ uint32_t touch_pad_read_intr_status_mask(void); /** * @brief Enable touch sensor interrupt by bitmask. + * @note This API can be called in ISR handler. * @param int_mask Pad mask to enable interrupts * @return * - ESP_OK on success @@ -188,6 +189,7 @@ esp_err_t touch_pad_intr_enable(touch_pad_intr_mask_t int_mask); /** * @brief Disable touch sensor interrupt by bitmask. + * @note This API can be called in ISR handler. * @param int_mask Pad mask to disable interrupts * @return * - ESP_OK on success diff --git a/components/driver/esp32s3/touch_sensor.c b/components/driver/esp32s3/touch_sensor.c new file mode 100644 index 0000000000..ba6323ce30 --- /dev/null +++ b/components/driver/esp32s3/touch_sensor.c @@ -0,0 +1,4 @@ +/** + * The touch sensor function is the same as the esp32s2 platform. + * Please refer to the source files of the ESP32S2 platform. +*/ diff --git a/components/driver/test/touch_sensor_test/test_esp32s2.c b/components/driver/test/touch_sensor_test/test_esp32s2.c index a5ddf94ee7..9d9d9fbb14 100644 --- a/components/driver/test/touch_sensor_test/test_esp32s2.c +++ b/components/driver/test/touch_sensor_test/test_esp32s2.c @@ -8,7 +8,7 @@ Tests for the touch sensor device driver for ESP32-S2 only */ #include "sdkconfig.h" -#if CONFIG_IDF_TARGET_ESP32S2 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 #include #include "esp_system.h" @@ -64,9 +64,9 @@ void test_pxp_deinit_io(void) #define TOUCH_EXCEED_TIME_MS (1000) #define TOUCH_REG_BASE_TEST() ({ \ - TEST_ASSERT_EQUAL_UINT32(REG_GET_FIELD(RTC_CNTL_DATE_REG, RTC_CNTL_CNTL_DATE), RTCCNTL.date.date); \ - TEST_ASSERT_EQUAL_UINT32(REG_GET_FIELD(SENS_SARDATE_REG, SENS_SAR_DATE), SENS.sardate.sar_date); \ - TEST_ASSERT_EQUAL_UINT32(REG_GET_FIELD(RTC_IO_DATE_REG, RTC_IO_IO_DATE), RTCIO.date.date); \ + TEST_ASSERT_EQUAL_UINT32(REG_READ(RTC_CNTL_DATE_REG), RTCCNTL.date.date); \ + TEST_ASSERT_EQUAL_UINT32(REG_READ(SENS_SARDATE_REG), SENS.sardate.sar_date); \ + TEST_ASSERT_EQUAL_UINT32(REG_READ(RTC_IO_DATE_REG), RTCIO.date.date); \ }) #define TEST_TOUCH_COUNT_NUM (5) @@ -1157,16 +1157,28 @@ esp_err_t test_touch_filter_parameter_reset(int reset_cnt) } printf_touch_hw_read("[raw ] cnt:"); printf_touch_benchmark_read("[base] cnt:"); - - test_touch_measure_step(1); - /* ESP32S2 reset benchmark to raw data */ +#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_read_raw_data(touch_list[i], &touch_value) ); - TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &base_value) ); - TEST_ASSERT_EQUAL_UINT32(base_value, touch_value); + TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &(smooth_data[i])) ); } +#endif + 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. */ + TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_value) ); + 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. */ + TEST_ASSERT_EQUAL_UINT32(base_value, smooth_data[i]); +#endif + } int test_cnt = 2; while (test_cnt--) { @@ -2115,4 +2127,4 @@ void test_touch_slope_debug(int pad_num) TEST_ESP_OK( touch_pad_deinit() ); } -#endif // CONFIG_IDF_TARGET_ESP32S2 +#endif // CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 0b88d4c8ec..c9278b91ec 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -364,10 +364,12 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags) if (deep_sleep) { if (s_config.wakeup_triggers & RTC_TOUCH_TRIG_EN) { touch_wakeup_prepare(); +#if CONFIG_IDF_TARGET_ESP32S2 /* Workaround: In deep sleep, for ESP32S2, Power down the RTC_PERIPH will change the slope configuration of Touch sensor sleep pad. * The configuration change will change the reading of the sleep pad, which will cause the touch wake-up sensor to trigger falsely. */ pd_flags &= ~RTC_SLEEP_PD_RTC_PERIPH; +#endif } } else { /* In light sleep, the RTC_PERIPH power domain should be in the power-on state (Power on the touch circuit in light sleep), @@ -702,7 +704,7 @@ esp_err_t esp_sleep_disable_wakeup_source(esp_sleep_source_t source) s_config.ext1_trigger_mode = 0; s_config.wakeup_triggers &= ~RTC_EXT1_TRIG_EN; #endif -#if SOC_TOUCH_PAD_WAKE_SUPPORTED +#if SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP } else if (CHECK_SOURCE(source, ESP_SLEEP_WAKEUP_TOUCHPAD, RTC_TOUCH_TRIG_EN)) { s_config.wakeup_triggers &= ~RTC_TOUCH_TRIG_EN; #endif @@ -1065,7 +1067,7 @@ esp_sleep_wakeup_cause_t esp_sleep_get_wakeup_cause(void) } else if (wakeup_cause & RTC_EXT1_TRIG_EN) { return ESP_SLEEP_WAKEUP_EXT1; #endif -#if SOC_TOUCH_PAD_WAKE_SUPPORTED +#if SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP } else if (wakeup_cause & RTC_TOUCH_TRIG_EN) { return ESP_SLEEP_WAKEUP_TOUCHPAD; #endif @@ -1137,7 +1139,7 @@ static uint32_t get_power_down_flags(void) // RTC_PERIPH is needed for EXT0 wakeup and GPIO wakeup. // If RTC_PERIPH is auto, and EXT0/GPIO aren't enabled, power down RTC_PERIPH. if (s_config.pd_options[ESP_PD_DOMAIN_RTC_PERIPH] == ESP_PD_OPTION_AUTO) { -#if SOC_TOUCH_PAD_WAKE_SUPPORTED +#if SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP uint32_t wakeup_source = RTC_TOUCH_TRIG_EN; #if SOC_ULP_SUPPORTED wakeup_source |= RTC_ULP_TRIG_EN; @@ -1155,7 +1157,7 @@ static uint32_t get_power_down_flags(void) } else { s_config.pd_options[ESP_PD_DOMAIN_RTC_PERIPH] = ESP_PD_OPTION_OFF; } -#endif // SOC_TOUCH_PAD_WAKE_SUPPORTED +#endif // SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP } #if SOC_PM_SUPPORT_CPU_PD diff --git a/components/hal/esp32s3/include/hal/rtc_io_ll.h b/components/hal/esp32s3/include/hal/rtc_io_ll.h index bde6bf3c66..bdf3a77156 100644 --- a/components/hal/esp32s3/include/hal/rtc_io_ll.h +++ b/components/hal/esp32s3/include/hal/rtc_io_ll.h @@ -56,14 +56,14 @@ typedef enum { static inline void rtcio_ll_function_select(int rtcio_num, rtcio_ll_func_t func) { if (func == RTCIO_FUNC_RTC) { - // SENS.sar_io_mux_conf.iomux_clk_gate_en = 1; + SENS.sar_peri_clk_gate_conf.iomux_clk_en = 1; // 0: GPIO connected to digital GPIO module. 1: GPIO connected to analog RTC module. SET_PERI_REG_MASK(rtc_io_desc[rtcio_num].reg, (rtc_io_desc[rtcio_num].mux)); //0:RTC FUNCTION 1,2,3:Reserved SET_PERI_REG_BITS(rtc_io_desc[rtcio_num].reg, RTC_IO_TOUCH_PAD1_FUN_SEL_V, RTCIO_LL_PIN_FUNC, rtc_io_desc[rtcio_num].func); } else if (func == RTCIO_FUNC_DIGITAL) { CLEAR_PERI_REG_MASK(rtc_io_desc[rtcio_num].reg, (rtc_io_desc[rtcio_num].mux)); - // SENS.sar_io_mux_conf.iomux_clk_gate_en = 0; + SENS.sar_peri_clk_gate_conf.iomux_clk_en = 0; } } @@ -276,6 +276,7 @@ static inline void rtcio_ll_force_unhold_all(void) */ static inline void rtcio_ll_wakeup_enable(int rtcio_num, rtcio_ll_wake_type_t type) { + SENS.sar_peri_clk_gate_conf.iomux_clk_en = 1; RTCIO.pin[rtcio_num].wakeup_enable = 0x1; RTCIO.pin[rtcio_num].int_type = type; } diff --git a/components/hal/esp32s3/include/hal/touch_sensor_hal.h b/components/hal/esp32s3/include/hal/touch_sensor_hal.h index 565bde40c6..8dc0263d94 100644 --- a/components/hal/esp32s3/include/hal/touch_sensor_hal.h +++ b/components/hal/esp32s3/include/hal/touch_sensor_hal.h @@ -18,7 +18,7 @@ * See readme.md in hal/include/hal/readme.md ******************************************************************************/ -// The HAL layer for touch sensor (esp32s2 specific part) +// The HAL layer for touch sensor (ESP32-S3 specific part) #pragma once diff --git a/components/hal/esp32s3/include/hal/touch_sensor_ll.h b/components/hal/esp32s3/include/hal/touch_sensor_ll.h index 1d62690be0..7af44b463a 100644 --- a/components/hal/esp32s3/include/hal/touch_sensor_ll.h +++ b/components/hal/esp32s3/include/hal/touch_sensor_ll.h @@ -1,4 +1,4 @@ -// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD +// 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. @@ -174,7 +174,11 @@ static inline void touch_ll_get_voltage_attenuation(touch_volt_atten_t *atten) */ static inline void touch_ll_set_slope(touch_pad_t touch_num, touch_cnt_slope_t slope) { - abort();//IDF-3417 + if (touch_num < TOUCH_PAD_NUM10) { + SET_PERI_REG_BITS(RTC_CNTL_TOUCH_DAC_REG, RTC_CNTL_TOUCH_PAD0_DAC_V, slope, (RTC_CNTL_TOUCH_PAD0_DAC_S - touch_num * 3)); + } else { + SET_PERI_REG_BITS(RTC_CNTL_TOUCH_DAC1_REG, RTC_CNTL_TOUCH_PAD10_DAC_V, slope, (RTC_CNTL_TOUCH_PAD10_DAC_S - (touch_num - TOUCH_PAD_NUM10) * 3)); + } } /** @@ -189,7 +193,11 @@ static inline void touch_ll_set_slope(touch_pad_t touch_num, touch_cnt_slope_t s */ static inline void touch_ll_get_slope(touch_pad_t touch_num, touch_cnt_slope_t *slope) { - abort();//IDF-3417 + if (touch_num < TOUCH_PAD_NUM10) { + *slope = GET_PERI_REG_BITS2(RTC_CNTL_TOUCH_DAC_REG, RTC_CNTL_TOUCH_PAD0_DAC_V, (RTC_CNTL_TOUCH_PAD0_DAC_S - touch_num * 3)); + } else { + *slope = GET_PERI_REG_BITS2(RTC_CNTL_TOUCH_DAC1_REG, RTC_CNTL_TOUCH_PAD10_DAC_V, (RTC_CNTL_TOUCH_PAD10_DAC_S - (touch_num - TOUCH_PAD_NUM10) * 3)); + } } /** @@ -413,7 +421,7 @@ static inline void touch_ll_clear_trigger_status_mask(void) static inline uint32_t IRAM_ATTR touch_ll_read_raw_data(touch_pad_t touch_num) { SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_RAW; - return SENS.sar_touch_status[touch_num - 1].touch_pad1_data; + return SENS.sar_touch_status[touch_num - 1].touch_pad_data; } /** @@ -490,19 +498,22 @@ static inline touch_pad_t IRAM_ATTR touch_ll_get_current_meas_channel(void) static inline void touch_ll_intr_enable(touch_pad_intr_mask_t int_mask) { if (int_mask & TOUCH_PAD_INTR_MASK_DONE) { - RTCCNTL.int_ena.rtc_touch_done = 1; + RTCCNTL.int_ena_w1ts.rtc_touch_done_w1ts = 1; } if (int_mask & TOUCH_PAD_INTR_MASK_ACTIVE) { - RTCCNTL.int_ena.rtc_touch_active = 1; + RTCCNTL.int_ena_w1ts.rtc_touch_active_w1ts = 1; } if (int_mask & TOUCH_PAD_INTR_MASK_INACTIVE) { - RTCCNTL.int_ena.rtc_touch_inactive = 1; + RTCCNTL.int_ena_w1ts.rtc_touch_inactive_w1ts = 1; } if (int_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) { - RTCCNTL.int_ena.rtc_touch_scan_done = 1; + RTCCNTL.int_ena_w1ts.rtc_touch_scan_done_w1ts = 1; } if (int_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) { - RTCCNTL.int_ena.rtc_touch_timeout = 1; + RTCCNTL.int_ena_w1ts.rtc_touch_timeout_w1ts = 1; + } + if (int_mask & TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE) { + RTCCNTL.int_ena_w1ts.rtc_touch_approach_loop_done_w1ts = 1; } } @@ -514,19 +525,22 @@ static inline void touch_ll_intr_enable(touch_pad_intr_mask_t int_mask) static inline void touch_ll_intr_disable(touch_pad_intr_mask_t int_mask) { if (int_mask & TOUCH_PAD_INTR_MASK_DONE) { - RTCCNTL.int_ena.rtc_touch_done = 0; + RTCCNTL.int_ena_w1tc.rtc_touch_done_w1tc = 1; } if (int_mask & TOUCH_PAD_INTR_MASK_ACTIVE) { - RTCCNTL.int_ena.rtc_touch_active = 0; + RTCCNTL.int_ena_w1tc.rtc_touch_active_w1tc = 1; } if (int_mask & TOUCH_PAD_INTR_MASK_INACTIVE) { - RTCCNTL.int_ena.rtc_touch_inactive = 0; + RTCCNTL.int_ena_w1tc.rtc_touch_inactive_w1tc = 1; } if (int_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) { - RTCCNTL.int_ena.rtc_touch_scan_done = 0; + RTCCNTL.int_ena_w1tc.rtc_touch_scan_done_w1tc = 1; } if (int_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) { - RTCCNTL.int_ena.rtc_touch_timeout = 0; + RTCCNTL.int_ena_w1tc.rtc_touch_timeout_w1tc = 1; + } + if (int_mask & TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE) { + RTCCNTL.int_ena_w1tc.rtc_touch_approach_loop_done_w1tc = 1; } } @@ -552,6 +566,9 @@ static inline void touch_ll_intr_clear(touch_pad_intr_mask_t int_mask) if (int_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) { RTCCNTL.int_clr.rtc_touch_timeout = 1; } + if (int_mask & TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE) { + RTCCNTL.int_clr.rtc_touch_approach_loop_done = 1; + } } /** @@ -579,6 +596,9 @@ static inline uint32_t touch_ll_read_intr_status_mask(void) if (intr_st & RTC_CNTL_TOUCH_TIMEOUT_INT_ST_M) { intr_msk |= TOUCH_PAD_INTR_MASK_TIMEOUT; } + if (intr_st & RTC_CNTL_TOUCH_APPROACH_LOOP_DONE_INT_ST_M) { + intr_msk |= TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE; + } return (intr_msk & TOUCH_PAD_INTR_MASK_ALL); } @@ -641,7 +661,7 @@ static inline void touch_ll_timeout_get_threshold(uint32_t *threshold) static inline void IRAM_ATTR touch_ll_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth_data) { SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_SMOOTH; - *smooth_data = SENS.sar_touch_status[touch_num - 1].touch_pad1_data; + *smooth_data = SENS.sar_touch_status[touch_num - 1].touch_pad_data; } /** @@ -654,7 +674,7 @@ static inline void IRAM_ATTR touch_ll_filter_read_smooth(touch_pad_t touch_num, static inline void IRAM_ATTR touch_ll_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark) { SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_BENCHMARK; - *benchmark = SENS.sar_touch_status[touch_num - 1].touch_pad1_data; + *benchmark = SENS.sar_touch_status[touch_num - 1].touch_pad_data; } /** @@ -749,9 +769,9 @@ static inline void touch_ll_filter_get_debounce(uint32_t *dbc_cnt) static inline void touch_ll_filter_set_noise_thres(uint32_t noise_thr) { RTCCNTL.touch_filter_ctrl.touch_noise_thres = noise_thr; - RTCCNTL.touch_filter_ctrl.touch_neg_noise_thres = noise_thr; - RTCCNTL.touch_filter_ctrl.touch_neg_noise_limit = 0xF; - RTCCNTL.touch_filter_ctrl.touch_hysteresis = 2; + RTCCNTL.touch_filter_ctrl.config2 = noise_thr; + RTCCNTL.touch_filter_ctrl.config1 = 0xF; + RTCCNTL.touch_filter_ctrl.config3 = 2; } /** @@ -889,7 +909,7 @@ static inline void touch_ll_denoise_get_grade(touch_pad_denoise_grade_t *grade) */ static inline void touch_ll_denoise_read_data(uint32_t *data) { - *data = SENS.sar_touch_status0.touch_denoise_data; + *data = SENS.sar_touch_denoise.touch_denoise_data; } /************************ Waterproof register setting ************************/ @@ -1014,6 +1034,13 @@ static inline void touch_ll_proximity_get_meas_times(uint32_t *times) */ static inline void touch_ll_proximity_read_meas_cnt(touch_pad_t touch_num, uint32_t *cnt) { + if (SENS.sar_touch_conf.touch_approach_pad0 == touch_num) { + *cnt = SENS.sar_touch_appr_status.touch_approach_pad0_cnt; + } else if (SENS.sar_touch_conf.touch_approach_pad1 == touch_num) { + *cnt = SENS.sar_touch_appr_status.touch_approach_pad1_cnt; + } else if (SENS.sar_touch_conf.touch_approach_pad2 == touch_num) { + *cnt = SENS.sar_touch_appr_status.touch_approach_pad2_cnt; + } } /** @@ -1111,17 +1138,22 @@ static inline bool touch_ll_sleep_get_approach_status(void) */ static inline void touch_ll_sleep_read_benchmark(uint32_t *benchmark) { + SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_BENCHMARK; + *benchmark = SENS.sar_touch_slp_status.touch_slp_data; } static inline void touch_ll_sleep_read_smooth(uint32_t *smooth_data) { + SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_SMOOTH; + *smooth_data = SENS.sar_touch_slp_status.touch_slp_data; } +/* Workaround: Note: sleep pad raw data is not in `sar_touch_slp_status` */ static inline void touch_ll_sleep_read_data(uint32_t *raw_data) { uint32_t touch_num = RTCCNTL.touch_slp_thres.touch_slp_pad; SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_RAW; - *raw_data = SENS.sar_touch_status[touch_num - 1].touch_pad1_data; + *raw_data = SENS.sar_touch_status[touch_num - 1].touch_pad_data; } static inline void touch_ll_sleep_reset_benchmark(void) @@ -1146,6 +1178,7 @@ static inline void touch_ll_sleep_low_power(bool is_low_power) */ static inline void touch_ll_sleep_read_debounce(uint32_t *debounce) { + *debounce = SENS.sar_touch_slp_status.touch_slp_debounce; } /** @@ -1154,6 +1187,7 @@ static inline void touch_ll_sleep_read_debounce(uint32_t *debounce) */ static inline void touch_ll_sleep_read_proximity_cnt(uint32_t *approach_cnt) { + *approach_cnt = SENS.sar_touch_appr_status.touch_slp_approach_cnt; } /** diff --git a/components/hal/esp32s3/touch_sensor_hal.c b/components/hal/esp32s3/touch_sensor_hal.c index f9a43465d8..99d5a3699d 100644 --- a/components/hal/esp32s3/touch_sensor_hal.c +++ b/components/hal/esp32s3/touch_sensor_hal.c @@ -1,4 +1,4 @@ -// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD +// 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. @@ -14,6 +14,7 @@ // The HAL layer for Touch Sensor (common part) +#include "soc/soc_pins.h" #include "hal/touch_sensor_hal.h" #include "hal/touch_sensor_types.h" #include "soc/soc_caps.h" diff --git a/components/hal/include/hal/touch_sensor_types.h b/components/hal/include/hal/touch_sensor_types.h index ec027bf870..373d978260 100644 --- a/components/hal/include/hal/touch_sensor_types.h +++ b/components/hal/include/hal/touch_sensor_types.h @@ -155,12 +155,23 @@ typedef enum { TOUCH_PAD_INTR_MASK_INACTIVE = BIT(2), /*! +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "esp_log.h" +#include "driver/touch_pad.h" +#include "soc/rtc_periph.h" +#include "soc/sens_periph.h" +#include "esp_sleep.h" + +static const char *TAG = "Touch pad"; + +static QueueHandle_t que_touch = NULL; +typedef struct touch_msg { + touch_pad_intr_mask_t intr_mask; + uint32_t pad_status_msk; + uint32_t curr_pad; +} touch_event_t; + +#define TOUCH_BUTTON_NUM 4 +#define TOUCH_BUTTON_WATERPROOF_ENABLE 1 +#define TOUCH_BUTTON_DENOISE_ENABLE 1 +#define TOUCH_CHANGE_CONFIG 0 + +static const touch_pad_t button[TOUCH_BUTTON_NUM] = { + TOUCH_PAD_NUM7, // 'SELECT' button. + TOUCH_PAD_NUM9, // 'MENU' button. + TOUCH_PAD_NUM11, // 'BACK' button. + TOUCH_PAD_NUM13, // Guard ring for waterproof design. + // If this pad be touched, other pads no response. +}; + +/* + * Touch threshold. The threshold determines the sensitivity of the touch. + * This threshold is derived by testing changes in readings from different touch channels. + * If (raw_data - benchmark) > benchmark * threshold, the pad be activated. + * If (raw_data - benchmark) < benchmark * threshold, the pad be inactivated. + */ +static const float button_threshold[TOUCH_BUTTON_NUM] = { + 0.2, // 20%. + 0.2, // 20%. + 0.2, // 20%. + 0.1, // 10%. +}; + +/* + Handle an interrupt triggered when a pad is touched. + Recognize what pad has been touched and save it in a table. + */ +static void touchsensor_interrupt_cb(void *arg) +{ + int task_awoken = pdFALSE; + touch_event_t evt; + + evt.intr_mask = touch_pad_read_intr_status_mask(); + evt.pad_status_msk = touch_pad_get_status(); + /* Note: Obtaining channel information in the interrupt callback function as the channel that triggers the interrupt is risky. + If the execution of the interrupt callback function is delayed by a channel measurement time, + the channel information obtained is wrong. Both light sleep and SPI FLASH reading and + writing may delay the response of the interrupt function. */ + evt.curr_pad = touch_pad_get_current_meas_channel(); + + xQueueSendFromISR(que_touch, &evt, &task_awoken); + if (task_awoken == pdTRUE) { + portYIELD_FROM_ISR(); + } +} + +static void tp_example_set_thresholds(void) +{ + uint32_t touch_value; + for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { + //read benchmark value + touch_pad_read_benchmark(button[i], &touch_value); + //set interrupt threshold. + touch_pad_set_thresh(button[i], touch_value * button_threshold[i]); + ESP_LOGI(TAG, "touch pad [%d] base %d, thresh %d", \ + button[i], touch_value, (uint32_t)(touch_value * button_threshold[i])); + } +} + +static void touchsensor_filter_set(touch_filter_mode_t mode) +{ + /* Filter function */ + touch_filter_config_t filter_info = { + .mode = mode, // Test jitter and filter 1/4. + .debounce_cnt = 1, // 1 time count. + .noise_thr = 0, // 50% + .jitter_step = 4, // use for jitter mode. + .smh_lvl = TOUCH_PAD_SMOOTH_IIR_2, + }; + touch_pad_filter_set_config(&filter_info); + touch_pad_filter_enable(); + ESP_LOGI(TAG, "touch pad filter init"); +} + +static void tp_example_read_task(void *pvParameter) +{ + uint8_t pad_num = 0; + uint32_t touch_trig_diff = 0; + touch_event_t evt = {0}; + static uint8_t guard_mode_flag = 0; + /* Wait touch sensor init done */ + vTaskDelay(50 / portTICK_RATE_MS); + uint32_t last_pad_status_msk = touch_pad_get_status(); + tp_example_set_thresholds(); + + while (1) { + int ret = xQueueReceive(que_touch, &evt, (portTickType)portMAX_DELAY); + if (ret != pdTRUE) { + continue; + } + if (evt.intr_mask & (TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE)) { + if (last_pad_status_msk == evt.pad_status_msk) { + ESP_LOGW(TAG, "TouchSensor status no changes, pad mask 0x%x", evt.pad_status_msk); + continue; + } + pad_num = 0; + touch_trig_diff = evt.pad_status_msk ^ last_pad_status_msk; // Record changes in channel status. Each bit represents a channel + last_pad_status_msk = evt.pad_status_msk; // Update the pad active status + + /* Traverse all channels and find out the channel where the state changes, and determine the state type */ + while (touch_trig_diff) { + if (touch_trig_diff & BIT(pad_num)) { + if (evt.pad_status_msk & BIT(pad_num)) { // Touch channel active + /* if guard pad be touched, other pads no response. */ + if (pad_num == button[3]) { + guard_mode_flag = 1; + ESP_LOGW(TAG, "TouchSensor [%d] be activated, enter guard mode", pad_num); + } else { + if (guard_mode_flag == 0) { + ESP_LOGI(TAG, "TouchSensor [%d] be activated, status mask 0x%x", pad_num, evt.pad_status_msk); + } else { + ESP_LOGW(TAG, "In guard mode. No response"); + } + } + } else { // Touch channel inactive + /* if guard pad be touched, other pads no response. */ + if (pad_num == button[3]) { + guard_mode_flag = 0; + ESP_LOGW(TAG, "TouchSensor [%d] be inactivated, exit guard mode", pad_num); + } else { + if (guard_mode_flag == 0) { + ESP_LOGI(TAG, "TouchSensor [%d] be inactivated, status mask 0x%x", pad_num, evt.pad_status_msk); + } + } + } + touch_trig_diff &= (~(BIT(pad_num))); // Clear the channels that have been checked + } + pad_num ++; + } + } + + if (evt.intr_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) { + ESP_LOGI(TAG, "The touch sensor group measurement is done [%d].", evt.curr_pad); + } + if (evt.intr_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) { + /* Add your exception handling in here. */ + ESP_LOGI(TAG, "Touch sensor channel %d measure timeout. Skip this exception channel!!", evt.curr_pad); + touch_pad_timeout_resume(); // Point on the next channel to measure. + } + } +} + +void app_main(void) +{ + if (que_touch == NULL) { + que_touch = xQueueCreate(TOUCH_BUTTON_NUM, sizeof(touch_event_t)); + } + // Initialize touch pad peripheral, it will start a timer to run a filter + ESP_LOGI(TAG, "Initializing touch pad"); + /* Initialize touch pad peripheral. */ + touch_pad_init(); + for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { + touch_pad_config(button[i]); + } + +#if TOUCH_CHANGE_CONFIG + /* If you want change the touch sensor default setting, please write here(after initialize). There are examples: */ + touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_MEASURE_CYCLE_DEFAULT); + 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); + } +#endif + +#if TOUCH_BUTTON_DENOISE_ENABLE + /* Denoise setting at TouchSensor 0. */ + touch_pad_denoise_t denoise = { + /* The bits to be cancelled are determined according to the noise level. */ + .grade = TOUCH_PAD_DENOISE_BIT4, + /* By adjusting the parameters, the reading of T0 should be approximated to the reading of the measured channel. */ + .cap_level = TOUCH_PAD_DENOISE_CAP_L4, + }; + touch_pad_denoise_set_config(&denoise); + touch_pad_denoise_enable(); + ESP_LOGI(TAG, "Denoise function init"); +#endif + +#if TOUCH_BUTTON_WATERPROOF_ENABLE + /* Waterproof function */ + touch_pad_waterproof_t waterproof = { + .guard_ring_pad = button[3], // If no ring pad, set 0; + /* It depends on the number of the parasitic capacitance of the shield pad. + Based on the touch readings of T14 and T0, estimate the size of the parasitic capacitance on T14 + and set the parameters of the appropriate hardware. */ + .shield_driver = TOUCH_PAD_SHIELD_DRV_L2, + }; + touch_pad_waterproof_set_config(&waterproof); + touch_pad_waterproof_enable(); + ESP_LOGI(TAG, "touch pad waterproof init"); +#endif + + /* Filter setting */ + touchsensor_filter_set(TOUCH_PAD_FILTER_IIR_16); + touch_pad_timeout_set(true, SOC_TOUCH_PAD_THRESHOLD_MAX); + /* Register touch interrupt ISR, enable intr type. */ + touch_pad_isr_register(touchsensor_interrupt_cb, NULL, TOUCH_PAD_INTR_MASK_ALL); + /* If you have other touch algorithm, you can get the measured value after the `TOUCH_PAD_INTR_MASK_SCAN_DONE` interrupt is generated. */ + touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE | TOUCH_PAD_INTR_MASK_TIMEOUT); + + /* In ESP32-S3 If the touch wakeup not enable, the touch action of the touch sensor during light sleep may be lost. */ + esp_sleep_enable_touchpad_wakeup(); + + /* Enable touch sensor clock. Work mode is "timer trigger". */ + touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); + touch_pad_fsm_start(); + + // Start a task to show what pads have been touched + xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); +} diff --git a/examples/peripherals/touch_pad_read/main/esp32s3/tp_read_main.c b/examples/peripherals/touch_pad_read/main/esp32s3/tp_read_main.c new file mode 100644 index 0000000000..b6c0472ce5 --- /dev/null +++ b/examples/peripherals/touch_pad_read/main/esp32s3/tp_read_main.c @@ -0,0 +1,90 @@ +/* Touch Pad Read Example + + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "driver/touch_pad.h" +#include "esp_log.h" + +#define TOUCH_BUTTON_NUM 14 +#define TOUCH_CHANGE_CONFIG 0 + +static const char *TAG = "touch read"; +static const touch_pad_t button[TOUCH_BUTTON_NUM] = { + TOUCH_PAD_NUM1, + TOUCH_PAD_NUM2, + TOUCH_PAD_NUM3, + TOUCH_PAD_NUM4, + TOUCH_PAD_NUM5, + TOUCH_PAD_NUM6, + TOUCH_PAD_NUM7, + TOUCH_PAD_NUM8, + TOUCH_PAD_NUM9, + TOUCH_PAD_NUM10, + TOUCH_PAD_NUM11, + TOUCH_PAD_NUM12, + TOUCH_PAD_NUM13, + TOUCH_PAD_NUM14 +}; + +/* + Read values sensed at all available touch pads. + Print out values in a loop on a serial monitor. + */ +static void tp_example_read_task(void *pvParameter) +{ + uint32_t touch_value; + + /* Wait touch sensor init done */ + vTaskDelay(100 / portTICK_RATE_MS); + printf("Touch Sensor read, the output format is: \nTouchpad num:[raw data]\n\n"); + + while (1) { + for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { + touch_pad_read_raw_data(button[i], &touch_value); // read raw data. + printf("T%d: [%4d] ", button[i], touch_value); + } + printf("\n"); + vTaskDelay(200 / portTICK_PERIOD_MS); + } +} + +void app_main(void) +{ + /* Initialize touch pad peripheral. */ + touch_pad_init(); + for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { + touch_pad_config(button[i]); + } +#if TOUCH_CHANGE_CONFIG + /* If you want change the touch sensor default setting, please write here(after initialize). There are examples: */ + touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT); + 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); + } +#endif + /* Denoise setting at TouchSensor 0. */ + touch_pad_denoise_t denoise = { + /* The bits to be cancelled are determined according to the noise level. */ + .grade = TOUCH_PAD_DENOISE_BIT4, + .cap_level = TOUCH_PAD_DENOISE_CAP_L4, + }; + touch_pad_denoise_set_config(&denoise); + touch_pad_denoise_enable(); + ESP_LOGI(TAG, "Denoise function init"); + + /* Enable touch sensor clock. Work mode is "timer trigger". */ + touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); + touch_pad_fsm_start(); + + /* Start task to read values by pads. */ + xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); +} diff --git a/examples/system/deep_sleep/main/deep_sleep_example_main.c b/examples/system/deep_sleep/main/deep_sleep_example_main.c index a53a8f939e..1b09748ae6 100644 --- a/examples/system/deep_sleep/main/deep_sleep_example_main.c +++ b/examples/system/deep_sleep/main/deep_sleep_example_main.c @@ -211,7 +211,7 @@ void app_main(void) touch_pad_config(TOUCH_PAD_NUM9, TOUCH_THRESH_NO_USE); calibrate_touch_pad(TOUCH_PAD_NUM8); calibrate_touch_pad(TOUCH_PAD_NUM9); -#elif CONFIG_IDF_TARGET_ESP32S2 +#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 /* Initialize touch pad peripheral. */ touch_pad_init(); /* Only support one touch channel in sleep mode. */ From 3ca9da0386d2d25a9e68954cf4fbd59a580600ec Mon Sep 17 00:00:00 2001 From: fuzhibo Date: Tue, 24 Aug 2021 21:38:12 +0800 Subject: [PATCH 2/6] update touch sensor examples --- components/driver/esp32s2/touch_sensor.c | 10 +- .../touch_pad_interrupt/main/CMakeLists.txt | 2 - .../main/esp32s3/tp_interrupt_main.c | 240 ------------------ .../touch_pad_read/main/CMakeLists.txt | 2 - .../main/esp32s3/tp_read_main.c | 90 ------- .../esp32}/touch_pad_interrupt/CMakeLists.txt | 0 .../esp32}/touch_pad_interrupt/Makefile | 0 .../esp32}/touch_pad_interrupt/README.md | 28 +- .../touch_pad_interrupt/main/CMakeLists.txt | 2 + .../touch_pad_interrupt}/main/component.mk | 2 - .../main}/tp_interrupt_main.c | 4 + .../esp32}/touch_pad_read/CMakeLists.txt | 0 .../esp32}/touch_pad_read/Makefile | 0 .../esp32/touch_pad_read/README.md | 31 +++ .../esp32/touch_pad_read/main/CMakeLists.txt | 2 + .../esp32/touch_pad_read}/main/component.mk | 2 - .../esp32/touch_pad_read/main}/tp_read_main.c | 4 + .../touch_element/touch_button/CMakeLists.txt | 0 .../touch_element/touch_button/README.md | 0 .../touch_button/main/CMakeLists.txt | 0 .../touch_button/main/Kconfig.projbuild | 0 .../main/touch_button_example_main.c | 0 .../touch_element_waterproof/CMakeLists.txt | 0 .../touch_element_waterproof/README.md | 0 .../main/CMakeLists.txt | 0 .../main/Kconfig.projbuild | 0 .../main/waterproof_example_main.c | 0 .../touch_elements_combination/CMakeLists.txt | 0 .../touch_elements_combination/README.md | 0 .../main/CMakeLists.txt | 0 .../main/touch_elements_example_main.c | 0 .../touch_element/touch_matrix/CMakeLists.txt | 0 .../touch_element/touch_matrix/README.md | 0 .../touch_matrix/main/CMakeLists.txt | 0 .../touch_matrix/main/Kconfig.projbuild | 0 .../main/touch_matrix_example_main.c | 0 .../touch_element/touch_slider/CMakeLists.txt | 0 .../touch_element/touch_slider/README.md | 0 .../touch_slider/main/CMakeLists.txt | 0 .../touch_slider/main/Kconfig.projbuild | 0 .../main/touch_slider_example_main.c | 0 .../touch_pad_interrupt/CMakeLists.txt | 6 + .../touch_sensor/touch_pad_interrupt/Makefile | 8 + .../touch_pad_interrupt/README.md | 36 +++ .../touch_pad_interrupt/main/CMakeLists.txt | 2 + .../touch_pad_interrupt/main/component.mk | 4 + .../main}/tp_interrupt_main.c | 2 +- .../touch_pad_read/CMakeLists.txt | 6 + .../touch_sensor/touch_pad_read/Makefile | 8 + .../touch_pad_read/README.md | 25 +- .../touch_pad_read/main/CMakeLists.txt | 2 + .../touch_pad_read/main/component.mk | 4 + .../touch_pad_read/main}/tp_read_main.c | 0 53 files changed, 134 insertions(+), 388 deletions(-) delete mode 100644 examples/peripherals/touch_pad_interrupt/main/CMakeLists.txt delete mode 100644 examples/peripherals/touch_pad_interrupt/main/esp32s3/tp_interrupt_main.c delete mode 100644 examples/peripherals/touch_pad_read/main/CMakeLists.txt delete mode 100644 examples/peripherals/touch_pad_read/main/esp32s3/tp_read_main.c rename examples/peripherals/{ => touch_sensor/esp32}/touch_pad_interrupt/CMakeLists.txt (100%) rename examples/peripherals/{ => touch_sensor/esp32}/touch_pad_interrupt/Makefile (100%) rename examples/peripherals/{ => touch_sensor/esp32}/touch_pad_interrupt/README.md (64%) create mode 100644 examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/main/CMakeLists.txt rename examples/peripherals/{touch_pad_read => touch_sensor/esp32/touch_pad_interrupt}/main/component.mk (80%) rename examples/peripherals/{touch_pad_interrupt/main/esp32 => touch_sensor/esp32/touch_pad_interrupt/main}/tp_interrupt_main.c (98%) rename examples/peripherals/{ => touch_sensor/esp32}/touch_pad_read/CMakeLists.txt (100%) rename examples/peripherals/{ => touch_sensor/esp32}/touch_pad_read/Makefile (100%) create mode 100644 examples/peripherals/touch_sensor/esp32/touch_pad_read/README.md create mode 100644 examples/peripherals/touch_sensor/esp32/touch_pad_read/main/CMakeLists.txt rename examples/peripherals/{touch_pad_interrupt => touch_sensor/esp32/touch_pad_read}/main/component.mk (80%) rename examples/peripherals/{touch_pad_read/main/esp32 => touch_sensor/esp32/touch_pad_read/main}/tp_read_main.c (97%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_button/CMakeLists.txt (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_button/README.md (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_button/main/CMakeLists.txt (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_button/main/Kconfig.projbuild (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_button/main/touch_button_example_main.c (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_element_waterproof/CMakeLists.txt (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_element_waterproof/README.md (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_element_waterproof/main/CMakeLists.txt (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_element_waterproof/main/Kconfig.projbuild (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_element_waterproof/main/waterproof_example_main.c (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_elements_combination/CMakeLists.txt (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_elements_combination/README.md (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_elements_combination/main/CMakeLists.txt (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_elements_combination/main/touch_elements_example_main.c (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_matrix/CMakeLists.txt (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_matrix/README.md (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_matrix/main/CMakeLists.txt (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_matrix/main/Kconfig.projbuild (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_matrix/main/touch_matrix_example_main.c (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_slider/CMakeLists.txt (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_slider/README.md (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_slider/main/CMakeLists.txt (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_slider/main/Kconfig.projbuild (100%) rename examples/peripherals/{ => touch_sensor}/touch_element/touch_slider/main/touch_slider_example_main.c (100%) create mode 100644 examples/peripherals/touch_sensor/touch_pad_interrupt/CMakeLists.txt create mode 100644 examples/peripherals/touch_sensor/touch_pad_interrupt/Makefile create mode 100644 examples/peripherals/touch_sensor/touch_pad_interrupt/README.md create mode 100644 examples/peripherals/touch_sensor/touch_pad_interrupt/main/CMakeLists.txt create mode 100644 examples/peripherals/touch_sensor/touch_pad_interrupt/main/component.mk rename examples/peripherals/{touch_pad_interrupt/main/esp32s2 => touch_sensor/touch_pad_interrupt/main}/tp_interrupt_main.c (99%) create mode 100644 examples/peripherals/touch_sensor/touch_pad_read/CMakeLists.txt create mode 100644 examples/peripherals/touch_sensor/touch_pad_read/Makefile rename examples/peripherals/{ => touch_sensor}/touch_pad_read/README.md (59%) create mode 100644 examples/peripherals/touch_sensor/touch_pad_read/main/CMakeLists.txt create mode 100644 examples/peripherals/touch_sensor/touch_pad_read/main/component.mk rename examples/peripherals/{touch_pad_read/main/esp32s2 => touch_sensor/touch_pad_read/main}/tp_read_main.c (100%) diff --git a/components/driver/esp32s2/touch_sensor.c b/components/driver/esp32s2/touch_sensor.c index 29a4da3ddc..c3c35824f8 100644 --- a/components/driver/esp32s2/touch_sensor.c +++ b/components/driver/esp32s2/touch_sensor.c @@ -62,6 +62,7 @@ static SemaphoreHandle_t rtc_touch_mux = NULL; Touch Pad ---------------------------------------------------------------*/ +#if CONFIG_IDF_TARGET_ESP32S2 /** Workaround for scan done interrupt issue. */ static void touch_pad_workaround_isr_internal(void *arg) { @@ -81,6 +82,7 @@ static void touch_pad_workaround_isr_internal(void *arg) } } } +#endif esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_mask_t intr_mask) { @@ -104,13 +106,19 @@ esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_ma if (intr_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) { en_msk |= RTC_CNTL_TOUCH_TIMEOUT_INT_ST_M; } +#if SOC_TOUCH_PROXIMITY_MEAS_DONE_SUPPORTED + if (intr_mask & TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE) { + en_msk |= RTC_CNTL_TOUCH_APPROACH_LOOP_DONE_INT_ST_M; + } +#endif esp_err_t ret = rtc_isr_register(fn, arg, en_msk); +#if CONFIG_IDF_TARGET_ESP32S2 /* Must ensure: After being registered, it is executed first. */ if ( (ret == ESP_OK) && (reg_flag == false) && (intr_mask & (TOUCH_PAD_INTR_MASK_SCAN_DONE | TOUCH_PAD_INTR_MASK_TIMEOUT)) ) { rtc_isr_register(touch_pad_workaround_isr_internal, NULL, RTC_CNTL_TOUCH_SCAN_DONE_INT_ST_M | RTC_CNTL_TOUCH_TIMEOUT_INT_ST_M); reg_flag = true; } - +#endif return ret; } diff --git a/examples/peripherals/touch_pad_interrupt/main/CMakeLists.txt b/examples/peripherals/touch_pad_interrupt/main/CMakeLists.txt deleted file mode 100644 index 61af5d42a0..0000000000 --- a/examples/peripherals/touch_pad_interrupt/main/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -idf_component_register(SRCS "${CONFIG_IDF_TARGET}/tp_interrupt_main.c" - INCLUDE_DIRS ".") diff --git a/examples/peripherals/touch_pad_interrupt/main/esp32s3/tp_interrupt_main.c b/examples/peripherals/touch_pad_interrupt/main/esp32s3/tp_interrupt_main.c deleted file mode 100644 index 6088d90242..0000000000 --- a/examples/peripherals/touch_pad_interrupt/main/esp32s3/tp_interrupt_main.c +++ /dev/null @@ -1,240 +0,0 @@ -/* Touch Pad Interrupt Example - - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ -#include -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/queue.h" -#include "esp_log.h" -#include "driver/touch_pad.h" -#include "soc/rtc_periph.h" -#include "soc/sens_periph.h" -#include "esp_sleep.h" - -static const char *TAG = "Touch pad"; - -static QueueHandle_t que_touch = NULL; -typedef struct touch_msg { - touch_pad_intr_mask_t intr_mask; - uint32_t pad_status_msk; - uint32_t curr_pad; -} touch_event_t; - -#define TOUCH_BUTTON_NUM 4 -#define TOUCH_BUTTON_WATERPROOF_ENABLE 1 -#define TOUCH_BUTTON_DENOISE_ENABLE 1 -#define TOUCH_CHANGE_CONFIG 0 - -static const touch_pad_t button[TOUCH_BUTTON_NUM] = { - TOUCH_PAD_NUM7, // 'SELECT' button. - TOUCH_PAD_NUM9, // 'MENU' button. - TOUCH_PAD_NUM11, // 'BACK' button. - TOUCH_PAD_NUM13, // Guard ring for waterproof design. - // If this pad be touched, other pads no response. -}; - -/* - * Touch threshold. The threshold determines the sensitivity of the touch. - * This threshold is derived by testing changes in readings from different touch channels. - * If (raw_data - benchmark) > benchmark * threshold, the pad be activated. - * If (raw_data - benchmark) < benchmark * threshold, the pad be inactivated. - */ -static const float button_threshold[TOUCH_BUTTON_NUM] = { - 0.2, // 20%. - 0.2, // 20%. - 0.2, // 20%. - 0.1, // 10%. -}; - -/* - Handle an interrupt triggered when a pad is touched. - Recognize what pad has been touched and save it in a table. - */ -static void touchsensor_interrupt_cb(void *arg) -{ - int task_awoken = pdFALSE; - touch_event_t evt; - - evt.intr_mask = touch_pad_read_intr_status_mask(); - evt.pad_status_msk = touch_pad_get_status(); - /* Note: Obtaining channel information in the interrupt callback function as the channel that triggers the interrupt is risky. - If the execution of the interrupt callback function is delayed by a channel measurement time, - the channel information obtained is wrong. Both light sleep and SPI FLASH reading and - writing may delay the response of the interrupt function. */ - evt.curr_pad = touch_pad_get_current_meas_channel(); - - xQueueSendFromISR(que_touch, &evt, &task_awoken); - if (task_awoken == pdTRUE) { - portYIELD_FROM_ISR(); - } -} - -static void tp_example_set_thresholds(void) -{ - uint32_t touch_value; - for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { - //read benchmark value - touch_pad_read_benchmark(button[i], &touch_value); - //set interrupt threshold. - touch_pad_set_thresh(button[i], touch_value * button_threshold[i]); - ESP_LOGI(TAG, "touch pad [%d] base %d, thresh %d", \ - button[i], touch_value, (uint32_t)(touch_value * button_threshold[i])); - } -} - -static void touchsensor_filter_set(touch_filter_mode_t mode) -{ - /* Filter function */ - touch_filter_config_t filter_info = { - .mode = mode, // Test jitter and filter 1/4. - .debounce_cnt = 1, // 1 time count. - .noise_thr = 0, // 50% - .jitter_step = 4, // use for jitter mode. - .smh_lvl = TOUCH_PAD_SMOOTH_IIR_2, - }; - touch_pad_filter_set_config(&filter_info); - touch_pad_filter_enable(); - ESP_LOGI(TAG, "touch pad filter init"); -} - -static void tp_example_read_task(void *pvParameter) -{ - uint8_t pad_num = 0; - uint32_t touch_trig_diff = 0; - touch_event_t evt = {0}; - static uint8_t guard_mode_flag = 0; - /* Wait touch sensor init done */ - vTaskDelay(50 / portTICK_RATE_MS); - uint32_t last_pad_status_msk = touch_pad_get_status(); - tp_example_set_thresholds(); - - while (1) { - int ret = xQueueReceive(que_touch, &evt, (portTickType)portMAX_DELAY); - if (ret != pdTRUE) { - continue; - } - if (evt.intr_mask & (TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE)) { - if (last_pad_status_msk == evt.pad_status_msk) { - ESP_LOGW(TAG, "TouchSensor status no changes, pad mask 0x%x", evt.pad_status_msk); - continue; - } - pad_num = 0; - touch_trig_diff = evt.pad_status_msk ^ last_pad_status_msk; // Record changes in channel status. Each bit represents a channel - last_pad_status_msk = evt.pad_status_msk; // Update the pad active status - - /* Traverse all channels and find out the channel where the state changes, and determine the state type */ - while (touch_trig_diff) { - if (touch_trig_diff & BIT(pad_num)) { - if (evt.pad_status_msk & BIT(pad_num)) { // Touch channel active - /* if guard pad be touched, other pads no response. */ - if (pad_num == button[3]) { - guard_mode_flag = 1; - ESP_LOGW(TAG, "TouchSensor [%d] be activated, enter guard mode", pad_num); - } else { - if (guard_mode_flag == 0) { - ESP_LOGI(TAG, "TouchSensor [%d] be activated, status mask 0x%x", pad_num, evt.pad_status_msk); - } else { - ESP_LOGW(TAG, "In guard mode. No response"); - } - } - } else { // Touch channel inactive - /* if guard pad be touched, other pads no response. */ - if (pad_num == button[3]) { - guard_mode_flag = 0; - ESP_LOGW(TAG, "TouchSensor [%d] be inactivated, exit guard mode", pad_num); - } else { - if (guard_mode_flag == 0) { - ESP_LOGI(TAG, "TouchSensor [%d] be inactivated, status mask 0x%x", pad_num, evt.pad_status_msk); - } - } - } - touch_trig_diff &= (~(BIT(pad_num))); // Clear the channels that have been checked - } - pad_num ++; - } - } - - if (evt.intr_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) { - ESP_LOGI(TAG, "The touch sensor group measurement is done [%d].", evt.curr_pad); - } - if (evt.intr_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) { - /* Add your exception handling in here. */ - ESP_LOGI(TAG, "Touch sensor channel %d measure timeout. Skip this exception channel!!", evt.curr_pad); - touch_pad_timeout_resume(); // Point on the next channel to measure. - } - } -} - -void app_main(void) -{ - if (que_touch == NULL) { - que_touch = xQueueCreate(TOUCH_BUTTON_NUM, sizeof(touch_event_t)); - } - // Initialize touch pad peripheral, it will start a timer to run a filter - ESP_LOGI(TAG, "Initializing touch pad"); - /* Initialize touch pad peripheral. */ - touch_pad_init(); - for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { - touch_pad_config(button[i]); - } - -#if TOUCH_CHANGE_CONFIG - /* If you want change the touch sensor default setting, please write here(after initialize). There are examples: */ - touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_MEASURE_CYCLE_DEFAULT); - 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); - } -#endif - -#if TOUCH_BUTTON_DENOISE_ENABLE - /* Denoise setting at TouchSensor 0. */ - touch_pad_denoise_t denoise = { - /* The bits to be cancelled are determined according to the noise level. */ - .grade = TOUCH_PAD_DENOISE_BIT4, - /* By adjusting the parameters, the reading of T0 should be approximated to the reading of the measured channel. */ - .cap_level = TOUCH_PAD_DENOISE_CAP_L4, - }; - touch_pad_denoise_set_config(&denoise); - touch_pad_denoise_enable(); - ESP_LOGI(TAG, "Denoise function init"); -#endif - -#if TOUCH_BUTTON_WATERPROOF_ENABLE - /* Waterproof function */ - touch_pad_waterproof_t waterproof = { - .guard_ring_pad = button[3], // If no ring pad, set 0; - /* It depends on the number of the parasitic capacitance of the shield pad. - Based on the touch readings of T14 and T0, estimate the size of the parasitic capacitance on T14 - and set the parameters of the appropriate hardware. */ - .shield_driver = TOUCH_PAD_SHIELD_DRV_L2, - }; - touch_pad_waterproof_set_config(&waterproof); - touch_pad_waterproof_enable(); - ESP_LOGI(TAG, "touch pad waterproof init"); -#endif - - /* Filter setting */ - touchsensor_filter_set(TOUCH_PAD_FILTER_IIR_16); - touch_pad_timeout_set(true, SOC_TOUCH_PAD_THRESHOLD_MAX); - /* Register touch interrupt ISR, enable intr type. */ - touch_pad_isr_register(touchsensor_interrupt_cb, NULL, TOUCH_PAD_INTR_MASK_ALL); - /* If you have other touch algorithm, you can get the measured value after the `TOUCH_PAD_INTR_MASK_SCAN_DONE` interrupt is generated. */ - touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE | TOUCH_PAD_INTR_MASK_TIMEOUT); - - /* In ESP32-S3 If the touch wakeup not enable, the touch action of the touch sensor during light sleep may be lost. */ - esp_sleep_enable_touchpad_wakeup(); - - /* Enable touch sensor clock. Work mode is "timer trigger". */ - touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); - touch_pad_fsm_start(); - - // Start a task to show what pads have been touched - xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); -} diff --git a/examples/peripherals/touch_pad_read/main/CMakeLists.txt b/examples/peripherals/touch_pad_read/main/CMakeLists.txt deleted file mode 100644 index a817d78c0d..0000000000 --- a/examples/peripherals/touch_pad_read/main/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -idf_component_register(SRCS "${CONFIG_IDF_TARGET}/tp_read_main.c" - INCLUDE_DIRS ".") diff --git a/examples/peripherals/touch_pad_read/main/esp32s3/tp_read_main.c b/examples/peripherals/touch_pad_read/main/esp32s3/tp_read_main.c deleted file mode 100644 index b6c0472ce5..0000000000 --- a/examples/peripherals/touch_pad_read/main/esp32s3/tp_read_main.c +++ /dev/null @@ -1,90 +0,0 @@ -/* Touch Pad Read Example - - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ -#include -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "driver/touch_pad.h" -#include "esp_log.h" - -#define TOUCH_BUTTON_NUM 14 -#define TOUCH_CHANGE_CONFIG 0 - -static const char *TAG = "touch read"; -static const touch_pad_t button[TOUCH_BUTTON_NUM] = { - TOUCH_PAD_NUM1, - TOUCH_PAD_NUM2, - TOUCH_PAD_NUM3, - TOUCH_PAD_NUM4, - TOUCH_PAD_NUM5, - TOUCH_PAD_NUM6, - TOUCH_PAD_NUM7, - TOUCH_PAD_NUM8, - TOUCH_PAD_NUM9, - TOUCH_PAD_NUM10, - TOUCH_PAD_NUM11, - TOUCH_PAD_NUM12, - TOUCH_PAD_NUM13, - TOUCH_PAD_NUM14 -}; - -/* - Read values sensed at all available touch pads. - Print out values in a loop on a serial monitor. - */ -static void tp_example_read_task(void *pvParameter) -{ - uint32_t touch_value; - - /* Wait touch sensor init done */ - vTaskDelay(100 / portTICK_RATE_MS); - printf("Touch Sensor read, the output format is: \nTouchpad num:[raw data]\n\n"); - - while (1) { - for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { - touch_pad_read_raw_data(button[i], &touch_value); // read raw data. - printf("T%d: [%4d] ", button[i], touch_value); - } - printf("\n"); - vTaskDelay(200 / portTICK_PERIOD_MS); - } -} - -void app_main(void) -{ - /* Initialize touch pad peripheral. */ - touch_pad_init(); - for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { - touch_pad_config(button[i]); - } -#if TOUCH_CHANGE_CONFIG - /* If you want change the touch sensor default setting, please write here(after initialize). There are examples: */ - touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT); - 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); - } -#endif - /* Denoise setting at TouchSensor 0. */ - touch_pad_denoise_t denoise = { - /* The bits to be cancelled are determined according to the noise level. */ - .grade = TOUCH_PAD_DENOISE_BIT4, - .cap_level = TOUCH_PAD_DENOISE_CAP_L4, - }; - touch_pad_denoise_set_config(&denoise); - touch_pad_denoise_enable(); - ESP_LOGI(TAG, "Denoise function init"); - - /* Enable touch sensor clock. Work mode is "timer trigger". */ - touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); - touch_pad_fsm_start(); - - /* Start task to read values by pads. */ - xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); -} diff --git a/examples/peripherals/touch_pad_interrupt/CMakeLists.txt b/examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/CMakeLists.txt similarity index 100% rename from examples/peripherals/touch_pad_interrupt/CMakeLists.txt rename to examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/CMakeLists.txt diff --git a/examples/peripherals/touch_pad_interrupt/Makefile b/examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/Makefile similarity index 100% rename from examples/peripherals/touch_pad_interrupt/Makefile rename to examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/Makefile diff --git a/examples/peripherals/touch_pad_interrupt/README.md b/examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/README.md similarity index 64% rename from examples/peripherals/touch_pad_interrupt/README.md rename to examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/README.md index e39c0bc46f..8ca98442c6 100644 --- a/examples/peripherals/touch_pad_interrupt/README.md +++ b/examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32 | ESP32-S2 | -| ----------------- | ----- | -------- | +| Supported Targets | ESP32 | +| ----------------- | ----- | # Touch Pad Interrupt Example @@ -35,30 +35,6 @@ I (22903) Touch pad: Waiting for any pad being touched... Note: Sensing threshold is set up automatically at start up by performing simple calibration. Application is reading current value for each pad and assuming two thirds of this value as the sensing threshold. Do not touch pads on application start up, otherwise sensing may not work correctly. -## ESP32-S2 platform - -Demonstrates how to set up ESP32-S2's capacitive touch pad peripheral to trigger interrupt when a pad is touched. It also shows how to detect the touch event by the software for sensor designs when greater touch detection sensitivity is required. - -ESP32-S2 supports touch detection by configuring hardware registers. The hardware periodically detects the pulse counts. If the number of pulse counts exceeds the set threshold, a hardware interrupt will be generated to notify the application layer that a certain touch sensor channel may be triggered. - -The application is cycling between the interrupt mode and the pooling mode with a filter, to compare performance of the touch sensor system in both scenarios: - -``` -I (304) Touch pad: Initializing touch pad -I (304) Touch pad: Denoise function init -I (304) Touch pad: touch pad waterproof init -I (304) Touch pad: touch pad filter init 2 -I (414) Touch pad: test init: touch pad [7] base 7382, thresh 1476 -I (414) Touch pad: test init: touch pad [9] base 7349, thresh 1469 -I (414) Touch pad: test init: touch pad [11] base 8047, thresh 1609 -I (414) Touch pad: test init: touch pad [13] base 8104, thresh 810 -I (5954) Touch pad: TouchSensor [9] be actived, status mask 0x200 -W (6034) Touch pad: TouchSensor [13] be actived, enter guard mode -W (6034) Touch pad: In guard mode. No response -W (6174) Touch pad: TouchSensor [13] be actived, exit guard mode -I (6194) Touch pad: TouchSensor [9] be inactived, status mask 0x0 -``` - ## Reference Information For a simpler example how to configure and read capacitive touch pads, please refer to [touch_pad_read](../touch_pad_read). diff --git a/examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/main/CMakeLists.txt b/examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/main/CMakeLists.txt new file mode 100644 index 0000000000..94fac9872e --- /dev/null +++ b/examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "tp_interrupt_main.c" + INCLUDE_DIRS ".") diff --git a/examples/peripherals/touch_pad_read/main/component.mk b/examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/main/component.mk similarity index 80% rename from examples/peripherals/touch_pad_read/main/component.mk rename to examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/main/component.mk index 4d5ac5eb96..a98f634eae 100644 --- a/examples/peripherals/touch_pad_read/main/component.mk +++ b/examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/main/component.mk @@ -2,5 +2,3 @@ # "main" pseudo-component makefile. # # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) - -COMPONENT_SRCDIRS := $(IDF_TARGET) diff --git a/examples/peripherals/touch_pad_interrupt/main/esp32/tp_interrupt_main.c b/examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/main/tp_interrupt_main.c similarity index 98% rename from examples/peripherals/touch_pad_interrupt/main/esp32/tp_interrupt_main.c rename to examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/main/tp_interrupt_main.c index 0c0187c498..d1ff2f8995 100644 --- a/examples/peripherals/touch_pad_interrupt/main/esp32/tp_interrupt_main.c +++ b/examples/peripherals/touch_sensor/esp32/touch_pad_interrupt/main/tp_interrupt_main.c @@ -16,6 +16,8 @@ #include "soc/rtc_periph.h" #include "soc/sens_periph.h" +#if CONFIG_IDF_TARGET_ESP32 + static const char *TAG = "Touch pad"; #define TOUCH_THRESH_NO_USE (0) @@ -169,3 +171,5 @@ void app_main(void) // Start a task to show what pads have been touched xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); } + +#endif // CONFIG_IDF_TARGET_ESP32 diff --git a/examples/peripherals/touch_pad_read/CMakeLists.txt b/examples/peripherals/touch_sensor/esp32/touch_pad_read/CMakeLists.txt similarity index 100% rename from examples/peripherals/touch_pad_read/CMakeLists.txt rename to examples/peripherals/touch_sensor/esp32/touch_pad_read/CMakeLists.txt diff --git a/examples/peripherals/touch_pad_read/Makefile b/examples/peripherals/touch_sensor/esp32/touch_pad_read/Makefile similarity index 100% rename from examples/peripherals/touch_pad_read/Makefile rename to examples/peripherals/touch_sensor/esp32/touch_pad_read/Makefile diff --git a/examples/peripherals/touch_sensor/esp32/touch_pad_read/README.md b/examples/peripherals/touch_sensor/esp32/touch_pad_read/README.md new file mode 100644 index 0000000000..d61c04fa7a --- /dev/null +++ b/examples/peripherals/touch_sensor/esp32/touch_pad_read/README.md @@ -0,0 +1,31 @@ +| Supported Targets | ESP32 | +| ----------------- | ----- | + +# Touch Pad Read Example + +## ESP32 plaform + +Read and display raw values or IIR filtered values from capacitive touch pad sensors. + +Once configured, ESP32 is continuously measuring capacitance of touch pad sensors. Measurement is reflected as numeric value inversely related to sensor's capacitance. The capacitance is bigger when sensor is touched with a finger and the measured value smaller. In opposite situation, when finger is released, capacitance is smaller and the measured value bigger. + +To detect when a sensor is touched and when not, each particular design should be calibrated by obtaining both measurements for each individual sensor. Then a threshold between both values should be established. Using specific threshold, API is then able to distinguish whether specific sensor is touched or released. + +ESP32 supports reading up to ten capacitive touch pad sensors T0 - T9, connected to specific GPIO pins. For information on available pins please refer to [Technical Reference Manual](https://espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf). Application initializes all ten sensor pads. Then in a loop reads sensors T0 - T9 and displays obtained values (after a colon) on a serial terminal: + +``` +Touch Sensor filter mode read, the output format is: +Touchpad num:[raw data, filtered data] + +T0:[1072,1071] T1:[ 475, 475] T2:[1004,1003] T3:[1232,1231] T4:[1675,1676] T5:[1146,1146] T6:[1607,1607] T7:[1118,1118] T8:[1695,1695] T9:[1223,1222] +T0:[1072,1071] T1:[ 475, 475] T2:[1003,1003] T3:[1231,1231] T4:[1676,1676] T5:[1146,1146] T6:[1607,1607] T7:[1118,1118] T8:[1694,1694] T9:[1222,1221] +T0:[1071,1071] T1:[ 475, 475] T2:[1004,1004] T3:[1231,1231] T4:[1678,1677] T5:[1147,1146] T6:[1607,1607] T7:[1118,1118] T8:[1694,1694] T9:[1222,1221] +``` + +## Reference Information + +For hardware and firmware design guidelines on ESP32 touch sensor system, please refer to [Touch Sensor Application Note](https://github.com/espressif/esp-iot-solution/blob/release/v1.0/documents/touch_pad_solution/touch_sensor_design_en.md), where you may find comprehensive information on how to design and implement touch sensing applications, such as linear slider, wheel slider, matrix buttons and spring buttons. + +There is another similar example that demonstrates how to perform simple calibration and trigger an interrupt when a pat is touched - see [touch_pad_interrupt](../touch_pad_interrupt). + +See the README.md file in the upper level 'examples' directory for more information about examples. diff --git a/examples/peripherals/touch_sensor/esp32/touch_pad_read/main/CMakeLists.txt b/examples/peripherals/touch_sensor/esp32/touch_pad_read/main/CMakeLists.txt new file mode 100644 index 0000000000..2b9a209ec4 --- /dev/null +++ b/examples/peripherals/touch_sensor/esp32/touch_pad_read/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "tp_read_main.c" + INCLUDE_DIRS ".") diff --git a/examples/peripherals/touch_pad_interrupt/main/component.mk b/examples/peripherals/touch_sensor/esp32/touch_pad_read/main/component.mk similarity index 80% rename from examples/peripherals/touch_pad_interrupt/main/component.mk rename to examples/peripherals/touch_sensor/esp32/touch_pad_read/main/component.mk index 4d5ac5eb96..a98f634eae 100644 --- a/examples/peripherals/touch_pad_interrupt/main/component.mk +++ b/examples/peripherals/touch_sensor/esp32/touch_pad_read/main/component.mk @@ -2,5 +2,3 @@ # "main" pseudo-component makefile. # # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) - -COMPONENT_SRCDIRS := $(IDF_TARGET) diff --git a/examples/peripherals/touch_pad_read/main/esp32/tp_read_main.c b/examples/peripherals/touch_sensor/esp32/touch_pad_read/main/tp_read_main.c similarity index 97% rename from examples/peripherals/touch_pad_read/main/esp32/tp_read_main.c rename to examples/peripherals/touch_sensor/esp32/touch_pad_read/main/tp_read_main.c index 4ab44003c8..dcf78fd20d 100644 --- a/examples/peripherals/touch_pad_read/main/esp32/tp_read_main.c +++ b/examples/peripherals/touch_sensor/esp32/touch_pad_read/main/tp_read_main.c @@ -12,6 +12,8 @@ #include "driver/touch_pad.h" #include "esp_log.h" +#if CONFIG_IDF_TARGET_ESP32 + #define TOUCH_PAD_NO_CHANGE (-1) #define TOUCH_THRESH_NO_USE (0) #define TOUCH_FILTER_MODE_EN (1) @@ -70,3 +72,5 @@ void app_main(void) // Start task to read values sensed by pads xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); } + +#endif // CONFIG_IDF_TARGET_ESP32 diff --git a/examples/peripherals/touch_element/touch_button/CMakeLists.txt b/examples/peripherals/touch_sensor/touch_element/touch_button/CMakeLists.txt similarity index 100% rename from examples/peripherals/touch_element/touch_button/CMakeLists.txt rename to examples/peripherals/touch_sensor/touch_element/touch_button/CMakeLists.txt diff --git a/examples/peripherals/touch_element/touch_button/README.md b/examples/peripherals/touch_sensor/touch_element/touch_button/README.md similarity index 100% rename from examples/peripherals/touch_element/touch_button/README.md rename to examples/peripherals/touch_sensor/touch_element/touch_button/README.md diff --git a/examples/peripherals/touch_element/touch_button/main/CMakeLists.txt b/examples/peripherals/touch_sensor/touch_element/touch_button/main/CMakeLists.txt similarity index 100% rename from examples/peripherals/touch_element/touch_button/main/CMakeLists.txt rename to examples/peripherals/touch_sensor/touch_element/touch_button/main/CMakeLists.txt diff --git a/examples/peripherals/touch_element/touch_button/main/Kconfig.projbuild b/examples/peripherals/touch_sensor/touch_element/touch_button/main/Kconfig.projbuild similarity index 100% rename from examples/peripherals/touch_element/touch_button/main/Kconfig.projbuild rename to examples/peripherals/touch_sensor/touch_element/touch_button/main/Kconfig.projbuild diff --git a/examples/peripherals/touch_element/touch_button/main/touch_button_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_button/main/touch_button_example_main.c similarity index 100% rename from examples/peripherals/touch_element/touch_button/main/touch_button_example_main.c rename to examples/peripherals/touch_sensor/touch_element/touch_button/main/touch_button_example_main.c diff --git a/examples/peripherals/touch_element/touch_element_waterproof/CMakeLists.txt b/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/CMakeLists.txt similarity index 100% rename from examples/peripherals/touch_element/touch_element_waterproof/CMakeLists.txt rename to examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/CMakeLists.txt diff --git a/examples/peripherals/touch_element/touch_element_waterproof/README.md b/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/README.md similarity index 100% rename from examples/peripherals/touch_element/touch_element_waterproof/README.md rename to examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/README.md diff --git a/examples/peripherals/touch_element/touch_element_waterproof/main/CMakeLists.txt b/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/CMakeLists.txt similarity index 100% rename from examples/peripherals/touch_element/touch_element_waterproof/main/CMakeLists.txt rename to examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/CMakeLists.txt diff --git a/examples/peripherals/touch_element/touch_element_waterproof/main/Kconfig.projbuild b/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/Kconfig.projbuild similarity index 100% rename from examples/peripherals/touch_element/touch_element_waterproof/main/Kconfig.projbuild rename to examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/Kconfig.projbuild diff --git a/examples/peripherals/touch_element/touch_element_waterproof/main/waterproof_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/waterproof_example_main.c similarity index 100% rename from examples/peripherals/touch_element/touch_element_waterproof/main/waterproof_example_main.c rename to examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/waterproof_example_main.c diff --git a/examples/peripherals/touch_element/touch_elements_combination/CMakeLists.txt b/examples/peripherals/touch_sensor/touch_element/touch_elements_combination/CMakeLists.txt similarity index 100% rename from examples/peripherals/touch_element/touch_elements_combination/CMakeLists.txt rename to examples/peripherals/touch_sensor/touch_element/touch_elements_combination/CMakeLists.txt diff --git a/examples/peripherals/touch_element/touch_elements_combination/README.md b/examples/peripherals/touch_sensor/touch_element/touch_elements_combination/README.md similarity index 100% rename from examples/peripherals/touch_element/touch_elements_combination/README.md rename to examples/peripherals/touch_sensor/touch_element/touch_elements_combination/README.md diff --git a/examples/peripherals/touch_element/touch_elements_combination/main/CMakeLists.txt b/examples/peripherals/touch_sensor/touch_element/touch_elements_combination/main/CMakeLists.txt similarity index 100% rename from examples/peripherals/touch_element/touch_elements_combination/main/CMakeLists.txt rename to examples/peripherals/touch_sensor/touch_element/touch_elements_combination/main/CMakeLists.txt diff --git a/examples/peripherals/touch_element/touch_elements_combination/main/touch_elements_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_elements_combination/main/touch_elements_example_main.c similarity index 100% rename from examples/peripherals/touch_element/touch_elements_combination/main/touch_elements_example_main.c rename to examples/peripherals/touch_sensor/touch_element/touch_elements_combination/main/touch_elements_example_main.c diff --git a/examples/peripherals/touch_element/touch_matrix/CMakeLists.txt b/examples/peripherals/touch_sensor/touch_element/touch_matrix/CMakeLists.txt similarity index 100% rename from examples/peripherals/touch_element/touch_matrix/CMakeLists.txt rename to examples/peripherals/touch_sensor/touch_element/touch_matrix/CMakeLists.txt diff --git a/examples/peripherals/touch_element/touch_matrix/README.md b/examples/peripherals/touch_sensor/touch_element/touch_matrix/README.md similarity index 100% rename from examples/peripherals/touch_element/touch_matrix/README.md rename to examples/peripherals/touch_sensor/touch_element/touch_matrix/README.md diff --git a/examples/peripherals/touch_element/touch_matrix/main/CMakeLists.txt b/examples/peripherals/touch_sensor/touch_element/touch_matrix/main/CMakeLists.txt similarity index 100% rename from examples/peripherals/touch_element/touch_matrix/main/CMakeLists.txt rename to examples/peripherals/touch_sensor/touch_element/touch_matrix/main/CMakeLists.txt diff --git a/examples/peripherals/touch_element/touch_matrix/main/Kconfig.projbuild b/examples/peripherals/touch_sensor/touch_element/touch_matrix/main/Kconfig.projbuild similarity index 100% rename from examples/peripherals/touch_element/touch_matrix/main/Kconfig.projbuild rename to examples/peripherals/touch_sensor/touch_element/touch_matrix/main/Kconfig.projbuild diff --git a/examples/peripherals/touch_element/touch_matrix/main/touch_matrix_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_matrix/main/touch_matrix_example_main.c similarity index 100% rename from examples/peripherals/touch_element/touch_matrix/main/touch_matrix_example_main.c rename to examples/peripherals/touch_sensor/touch_element/touch_matrix/main/touch_matrix_example_main.c diff --git a/examples/peripherals/touch_element/touch_slider/CMakeLists.txt b/examples/peripherals/touch_sensor/touch_element/touch_slider/CMakeLists.txt similarity index 100% rename from examples/peripherals/touch_element/touch_slider/CMakeLists.txt rename to examples/peripherals/touch_sensor/touch_element/touch_slider/CMakeLists.txt diff --git a/examples/peripherals/touch_element/touch_slider/README.md b/examples/peripherals/touch_sensor/touch_element/touch_slider/README.md similarity index 100% rename from examples/peripherals/touch_element/touch_slider/README.md rename to examples/peripherals/touch_sensor/touch_element/touch_slider/README.md diff --git a/examples/peripherals/touch_element/touch_slider/main/CMakeLists.txt b/examples/peripherals/touch_sensor/touch_element/touch_slider/main/CMakeLists.txt similarity index 100% rename from examples/peripherals/touch_element/touch_slider/main/CMakeLists.txt rename to examples/peripherals/touch_sensor/touch_element/touch_slider/main/CMakeLists.txt diff --git a/examples/peripherals/touch_element/touch_slider/main/Kconfig.projbuild b/examples/peripherals/touch_sensor/touch_element/touch_slider/main/Kconfig.projbuild similarity index 100% rename from examples/peripherals/touch_element/touch_slider/main/Kconfig.projbuild rename to examples/peripherals/touch_sensor/touch_element/touch_slider/main/Kconfig.projbuild diff --git a/examples/peripherals/touch_element/touch_slider/main/touch_slider_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_slider/main/touch_slider_example_main.c similarity index 100% rename from examples/peripherals/touch_element/touch_slider/main/touch_slider_example_main.c rename to examples/peripherals/touch_sensor/touch_element/touch_slider/main/touch_slider_example_main.c diff --git a/examples/peripherals/touch_sensor/touch_pad_interrupt/CMakeLists.txt b/examples/peripherals/touch_sensor/touch_pad_interrupt/CMakeLists.txt new file mode 100644 index 0000000000..9ab076f8e9 --- /dev/null +++ b/examples/peripherals/touch_sensor/touch_pad_interrupt/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(touch_pad_interrupt) diff --git a/examples/peripherals/touch_sensor/touch_pad_interrupt/Makefile b/examples/peripherals/touch_sensor/touch_pad_interrupt/Makefile new file mode 100644 index 0000000000..cbe818b212 --- /dev/null +++ b/examples/peripherals/touch_sensor/touch_pad_interrupt/Makefile @@ -0,0 +1,8 @@ +# +# This is a project Makefile. It is assumed the directory this Makefile resides in is a +# project subdirectory. +# + +PROJECT_NAME := touch_pad_interrupt + +include $(IDF_PATH)/make/project.mk diff --git a/examples/peripherals/touch_sensor/touch_pad_interrupt/README.md b/examples/peripherals/touch_sensor/touch_pad_interrupt/README.md new file mode 100644 index 0000000000..dd98af6762 --- /dev/null +++ b/examples/peripherals/touch_sensor/touch_pad_interrupt/README.md @@ -0,0 +1,36 @@ +| Supported Targets | ESP32-S2 | ESP32-S3 | +| ----------------- | -------- | -------- | + +# Touch Pad Interrupt Example + +## ESP32-S2, ESP32-S3 platform + +Demonstrates how to set up ESP32-S2's capacitive touch pad peripheral to trigger interrupt when a pad is touched. It also shows how to detect the touch event by the software for sensor designs when greater touch detection sensitivity is required. + +ESP32-S2 supports touch detection by configuring hardware registers. The hardware periodically detects the pulse counts. If the number of pulse counts exceeds the set threshold, a hardware interrupt will be generated to notify the application layer that a certain touch sensor channel may be triggered. + +The application is cycling between the interrupt mode and the pooling mode with a filter, to compare performance of the touch sensor system in both scenarios: + +``` +I (304) Touch pad: Initializing touch pad +I (304) Touch pad: Denoise function init +I (304) Touch pad: touch pad waterproof init +I (304) Touch pad: touch pad filter init 2 +I (414) Touch pad: test init: touch pad [7] base 7382, thresh 1476 +I (414) Touch pad: test init: touch pad [9] base 7349, thresh 1469 +I (414) Touch pad: test init: touch pad [11] base 8047, thresh 1609 +I (414) Touch pad: test init: touch pad [13] base 8104, thresh 810 +I (5954) Touch pad: TouchSensor [9] be actived, status mask 0x200 +W (6034) Touch pad: TouchSensor [13] be actived, enter guard mode +W (6034) Touch pad: In guard mode. No response +W (6174) Touch pad: TouchSensor [13] be actived, exit guard mode +I (6194) Touch pad: TouchSensor [9] be inactived, status mask 0x0 +``` + +## Reference Information + +For a simpler example how to configure and read capacitive touch pads, please refer to [touch_pad_read](../touch_pad_read). + +Design and implementation of the touch sensor system is a complex process. The [Touch Sensor Application Note](https://github.com/espressif/esp-iot-solution/blob/release/v1.0/documents/touch_pad_solution/touch_sensor_design_en.md) contains several ESP32 specific notes and comments to optimize the design and get the best out of the application with sensors controlled with the ESP32. + +See the README.md file in the upper level 'examples' directory for more information about examples. \ No newline at end of file diff --git a/examples/peripherals/touch_sensor/touch_pad_interrupt/main/CMakeLists.txt b/examples/peripherals/touch_sensor/touch_pad_interrupt/main/CMakeLists.txt new file mode 100644 index 0000000000..94fac9872e --- /dev/null +++ b/examples/peripherals/touch_sensor/touch_pad_interrupt/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "tp_interrupt_main.c" + INCLUDE_DIRS ".") diff --git a/examples/peripherals/touch_sensor/touch_pad_interrupt/main/component.mk b/examples/peripherals/touch_sensor/touch_pad_interrupt/main/component.mk new file mode 100644 index 0000000000..a98f634eae --- /dev/null +++ b/examples/peripherals/touch_sensor/touch_pad_interrupt/main/component.mk @@ -0,0 +1,4 @@ +# +# "main" pseudo-component makefile. +# +# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) diff --git a/examples/peripherals/touch_pad_interrupt/main/esp32s2/tp_interrupt_main.c b/examples/peripherals/touch_sensor/touch_pad_interrupt/main/tp_interrupt_main.c similarity index 99% rename from examples/peripherals/touch_pad_interrupt/main/esp32s2/tp_interrupt_main.c rename to examples/peripherals/touch_sensor/touch_pad_interrupt/main/tp_interrupt_main.c index 2b8ee7a014..226210a142 100644 --- a/examples/peripherals/touch_pad_interrupt/main/esp32s2/tp_interrupt_main.c +++ b/examples/peripherals/touch_sensor/touch_pad_interrupt/main/tp_interrupt_main.c @@ -161,7 +161,7 @@ void app_main(void) #if TOUCH_CHANGE_CONFIG /* If you want change the touch sensor default setting, please write here(after initialize). There are examples: */ - touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT); + touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_MEASURE_CYCLE_DEFAULT); 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++) { diff --git a/examples/peripherals/touch_sensor/touch_pad_read/CMakeLists.txt b/examples/peripherals/touch_sensor/touch_pad_read/CMakeLists.txt new file mode 100644 index 0000000000..828816fe4d --- /dev/null +++ b/examples/peripherals/touch_sensor/touch_pad_read/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(touch_pad_read) diff --git a/examples/peripherals/touch_sensor/touch_pad_read/Makefile b/examples/peripherals/touch_sensor/touch_pad_read/Makefile new file mode 100644 index 0000000000..12c01b12aa --- /dev/null +++ b/examples/peripherals/touch_sensor/touch_pad_read/Makefile @@ -0,0 +1,8 @@ +# +# This is a project Makefile. It is assumed the directory this Makefile resides in is a +# project subdirectory. +# + +PROJECT_NAME := touch_pad_read + +include $(IDF_PATH)/make/project.mk diff --git a/examples/peripherals/touch_pad_read/README.md b/examples/peripherals/touch_sensor/touch_pad_read/README.md similarity index 59% rename from examples/peripherals/touch_pad_read/README.md rename to examples/peripherals/touch_sensor/touch_pad_read/README.md index 3bfd7040e5..5f9bc5a108 100644 --- a/examples/peripherals/touch_pad_read/README.md +++ b/examples/peripherals/touch_sensor/touch_pad_read/README.md @@ -1,28 +1,9 @@ -| Supported Targets | ESP32 | ESP32-S2 | -| ----------------- | ----- | -------- | +| Supported Targets | ESP32-S2 | ESP32-S3 | +| ----------------- | -------- | -------- | # Touch Pad Read Example -## ESP32 plaform - -Read and display raw values or IIR filtered values from capacitive touch pad sensors. - -Once configured, ESP32 is continuously measuring capacitance of touch pad sensors. Measurement is reflected as numeric value inversely related to sensor's capacitance. The capacitance is bigger when sensor is touched with a finger and the measured value smaller. In opposite situation, when finger is released, capacitance is smaller and the measured value bigger. - -To detect when a sensor is touched and when not, each particular design should be calibrated by obtaining both measurements for each individual sensor. Then a threshold between both values should be established. Using specific threshold, API is then able to distinguish whether specific sensor is touched or released. - -ESP32 supports reading up to ten capacitive touch pad sensors T0 - T9, connected to specific GPIO pins. For information on available pins please refer to [Technical Reference Manual](https://espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf). Application initializes all ten sensor pads. Then in a loop reads sensors T0 - T9 and displays obtained values (after a colon) on a serial terminal: - -``` -Touch Sensor filter mode read, the output format is: -Touchpad num:[raw data, filtered data] - -T0:[1072,1071] T1:[ 475, 475] T2:[1004,1003] T3:[1232,1231] T4:[1675,1676] T5:[1146,1146] T6:[1607,1607] T7:[1118,1118] T8:[1695,1695] T9:[1223,1222] -T0:[1072,1071] T1:[ 475, 475] T2:[1003,1003] T3:[1231,1231] T4:[1676,1676] T5:[1146,1146] T6:[1607,1607] T7:[1118,1118] T8:[1694,1694] T9:[1222,1221] -T0:[1071,1071] T1:[ 475, 475] T2:[1004,1004] T3:[1231,1231] T4:[1678,1677] T5:[1147,1146] T6:[1607,1607] T7:[1118,1118] T8:[1694,1694] T9:[1222,1221] -``` - -## ESP32-S2 platform +## ESP32-S2, ESP32-S3 platform Read and display raw values from capacitive touch pad sensors. diff --git a/examples/peripherals/touch_sensor/touch_pad_read/main/CMakeLists.txt b/examples/peripherals/touch_sensor/touch_pad_read/main/CMakeLists.txt new file mode 100644 index 0000000000..2b9a209ec4 --- /dev/null +++ b/examples/peripherals/touch_sensor/touch_pad_read/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "tp_read_main.c" + INCLUDE_DIRS ".") diff --git a/examples/peripherals/touch_sensor/touch_pad_read/main/component.mk b/examples/peripherals/touch_sensor/touch_pad_read/main/component.mk new file mode 100644 index 0000000000..a98f634eae --- /dev/null +++ b/examples/peripherals/touch_sensor/touch_pad_read/main/component.mk @@ -0,0 +1,4 @@ +# +# "main" pseudo-component makefile. +# +# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) diff --git a/examples/peripherals/touch_pad_read/main/esp32s2/tp_read_main.c b/examples/peripherals/touch_sensor/touch_pad_read/main/tp_read_main.c similarity index 100% rename from examples/peripherals/touch_pad_read/main/esp32s2/tp_read_main.c rename to examples/peripherals/touch_sensor/touch_pad_read/main/tp_read_main.c From 589646a31eea9b3dfdd92e3a3d06540dfa23f4d0 Mon Sep 17 00:00:00 2001 From: fuzhibo Date: Mon, 6 Sep 2021 21:45:08 +0800 Subject: [PATCH 3/6] update touch with review advice --- components/driver/CMakeLists.txt | 2 +- components/driver/esp32s2/touch_sensor.c | 5 +- components/driver/esp32s3/touch_sensor.c | 610 +++++++++++++++++- components/soc/esp32/include/soc/soc_caps.h | 2 +- components/soc/esp32s2/include/soc/soc_caps.h | 3 +- .../touch_sensor/touch_periph_version.txt | 4 + .../touch_pad_interrupt/CMakeLists.txt | 0 .../touch_pad_interrupt/Makefile | 0 .../touch_pad_interrupt/README.md | 0 .../touch_pad_interrupt/main/CMakeLists.txt | 0 .../touch_pad_interrupt/main/component.mk | 0 .../main/tp_interrupt_main.c | 4 - .../touch_pad_read/CMakeLists.txt | 0 .../touch_pad_read/Makefile | 0 .../touch_pad_read/README.md | 0 .../touch_pad_read/main/CMakeLists.txt | 0 .../touch_pad_read/main/component.mk | 0 .../touch_pad_read/main/tp_read_main.c | 4 - .../touch_pad_interrupt/CMakeLists.txt | 0 .../touch_pad_interrupt/Makefile | 0 .../touch_pad_interrupt/README.md | 0 .../touch_pad_interrupt/main/CMakeLists.txt | 0 .../touch_pad_interrupt/main/component.mk | 0 .../main/tp_interrupt_main.c | 0 .../touch_pad_read/CMakeLists.txt | 0 .../touch_pad_read/Makefile | 0 .../touch_pad_read/README.md | 0 .../touch_pad_read/main/CMakeLists.txt | 0 .../touch_pad_read/main/component.mk | 0 .../touch_pad_read/main/tp_read_main.c | 2 +- 30 files changed, 617 insertions(+), 19 deletions(-) create mode 100644 examples/peripherals/touch_sensor/touch_periph_version.txt rename examples/peripherals/touch_sensor/{esp32 => touch_sensor_v1}/touch_pad_interrupt/CMakeLists.txt (100%) rename examples/peripherals/touch_sensor/{esp32 => touch_sensor_v1}/touch_pad_interrupt/Makefile (100%) rename examples/peripherals/touch_sensor/{esp32 => touch_sensor_v1}/touch_pad_interrupt/README.md (100%) rename examples/peripherals/touch_sensor/{esp32 => touch_sensor_v1}/touch_pad_interrupt/main/CMakeLists.txt (100%) rename examples/peripherals/touch_sensor/{esp32 => touch_sensor_v1}/touch_pad_interrupt/main/component.mk (100%) rename examples/peripherals/touch_sensor/{esp32 => touch_sensor_v1}/touch_pad_interrupt/main/tp_interrupt_main.c (98%) rename examples/peripherals/touch_sensor/{esp32 => touch_sensor_v1}/touch_pad_read/CMakeLists.txt (100%) rename examples/peripherals/touch_sensor/{esp32 => touch_sensor_v1}/touch_pad_read/Makefile (100%) rename examples/peripherals/touch_sensor/{esp32 => touch_sensor_v1}/touch_pad_read/README.md (100%) rename examples/peripherals/touch_sensor/{esp32 => touch_sensor_v1}/touch_pad_read/main/CMakeLists.txt (100%) rename examples/peripherals/touch_sensor/{esp32 => touch_sensor_v1}/touch_pad_read/main/component.mk (100%) rename examples/peripherals/touch_sensor/{esp32 => touch_sensor_v1}/touch_pad_read/main/tp_read_main.c (97%) rename examples/peripherals/touch_sensor/{ => touch_sensor_v2}/touch_pad_interrupt/CMakeLists.txt (100%) rename examples/peripherals/touch_sensor/{ => touch_sensor_v2}/touch_pad_interrupt/Makefile (100%) rename examples/peripherals/touch_sensor/{ => touch_sensor_v2}/touch_pad_interrupt/README.md (100%) rename examples/peripherals/touch_sensor/{ => touch_sensor_v2}/touch_pad_interrupt/main/CMakeLists.txt (100%) rename examples/peripherals/touch_sensor/{ => touch_sensor_v2}/touch_pad_interrupt/main/component.mk (100%) rename examples/peripherals/touch_sensor/{ => touch_sensor_v2}/touch_pad_interrupt/main/tp_interrupt_main.c (100%) rename examples/peripherals/touch_sensor/{ => touch_sensor_v2}/touch_pad_read/CMakeLists.txt (100%) rename examples/peripherals/touch_sensor/{ => touch_sensor_v2}/touch_pad_read/Makefile (100%) rename examples/peripherals/touch_sensor/{ => touch_sensor_v2}/touch_pad_read/README.md (100%) rename examples/peripherals/touch_sensor/{ => touch_sensor_v2}/touch_pad_read/main/CMakeLists.txt (100%) rename examples/peripherals/touch_sensor/{ => touch_sensor_v2}/touch_pad_read/main/component.mk (100%) rename examples/peripherals/touch_sensor/{ => touch_sensor_v2}/touch_pad_read/main/tp_read_main.c (99%) diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index c9026b268c..4671b23e7c 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -61,7 +61,7 @@ if(${target} STREQUAL "esp32s3") "usb_serial_jtag.c" "spi_slave_hd.c" "touch_sensor_common.c" - "esp32s2/touch_sensor.c" # The touch sensor function is the same as the esp32s2 platform. + "esp32s3/touch_sensor.c" ) endif() diff --git a/components/driver/esp32s2/touch_sensor.c b/components/driver/esp32s2/touch_sensor.c index c3c35824f8..98e390704b 100644 --- a/components/driver/esp32s2/touch_sensor.c +++ b/components/driver/esp32s2/touch_sensor.c @@ -62,7 +62,6 @@ static SemaphoreHandle_t rtc_touch_mux = NULL; Touch Pad ---------------------------------------------------------------*/ -#if CONFIG_IDF_TARGET_ESP32S2 /** Workaround for scan done interrupt issue. */ static void touch_pad_workaround_isr_internal(void *arg) { @@ -82,7 +81,6 @@ static void touch_pad_workaround_isr_internal(void *arg) } } } -#endif esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_mask_t intr_mask) { @@ -112,13 +110,12 @@ esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_ma } #endif esp_err_t ret = rtc_isr_register(fn, arg, en_msk); -#if CONFIG_IDF_TARGET_ESP32S2 /* Must ensure: After being registered, it is executed first. */ if ( (ret == ESP_OK) && (reg_flag == false) && (intr_mask & (TOUCH_PAD_INTR_MASK_SCAN_DONE | TOUCH_PAD_INTR_MASK_TIMEOUT)) ) { rtc_isr_register(touch_pad_workaround_isr_internal, NULL, RTC_CNTL_TOUCH_SCAN_DONE_INT_ST_M | RTC_CNTL_TOUCH_TIMEOUT_INT_ST_M); reg_flag = true; } -#endif + return ret; } diff --git a/components/driver/esp32s3/touch_sensor.c b/components/driver/esp32s3/touch_sensor.c index ba6323ce30..9a224d78b2 100644 --- a/components/driver/esp32s3/touch_sensor.c +++ b/components/driver/esp32s3/touch_sensor.c @@ -1,4 +1,608 @@ +/* + * SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include "esp_log.h" +#include "sys/lock.h" +#include "soc/soc_pins.h" +#include "freertos/FreeRTOS.h" +#include "freertos/xtensa_api.h" +#include "freertos/semphr.h" +#include "freertos/timers.h" +#include "esp_intr_alloc.h" +#include "driver/rtc_io.h" +#include "driver/touch_pad.h" +#include "driver/rtc_cntl.h" +#include "driver/gpio.h" +#include "sdkconfig.h" + +#include "hal/touch_sensor_types.h" +#include "hal/touch_sensor_hal.h" + +#ifndef NDEBUG +// Enable built-in checks in queue.h in debug builds +#define INVARIANTS +#endif +#include "sys/queue.h" + +#define TOUCH_PAD_FILTER_FACTOR_DEFAULT (4) // IIR filter coefficient. +#define TOUCH_PAD_SHIFT_DEFAULT (4) // Increase computing accuracy. +#define TOUCH_PAD_SHIFT_ROUND_DEFAULT (8) // ROUND = 2^(n-1); rounding off for fractional. +#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); \ + } 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_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. +#define TOUCH_ENTER_CRITICAL_SAFE() portENTER_CRITICAL_SAFE(&rtc_spinlock) // Can be called in isr and task. +#define TOUCH_EXIT_CRITICAL_SAFE() portEXIT_CRITICAL_SAFE(&rtc_spinlock) +#define TOUCH_ENTER_CRITICAL() portENTER_CRITICAL(&rtc_spinlock) +#define TOUCH_EXIT_CRITICAL() portEXIT_CRITICAL(&rtc_spinlock) + +static SemaphoreHandle_t rtc_touch_mux = NULL; + +/*--------------------------------------------------------------- + Touch Pad +---------------------------------------------------------------*/ + +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); + TOUCH_INTR_MASK_CHECK(intr_mask); + + uint32_t en_msk = 0; + if (intr_mask & TOUCH_PAD_INTR_MASK_DONE) { + en_msk |= RTC_CNTL_TOUCH_DONE_INT_ST_M; + } + if (intr_mask & TOUCH_PAD_INTR_MASK_ACTIVE) { + en_msk |= RTC_CNTL_TOUCH_ACTIVE_INT_ST_M; + } + if (intr_mask & TOUCH_PAD_INTR_MASK_INACTIVE) { + en_msk |= RTC_CNTL_TOUCH_INACTIVE_INT_ST_M; + } + if (intr_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) { + en_msk |= RTC_CNTL_TOUCH_SCAN_DONE_INT_ST_M; + } + if (intr_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) { + en_msk |= RTC_CNTL_TOUCH_TIMEOUT_INT_ST_M; + } +#if SOC_TOUCH_PROXIMITY_MEAS_DONE_SUPPORTED + if (intr_mask & TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE) { + en_msk |= RTC_CNTL_TOUCH_APPROACH_LOOP_DONE_INT_ST_M; + } +#endif + esp_err_t ret = rtc_isr_register(fn, arg, en_msk); + + return ret; +} + +esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_times) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_set_meas_times(meas_times); + touch_hal_set_sleep_time(sleep_cycle); + TOUCH_EXIT_CRITICAL(); + + return ESP_OK; +} + +esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_times) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_get_measure_times(meas_times); + touch_hal_get_sleep_time(sleep_cycle); + TOUCH_EXIT_CRITICAL(); + + return ESP_OK; +} + +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); + TOUCH_ENTER_CRITICAL(); + touch_hal_set_idle_channel_connect(type); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_get_idle_channel_connect(touch_pad_conn_type_t *type) +{ + touch_hal_get_idle_channel_connect(type); + return ESP_OK; +} + +bool touch_pad_meas_is_done(void) +{ + return touch_hal_meas_is_done(); +} + +esp_err_t touch_pad_set_channel_mask(uint16_t enable_mask) +{ + TOUCH_CH_MASK_CHECK(enable_mask); + TOUCH_ENTER_CRITICAL(); + touch_hal_set_channel_mask(enable_mask); + TOUCH_EXIT_CRITICAL(); + + return ESP_OK; +} + +esp_err_t touch_pad_get_channel_mask(uint16_t *enable_mask) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_get_channel_mask(enable_mask); + TOUCH_EXIT_CRITICAL(); + + return ESP_OK; +} + +esp_err_t touch_pad_clear_channel_mask(uint16_t enable_mask) +{ + TOUCH_CH_MASK_CHECK(enable_mask); + TOUCH_ENTER_CRITICAL(); + touch_hal_clear_channel_mask(enable_mask); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +touch_pad_t IRAM_ATTR touch_pad_get_current_meas_channel(void) +{ + return (touch_pad_t)touch_hal_get_current_meas_channel(); +} + +esp_err_t touch_pad_intr_enable(touch_pad_intr_mask_t int_mask) +{ + if (!(int_mask & TOUCH_PAD_INTR_MASK_ALL)) { + return ESP_ERR_INVALID_ARG; + } + TOUCH_ENTER_CRITICAL_SAFE(); + touch_hal_intr_enable(int_mask); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +esp_err_t touch_pad_intr_disable(touch_pad_intr_mask_t int_mask) +{ + if (!(int_mask & TOUCH_PAD_INTR_MASK_ALL)) { + return ESP_ERR_INVALID_ARG; + } + TOUCH_ENTER_CRITICAL_SAFE(); + touch_hal_intr_disable(int_mask); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +esp_err_t touch_pad_intr_clear(touch_pad_intr_mask_t int_mask) +{ + TOUCH_INTR_MASK_CHECK(int_mask); + TOUCH_ENTER_CRITICAL(); + touch_hal_intr_clear(int_mask); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +uint32_t touch_pad_read_intr_status_mask(void) +{ + return touch_hal_read_intr_status_mask(); +} + +esp_err_t touch_pad_timeout_set(bool enable, uint32_t threshold) +{ + TOUCH_ENTER_CRITICAL(); + if (enable) { + touch_hal_timeout_enable(); + } else { + touch_hal_timeout_disable(); + } + touch_hal_timeout_set_threshold(threshold); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_timeout_get_threshold(uint32_t *threshold) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_timeout_get_threshold(threshold); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_timeout_resume(void) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_timer_force_done(); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_config(touch_pad_t touch_num) +{ + TOUCH_CHANNEL_CHECK(touch_num); + + touch_pad_io_init(touch_num); + TOUCH_ENTER_CRITICAL(); + touch_hal_config(touch_num); + touch_hal_set_channel_mask(BIT(touch_num)); + TOUCH_EXIT_CRITICAL(); + + return ESP_OK; +} + +esp_err_t touch_pad_init(void) +{ + if (rtc_touch_mux == NULL) { + rtc_touch_mux = xSemaphoreCreateMutex(); + } + if (rtc_touch_mux == NULL) { + return ESP_ERR_NO_MEM; + } + TOUCH_ENTER_CRITICAL(); + touch_hal_init(); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_deinit(void) +{ + TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); + xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); + TOUCH_ENTER_CRITICAL(); + touch_hal_deinit(); + TOUCH_EXIT_CRITICAL(); + xSemaphoreGive(rtc_touch_mux); + vSemaphoreDelete(rtc_touch_mux); + rtc_touch_mux = NULL; + return ESP_OK; +} + +esp_err_t touch_pad_reset(void) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_reset(); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +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_ENTER_CRITICAL_SAFE(); + *raw_data = touch_hal_read_raw_data(touch_num); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +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_ENTER_CRITICAL_SAFE(); + touch_hal_filter_read_smooth(touch_num, smooth_data); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +esp_err_t IRAM_ATTR touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark) +{ + TOUCH_CHANNEL_CHECK(touch_num); + TOUCH_ENTER_CRITICAL_SAFE(); + touch_hal_read_benchmark(touch_num, benchmark); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +/* 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); + 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) +{ + 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_ENTER_CRITICAL(); + touch_hal_filter_set_config(filter_info); + TOUCH_EXIT_CRITICAL(); + + return ESP_OK; +} + +esp_err_t touch_pad_filter_get_config(touch_filter_config_t *filter_info) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_filter_get_config(filter_info); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_filter_enable(void) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_filter_enable(); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_filter_disable(void) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_filter_disable(); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_denoise_enable(void) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_clear_channel_mask(BIT(SOC_TOUCH_DENOISE_CHANNEL)); + touch_hal_denoise_enable(); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_denoise_disable(void) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_denoise_disable(); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_denoise_set_config(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); + + const touch_hal_meas_mode_t meas = { + .slope = TOUCH_PAD_SLOPE_DEFAULT, + .tie_opt = TOUCH_PAD_TIE_OPT_DEFAULT, + }; + TOUCH_ENTER_CRITICAL(); + touch_hal_set_meas_mode(SOC_TOUCH_DENOISE_CHANNEL, &meas); + touch_hal_denoise_set_config(denoise); + TOUCH_EXIT_CRITICAL(); + + return ESP_OK; +} + +esp_err_t touch_pad_denoise_get_config(touch_pad_denoise_t *denoise) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_denoise_get_config(denoise); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_denoise_read_data(uint32_t *data) +{ + touch_hal_denoise_read_data(data); + return ESP_OK; +} + +esp_err_t touch_pad_waterproof_set_config(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_ENTER_CRITICAL(); + touch_hal_waterproof_set_config(waterproof); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_waterproof_get_config(touch_pad_waterproof_t *waterproof) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_waterproof_get_config(waterproof); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_waterproof_enable(void) +{ + touch_pad_io_init(SOC_TOUCH_SHIELD_CHANNEL); + TOUCH_ENTER_CRITICAL(); + touch_hal_waterproof_enable(); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_waterproof_disable(void) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_waterproof_disable(); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +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); + + TOUCH_ENTER_CRITICAL(); + if (!touch_hal_enable_proximity(touch_num, enabled)) { + ret = ESP_ERR_NOT_SUPPORTED; + } + TOUCH_EXIT_CRITICAL(); + return ret; +} + +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); + + TOUCH_ENTER_CRITICAL(); + touch_hal_proximity_set_meas_times(count); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +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); + + TOUCH_ENTER_CRITICAL_SAFE(); + touch_hal_proximity_get_meas_times(count); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + /** - * The touch sensor function is the same as the esp32s2 platform. - * Please refer to the source files of the ESP32S2 platform. -*/ + * @brief Get measure count of proximity channel. + * The proximity sensor measurement is the accumulation of touch channel measurements. + * @param touch_num touch pad index + * @param cnt Pointer to receive proximity channel measurement count + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG parameter is NULL + */ +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_ENTER_CRITICAL_SAFE(); + touch_hal_proximity_read_meas_cnt(touch_num, cnt); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +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_ENTER_CRITICAL_SAFE(); + touch_hal_read_benchmark(touch_num, measure_out); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +/************** sleep pad setting ***********************/ + +esp_err_t touch_pad_sleep_channel_get_info(touch_pad_sleep_channel_t *slp_config) +{ + TOUCH_ENTER_CRITICAL_SAFE(); + touch_hal_sleep_channel_get_config(slp_config); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_enable(touch_pad_t pad_num, bool enable) +{ + TOUCH_CHANNEL_CHECK(pad_num); + + TOUCH_ENTER_CRITICAL(); + touch_hal_sleep_channel_enable(pad_num, enable); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_enable_proximity(touch_pad_t pad_num, bool enable) +{ + TOUCH_CHANNEL_CHECK(pad_num); + + TOUCH_ENTER_CRITICAL(); + if (enable) { + touch_hal_sleep_enable_approach(); + } else { + touch_hal_sleep_disable_approach(); + } + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_get_channel_num(touch_pad_t *pad_num) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_sleep_get_channel_num(pad_num); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_set_threshold(touch_pad_t pad_num, uint32_t touch_thres) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_sleep_set_threshold(touch_thres); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_get_threshold(touch_pad_t pad_num, uint32_t *touch_thres) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_sleep_get_threshold(touch_thres); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_read_benchmark(touch_pad_t pad_num, uint32_t *benchmark) +{ + TOUCH_ENTER_CRITICAL_SAFE(); + touch_hal_sleep_read_benchmark(benchmark); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_read_smooth(touch_pad_t pad_num, uint32_t *smooth_data) +{ + TOUCH_ENTER_CRITICAL_SAFE(); + touch_hal_sleep_read_smooth(smooth_data); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_read_data(touch_pad_t pad_num, uint32_t *raw_data) +{ + TOUCH_ENTER_CRITICAL_SAFE(); + touch_hal_sleep_read_data(raw_data); + TOUCH_EXIT_CRITICAL_SAFE(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_reset_benchmark(void) +{ + TOUCH_ENTER_CRITICAL(); + touch_hal_sleep_reset_benchmark(); + TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_read_debounce(touch_pad_t pad_num, uint32_t *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_hal_sleep_read_proximity_cnt(approach_cnt); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times) +{ + touch_hal_sleep_channel_set_work_time(sleep_cycle, meas_times); + return ESP_OK; +} diff --git a/components/soc/esp32/include/soc/soc_caps.h b/components/soc/esp32/include/soc/soc_caps.h index e39984ec51..02e4b1acc7 100644 --- a/components/soc/esp32/include/soc/soc_caps.h +++ b/components/soc/esp32/include/soc/soc_caps.h @@ -243,7 +243,6 @@ #define SOC_TOUCH_PAD_MEASURE_WAIT_MAX (0xFF) /*! Date: Wed, 8 Sep 2021 12:58:30 +0800 Subject: [PATCH 4/6] doc/touch: update touch sensor doc for S3 --- .../api-reference/peripherals/touch_pad.rst | 22 ++++++++++--------- .../api-reference/peripherals/touch_pad.rst | 20 +++++++++-------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/docs/en/api-reference/peripherals/touch_pad.rst b/docs/en/api-reference/peripherals/touch_pad.rst index 0e811669de..556ff39e63 100644 --- a/docs/en/api-reference/peripherals/touch_pad.rst +++ b/docs/en/api-reference/peripherals/touch_pad.rst @@ -2,6 +2,8 @@ Touch Sensor ============ :link_to_translation:`zh_CN:[中文]` +{IDF_TARGET_TOUCH_SENSOR_VERSION:default="v2", esp32="v1"} + Introduction ------------ @@ -9,13 +11,13 @@ A touch sensor system is built on a substrate which carries electrodes and relev .. only:: esp32 - ESP32 can handle up to 10 capacitive touch pads / GPIOs. + Touch sensor on {IDF_TARGET_NAME} is version 1 which supports up to 10 capacitive touch pads / GPIOs. -.. only:: esp32s2 +.. only:: esp32s2 or esp32s3 - {IDF_TARGET_NAME} can handle up to 14 capacitive touch pads / GPIOs. + Touch sensor on {IDF_TARGET_NAME} is version 2 which supports up to 14 capacitive touch pads / GPIOs. - The sensing pads can be arranged in different combinations (e.g., matrix, slider), so that a larger area or more points can be detected. The touch pad sensing process is under the control of a hardware-implemented finite-state machine (FSM) which is initiated by software or a dedicated hardware timer. +The sensing pads can be arranged in different combinations (e.g., matrix, slider), so that a larger area or more points can be detected. The touch pad sensing process is under the control of a hardware-implemented finite-state machine (FSM) which is initiated by software or a dedicated hardware timer. For design, operation, and control registers of a touch sensor, see *{IDF_TARGET_NAME} Technical Reference Manual* > *On-Chip Sensors and Analog Signal Processing* [`PDF <{IDF_TARGET_TRM_EN_URL}#sensor>`__]. @@ -72,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 +.. only:: esp32s2 or esp32s3 The following function come in handy to read raw measurements from the sensor: @@ -80,7 +82,7 @@ Touch State Measurements It can also be used, for example, to evaluate a particular touch pad design by checking the range of sensor readings when a pad is touched or released. This information can be then used to establish a touch threshold. -For the demonstration of how to read the touch pad data, check the application example :example:`peripherals/touch_pad_read`. +For the demonstration of how to read the touch pad data, check the application example :example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_read`. Optimization of Measurements ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -123,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 +.. only:: esp32s2 or esp32s3 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. @@ -139,7 +141,7 @@ Touch detection is implemented in ESP32's hardware based on the user-configured Hardware touch detection can also be wired to interrupts. This is described in the next section. -If measurements are noisy and capacity changes are small, hardware touch detection might be unreliable. To resolve this issue, instead of using hardware detection / provided interrupts, implement measurement filtering and perform touch detection in your own application. For sample implementation of both methods of touch detection, see :example:`peripherals/touch_pad_interrupt`. +If measurements are noisy and capacity changes are small, hardware touch detection might be unreliable. To resolve this issue, instead of using hardware detection / provided interrupts, implement measurement filtering and perform touch detection in your own application. For sample implementation of both methods of touch detection, see :example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_interrupt`. Touch Triggered Interrupts ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -182,8 +184,8 @@ When interrupts are operational, you can obtain the information from which parti Application Examples -------------------- -- Touch sensor read example: :example:`peripherals/touch_pad_read`. -- Touch sensor interrupt example: :example:`peripherals/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 8414032840..515b361051 100644 --- a/docs/zh_CN/api-reference/peripherals/touch_pad.rst +++ b/docs/zh_CN/api-reference/peripherals/touch_pad.rst @@ -2,6 +2,8 @@ ============ :link_to_translation:`en:[English]` +{IDF_TARGET_TOUCH_SENSOR_VERSION:default="v2", esp32="v1"} + 概述 ------------ @@ -9,11 +11,11 @@ .. only:: esp32 - ESP32 可最多支持 10 个电容式触摸传感器通道/GPIO。 + ESP32 上的触摸传感器硬件版本为V1.0,可最多支持 10 个电容式触摸传感器通道/GPIO。 -.. only:: esp32s2 +.. only:: esp32s2 or esp32s3 - {IDF_TARGET_NAME} 可最多支持 14 个电容式触摸传感器通道/GPIO。 + {IDF_TARGET_NAME} 上的触摸传感器硬件版本为V2.0,可最多支持 14 个电容式触摸传感器通道/GPIO。 触摸传感器可以以矩阵或滑条等方式组合使用,从而覆盖更大触感区域及更多触感点。触摸传感由软件或专用硬件计时器发起,由有限状态机 (FSM) 硬件控制。 @@ -72,7 +74,7 @@ 使用 :cpp:func:`touch_pad_read_filtered` 之前,需要先调用 `滤波采样`_ 中特定的滤波器函数来初始化并配置该滤波器。 -.. only:: esp32s2 +.. only:: esp32s2 or esp32s3 借助以下函数从传感器读取原始数据: @@ -80,7 +82,7 @@ 该函数也可以用于检查触碰和释放触摸传感器时传感器读数变化范围,然后根据这些信息设定触摸传感器的触摸阈值。 -请参考应用示例 :example:`peripherals/touch_pad_read`,查看如何使用读取触摸传感器数据。 +请参考应用示例 :example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_read`,查看如何使用读取触摸传感器数据。 优化测量 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -123,7 +125,7 @@ 如需停止滤波器,请调用 :cpp:func:`touch_pad_filter_stop` 函数。如果不再使用该滤波器,请调用 :cpp:func:`touch_pad_filter_delete` 删除此滤波器。 -.. only:: esp32s2 +.. only:: esp32s2 or esp32s3 如果测量中存在噪声,可以使用提供的 API 函数对采样进行滤波。{IDF_TARGET_NAME} 的触摸功能提供了两套 API 可实现此功能。 @@ -139,7 +141,7 @@ 用户也可以将硬件触摸监测连接至中断,详细介绍见下一章节。 -如果测量中存在噪声,且电容变化幅度较小,硬件触摸监测结果可能就不太理想。如需解决这一问题,不建议使用硬件监测或中断信号,建议用户在自己的应用程序中进行采样滤波,并执行触摸监测。请参考 :example:`peripherals/touch_pad_interrupt`,查看以上两种触摸监测的实现方式。 +如果测量中存在噪声,且电容变化幅度较小,硬件触摸监测结果可能就不太理想。如需解决这一问题,不建议使用硬件监测或中断信号,建议用户在自己的应用程序中进行采样滤波,并执行触摸监测。请参考 :example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_interrupt`,查看以上两种触摸监测的实现方式。 中断触发 ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -182,8 +184,8 @@ 应用示例 -------------------- -- 触摸传感器读值示例::example:`peripherals/touch_pad_read` -- 触摸传感器中断示例::example:`peripherals/touch_pad_interrupt` +- 触摸传感器读值示例::example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_read` +- 触摸传感器中断示例::example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_interrupt` .. _touch_pad-api-reference: From a1cadba191ecc9a1ed365caaf75be90ac9199cb8 Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Tue, 14 Sep 2021 14:36:18 +0800 Subject: [PATCH 5/6] touch_sensor: apply general check --- components/driver/esp32/touch_sensor.c | 96 ++++++++++--------- .../esp32s2/include/driver/touch_sensor.h | 6 +- components/driver/esp32s2/touch_sensor.c | 84 +++++++++------- .../esp32s3/include/driver/touch_sensor.h | 6 +- components/driver/esp32s3/touch_sensor.c | 84 +++++++++------- .../{test_esp32.c => test_touch_v1.c} | 0 .../{test_esp32s2.c => test_touch_v2.c} | 15 ++- components/hal/esp32s3/touch_sensor_hal.c | 18 +--- components/soc/esp32/include/soc/soc_caps.h | 1 + components/soc/esp32s2/include/soc/soc_caps.h | 5 +- components/soc/esp32s3/include/soc/soc_caps.h | 1 + .../api-reference/peripherals/touch_pad.rst | 28 +++--- .../api-reference/peripherals/touch_pad.rst | 24 ++--- .../main/tp_interrupt_main.c | 2 +- .../touch_pad_read/main/tp_read_main.c | 2 +- tools/ci/check_copyright_ignore.txt | 13 --- 16 files changed, 209 insertions(+), 176 deletions(-) rename components/driver/test/touch_sensor_test/{test_esp32.c => test_touch_v1.c} (100%) rename components/driver/test/touch_sensor_test/{test_esp32s2.c => test_touch_v2.c} (99%) 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 From f4705f8eb44fa2e07e09618178b832ac3b5d024b Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Fri, 8 Oct 2021 11:45:57 +0800 Subject: [PATCH 6/6] touch sensor: update copyright notice --- .../hal/esp32s3/include/hal/rtc_io_ll.h | 18 +++++------------- .../esp32s3/include/hal/touch_sensor_hal.h | 18 +++++------------- .../hal/esp32s3/include/hal/touch_sensor_ll.h | 18 +++++------------- .../hal/include/hal/touch_sensor_types.h | 18 +++++------------- components/soc/esp32/include/soc/soc_caps.h | 18 +++++------------- components/soc/esp32s3/include/soc/rtc.h | 19 ++++++------------- .../soc/esp32s3/include/soc/rtc_cntl_reg.h | 19 ++++++------------- .../soc/esp32s3/include/soc/rtc_cntl_struct.h | 19 ++++++------------- .../soc/esp32s3/include/soc/sens_struct.h | 19 ++++++------------- components/soc/esp32s3/include/soc/soc_pins.h | 18 +++++------------- .../include/soc/touch_sensor_channel.h | 18 +++++------------- .../esp32s3/include/soc/touch_sensor_pins.h | 18 +++++------------- components/soc/esp32s3/touch_sensor_periph.c | 18 +++++------------- .../main/touch_button_example_main.c | 18 +++++------------- .../main/waterproof_example_main.c | 18 +++++------------- .../main/touch_elements_example_main.c | 18 +++++------------- .../main/touch_matrix_example_main.c | 18 +++++------------- .../main/touch_slider_example_main.c | 18 +++++------------- .../main/tp_interrupt_main.c | 12 +++++------- .../touch_pad_read/main/tp_read_main.c | 12 +++++------- .../main/tp_interrupt_main.c | 12 +++++------- .../touch_pad_read/main/tp_read_main.c | 12 +++++------- 22 files changed, 114 insertions(+), 262 deletions(-) diff --git a/components/hal/esp32s3/include/hal/rtc_io_ll.h b/components/hal/esp32s3/include/hal/rtc_io_ll.h index bdf3a77156..2bd6d12fad 100644 --- a/components/hal/esp32s3/include/hal/rtc_io_ll.h +++ b/components/hal/esp32s3/include/hal/rtc_io_ll.h @@ -1,16 +1,8 @@ -// Copyright 2015-2020 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 + */ /******************************************************************************* * NOTICE diff --git a/components/hal/esp32s3/include/hal/touch_sensor_hal.h b/components/hal/esp32s3/include/hal/touch_sensor_hal.h index 8dc0263d94..603c437f16 100644 --- a/components/hal/esp32s3/include/hal/touch_sensor_hal.h +++ b/components/hal/esp32s3/include/hal/touch_sensor_hal.h @@ -1,16 +1,8 @@ -// Copyright 2019 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 + */ /******************************************************************************* * NOTICE diff --git a/components/hal/esp32s3/include/hal/touch_sensor_ll.h b/components/hal/esp32s3/include/hal/touch_sensor_ll.h index 7af44b463a..d2d0d24fc4 100644 --- a/components/hal/esp32s3/include/hal/touch_sensor_ll.h +++ b/components/hal/esp32s3/include/hal/touch_sensor_ll.h @@ -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 + */ /******************************************************************************* * NOTICE diff --git a/components/hal/include/hal/touch_sensor_types.h b/components/hal/include/hal/touch_sensor_types.h index 373d978260..9085f5eecd 100644 --- a/components/hal/include/hal/touch_sensor_types.h +++ b/components/hal/include/hal/touch_sensor_types.h @@ -1,16 +1,8 @@ -// Copyright 2015-2020 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 + */ #pragma once diff --git a/components/soc/esp32/include/soc/soc_caps.h b/components/soc/esp32/include/soc/soc_caps.h index c640df1286..88b6f1c8ee 100644 --- a/components/soc/esp32/include/soc/soc_caps.h +++ b/components/soc/esp32/include/soc/soc_caps.h @@ -1,16 +1,8 @@ -// Copyright 2020 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 + */ /* * Soc capabilities file, describing the following chip attributes: diff --git a/components/soc/esp32s3/include/soc/rtc.h b/components/soc/esp32s3/include/soc/rtc.h index b036b91126..aa09874f2c 100644 --- a/components/soc/esp32s3/include/soc/rtc.h +++ b/components/soc/esp32s3/include/soc/rtc.h @@ -1,16 +1,9 @@ -// Copyright 2015-2020 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 + */ + #pragma once #include diff --git a/components/soc/esp32s3/include/soc/rtc_cntl_reg.h b/components/soc/esp32s3/include/soc/rtc_cntl_reg.h index 7453e62c91..f2a859aed4 100644 --- a/components/soc/esp32s3/include/soc/rtc_cntl_reg.h +++ b/components/soc/esp32s3/include/soc/rtc_cntl_reg.h @@ -1,16 +1,9 @@ -// Copyright 2017-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 + */ + #ifndef _SOC_RTC_CNTL_REG_H_ #define _SOC_RTC_CNTL_REG_H_ diff --git a/components/soc/esp32s3/include/soc/rtc_cntl_struct.h b/components/soc/esp32s3/include/soc/rtc_cntl_struct.h index c37c5201b6..70b4b511fd 100644 --- a/components/soc/esp32s3/include/soc/rtc_cntl_struct.h +++ b/components/soc/esp32s3/include/soc/rtc_cntl_struct.h @@ -1,16 +1,9 @@ -// Copyright 2017-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 + */ + #ifndef _SOC_RTC_CNTL_STRUCT_H_ #define _SOC_RTC_CNTL_STRUCT_H_ diff --git a/components/soc/esp32s3/include/soc/sens_struct.h b/components/soc/esp32s3/include/soc/sens_struct.h index 25e875c995..c2a104d4cc 100644 --- a/components/soc/esp32s3/include/soc/sens_struct.h +++ b/components/soc/esp32s3/include/soc/sens_struct.h @@ -1,16 +1,9 @@ -// Copyright 2017-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 + */ + #ifndef _SOC_SENS_STRUCT_H_ #define _SOC_SENS_STRUCT_H_ diff --git a/components/soc/esp32s3/include/soc/soc_pins.h b/components/soc/esp32s3/include/soc/soc_pins.h index 233325844c..dfb6b00637 100644 --- a/components/soc/esp32s3/include/soc/soc_pins.h +++ b/components/soc/esp32s3/include/soc/soc_pins.h @@ -1,16 +1,8 @@ -// Copyright 2020 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 + */ /* * Pin definition header file. The long term plan is to have a single soc_pins.h for all diff --git a/components/soc/esp32s3/include/soc/touch_sensor_channel.h b/components/soc/esp32s3/include/soc/touch_sensor_channel.h index 297458d38e..d5065eac4f 100644 --- a/components/soc/esp32s3/include/soc/touch_sensor_channel.h +++ b/components/soc/esp32s3/include/soc/touch_sensor_channel.h @@ -1,16 +1,8 @@ -// Copyright 2010-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 + */ #pragma once diff --git a/components/soc/esp32s3/include/soc/touch_sensor_pins.h b/components/soc/esp32s3/include/soc/touch_sensor_pins.h index 6ec17be72a..70046fc649 100644 --- a/components/soc/esp32s3/include/soc/touch_sensor_pins.h +++ b/components/soc/esp32s3/include/soc/touch_sensor_pins.h @@ -1,16 +1,8 @@ -// Copyright 2019 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 + */ #pragma once diff --git a/components/soc/esp32s3/touch_sensor_periph.c b/components/soc/esp32s3/touch_sensor_periph.c index eb575c02ba..f9f4246ab1 100644 --- a/components/soc/esp32s3/touch_sensor_periph.c +++ b/components/soc/esp32s3/touch_sensor_periph.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 + */ #include "soc/touch_sensor_periph.h" diff --git a/examples/peripherals/touch_sensor/touch_element/touch_button/main/touch_button_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_button/main/touch_button_example_main.c index 76285e7846..ef3f389c67 100644 --- a/examples/peripherals/touch_sensor/touch_element/touch_button/main/touch_button_example_main.c +++ b/examples/peripherals/touch_sensor/touch_element/touch_button/main/touch_button_example_main.c @@ -1,16 +1,8 @@ -/* Touch Sensor - Example - - For other examples please check: - https://github.com/espressif/esp-idf/tree/master/examples - - See README.md file to get detailed usage of this example. - - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: CC0-1.0 + */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" diff --git a/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/waterproof_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/waterproof_example_main.c index 26abd4d5b3..a8828f2e23 100644 --- a/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/waterproof_example_main.c +++ b/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/waterproof_example_main.c @@ -1,16 +1,8 @@ -/* Touch Sensor waterproof - Example - - For other examples please check: - https://github.com/espressif/esp-idf/tree/master/examples - - See README.md file to get detailed usage of this example. - - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: CC0-1.0 + */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" diff --git a/examples/peripherals/touch_sensor/touch_element/touch_elements_combination/main/touch_elements_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_elements_combination/main/touch_elements_example_main.c index 484f9a4ef7..b89e42d224 100644 --- a/examples/peripherals/touch_sensor/touch_element/touch_elements_combination/main/touch_elements_example_main.c +++ b/examples/peripherals/touch_sensor/touch_element/touch_elements_combination/main/touch_elements_example_main.c @@ -1,16 +1,8 @@ -/* Touch Sensor - Example - - For other examples please check: - https://github.com/espressif/esp-idf/tree/master/examples - - See README.md file to get detailed usage of this example. - - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: CC0-1.0 + */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" diff --git a/examples/peripherals/touch_sensor/touch_element/touch_matrix/main/touch_matrix_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_matrix/main/touch_matrix_example_main.c index ec2dacc172..51507889bf 100644 --- a/examples/peripherals/touch_sensor/touch_element/touch_matrix/main/touch_matrix_example_main.c +++ b/examples/peripherals/touch_sensor/touch_element/touch_matrix/main/touch_matrix_example_main.c @@ -1,16 +1,8 @@ -/* Touch Sensor - Example - - For other examples please check: - https://github.com/espressif/esp-idf/tree/master/examples - - See README.md file to get detailed usage of this example. - - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: CC0-1.0 + */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" diff --git a/examples/peripherals/touch_sensor/touch_element/touch_slider/main/touch_slider_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_slider/main/touch_slider_example_main.c index fefe6e0832..6ec3d32728 100644 --- a/examples/peripherals/touch_sensor/touch_element/touch_slider/main/touch_slider_example_main.c +++ b/examples/peripherals/touch_sensor/touch_element/touch_slider/main/touch_slider_example_main.c @@ -1,16 +1,8 @@ -/* Touch Sensor - Example - - For other examples please check: - https://github.com/espressif/esp-idf/tree/master/examples - - See README.md file to get detailed usage of this example. - - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: CC0-1.0 + */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" diff --git a/examples/peripherals/touch_sensor/touch_sensor_v1/touch_pad_interrupt/main/tp_interrupt_main.c b/examples/peripherals/touch_sensor/touch_sensor_v1/touch_pad_interrupt/main/tp_interrupt_main.c index 0c0187c498..63b790c662 100644 --- a/examples/peripherals/touch_sensor/touch_sensor_v1/touch_pad_interrupt/main/tp_interrupt_main.c +++ b/examples/peripherals/touch_sensor/touch_sensor_v1/touch_pad_interrupt/main/tp_interrupt_main.c @@ -1,11 +1,9 @@ -/* Touch Pad Interrupt Example +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: CC0-1.0 + */ - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" diff --git a/examples/peripherals/touch_sensor/touch_sensor_v1/touch_pad_read/main/tp_read_main.c b/examples/peripherals/touch_sensor/touch_sensor_v1/touch_pad_read/main/tp_read_main.c index 4ab44003c8..2d1424bbd3 100644 --- a/examples/peripherals/touch_sensor/touch_sensor_v1/touch_pad_read/main/tp_read_main.c +++ b/examples/peripherals/touch_sensor/touch_sensor_v1/touch_pad_read/main/tp_read_main.c @@ -1,11 +1,9 @@ -/* Touch Pad Read Example +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: CC0-1.0 + */ - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" 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 b3e743ab8d..0bc745e14e 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 @@ -1,11 +1,9 @@ -/* Touch Pad Interrupt Example +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: CC0-1.0 + */ - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" 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 16d2b712fb..ad6a1f753d 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 @@ -1,11 +1,9 @@ -/* Touch Pad Read Example +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: CC0-1.0 + */ - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ #include #include "freertos/FreeRTOS.h" #include "freertos/task.h"