Merge branch 'feature/touch_driver_ng_on_s2_s3' into 'master'

feat(touch): touch driver-NG on S2 & S3

Closes IDF-10182

See merge request espressif/esp-idf!34051
This commit is contained in:
Kevin (Lao Kaiyao)
2024-10-30 14:28:01 +08:00
96 changed files with 4912 additions and 2745 deletions

View File

@@ -152,4 +152,15 @@ menu "Driver Configurations"
and don't want to see related deprecation warnings, you can enable this option. and don't want to see related deprecation warnings, you can enable this option.
endmenu # Legacy Temperature Sensor Driver Configurationss endmenu # Legacy Temperature Sensor Driver Configurationss
menu "Legacy Touch Sensor Driver Configurations"
depends on SOC_TOUCH_SENSOR_SUPPORTED
config TOUCH_SUPPRESS_DEPRECATE_WARN
bool "Suppress legacy driver deprecated warning"
default n
help
whether to suppress the deprecation warnings when using legacy touch sensor driver
(driver/touch_sensor.h). If you want to continue using the legacy driver,
and don't want to see related deprecation warnings, you can enable this option.
endmenu # Legacy Touch Sensor Driver Configurationss
endmenu # Driver configurations endmenu # Driver configurations

View File

@@ -10,20 +10,19 @@
#include "sdkconfig.h" #include "sdkconfig.h"
#include "esp_system.h" #include "esp_system.h"
#include "driver/touch_pad.h"
#include "unity.h" #include "unity.h"
#include "esp_system.h" #include "esp_system.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_log.h" #include "esp_log.h"
#include "soc/rtc_cntl_reg.h" #include "soc/soc_caps.h"
#include "soc/rtc_cntl_struct.h"
#include "soc/sens_reg.h" #include "soc/sens_reg.h"
#include "soc/sens_struct.h" #include "soc/sens_struct.h"
#include "soc/rtc_cntl_reg.h" #include "soc/rtc_cntl_reg.h"
#include "soc/rtc_cntl_struct.h" #include "soc/rtc_cntl_struct.h"
#include "soc/rtc_io_reg.h" #include "soc/rtc_io_reg.h"
#include "soc/rtc_io_struct.h" #include "soc/rtc_io_struct.h"
#include "driver/touch_sensor.h"
#include "esp_rom_sys.h" #include "esp_rom_sys.h"
#if CONFIG_PM_ENABLE #if CONFIG_PM_ENABLE
#include "esp_pm.h" #include "esp_pm.h"

View File

@@ -12,7 +12,6 @@
#include <string.h> #include <string.h>
#include <inttypes.h> #include <inttypes.h>
#include "esp_system.h" #include "esp_system.h"
#include "driver/touch_pad.h"
#include "unity.h" #include "unity.h"
#include "esp_system.h" #include "esp_system.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
@@ -20,8 +19,7 @@
#include "freertos/semphr.h" #include "freertos/semphr.h"
#include "freertos/queue.h" #include "freertos/queue.h"
#include "esp_log.h" #include "esp_log.h"
#include "soc/rtc_cntl_reg.h" #include "soc/soc_caps.h"
#include "soc/rtc_cntl_struct.h"
#include "soc/sens_reg.h" #include "soc/sens_reg.h"
#include "soc/sens_struct.h" #include "soc/sens_struct.h"
#include "soc/rtc_cntl_reg.h" #include "soc/rtc_cntl_reg.h"
@@ -30,6 +28,7 @@
#include "soc/rtc_io_struct.h" #include "soc/rtc_io_struct.h"
#include "soc/syscon_reg.h" #include "soc/syscon_reg.h"
#include "driver/rtc_io.h" #include "driver/rtc_io.h"
#include "driver/touch_sensor_legacy.h"
#include "esp_rom_sys.h" #include "esp_rom_sys.h"
static const char *TAG = "test_touch"; static const char *TAG = "test_touch";

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */

View File

@@ -27,7 +27,7 @@
#define INVARIANTS #define INVARIANTS
#endif #endif
#include "sys/queue.h" #include "sys/queue.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sensor_legacy_types.h"
#include "hal/touch_sensor_hal.h" #include "hal/touch_sensor_hal.h"
typedef struct { typedef struct {

View File

@@ -1,646 +1,17 @@
/* /*
* SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#pragma once #pragma once
#include "driver/touch_sensor_common.h" #include "sdkconfig.h"
#include "driver/touch_sensor_legacy.h"
#ifdef __cplusplus #if !CONFIG_TOUCH_SUPPRESS_DEPRECATE_WARN
extern "C" { #warning "This set of Touch APIs has been deprecated, \
#endif please include 'driver/touch_sens.h' instead. \
if you want to keep using the old APIs and ignore this warning, \
/** you can enable 'Suppress legacy driver deprecated warning' option under 'Touch Configuration' menu in Kconfig"
* @brief Set touch sensor FSM start
* @note Start FSM after the touch sensor FSM mode is set.
* @note Call this function will reset benchmark of all touch channels.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_fsm_start(void);
/**
* @brief Stop touch sensor FSM.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_fsm_stop(void);
/**
* @brief Trigger a touch sensor measurement, only support in SW mode of FSM
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_sw_start(void);
/**
* @brief Set charge and discharge times of each measurement
* @note This function will specify the charge and discharge times in each measurement period
* The clock is sourced from SOC_MOD_CLK_RTC_FAST, and its default frequency is SOC_CLK_RC_FAST_FREQ_APPROX
* The touch sensor will record the total clock cycles of all the charge and discharge cycles as the final result (raw value)
* @note If the charge and discharge times is too small, it may lead to inaccurate results.
*
* @param charge_discharge_times Charge and discharge times, range: 0 ~ 0xffff.
* No exact typical value can be recommended because the capacity is influenced by the hardware design and how finger touches,
* but suggest adjusting this value to make the measurement time around 1 ms.
* @return
* - ESP_OK Set charge and discharge times success
*/
esp_err_t touch_pad_set_charge_discharge_times(uint16_t charge_discharge_times);
/**
* @brief Get charge and discharge times of each measurement
*
* @param charge_discharge_times Charge and discharge times
* @return
* - ESP_OK Get charge_discharge_times success
* - ESP_ERR_INVALID_ARG The input parameter is NULL
*/
esp_err_t touch_pad_get_charge_discharge_times(uint16_t *charge_discharge_times);
/**
* @brief Set the interval between two measurements
* @note The touch sensor will sleep between two measurements
* This function is to set the interval cycle
* And the interval is clocked from SOC_MOD_CLK_RTC_SLOW, its default frequency is SOC_CLK_RC_SLOW_FREQ_APPROX
*
* @param interval_cycle The interval between two measurements
* sleep_time = interval_cycle / SOC_CLK_RC_SLOW_FREQ_APPROX.
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
* @return
* - ESP_OK Set interval cycle success
*/
esp_err_t touch_pad_set_measurement_interval(uint16_t interval_cycle);
/**
* @brief Get the interval between two measurements
*
* @param interval_cycle The interval between two measurements
* @return
* - ESP_OK Get interval cycle success
* - ESP_ERR_INVALID_ARG The input parameter is NULL
*/
esp_err_t touch_pad_get_measurement_interval(uint16_t *interval_cycle);
/**
* @brief Set touch sensor times of charge and discharge and sleep time.
* Excessive total time will slow down the touch response.
* Too small measurement time will not be sampled enough, resulting in inaccurate measurements.
* @note The touch sensor will measure time of a fixed number of charge/discharge cycles (specified as the second parameter).
* That means the time (raw value) will increase as the capacity of the touch pad is increasing.
* The time (raw value) here is the number of clock cycles which is sourced from SOC_MOD_CLK_RTC_FAST and at (SOC_CLK_RC_FAST_FREQ_APPROX) Hz as default
* @note The greater the duty cycle of the measurement time, the more system power is consumed.
*
* @param sleep_cycle The touch sensor will sleep after each measurement.
* sleep_cycle decide the interval between each measurement.
* t_sleep = sleep_cycle / SOC_CLK_RC_SLOW_FREQ_APPROX.
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
* @param meas_times The times of charge and discharge in each measurement of touch channels. Range: 0 ~ 0xffff.
* Recommended typical value: Modify this value to make the measurement time around 1 ms.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_times)
__attribute__((deprecated("please use 'touch_pad_set_charge_discharge_times' and 'touch_pad_set_measurement_interval' instead")));
/**
* @brief Get touch sensor times of charge and discharge and sleep time
* @param sleep_cycle Pointer to accept sleep cycle number
* @param meas_times Pointer to accept measurement times count.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_times)
__attribute__((deprecated("please use 'touch_pad_get_charge_discharge_times' and 'touch_pad_get_measurement_interval' instead")));
/**
* @brief Set the connection type of touch channels in idle status.
* When a channel is in measurement mode, other initialized channels are in idle mode.
* The touch channel is generally adjacent to the trace, so the connection state of the idle channel
* affects the stability and sensitivity of the test channel.
* The `CONN_HIGHZ`(high resistance) setting increases the sensitivity of touch channels.
* The `CONN_GND`(grounding) setting increases the stability of touch channels.
* @param type Select idle channel connect to high resistance state or ground.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_set_idle_channel_connect(touch_pad_conn_type_t type);
/**
* @brief Get the connection type of touch channels in idle status.
* When a channel is in measurement mode, other initialized channels are in idle mode.
* The touch channel is generally adjacent to the trace, so the connection state of the idle channel
* affects the stability and sensitivity of the test channel.
* The `CONN_HIGHZ`(high resistance) setting increases the sensitivity of touch channels.
* The `CONN_GND`(grounding) setting increases the stability of touch channels.
* @param type Pointer to connection type.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_get_idle_channel_connect(touch_pad_conn_type_t *type);
/**
* @brief Set the trigger threshold of touch sensor.
* The threshold determines the sensitivity of the touch sensor.
* The threshold is the original value of the trigger state minus the benchmark value.
* @note If set "TOUCH_PAD_THRESHOLD_MAX", the touch is never be triggered.
* @param touch_num touch pad index
* @param threshold threshold of touch sensor. Should be less than the max change value of touch.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_set_thresh(touch_pad_t touch_num, uint32_t threshold);
/**
* @brief Get touch sensor trigger threshold
* @param touch_num touch pad index
* @param threshold pointer to accept threshold
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG if argument is wrong
*/
esp_err_t touch_pad_get_thresh(touch_pad_t touch_num, uint32_t *threshold);
/**
* @brief Register touch channel into touch sensor scan group.
* The working mode of the touch sensor is cyclically scanned.
* This function will set the scan bits according to the given bitmask.
* @note If set this mask, the FSM timer should be stop firsty.
* @note The touch sensor that in scan map, should be deinit GPIO function firstly by `touch_pad_io_init`.
* @param enable_mask bitmask of touch sensor scan group.
* e.g. TOUCH_PAD_NUM14 -> BIT(14)
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_set_channel_mask(uint16_t enable_mask);
/**
* @brief Get the touch sensor scan group bit mask.
* @param enable_mask Pointer to bitmask of touch sensor scan group.
* e.g. TOUCH_PAD_NUM14 -> BIT(14)
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_get_channel_mask(uint16_t *enable_mask);
/**
* @brief Clear touch channel from touch sensor scan group.
* The working mode of the touch sensor is cyclically scanned.
* This function will clear the scan bits according to the given bitmask.
* @note If clear all mask, the FSM timer should be stop firsty.
* @param enable_mask bitmask of touch sensor scan group.
* e.g. TOUCH_PAD_NUM14 -> BIT(14)
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_clear_channel_mask(uint16_t enable_mask);
/**
* @brief Configure parameter for each touch channel.
* @note Touch num 0 is denoise channel, please use `touch_pad_denoise_enable` to set denoise function
* @param touch_num touch pad index
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG if argument wrong
* - ESP_FAIL if touch pad not initialized
*/
esp_err_t touch_pad_config(touch_pad_t touch_num);
/**
* @brief Reset the FSM of touch module.
* @note Call this function after `touch_pad_fsm_stop`.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_reset(void);
/**
* @brief Get the current measure channel.
* @note Should be called when touch sensor measurement is in cyclic scan mode.
* @return
* - touch channel number
*/
touch_pad_t touch_pad_get_current_meas_channel(void);
/**
* @brief Get the touch sensor interrupt status mask.
* @return
* - touch interrupt bit
*/
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
*/
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
*/
esp_err_t touch_pad_intr_disable(touch_pad_intr_mask_t int_mask);
/**
* @brief Clear touch sensor interrupt by bitmask.
* @param int_mask Pad mask to clear interrupts
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_intr_clear(touch_pad_intr_mask_t int_mask);
/**
* @brief Register touch-pad ISR.
* The handler will be attached to the same CPU core that this function is running on.
* @param fn Pointer to ISR handler
* @param arg Parameter for ISR
* @param intr_mask Enable touch sensor interrupt handler by bitmask.
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Arguments error
* - ESP_ERR_NO_MEM No memory
*/
esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_mask_t intr_mask);
/**
* @brief Enable/disable the timeout check and set timeout threshold for all touch sensor channels measurements.
* If enable: When the touch reading of a touch channel exceeds the measurement threshold, a timeout interrupt will be generated.
* If disable: the FSM does not check if the channel under measurement times out.
*
* @note The threshold compared with touch readings.
* @note In order to avoid abnormal short circuit of some touch channels. This function should be turned on.
* Ensure the normal operation of other touch channels.
*
* @param enable true(default): Enable the timeout check; false: Disable the timeout check.
* @param threshold For all channels, the maximum value that will not be exceeded during normal operation.
*
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_timeout_set(bool enable, uint32_t threshold);
/**
* @brief Call this interface after timeout to make the touch channel resume normal work. Point on the next channel to measure.
* If this API is not called, the touch FSM will stop the measurement after timeout interrupt.
*
* @note Call this API after finishes the exception handling by user.
*
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_timeout_resume(void);
/**
* @brief get raw data of touch sensor.
* @note After the initialization is complete, the "raw_data" is max value. You need to wait for a measurement
* cycle before you can read the correct touch value.
* @param touch_num touch pad index
* @param raw_data pointer to accept touch sensor value
* @return
* - ESP_OK Success
* - ESP_FAIL Touch channel 0 haven't this parameter.
*/
esp_err_t touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data);
/**
* @brief get benchmark of touch sensor.
* @note After initialization, the benchmark value is the maximum during the first measurement period.
* @param touch_num touch pad index
* @param benchmark pointer to accept touch sensor benchmark value
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Touch channel 0 haven't this parameter.
*/
esp_err_t touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark);
/**
* @brief Get smoothed data that obtained by filtering the raw data.
*
* @param touch_num touch pad index
* @param smooth pointer to smoothed data
*/
esp_err_t touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth);
/**
* @brief Force reset benchmark to raw data of touch sensor.
* @param touch_num touch pad index
* - TOUCH_PAD_MAX Reset basaline of all channels
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_reset_benchmark(touch_pad_t touch_num);
/**
* @brief set parameter of touch sensor filter and detection algorithm.
* For more details on the detection algorithm, please refer to the application documentation.
* @param filter_info select filter type and threshold of detection algorithm
* @return
* - ESP_OK Success
*/
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.
* For more details on the detection algorithm, please refer to the application documentation.
* @param filter_info select filter type and threshold of detection algorithm
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_filter_get_config(touch_filter_config_t *filter_info);
/**
* @brief enable touch sensor filter for detection algorithm.
* For more details on the detection algorithm, please refer to the application documentation.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_filter_enable(void);
/**
* @brief disable touch sensor filter for detection algorithm.
* For more details on the detection algorithm, please refer to the application documentation.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_filter_disable(void);
/**
* @brief set parameter of denoise pad (TOUCH_PAD_NUM0).
* T0 is an internal channel that does not have a corresponding external GPIO.
* T0 will work simultaneously with the measured channel Tn. Finally, the actual
* measured value of Tn is the value after subtracting lower bits of T0.
* The noise reduction function filters out interference introduced simultaneously on all channels,
* such as noise introduced by power supplies and external EMI.
* @param denoise parameter of denoise
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_set_config(const touch_pad_denoise_t *denoise);
/**
* @brief get parameter of denoise pad (TOUCH_PAD_NUM0).
* @param denoise Pointer to parameter of denoise
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_get_config(touch_pad_denoise_t *denoise);
/**
* @brief enable denoise function.
* T0 is an internal channel that does not have a corresponding external GPIO.
* T0 will work simultaneously with the measured channel Tn. Finally, the actual
* measured value of Tn is the value after subtracting lower bits of T0.
* The noise reduction function filters out interference introduced simultaneously on all channels,
* such as noise introduced by power supplies and external EMI.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_enable(void);
/**
* @brief disable denoise function.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_disable(void);
/**
* @brief Get denoise measure value (TOUCH_PAD_NUM0).
* @param data Pointer to receive denoise value
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_read_data(uint32_t *data);
/**
* @brief set parameter of waterproof function.
*
* The waterproof function includes a shielded channel (TOUCH_PAD_NUM14) and a guard channel.
* Guard pad is used to detect the large area of water covering the touch panel.
* Shield pad is used to shield the influence of water droplets covering the touch panel.
* It is generally designed as a grid and is placed around the touch buttons.
*
* @param waterproof parameter of waterproof
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_set_config(const touch_pad_waterproof_t *waterproof);
/**
* @brief get parameter of waterproof function.
* @param waterproof parameter of waterproof
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_get_config(touch_pad_waterproof_t *waterproof);
/**
* @brief Enable parameter of waterproof function.
* Should be called after function ``touch_pad_waterproof_set_config``.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_enable(void);
/**
* @brief Disable parameter of waterproof function.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_disable(void);
/**
* @brief Enable/disable proximity function of touch channels.
* The proximity sensor measurement is the accumulation of touch channel measurements.
*
* @note Supports up to three touch channels configured as proximity sensors.
* @param touch_num touch pad index
* @param enabled true: enable the proximity function; false: disable the proximity function
* @return
* - ESP_OK: Configured correctly.
* - ESP_ERR_INVALID_ARG: Touch channel number error.
* - ESP_ERR_NOT_SUPPORTED: Don't support configured.
*/
esp_err_t touch_pad_proximity_enable(touch_pad_t touch_num, bool enabled);
/**
* @brief Set measure count of proximity channel.
* The proximity sensor measurement is the accumulation of touch channel measurements.
*
* @note All proximity channels use the same `count` value. So please pass the parameter `TOUCH_PAD_MAX`.
* @param touch_num Touch pad index. In this version, pass the parameter `TOUCH_PAD_MAX`.
* @param count The cumulative times of measurements for proximity pad. Range: 0 ~ 255.
* @return
* - ESP_OK: Configured correctly.
* - ESP_ERR_INVALID_ARG: Touch channel number error.
*/
esp_err_t touch_pad_proximity_set_count(touch_pad_t touch_num, uint32_t count);
/**
* @brief Get measure count of proximity channel.
* The proximity sensor measurement is the accumulation of touch channel measurements.
*
* @note All proximity channels use the same `count` value. So please pass the parameter `TOUCH_PAD_MAX`.
* @param touch_num Touch pad index. In this version, pass the parameter `TOUCH_PAD_MAX`.
* @param count The cumulative times of measurements for proximity pad. Range: 0 ~ 255.
* @return
* - ESP_OK: Configured correctly.
* - ESP_ERR_INVALID_ARG: Touch channel number error.
*/
esp_err_t touch_pad_proximity_get_count(touch_pad_t touch_num, uint32_t *count);
/**
* @brief Get the accumulated measurement of the proximity sensor.
* The proximity sensor measurement is the accumulation of touch channel measurements.
* @param touch_num touch pad index
* @param measure_out If the accumulation process does not end, the `measure_out` is the process value.
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Touch num is not proximity
*/
esp_err_t touch_pad_proximity_get_data(touch_pad_t touch_num, uint32_t *measure_out);
/**
* @brief Get parameter of touch sensor sleep channel.
* The touch sensor can works in sleep mode to wake up sleep.
*
* @note After the sleep channel is configured, Please use special functions for sleep channel.
* e.g. The user should uses `touch_pad_sleep_channel_read_data` instead of `touch_pad_read_raw_data` to obtain the sleep channel reading.
*
* @param slp_config touch sleep pad config.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_get_info(touch_pad_sleep_channel_t *slp_config);
/**
* @brief Enable/Disable sleep channel function for touch sensor.
* The touch sensor can works in sleep mode to wake up sleep.
*
* @note ESP32S2 only support one sleep channel.
* @note After the sleep channel is configured, Please use special functions for sleep channel.
* e.g. The user should uses `touch_pad_sleep_channel_read_data` instead of `touch_pad_read_raw_data` to obtain the sleep channel reading.
*
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param enable true: enable sleep pad for touch sensor; false: disable sleep pad for touch sensor;
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_enable(touch_pad_t pad_num, bool enable);
/**
* @brief Enable/Disable proximity function for sleep channel.
* The touch sensor can works in sleep mode to wake up sleep.
*
* @note ESP32S2 only support one sleep channel.
*
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param enable true: enable proximity for sleep channel; false: disable proximity for sleep channel;
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_enable_proximity(touch_pad_t pad_num, bool enable);
/**
* @brief Set the trigger threshold of touch sensor in deep sleep.
* The threshold determines the sensitivity of the touch sensor.
*
* @note In general, the touch threshold during sleep can use the threshold parameter parameters before sleep.
*
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param touch_thres touch sleep pad threshold
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_set_threshold(touch_pad_t pad_num, uint32_t touch_thres);
/**
* @brief Get the trigger threshold of touch sensor in deep sleep.
* The threshold determines the sensitivity of the touch sensor.
*
* @note In general, the touch threshold during sleep can use the threshold parameter parameters before sleep.
*
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param touch_thres touch sleep pad threshold
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_get_threshold(touch_pad_t pad_num, uint32_t *touch_thres);
/**
* @brief Read benchmark of touch sensor sleep channel.
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param benchmark pointer to accept touch sensor benchmark value
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_sleep_channel_read_benchmark(touch_pad_t pad_num, uint32_t *benchmark);
/**
* @brief Read smoothed data of touch sensor sleep channel.
* Smoothed data is filtered from the raw data.
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param smooth_data pointer to accept touch sensor smoothed data
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_sleep_channel_read_smooth(touch_pad_t pad_num, uint32_t *smooth_data);
/**
* @brief Read raw data of touch sensor sleep channel.
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param raw_data pointer to accept touch sensor raw data
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_sleep_channel_read_data(touch_pad_t pad_num, uint32_t *raw_data);
/**
* @brief Reset benchmark of touch sensor sleep channel.
*
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_reset_benchmark(void);
/**
* @brief Read proximity count of touch sensor sleep channel.
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param proximity_cnt pointer to accept touch sensor proximity count value
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_sleep_channel_read_proximity_cnt(touch_pad_t pad_num, uint32_t *proximity_cnt);
/**
* @brief Change the operating frequency of touch pad in deep sleep state. Reducing the operating frequency can effectively reduce power consumption.
* If this function is not called, the working frequency of touch in the deep sleep state is the same as that in the wake-up state.
*
* @param sleep_cycle The touch sensor will sleep after each measurement.
* sleep_cycle decide the interval between each measurement.
* t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
* @param meas_times The times of charge and discharge in each measure process of touch channels.
* The timer frequency is 8Mhz. Range: 0 ~ 0xffff.
* Recommended typical value: Modify this value to make the measurement time around 1ms.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times);
#ifdef __cplusplus
}
#endif #endif

View File

@@ -0,0 +1,646 @@
/*
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "driver/touch_sensor_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Set touch sensor FSM start
* @note Start FSM after the touch sensor FSM mode is set.
* @note Call this function will reset benchmark of all touch channels.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_fsm_start(void);
/**
* @brief Stop touch sensor FSM.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_fsm_stop(void);
/**
* @brief Trigger a touch sensor measurement, only support in SW mode of FSM
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_sw_start(void);
/**
* @brief Set charge and discharge times of each measurement
* @note This function will specify the charge and discharge times in each measurement period
* The clock is sourced from SOC_MOD_CLK_RTC_FAST, and its default frequency is SOC_CLK_RC_FAST_FREQ_APPROX
* The touch sensor will record the total clock cycles of all the charge and discharge cycles as the final result (raw value)
* @note If the charge and discharge times is too small, it may lead to inaccurate results.
*
* @param charge_discharge_times Charge and discharge times, range: 0 ~ 0xffff.
* No exact typical value can be recommended because the capacity is influenced by the hardware design and how finger touches,
* but suggest adjusting this value to make the measurement time around 1 ms.
* @return
* - ESP_OK Set charge and discharge times success
*/
esp_err_t touch_pad_set_charge_discharge_times(uint16_t charge_discharge_times);
/**
* @brief Get charge and discharge times of each measurement
*
* @param charge_discharge_times Charge and discharge times
* @return
* - ESP_OK Get charge_discharge_times success
* - ESP_ERR_INVALID_ARG The input parameter is NULL
*/
esp_err_t touch_pad_get_charge_discharge_times(uint16_t *charge_discharge_times);
/**
* @brief Set the interval between two measurements
* @note The touch sensor will sleep between two measurements
* This function is to set the interval cycle
* And the interval is clocked from SOC_MOD_CLK_RTC_SLOW, its default frequency is SOC_CLK_RC_SLOW_FREQ_APPROX
*
* @param interval_cycle The interval between two measurements
* sleep_time = interval_cycle / SOC_CLK_RC_SLOW_FREQ_APPROX.
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
* @return
* - ESP_OK Set interval cycle success
*/
esp_err_t touch_pad_set_measurement_interval(uint16_t interval_cycle);
/**
* @brief Get the interval between two measurements
*
* @param interval_cycle The interval between two measurements
* @return
* - ESP_OK Get interval cycle success
* - ESP_ERR_INVALID_ARG The input parameter is NULL
*/
esp_err_t touch_pad_get_measurement_interval(uint16_t *interval_cycle);
/**
* @brief Set touch sensor times of charge and discharge and sleep time.
* Excessive total time will slow down the touch response.
* Too small measurement time will not be sampled enough, resulting in inaccurate measurements.
* @note The touch sensor will measure time of a fixed number of charge/discharge cycles (specified as the second parameter).
* That means the time (raw value) will increase as the capacity of the touch pad is increasing.
* The time (raw value) here is the number of clock cycles which is sourced from SOC_MOD_CLK_RTC_FAST and at (SOC_CLK_RC_FAST_FREQ_APPROX) Hz as default
* @note The greater the duty cycle of the measurement time, the more system power is consumed.
*
* @param sleep_cycle The touch sensor will sleep after each measurement.
* sleep_cycle decide the interval between each measurement.
* t_sleep = sleep_cycle / SOC_CLK_RC_SLOW_FREQ_APPROX.
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
* @param meas_times The times of charge and discharge in each measurement of touch channels. Range: 0 ~ 0xffff.
* Recommended typical value: Modify this value to make the measurement time around 1 ms.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_times)
__attribute__((deprecated("please use 'touch_pad_set_charge_discharge_times' and 'touch_pad_set_measurement_interval' instead")));
/**
* @brief Get touch sensor times of charge and discharge and sleep time
* @param sleep_cycle Pointer to accept sleep cycle number
* @param meas_times Pointer to accept measurement times count.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_times)
__attribute__((deprecated("please use 'touch_pad_get_charge_discharge_times' and 'touch_pad_get_measurement_interval' instead")));
/**
* @brief Set the connection type of touch channels in idle status.
* When a channel is in measurement mode, other initialized channels are in idle mode.
* The touch channel is generally adjacent to the trace, so the connection state of the idle channel
* affects the stability and sensitivity of the test channel.
* The `CONN_HIGHZ`(high resistance) setting increases the sensitivity of touch channels.
* The `CONN_GND`(grounding) setting increases the stability of touch channels.
* @param type Select idle channel connect to high resistance state or ground.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_set_idle_channel_connect(touch_pad_conn_type_t type);
/**
* @brief Get the connection type of touch channels in idle status.
* When a channel is in measurement mode, other initialized channels are in idle mode.
* The touch channel is generally adjacent to the trace, so the connection state of the idle channel
* affects the stability and sensitivity of the test channel.
* The `CONN_HIGHZ`(high resistance) setting increases the sensitivity of touch channels.
* The `CONN_GND`(grounding) setting increases the stability of touch channels.
* @param type Pointer to connection type.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_get_idle_channel_connect(touch_pad_conn_type_t *type);
/**
* @brief Set the trigger threshold of touch sensor.
* The threshold determines the sensitivity of the touch sensor.
* The threshold is the original value of the trigger state minus the benchmark value.
* @note If set "TOUCH_PAD_THRESHOLD_MAX", the touch is never be triggered.
* @param touch_num touch pad index
* @param threshold threshold of touch sensor. Should be less than the max change value of touch.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_set_thresh(touch_pad_t touch_num, uint32_t threshold);
/**
* @brief Get touch sensor trigger threshold
* @param touch_num touch pad index
* @param threshold pointer to accept threshold
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG if argument is wrong
*/
esp_err_t touch_pad_get_thresh(touch_pad_t touch_num, uint32_t *threshold);
/**
* @brief Register touch channel into touch sensor scan group.
* The working mode of the touch sensor is cyclically scanned.
* This function will set the scan bits according to the given bitmask.
* @note If set this mask, the FSM timer should be stop firsty.
* @note The touch sensor that in scan map, should be deinit GPIO function firstly by `touch_pad_io_init`.
* @param enable_mask bitmask of touch sensor scan group.
* e.g. TOUCH_PAD_NUM14 -> BIT(14)
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_set_channel_mask(uint16_t enable_mask);
/**
* @brief Get the touch sensor scan group bit mask.
* @param enable_mask Pointer to bitmask of touch sensor scan group.
* e.g. TOUCH_PAD_NUM14 -> BIT(14)
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_get_channel_mask(uint16_t *enable_mask);
/**
* @brief Clear touch channel from touch sensor scan group.
* The working mode of the touch sensor is cyclically scanned.
* This function will clear the scan bits according to the given bitmask.
* @note If clear all mask, the FSM timer should be stop firsty.
* @param enable_mask bitmask of touch sensor scan group.
* e.g. TOUCH_PAD_NUM14 -> BIT(14)
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_clear_channel_mask(uint16_t enable_mask);
/**
* @brief Configure parameter for each touch channel.
* @note Touch num 0 is denoise channel, please use `touch_pad_denoise_enable` to set denoise function
* @param touch_num touch pad index
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG if argument wrong
* - ESP_FAIL if touch pad not initialized
*/
esp_err_t touch_pad_config(touch_pad_t touch_num);
/**
* @brief Reset the FSM of touch module.
* @note Call this function after `touch_pad_fsm_stop`.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_reset(void);
/**
* @brief Get the current measure channel.
* @note Should be called when touch sensor measurement is in cyclic scan mode.
* @return
* - touch channel number
*/
touch_pad_t touch_pad_get_current_meas_channel(void);
/**
* @brief Get the touch sensor interrupt status mask.
* @return
* - touch interrupt bit
*/
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
*/
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
*/
esp_err_t touch_pad_intr_disable(touch_pad_intr_mask_t int_mask);
/**
* @brief Clear touch sensor interrupt by bitmask.
* @param int_mask Pad mask to clear interrupts
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_intr_clear(touch_pad_intr_mask_t int_mask);
/**
* @brief Register touch-pad ISR.
* The handler will be attached to the same CPU core that this function is running on.
* @param fn Pointer to ISR handler
* @param arg Parameter for ISR
* @param intr_mask Enable touch sensor interrupt handler by bitmask.
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Arguments error
* - ESP_ERR_NO_MEM No memory
*/
esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_mask_t intr_mask);
/**
* @brief Enable/disable the timeout check and set timeout threshold for all touch sensor channels measurements.
* If enable: When the touch reading of a touch channel exceeds the measurement threshold, a timeout interrupt will be generated.
* If disable: the FSM does not check if the channel under measurement times out.
*
* @note The threshold compared with touch readings.
* @note In order to avoid abnormal short circuit of some touch channels. This function should be turned on.
* Ensure the normal operation of other touch channels.
*
* @param enable true(default): Enable the timeout check; false: Disable the timeout check.
* @param threshold For all channels, the maximum value that will not be exceeded during normal operation.
*
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_timeout_set(bool enable, uint32_t threshold);
/**
* @brief Call this interface after timeout to make the touch channel resume normal work. Point on the next channel to measure.
* If this API is not called, the touch FSM will stop the measurement after timeout interrupt.
*
* @note Call this API after finishes the exception handling by user.
*
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_timeout_resume(void);
/**
* @brief get raw data of touch sensor.
* @note After the initialization is complete, the "raw_data" is max value. You need to wait for a measurement
* cycle before you can read the correct touch value.
* @param touch_num touch pad index
* @param raw_data pointer to accept touch sensor value
* @return
* - ESP_OK Success
* - ESP_FAIL Touch channel 0 haven't this parameter.
*/
esp_err_t touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data);
/**
* @brief get benchmark of touch sensor.
* @note After initialization, the benchmark value is the maximum during the first measurement period.
* @param touch_num touch pad index
* @param benchmark pointer to accept touch sensor benchmark value
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Touch channel 0 haven't this parameter.
*/
esp_err_t touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark);
/**
* @brief Get smoothed data that obtained by filtering the raw data.
*
* @param touch_num touch pad index
* @param smooth pointer to smoothed data
*/
esp_err_t touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth);
/**
* @brief Force reset benchmark to raw data of touch sensor.
* @param touch_num touch pad index
* - TOUCH_PAD_MAX Reset basaline of all channels
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_reset_benchmark(touch_pad_t touch_num);
/**
* @brief set parameter of touch sensor filter and detection algorithm.
* For more details on the detection algorithm, please refer to the application documentation.
* @param filter_info select filter type and threshold of detection algorithm
* @return
* - ESP_OK Success
*/
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.
* For more details on the detection algorithm, please refer to the application documentation.
* @param filter_info select filter type and threshold of detection algorithm
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_filter_get_config(touch_filter_config_t *filter_info);
/**
* @brief enable touch sensor filter for detection algorithm.
* For more details on the detection algorithm, please refer to the application documentation.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_filter_enable(void);
/**
* @brief disable touch sensor filter for detection algorithm.
* For more details on the detection algorithm, please refer to the application documentation.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_filter_disable(void);
/**
* @brief set parameter of denoise pad (TOUCH_PAD_NUM0).
* T0 is an internal channel that does not have a corresponding external GPIO.
* T0 will work simultaneously with the measured channel Tn. Finally, the actual
* measured value of Tn is the value after subtracting lower bits of T0.
* The noise reduction function filters out interference introduced simultaneously on all channels,
* such as noise introduced by power supplies and external EMI.
* @param denoise parameter of denoise
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_set_config(const touch_pad_denoise_t *denoise);
/**
* @brief get parameter of denoise pad (TOUCH_PAD_NUM0).
* @param denoise Pointer to parameter of denoise
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_get_config(touch_pad_denoise_t *denoise);
/**
* @brief enable denoise function.
* T0 is an internal channel that does not have a corresponding external GPIO.
* T0 will work simultaneously with the measured channel Tn. Finally, the actual
* measured value of Tn is the value after subtracting lower bits of T0.
* The noise reduction function filters out interference introduced simultaneously on all channels,
* such as noise introduced by power supplies and external EMI.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_enable(void);
/**
* @brief disable denoise function.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_disable(void);
/**
* @brief Get denoise measure value (TOUCH_PAD_NUM0).
* @param data Pointer to receive denoise value
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_read_data(uint32_t *data);
/**
* @brief set parameter of waterproof function.
*
* The waterproof function includes a shielded channel (TOUCH_PAD_NUM14) and a guard channel.
* Guard pad is used to detect the large area of water covering the touch panel.
* Shield pad is used to shield the influence of water droplets covering the touch panel.
* It is generally designed as a grid and is placed around the touch buttons.
*
* @param waterproof parameter of waterproof
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_set_config(const touch_pad_waterproof_t *waterproof);
/**
* @brief get parameter of waterproof function.
* @param waterproof parameter of waterproof
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_get_config(touch_pad_waterproof_t *waterproof);
/**
* @brief Enable parameter of waterproof function.
* Should be called after function ``touch_pad_waterproof_set_config``.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_enable(void);
/**
* @brief Disable parameter of waterproof function.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_disable(void);
/**
* @brief Enable/disable proximity function of touch channels.
* The proximity sensor measurement is the accumulation of touch channel measurements.
*
* @note Supports up to three touch channels configured as proximity sensors.
* @param touch_num touch pad index
* @param enabled true: enable the proximity function; false: disable the proximity function
* @return
* - ESP_OK: Configured correctly.
* - ESP_ERR_INVALID_ARG: Touch channel number error.
* - ESP_ERR_NOT_SUPPORTED: Don't support configured.
*/
esp_err_t touch_pad_proximity_enable(touch_pad_t touch_num, bool enabled);
/**
* @brief Set measure count of proximity channel.
* The proximity sensor measurement is the accumulation of touch channel measurements.
*
* @note All proximity channels use the same `count` value. So please pass the parameter `TOUCH_PAD_MAX`.
* @param touch_num Touch pad index. In this version, pass the parameter `TOUCH_PAD_MAX`.
* @param count The cumulative times of measurements for proximity pad. Range: 0 ~ 255.
* @return
* - ESP_OK: Configured correctly.
* - ESP_ERR_INVALID_ARG: Touch channel number error.
*/
esp_err_t touch_pad_proximity_set_count(touch_pad_t touch_num, uint32_t count);
/**
* @brief Get measure count of proximity channel.
* The proximity sensor measurement is the accumulation of touch channel measurements.
*
* @note All proximity channels use the same `count` value. So please pass the parameter `TOUCH_PAD_MAX`.
* @param touch_num Touch pad index. In this version, pass the parameter `TOUCH_PAD_MAX`.
* @param count The cumulative times of measurements for proximity pad. Range: 0 ~ 255.
* @return
* - ESP_OK: Configured correctly.
* - ESP_ERR_INVALID_ARG: Touch channel number error.
*/
esp_err_t touch_pad_proximity_get_count(touch_pad_t touch_num, uint32_t *count);
/**
* @brief Get the accumulated measurement of the proximity sensor.
* The proximity sensor measurement is the accumulation of touch channel measurements.
* @param touch_num touch pad index
* @param measure_out If the accumulation process does not end, the `measure_out` is the process value.
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Touch num is not proximity
*/
esp_err_t touch_pad_proximity_get_data(touch_pad_t touch_num, uint32_t *measure_out);
/**
* @brief Get parameter of touch sensor sleep channel.
* The touch sensor can works in sleep mode to wake up sleep.
*
* @note After the sleep channel is configured, Please use special functions for sleep channel.
* e.g. The user should uses `touch_pad_sleep_channel_read_data` instead of `touch_pad_read_raw_data` to obtain the sleep channel reading.
*
* @param slp_config touch sleep pad config.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_get_info(touch_pad_sleep_channel_t *slp_config);
/**
* @brief Enable/Disable sleep channel function for touch sensor.
* The touch sensor can works in sleep mode to wake up sleep.
*
* @note ESP32S2 only support one sleep channel.
* @note After the sleep channel is configured, Please use special functions for sleep channel.
* e.g. The user should uses `touch_pad_sleep_channel_read_data` instead of `touch_pad_read_raw_data` to obtain the sleep channel reading.
*
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param enable true: enable sleep pad for touch sensor; false: disable sleep pad for touch sensor;
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_enable(touch_pad_t pad_num, bool enable);
/**
* @brief Enable/Disable proximity function for sleep channel.
* The touch sensor can works in sleep mode to wake up sleep.
*
* @note ESP32S2 only support one sleep channel.
*
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param enable true: enable proximity for sleep channel; false: disable proximity for sleep channel;
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_enable_proximity(touch_pad_t pad_num, bool enable);
/**
* @brief Set the trigger threshold of touch sensor in deep sleep.
* The threshold determines the sensitivity of the touch sensor.
*
* @note In general, the touch threshold during sleep can use the threshold parameter parameters before sleep.
*
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param touch_thres touch sleep pad threshold
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_set_threshold(touch_pad_t pad_num, uint32_t touch_thres);
/**
* @brief Get the trigger threshold of touch sensor in deep sleep.
* The threshold determines the sensitivity of the touch sensor.
*
* @note In general, the touch threshold during sleep can use the threshold parameter parameters before sleep.
*
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param touch_thres touch sleep pad threshold
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_get_threshold(touch_pad_t pad_num, uint32_t *touch_thres);
/**
* @brief Read benchmark of touch sensor sleep channel.
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param benchmark pointer to accept touch sensor benchmark value
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_sleep_channel_read_benchmark(touch_pad_t pad_num, uint32_t *benchmark);
/**
* @brief Read smoothed data of touch sensor sleep channel.
* Smoothed data is filtered from the raw data.
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param smooth_data pointer to accept touch sensor smoothed data
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_sleep_channel_read_smooth(touch_pad_t pad_num, uint32_t *smooth_data);
/**
* @brief Read raw data of touch sensor sleep channel.
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param raw_data pointer to accept touch sensor raw data
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_sleep_channel_read_data(touch_pad_t pad_num, uint32_t *raw_data);
/**
* @brief Reset benchmark of touch sensor sleep channel.
*
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_reset_benchmark(void);
/**
* @brief Read proximity count of touch sensor sleep channel.
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param proximity_cnt pointer to accept touch sensor proximity count value
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_sleep_channel_read_proximity_cnt(touch_pad_t pad_num, uint32_t *proximity_cnt);
/**
* @brief Change the operating frequency of touch pad in deep sleep state. Reducing the operating frequency can effectively reduce power consumption.
* If this function is not called, the working frequency of touch in the deep sleep state is the same as that in the wake-up state.
*
* @param sleep_cycle The touch sensor will sleep after each measurement.
* sleep_cycle decide the interval between each measurement.
* t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
* @param meas_times The times of charge and discharge in each measure process of touch channels.
* The timer frequency is 8Mhz. Range: 0 ~ 0xffff.
* Recommended typical value: Modify this value to make the measurement time around 1ms.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times);
#ifdef __cplusplus
}
#endif

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2016-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -16,13 +16,13 @@
#include "freertos/timers.h" #include "freertos/timers.h"
#include "esp_intr_alloc.h" #include "esp_intr_alloc.h"
#include "driver/rtc_io.h" #include "driver/rtc_io.h"
#include "driver/touch_pad.h" #include "driver/touch_sensor_common.h"
#include "esp_private/rtc_ctrl.h" #include "esp_private/rtc_ctrl.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#include "esp_check.h" #include "esp_check.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sensor_legacy_types.h"
#include "hal/touch_sensor_hal.h" #include "hal/touch_sensor_hal.h"
#ifndef NDEBUG #ifndef NDEBUG
@@ -405,7 +405,7 @@ esp_err_t touch_pad_filter_get_config(touch_filter_config_t *filter_info)
esp_err_t touch_pad_filter_enable(void) esp_err_t touch_pad_filter_enable(void)
{ {
TOUCH_ENTER_CRITICAL(); TOUCH_ENTER_CRITICAL();
touch_hal_filter_enable(); touch_hal_filter_enable(true);
TOUCH_EXIT_CRITICAL(); TOUCH_EXIT_CRITICAL();
return ESP_OK; return ESP_OK;
} }
@@ -413,7 +413,7 @@ esp_err_t touch_pad_filter_enable(void)
esp_err_t touch_pad_filter_disable(void) esp_err_t touch_pad_filter_disable(void)
{ {
TOUCH_ENTER_CRITICAL(); TOUCH_ENTER_CRITICAL();
touch_hal_filter_disable(); touch_hal_filter_enable(false);
TOUCH_EXIT_CRITICAL(); TOUCH_EXIT_CRITICAL();
return ESP_OK; return ESP_OK;
} }
@@ -596,9 +596,9 @@ esp_err_t touch_pad_sleep_channel_enable_proximity(touch_pad_t pad_num, bool ena
TOUCH_ENTER_CRITICAL(); TOUCH_ENTER_CRITICAL();
if (enable) { if (enable) {
touch_hal_sleep_enable_approach(); touch_hal_sleep_enable_approach(true);
} else { } else {
touch_hal_sleep_disable_approach(); touch_hal_sleep_enable_approach(false);
} }
TOUCH_EXIT_CRITICAL(); TOUCH_EXIT_CRITICAL();
return ESP_OK; return ESP_OK;
@@ -684,3 +684,17 @@ esp_err_t touch_pad_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t m
touch_hal_sleep_channel_set_work_time(sleep_cycle, meas_times); touch_hal_sleep_channel_set_work_time(sleep_cycle, meas_times);
return ESP_OK; return ESP_OK;
} }
/**
* @brief This function will be called during start up, to check that the new touch driver is not running along with the legacy touch driver
*/
static __attribute__((constructor)) void check_touch_driver_conflict(void)
{
extern __attribute__((weak)) esp_err_t touch_sensor_new_controller(const void*, void *);
/* If the new Touch driver is linked, the weak function will point to the actual function in the new driver, otherwise it is NULL*/
if ((void *)touch_sensor_new_controller != NULL) {
ESP_EARLY_LOGE("legacy_touch_driver", "CONFLICT! The new touch driver can't work along with the legacy touch driver");
abort();
}
ESP_EARLY_LOGW("legacy_touch_driver", "legacy touch driver is deprecated, please migrate to use driver/touch_sens.h");
}

View File

@@ -1,646 +1,17 @@
/* /*
* SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#pragma once #pragma once
#include "driver/touch_sensor_common.h" #include "sdkconfig.h"
#include "driver/touch_sensor_legacy.h"
#ifdef __cplusplus #if !CONFIG_TOUCH_SUPPRESS_DEPRECATE_WARN
extern "C" { #warning "This set of Touch APIs has been deprecated, \
#endif please include 'driver/touch_sens.h' instead. \
if you want to keep using the old APIs and ignore this warning, \
/** you can enable 'Suppress legacy driver deprecated warning' option under 'Touch Configuration' menu in Kconfig"
* @brief Set touch sensor FSM start
* @note Start FSM after the touch sensor FSM mode is set.
* @note Call this function will reset benchmark of all touch channels.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_fsm_start(void);
/**
* @brief Stop touch sensor FSM.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_fsm_stop(void);
/**
* @brief Trigger a touch sensor measurement, only support in SW mode of FSM
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_sw_start(void);
/**
* @brief Set charge and discharge times of each measurement
* @note This function will specify the charge and discharge times in each measurement period
* The clock is sourced from SOC_MOD_CLK_RTC_FAST, and its default frequency is SOC_CLK_RC_FAST_FREQ_APPROX
* The touch sensor will record the total clock cycles of all the charge and discharge cycles as the final result (raw value)
* @note If the charge and discharge times is too small, it may lead to inaccurate results.
*
* @param charge_discharge_times Charge and discharge times, range: 0 ~ 0xffff.
* No exact typical value can be recommended because the capacity is influenced by the hardware design and how finger touches,
* but suggest adjusting this value to make the measurement time around 1 ms.
* @return
* - ESP_OK Set charge and discharge times success
*/
esp_err_t touch_pad_set_charge_discharge_times(uint16_t charge_discharge_times);
/**
* @brief Get charge and discharge times of each measurement
*
* @param charge_discharge_times Charge and discharge times
* @return
* - ESP_OK Get charge_discharge_times success
* - ESP_ERR_INVALID_ARG The input parameter is NULL
*/
esp_err_t touch_pad_get_charge_discharge_times(uint16_t *charge_discharge_times);
/**
* @brief Set the interval between two measurements
* @note The touch sensor will sleep between two measurements
* This function is to set the interval cycle
* And the interval is clocked from SOC_MOD_CLK_RTC_SLOW, its default frequency is SOC_CLK_RC_SLOW_FREQ_APPROX
*
* @param interval_cycle The interval between two measurements
* sleep_time = interval_cycle / SOC_CLK_RC_SLOW_FREQ_APPROX.
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
* @return
* - ESP_OK Set interval cycle success
*/
esp_err_t touch_pad_set_measurement_interval(uint16_t interval_cycle);
/**
* @brief Get the interval between two measurements
*
* @param interval_cycle The interval between two measurements
* @return
* - ESP_OK Get interval cycle success
* - ESP_ERR_INVALID_ARG The input parameter is NULL
*/
esp_err_t touch_pad_get_measurement_interval(uint16_t *interval_cycle);
/**
* @brief Set touch sensor times of charge and discharge and sleep time.
* Excessive total time will slow down the touch response.
* Too small measurement time will not be sampled enough, resulting in inaccurate measurements.
* @note The touch sensor will measure time of a fixed number of charge/discharge cycles (specified as the second parameter).
* That means the time (raw value) will increase as the capacity of the touch pad is increasing.
* The time (raw value) here is the number of clock cycles which is sourced from SOC_MOD_CLK_RTC_FAST and at (SOC_CLK_RC_FAST_FREQ_APPROX) Hz as default
* @note The greater the duty cycle of the measurement time, the more system power is consumed.
*
* @param sleep_cycle The touch sensor will sleep after each measurement.
* sleep_cycle decide the interval between each measurement.
* t_sleep = sleep_cycle / SOC_CLK_RC_SLOW_FREQ_APPROX.
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
* @param meas_times The times of charge and discharge in each measurement of touch channels. Range: 0 ~ 0xffff.
* Recommended typical value: Modify this value to make the measurement time around 1 ms.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_times)
__attribute__((deprecated("please use 'touch_pad_set_charge_discharge_times' and 'touch_pad_set_measurement_interval' instead")));
/**
* @brief Get touch sensor times of charge and discharge and sleep time
* @param sleep_cycle Pointer to accept sleep cycle number
* @param meas_times Pointer to accept measurement times count.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_times)
__attribute__((deprecated("please use 'touch_pad_get_charge_discharge_times' and 'touch_pad_get_measurement_interval' instead")));
/**
* @brief Set the connection type of touch channels in idle status.
* When a channel is in measurement mode, other initialized channels are in idle mode.
* The touch channel is generally adjacent to the trace, so the connection state of the idle channel
* affects the stability and sensitivity of the test channel.
* The `CONN_HIGHZ`(high resistance) setting increases the sensitivity of touch channels.
* The `CONN_GND`(grounding) setting increases the stability of touch channels.
* @param type Select idle channel connect to high resistance state or ground.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_set_idle_channel_connect(touch_pad_conn_type_t type);
/**
* @brief Get the connection type of touch channels in idle status.
* When a channel is in measurement mode, other initialized channels are in idle mode.
* The touch channel is generally adjacent to the trace, so the connection state of the idle channel
* affects the stability and sensitivity of the test channel.
* The `CONN_HIGHZ`(high resistance) setting increases the sensitivity of touch channels.
* The `CONN_GND`(grounding) setting increases the stability of touch channels.
* @param type Pointer to connection type.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_get_idle_channel_connect(touch_pad_conn_type_t *type);
/**
* @brief Set the trigger threshold of touch sensor.
* The threshold determines the sensitivity of the touch sensor.
* The threshold is the original value of the trigger state minus the benchmark value.
* @note If set "TOUCH_PAD_THRESHOLD_MAX", the touch is never be triggered.
* @param touch_num touch pad index
* @param threshold threshold of touch sensor. Should be less than the max change value of touch.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_set_thresh(touch_pad_t touch_num, uint32_t threshold);
/**
* @brief Get touch sensor trigger threshold
* @param touch_num touch pad index
* @param threshold pointer to accept threshold
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG if argument is wrong
*/
esp_err_t touch_pad_get_thresh(touch_pad_t touch_num, uint32_t *threshold);
/**
* @brief Register touch channel into touch sensor scan group.
* The working mode of the touch sensor is cyclically scanned.
* This function will set the scan bits according to the given bitmask.
* @note If set this mask, the FSM timer should be stop firsty.
* @note The touch sensor that in scan map, should be deinit GPIO function firstly by `touch_pad_io_init`.
* @param enable_mask bitmask of touch sensor scan group.
* e.g. TOUCH_PAD_NUM14 -> BIT(14)
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_set_channel_mask(uint16_t enable_mask);
/**
* @brief Get the touch sensor scan group bit mask.
* @param enable_mask Pointer to bitmask of touch sensor scan group.
* e.g. TOUCH_PAD_NUM14 -> BIT(14)
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_get_channel_mask(uint16_t *enable_mask);
/**
* @brief Clear touch channel from touch sensor scan group.
* The working mode of the touch sensor is cyclically scanned.
* This function will clear the scan bits according to the given bitmask.
* @note If clear all mask, the FSM timer should be stop firsty.
* @param enable_mask bitmask of touch sensor scan group.
* e.g. TOUCH_PAD_NUM14 -> BIT(14)
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_clear_channel_mask(uint16_t enable_mask);
/**
* @brief Configure parameter for each touch channel.
* @note Touch num 0 is denoise channel, please use `touch_pad_denoise_enable` to set denoise function
* @param touch_num touch pad index
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG if argument wrong
* - ESP_FAIL if touch pad not initialized
*/
esp_err_t touch_pad_config(touch_pad_t touch_num);
/**
* @brief Reset the FSM of touch module.
* @note Call this function after `touch_pad_fsm_stop`.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_reset(void);
/**
* @brief Get the current measure channel.
* @note Should be called when touch sensor measurement is in cyclic scan mode.
* @return
* - touch channel number
*/
touch_pad_t touch_pad_get_current_meas_channel(void);
/**
* @brief Get the touch sensor interrupt status mask.
* @return
* - touch interrupt bit
*/
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
*/
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
*/
esp_err_t touch_pad_intr_disable(touch_pad_intr_mask_t int_mask);
/**
* @brief Clear touch sensor interrupt by bitmask.
* @param int_mask Pad mask to clear interrupts
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_intr_clear(touch_pad_intr_mask_t int_mask);
/**
* @brief Register touch-pad ISR.
* The handler will be attached to the same CPU core that this function is running on.
* @param fn Pointer to ISR handler
* @param arg Parameter for ISR
* @param intr_mask Enable touch sensor interrupt handler by bitmask.
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Arguments error
* - ESP_ERR_NO_MEM No memory
*/
esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_mask_t intr_mask);
/**
* @brief Enable/disable the timeout check and set timeout threshold for all touch sensor channels measurements.
* If enable: When the touch reading of a touch channel exceeds the measurement threshold, a timeout interrupt will be generated.
* If disable: the FSM does not check if the channel under measurement times out.
*
* @note The threshold compared with touch readings.
* @note In order to avoid abnormal short circuit of some touch channels. This function should be turned on.
* Ensure the normal operation of other touch channels.
*
* @param enable true(default): Enable the timeout check; false: Disable the timeout check.
* @param threshold For all channels, the maximum value that will not be exceeded during normal operation.
*
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_timeout_set(bool enable, uint32_t threshold);
/**
* @brief Call this interface after timeout to make the touch channel resume normal work. Point on the next channel to measure.
* If this API is not called, the touch FSM will stop the measurement after timeout interrupt.
*
* @note Call this API after finishes the exception handling by user.
*
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_timeout_resume(void);
/**
* @brief get raw data of touch sensor.
* @note After the initialization is complete, the "raw_data" is max value. You need to wait for a measurement
* cycle before you can read the correct touch value.
* @param touch_num touch pad index
* @param raw_data pointer to accept touch sensor value
* @return
* - ESP_OK Success
* - ESP_FAIL Touch channel 0 haven't this parameter.
*/
esp_err_t touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data);
/**
* @brief get benchmark of touch sensor.
* @note After initialization, the benchmark value is the maximum during the first measurement period.
* @param touch_num touch pad index
* @param benchmark pointer to accept touch sensor benchmark value
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Touch channel 0 haven't this parameter.
*/
esp_err_t touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark);
/**
* @brief Get smoothed data that obtained by filtering the raw data.
*
* @param touch_num touch pad index
* @param smooth pointer to smoothed data
*/
esp_err_t touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth);
/**
* @brief Force reset benchmark to raw data of touch sensor.
* @param touch_num touch pad index
* - TOUCH_PAD_MAX Reset basaline of all channels
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_reset_benchmark(touch_pad_t touch_num);
/**
* @brief set parameter of touch sensor filter and detection algorithm.
* For more details on the detection algorithm, please refer to the application documentation.
* @param filter_info select filter type and threshold of detection algorithm
* @return
* - ESP_OK Success
*/
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.
* For more details on the detection algorithm, please refer to the application documentation.
* @param filter_info select filter type and threshold of detection algorithm
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_filter_get_config(touch_filter_config_t *filter_info);
/**
* @brief enable touch sensor filter for detection algorithm.
* For more details on the detection algorithm, please refer to the application documentation.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_filter_enable(void);
/**
* @brief disable touch sensor filter for detection algorithm.
* For more details on the detection algorithm, please refer to the application documentation.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_filter_disable(void);
/**
* @brief set parameter of denoise pad (TOUCH_PAD_NUM0).
* T0 is an internal channel that does not have a corresponding external GPIO.
* T0 will work simultaneously with the measured channel Tn. Finally, the actual
* measured value of Tn is the value after subtracting lower bits of T0.
* The noise reduction function filters out interference introduced simultaneously on all channels,
* such as noise introduced by power supplies and external EMI.
* @param denoise parameter of denoise
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_set_config(const touch_pad_denoise_t *denoise);
/**
* @brief get parameter of denoise pad (TOUCH_PAD_NUM0).
* @param denoise Pointer to parameter of denoise
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_get_config(touch_pad_denoise_t *denoise);
/**
* @brief enable denoise function.
* T0 is an internal channel that does not have a corresponding external GPIO.
* T0 will work simultaneously with the measured channel Tn. Finally, the actual
* measured value of Tn is the value after subtracting lower bits of T0.
* The noise reduction function filters out interference introduced simultaneously on all channels,
* such as noise introduced by power supplies and external EMI.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_enable(void);
/**
* @brief disable denoise function.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_disable(void);
/**
* @brief Get denoise measure value (TOUCH_PAD_NUM0).
* @param data Pointer to receive denoise value
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_read_data(uint32_t *data);
/**
* @brief set parameter of waterproof function.
*
* The waterproof function includes a shielded channel (TOUCH_PAD_NUM14) and a guard channel.
* Guard pad is used to detect the large area of water covering the touch panel.
* Shield pad is used to shield the influence of water droplets covering the touch panel.
* It is generally designed as a grid and is placed around the touch buttons.
*
* @param waterproof parameter of waterproof
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_set_config(const touch_pad_waterproof_t *waterproof);
/**
* @brief get parameter of waterproof function.
* @param waterproof parameter of waterproof
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_get_config(touch_pad_waterproof_t *waterproof);
/**
* @brief Enable parameter of waterproof function.
* Should be called after function ``touch_pad_waterproof_set_config``.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_enable(void);
/**
* @brief Disable parameter of waterproof function.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_disable(void);
/**
* @brief Enable/disable proximity function of touch channels.
* The proximity sensor measurement is the accumulation of touch channel measurements.
*
* @note Supports up to three touch channels configured as proximity sensors.
* @param touch_num touch pad index
* @param enabled true: enable the proximity function; false: disable the proximity function
* @return
* - ESP_OK: Configured correctly.
* - ESP_ERR_INVALID_ARG: Touch channel number error.
* - ESP_ERR_NOT_SUPPORTED: Don't support configured.
*/
esp_err_t touch_pad_proximity_enable(touch_pad_t touch_num, bool enabled);
/**
* @brief Set measure count of proximity channel.
* The proximity sensor measurement is the accumulation of touch channel measurements.
*
* @note All proximity channels use the same `count` value. So please pass the parameter `TOUCH_PAD_MAX`.
* @param touch_num Touch pad index. In this version, pass the parameter `TOUCH_PAD_MAX`.
* @param count The cumulative times of measurements for proximity pad. Range: 0 ~ 255.
* @return
* - ESP_OK: Configured correctly.
* - ESP_ERR_INVALID_ARG: Touch channel number error.
*/
esp_err_t touch_pad_proximity_set_count(touch_pad_t touch_num, uint32_t count);
/**
* @brief Get measure count of proximity channel.
* The proximity sensor measurement is the accumulation of touch channel measurements.
*
* @note All proximity channels use the same `count` value. So please pass the parameter `TOUCH_PAD_MAX`.
* @param touch_num Touch pad index. In this version, pass the parameter `TOUCH_PAD_MAX`.
* @param count The cumulative times of measurements for proximity pad. Range: 0 ~ 255.
* @return
* - ESP_OK: Configured correctly.
* - ESP_ERR_INVALID_ARG: Touch channel number error.
*/
esp_err_t touch_pad_proximity_get_count(touch_pad_t touch_num, uint32_t *count);
/**
* @brief Get the accumulated measurement of the proximity sensor.
* The proximity sensor measurement is the accumulation of touch channel measurements.
* @param touch_num touch pad index
* @param measure_out If the accumulation process does not end, the `measure_out` is the process value.
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Touch num is not proximity
*/
esp_err_t touch_pad_proximity_get_data(touch_pad_t touch_num, uint32_t *measure_out);
/**
* @brief Get parameter of touch sensor sleep channel.
* The touch sensor can works in sleep mode to wake up sleep.
*
* @note After the sleep channel is configured, Please use special functions for sleep channel.
* e.g. The user should uses `touch_pad_sleep_channel_read_data` instead of `touch_pad_read_raw_data` to obtain the sleep channel reading.
*
* @param slp_config touch sleep pad config.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_get_info(touch_pad_sleep_channel_t *slp_config);
/**
* @brief Enable/Disable sleep channel function for touch sensor.
* The touch sensor can works in sleep mode to wake up sleep.
*
* @note ESP32S2 only support one sleep channel.
* @note After the sleep channel is configured, Please use special functions for sleep channel.
* e.g. The user should uses `touch_pad_sleep_channel_read_data` instead of `touch_pad_read_raw_data` to obtain the sleep channel reading.
*
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param enable true: enable sleep pad for touch sensor; false: disable sleep pad for touch sensor;
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_enable(touch_pad_t pad_num, bool enable);
/**
* @brief Enable/Disable proximity function for sleep channel.
* The touch sensor can works in sleep mode to wake up sleep.
*
* @note ESP32S2 only support one sleep channel.
*
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param enable true: enable proximity for sleep channel; false: disable proximity for sleep channel;
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_enable_proximity(touch_pad_t pad_num, bool enable);
/**
* @brief Set the trigger threshold of touch sensor in deep sleep.
* The threshold determines the sensitivity of the touch sensor.
*
* @note In general, the touch threshold during sleep can use the threshold parameter parameters before sleep.
*
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param touch_thres touch sleep pad threshold
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_set_threshold(touch_pad_t pad_num, uint32_t touch_thres);
/**
* @brief Get the trigger threshold of touch sensor in deep sleep.
* The threshold determines the sensitivity of the touch sensor.
*
* @note In general, the touch threshold during sleep can use the threshold parameter parameters before sleep.
*
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param touch_thres touch sleep pad threshold
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_get_threshold(touch_pad_t pad_num, uint32_t *touch_thres);
/**
* @brief Read benchmark of touch sensor sleep channel.
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param benchmark pointer to accept touch sensor benchmark value
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_sleep_channel_read_benchmark(touch_pad_t pad_num, uint32_t *benchmark);
/**
* @brief Read smoothed data of touch sensor sleep channel.
* Smoothed data is filtered from the raw data.
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param smooth_data pointer to accept touch sensor smoothed data
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_sleep_channel_read_smooth(touch_pad_t pad_num, uint32_t *smooth_data);
/**
* @brief Read raw data of touch sensor sleep channel.
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param raw_data pointer to accept touch sensor raw data
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_sleep_channel_read_data(touch_pad_t pad_num, uint32_t *raw_data);
/**
* @brief Reset benchmark of touch sensor sleep channel.
*
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_reset_benchmark(void);
/**
* @brief Read proximity count of touch sensor sleep channel.
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param proximity_cnt pointer to accept touch sensor proximity count value
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_sleep_channel_read_proximity_cnt(touch_pad_t pad_num, uint32_t *proximity_cnt);
/**
* @brief Change the operating frequency of touch pad in deep sleep state. Reducing the operating frequency can effectively reduce power consumption.
* If this function is not called, the working frequency of touch in the deep sleep state is the same as that in the wake-up state.
*
* @param sleep_cycle The touch sensor will sleep after each measurement.
* sleep_cycle decide the interval between each measurement.
* t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
* @param meas_times The times of charge and discharge in each measure process of touch channels.
* The timer frequency is 8Mhz. Range: 0 ~ 0xffff.
* Recommended typical value: Modify this value to make the measurement time around 1ms.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times);
#ifdef __cplusplus
}
#endif #endif

View File

@@ -0,0 +1,646 @@
/*
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "driver/touch_sensor_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Set touch sensor FSM start
* @note Start FSM after the touch sensor FSM mode is set.
* @note Call this function will reset benchmark of all touch channels.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_fsm_start(void);
/**
* @brief Stop touch sensor FSM.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_fsm_stop(void);
/**
* @brief Trigger a touch sensor measurement, only support in SW mode of FSM
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_sw_start(void);
/**
* @brief Set charge and discharge times of each measurement
* @note This function will specify the charge and discharge times in each measurement period
* The clock is sourced from SOC_MOD_CLK_RTC_FAST, and its default frequency is SOC_CLK_RC_FAST_FREQ_APPROX
* The touch sensor will record the total clock cycles of all the charge and discharge cycles as the final result (raw value)
* @note If the charge and discharge times is too small, it may lead to inaccurate results.
*
* @param charge_discharge_times Charge and discharge times, range: 0 ~ 0xffff.
* No exact typical value can be recommended because the capacity is influenced by the hardware design and how finger touches,
* but suggest adjusting this value to make the measurement time around 1 ms.
* @return
* - ESP_OK Set charge and discharge times success
*/
esp_err_t touch_pad_set_charge_discharge_times(uint16_t charge_discharge_times);
/**
* @brief Get charge and discharge times of each measurement
*
* @param charge_discharge_times Charge and discharge times
* @return
* - ESP_OK Get charge_discharge_times success
* - ESP_ERR_INVALID_ARG The input parameter is NULL
*/
esp_err_t touch_pad_get_charge_discharge_times(uint16_t *charge_discharge_times);
/**
* @brief Set the interval between two measurements
* @note The touch sensor will sleep between two measurements
* This function is to set the interval cycle
* And the interval is clocked from SOC_MOD_CLK_RTC_SLOW, its default frequency is SOC_CLK_RC_SLOW_FREQ_APPROX
*
* @param interval_cycle The interval between two measurements
* sleep_time = interval_cycle / SOC_CLK_RC_SLOW_FREQ_APPROX.
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
* @return
* - ESP_OK Set interval cycle success
*/
esp_err_t touch_pad_set_measurement_interval(uint16_t interval_cycle);
/**
* @brief Get the interval between two measurements
*
* @param interval_cycle The interval between two measurements
* @return
* - ESP_OK Get interval cycle success
* - ESP_ERR_INVALID_ARG The input parameter is NULL
*/
esp_err_t touch_pad_get_measurement_interval(uint16_t *interval_cycle);
/**
* @brief Set touch sensor times of charge and discharge and sleep time.
* Excessive total time will slow down the touch response.
* Too small measurement time will not be sampled enough, resulting in inaccurate measurements.
* @note The touch sensor will measure time of a fixed number of charge/discharge cycles (specified as the second parameter).
* That means the time (raw value) will increase as the capacity of the touch pad is increasing.
* The time (raw value) here is the number of clock cycles which is sourced from SOC_MOD_CLK_RTC_FAST and at (SOC_CLK_RC_FAST_FREQ_APPROX) Hz as default
* @note The greater the duty cycle of the measurement time, the more system power is consumed.
*
* @param sleep_cycle The touch sensor will sleep after each measurement.
* sleep_cycle decide the interval between each measurement.
* t_sleep = sleep_cycle / SOC_CLK_RC_SLOW_FREQ_APPROX.
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
* @param meas_times The times of charge and discharge in each measurement of touch channels. Range: 0 ~ 0xffff.
* Recommended typical value: Modify this value to make the measurement time around 1 ms.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_times)
__attribute__((deprecated("please use 'touch_pad_set_charge_discharge_times' and 'touch_pad_set_measurement_interval' instead")));
/**
* @brief Get touch sensor times of charge and discharge and sleep time
* @param sleep_cycle Pointer to accept sleep cycle number
* @param meas_times Pointer to accept measurement times count.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_times)
__attribute__((deprecated("please use 'touch_pad_get_charge_discharge_times' and 'touch_pad_get_measurement_interval' instead")));
/**
* @brief Set the connection type of touch channels in idle status.
* When a channel is in measurement mode, other initialized channels are in idle mode.
* The touch channel is generally adjacent to the trace, so the connection state of the idle channel
* affects the stability and sensitivity of the test channel.
* The `CONN_HIGHZ`(high resistance) setting increases the sensitivity of touch channels.
* The `CONN_GND`(grounding) setting increases the stability of touch channels.
* @param type Select idle channel connect to high resistance state or ground.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_set_idle_channel_connect(touch_pad_conn_type_t type);
/**
* @brief Get the connection type of touch channels in idle status.
* When a channel is in measurement mode, other initialized channels are in idle mode.
* The touch channel is generally adjacent to the trace, so the connection state of the idle channel
* affects the stability and sensitivity of the test channel.
* The `CONN_HIGHZ`(high resistance) setting increases the sensitivity of touch channels.
* The `CONN_GND`(grounding) setting increases the stability of touch channels.
* @param type Pointer to connection type.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_get_idle_channel_connect(touch_pad_conn_type_t *type);
/**
* @brief Set the trigger threshold of touch sensor.
* The threshold determines the sensitivity of the touch sensor.
* The threshold is the original value of the trigger state minus the benchmark value.
* @note If set "TOUCH_PAD_THRESHOLD_MAX", the touch is never be triggered.
* @param touch_num touch pad index
* @param threshold threshold of touch sensor. Should be less than the max change value of touch.
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_set_thresh(touch_pad_t touch_num, uint32_t threshold);
/**
* @brief Get touch sensor trigger threshold
* @param touch_num touch pad index
* @param threshold pointer to accept threshold
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG if argument is wrong
*/
esp_err_t touch_pad_get_thresh(touch_pad_t touch_num, uint32_t *threshold);
/**
* @brief Register touch channel into touch sensor scan group.
* The working mode of the touch sensor is cyclically scanned.
* This function will set the scan bits according to the given bitmask.
* @note If set this mask, the FSM timer should be stop firsty.
* @note The touch sensor that in scan map, should be deinit GPIO function firstly by `touch_pad_io_init`.
* @param enable_mask bitmask of touch sensor scan group.
* e.g. TOUCH_PAD_NUM14 -> BIT(14)
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_set_channel_mask(uint16_t enable_mask);
/**
* @brief Get the touch sensor scan group bit mask.
* @param enable_mask Pointer to bitmask of touch sensor scan group.
* e.g. TOUCH_PAD_NUM14 -> BIT(14)
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_get_channel_mask(uint16_t *enable_mask);
/**
* @brief Clear touch channel from touch sensor scan group.
* The working mode of the touch sensor is cyclically scanned.
* This function will clear the scan bits according to the given bitmask.
* @note If clear all mask, the FSM timer should be stop firsty.
* @param enable_mask bitmask of touch sensor scan group.
* e.g. TOUCH_PAD_NUM14 -> BIT(14)
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_clear_channel_mask(uint16_t enable_mask);
/**
* @brief Configure parameter for each touch channel.
* @note Touch num 0 is denoise channel, please use `touch_pad_denoise_enable` to set denoise function
* @param touch_num touch pad index
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG if argument wrong
* - ESP_FAIL if touch pad not initialized
*/
esp_err_t touch_pad_config(touch_pad_t touch_num);
/**
* @brief Reset the FSM of touch module.
* @note Call this function after `touch_pad_fsm_stop`.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_reset(void);
/**
* @brief Get the current measure channel.
* @note Should be called when touch sensor measurement is in cyclic scan mode.
* @return
* - touch channel number
*/
touch_pad_t touch_pad_get_current_meas_channel(void);
/**
* @brief Get the touch sensor interrupt status mask.
* @return
* - touch interrupt bit
*/
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
*/
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
*/
esp_err_t touch_pad_intr_disable(touch_pad_intr_mask_t int_mask);
/**
* @brief Clear touch sensor interrupt by bitmask.
* @param int_mask Pad mask to clear interrupts
* @return
* - ESP_OK on success
*/
esp_err_t touch_pad_intr_clear(touch_pad_intr_mask_t int_mask);
/**
* @brief Register touch-pad ISR.
* The handler will be attached to the same CPU core that this function is running on.
* @param fn Pointer to ISR handler
* @param arg Parameter for ISR
* @param intr_mask Enable touch sensor interrupt handler by bitmask.
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Arguments error
* - ESP_ERR_NO_MEM No memory
*/
esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_mask_t intr_mask);
/**
* @brief Enable/disable the timeout check and set timeout threshold for all touch sensor channels measurements.
* If enable: When the touch reading of a touch channel exceeds the measurement threshold, a timeout interrupt will be generated.
* If disable: the FSM does not check if the channel under measurement times out.
*
* @note The threshold compared with touch readings.
* @note In order to avoid abnormal short circuit of some touch channels. This function should be turned on.
* Ensure the normal operation of other touch channels.
*
* @param enable true(default): Enable the timeout check; false: Disable the timeout check.
* @param threshold For all channels, the maximum value that will not be exceeded during normal operation.
*
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_timeout_set(bool enable, uint32_t threshold);
/**
* @brief Call this interface after timeout to make the touch channel resume normal work. Point on the next channel to measure.
* If this API is not called, the touch FSM will stop the measurement after timeout interrupt.
*
* @note Call this API after finishes the exception handling by user.
*
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_timeout_resume(void);
/**
* @brief get raw data of touch sensor.
* @note After the initialization is complete, the "raw_data" is max value. You need to wait for a measurement
* cycle before you can read the correct touch value.
* @param touch_num touch pad index
* @param raw_data pointer to accept touch sensor value
* @return
* - ESP_OK Success
* - ESP_FAIL Touch channel 0 haven't this parameter.
*/
esp_err_t touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data);
/**
* @brief get benchmark of touch sensor.
* @note After initialization, the benchmark value is the maximum during the first measurement period.
* @param touch_num touch pad index
* @param benchmark pointer to accept touch sensor benchmark value
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Touch channel 0 haven't this parameter.
*/
esp_err_t touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark);
/**
* @brief Get smoothed data that obtained by filtering the raw data.
*
* @param touch_num touch pad index
* @param smooth pointer to smoothed data
*/
esp_err_t touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth);
/**
* @brief Force reset benchmark to raw data of touch sensor.
* @param touch_num touch pad index
* - TOUCH_PAD_MAX Reset basaline of all channels
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_reset_benchmark(touch_pad_t touch_num);
/**
* @brief set parameter of touch sensor filter and detection algorithm.
* For more details on the detection algorithm, please refer to the application documentation.
* @param filter_info select filter type and threshold of detection algorithm
* @return
* - ESP_OK Success
*/
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.
* For more details on the detection algorithm, please refer to the application documentation.
* @param filter_info select filter type and threshold of detection algorithm
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_filter_get_config(touch_filter_config_t *filter_info);
/**
* @brief enable touch sensor filter for detection algorithm.
* For more details on the detection algorithm, please refer to the application documentation.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_filter_enable(void);
/**
* @brief disable touch sensor filter for detection algorithm.
* For more details on the detection algorithm, please refer to the application documentation.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_filter_disable(void);
/**
* @brief set parameter of denoise pad (TOUCH_PAD_NUM0).
* T0 is an internal channel that does not have a corresponding external GPIO.
* T0 will work simultaneously with the measured channel Tn. Finally, the actual
* measured value of Tn is the value after subtracting lower bits of T0.
* The noise reduction function filters out interference introduced simultaneously on all channels,
* such as noise introduced by power supplies and external EMI.
* @param denoise parameter of denoise
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_set_config(const touch_pad_denoise_t *denoise);
/**
* @brief get parameter of denoise pad (TOUCH_PAD_NUM0).
* @param denoise Pointer to parameter of denoise
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_get_config(touch_pad_denoise_t *denoise);
/**
* @brief enable denoise function.
* T0 is an internal channel that does not have a corresponding external GPIO.
* T0 will work simultaneously with the measured channel Tn. Finally, the actual
* measured value of Tn is the value after subtracting lower bits of T0.
* The noise reduction function filters out interference introduced simultaneously on all channels,
* such as noise introduced by power supplies and external EMI.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_enable(void);
/**
* @brief disable denoise function.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_disable(void);
/**
* @brief Get denoise measure value (TOUCH_PAD_NUM0).
* @param data Pointer to receive denoise value
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_read_data(uint32_t *data);
/**
* @brief set parameter of waterproof function.
*
* The waterproof function includes a shielded channel (TOUCH_PAD_NUM14) and a guard channel.
* Guard pad is used to detect the large area of water covering the touch panel.
* Shield pad is used to shield the influence of water droplets covering the touch panel.
* It is generally designed as a grid and is placed around the touch buttons.
*
* @param waterproof parameter of waterproof
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_set_config(const touch_pad_waterproof_t *waterproof);
/**
* @brief get parameter of waterproof function.
* @param waterproof parameter of waterproof
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_get_config(touch_pad_waterproof_t *waterproof);
/**
* @brief Enable parameter of waterproof function.
* Should be called after function ``touch_pad_waterproof_set_config``.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_enable(void);
/**
* @brief Disable parameter of waterproof function.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_disable(void);
/**
* @brief Enable/disable proximity function of touch channels.
* The proximity sensor measurement is the accumulation of touch channel measurements.
*
* @note Supports up to three touch channels configured as proximity sensors.
* @param touch_num touch pad index
* @param enabled true: enable the proximity function; false: disable the proximity function
* @return
* - ESP_OK: Configured correctly.
* - ESP_ERR_INVALID_ARG: Touch channel number error.
* - ESP_ERR_NOT_SUPPORTED: Don't support configured.
*/
esp_err_t touch_pad_proximity_enable(touch_pad_t touch_num, bool enabled);
/**
* @brief Set measure count of proximity channel.
* The proximity sensor measurement is the accumulation of touch channel measurements.
*
* @note All proximity channels use the same `count` value. So please pass the parameter `TOUCH_PAD_MAX`.
* @param touch_num Touch pad index. In this version, pass the parameter `TOUCH_PAD_MAX`.
* @param count The cumulative times of measurements for proximity pad. Range: 0 ~ 255.
* @return
* - ESP_OK: Configured correctly.
* - ESP_ERR_INVALID_ARG: Touch channel number error.
*/
esp_err_t touch_pad_proximity_set_count(touch_pad_t touch_num, uint32_t count);
/**
* @brief Get measure count of proximity channel.
* The proximity sensor measurement is the accumulation of touch channel measurements.
*
* @note All proximity channels use the same `count` value. So please pass the parameter `TOUCH_PAD_MAX`.
* @param touch_num Touch pad index. In this version, pass the parameter `TOUCH_PAD_MAX`.
* @param count The cumulative times of measurements for proximity pad. Range: 0 ~ 255.
* @return
* - ESP_OK: Configured correctly.
* - ESP_ERR_INVALID_ARG: Touch channel number error.
*/
esp_err_t touch_pad_proximity_get_count(touch_pad_t touch_num, uint32_t *count);
/**
* @brief Get the accumulated measurement of the proximity sensor.
* The proximity sensor measurement is the accumulation of touch channel measurements.
* @param touch_num touch pad index
* @param measure_out If the accumulation process does not end, the `measure_out` is the process value.
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Touch num is not proximity
*/
esp_err_t touch_pad_proximity_get_data(touch_pad_t touch_num, uint32_t *measure_out);
/**
* @brief Get parameter of touch sensor sleep channel.
* The touch sensor can works in sleep mode to wake up sleep.
*
* @note After the sleep channel is configured, Please use special functions for sleep channel.
* e.g. The user should uses `touch_pad_sleep_channel_read_data` instead of `touch_pad_read_raw_data` to obtain the sleep channel reading.
*
* @param slp_config touch sleep pad config.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_get_info(touch_pad_sleep_channel_t *slp_config);
/**
* @brief Enable/Disable sleep channel function for touch sensor.
* The touch sensor can works in sleep mode to wake up sleep.
*
* @note ESP32S2 only support one sleep channel.
* @note After the sleep channel is configured, Please use special functions for sleep channel.
* e.g. The user should uses `touch_pad_sleep_channel_read_data` instead of `touch_pad_read_raw_data` to obtain the sleep channel reading.
*
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param enable true: enable sleep pad for touch sensor; false: disable sleep pad for touch sensor;
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_enable(touch_pad_t pad_num, bool enable);
/**
* @brief Enable/Disable proximity function for sleep channel.
* The touch sensor can works in sleep mode to wake up sleep.
*
* @note ESP32S2 only support one sleep channel.
*
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param enable true: enable proximity for sleep channel; false: disable proximity for sleep channel;
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_enable_proximity(touch_pad_t pad_num, bool enable);
/**
* @brief Set the trigger threshold of touch sensor in deep sleep.
* The threshold determines the sensitivity of the touch sensor.
*
* @note In general, the touch threshold during sleep can use the threshold parameter parameters before sleep.
*
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param touch_thres touch sleep pad threshold
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_set_threshold(touch_pad_t pad_num, uint32_t touch_thres);
/**
* @brief Get the trigger threshold of touch sensor in deep sleep.
* The threshold determines the sensitivity of the touch sensor.
*
* @note In general, the touch threshold during sleep can use the threshold parameter parameters before sleep.
*
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param touch_thres touch sleep pad threshold
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_get_threshold(touch_pad_t pad_num, uint32_t *touch_thres);
/**
* @brief Read benchmark of touch sensor sleep channel.
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param benchmark pointer to accept touch sensor benchmark value
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_sleep_channel_read_benchmark(touch_pad_t pad_num, uint32_t *benchmark);
/**
* @brief Read smoothed data of touch sensor sleep channel.
* Smoothed data is filtered from the raw data.
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param smooth_data pointer to accept touch sensor smoothed data
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_sleep_channel_read_smooth(touch_pad_t pad_num, uint32_t *smooth_data);
/**
* @brief Read raw data of touch sensor sleep channel.
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param raw_data pointer to accept touch sensor raw data
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_sleep_channel_read_data(touch_pad_t pad_num, uint32_t *raw_data);
/**
* @brief Reset benchmark of touch sensor sleep channel.
*
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_reset_benchmark(void);
/**
* @brief Read proximity count of touch sensor sleep channel.
* @param pad_num Set touch channel number for sleep pad. Only one touch sensor channel is supported in deep sleep mode.
* @param proximity_cnt pointer to accept touch sensor proximity count value
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_sleep_channel_read_proximity_cnt(touch_pad_t pad_num, uint32_t *proximity_cnt);
/**
* @brief Change the operating frequency of touch pad in deep sleep state. Reducing the operating frequency can effectively reduce power consumption.
* If this function is not called, the working frequency of touch in the deep sleep state is the same as that in the wake-up state.
*
* @param sleep_cycle The touch sensor will sleep after each measurement.
* sleep_cycle decide the interval between each measurement.
* t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
* @param meas_times The times of charge and discharge in each measure process of touch channels.
* The timer frequency is 8Mhz. Range: 0 ~ 0xffff.
* Recommended typical value: Modify this value to make the measurement time around 1ms.
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times);
#ifdef __cplusplus
}
#endif

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2016-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -16,13 +16,13 @@
#include "freertos/timers.h" #include "freertos/timers.h"
#include "esp_intr_alloc.h" #include "esp_intr_alloc.h"
#include "driver/rtc_io.h" #include "driver/rtc_io.h"
#include "driver/touch_pad.h" #include "driver/touch_sensor_common.h"
#include "esp_private/rtc_ctrl.h" #include "esp_private/rtc_ctrl.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#include "esp_check.h" #include "esp_check.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sensor_legacy_types.h"
#include "hal/touch_sensor_hal.h" #include "hal/touch_sensor_hal.h"
#ifndef NDEBUG #ifndef NDEBUG
@@ -379,7 +379,7 @@ esp_err_t touch_pad_filter_get_config(touch_filter_config_t *filter_info)
esp_err_t touch_pad_filter_enable(void) esp_err_t touch_pad_filter_enable(void)
{ {
TOUCH_ENTER_CRITICAL(); TOUCH_ENTER_CRITICAL();
touch_hal_filter_enable(); touch_hal_filter_enable(true);
TOUCH_EXIT_CRITICAL(); TOUCH_EXIT_CRITICAL();
return ESP_OK; return ESP_OK;
} }
@@ -387,7 +387,7 @@ esp_err_t touch_pad_filter_enable(void)
esp_err_t touch_pad_filter_disable(void) esp_err_t touch_pad_filter_disable(void)
{ {
TOUCH_ENTER_CRITICAL(); TOUCH_ENTER_CRITICAL();
touch_hal_filter_disable(); touch_hal_filter_enable(false);
TOUCH_EXIT_CRITICAL(); TOUCH_EXIT_CRITICAL();
return ESP_OK; return ESP_OK;
} }
@@ -569,9 +569,9 @@ esp_err_t touch_pad_sleep_channel_enable_proximity(touch_pad_t pad_num, bool ena
TOUCH_ENTER_CRITICAL(); TOUCH_ENTER_CRITICAL();
if (enable) { if (enable) {
touch_hal_sleep_enable_approach(); touch_hal_sleep_enable_approach(true);
} else { } else {
touch_hal_sleep_disable_approach(); touch_hal_sleep_enable_approach(false);
} }
TOUCH_EXIT_CRITICAL(); TOUCH_EXIT_CRITICAL();
return ESP_OK; return ESP_OK;
@@ -656,3 +656,17 @@ esp_err_t touch_pad_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t m
touch_hal_sleep_channel_set_work_time(sleep_cycle, meas_times); touch_hal_sleep_channel_set_work_time(sleep_cycle, meas_times);
return ESP_OK; return ESP_OK;
} }
/**
* @brief This function will be called during start up, to check that the new touch driver is not running along with the legacy touch driver
*/
static __attribute__((constructor)) void check_touch_driver_conflict(void)
{
extern __attribute__((weak)) esp_err_t touch_sensor_new_controller(const void*, void *);
/* If the new Touch driver is linked, the weak function will point to the actual function in the new driver, otherwise it is NULL*/
if ((void *)touch_sensor_new_controller != NULL) {
ESP_EARLY_LOGE("legacy_touch_driver", "CONFLICT! The new touch driver can't work along with the legacy touch driver");
abort();
}
ESP_EARLY_LOGW("legacy_touch_driver", "legacy touch driver is deprecated, please migrate to use driver/touch_sens.h");
}

View File

@@ -8,7 +8,7 @@
#include "esp_err.h" #include "esp_err.h"
#include "esp_intr_alloc.h" #include "esp_intr_alloc.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sensor_legacy_types.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@@ -16,10 +16,9 @@
#include "freertos/timers.h" #include "freertos/timers.h"
#include "esp_intr_alloc.h" #include "esp_intr_alloc.h"
#include "driver/rtc_io.h" #include "driver/rtc_io.h"
#include "driver/touch_pad.h"
#include "esp_private/rtc_ctrl.h" #include "esp_private/rtc_ctrl.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sensor_legacy_types.h"
#include "hal/touch_sensor_hal.h" #include "hal/touch_sensor_hal.h"
static const char *TOUCH_TAG = "TOUCH_SENSOR"; static const char *TOUCH_TAG = "TOUCH_SENSOR";

View File

@@ -8,10 +8,11 @@ set(srcs)
set(public_inc) set(public_inc)
if(CONFIG_SOC_TOUCH_SENSOR_SUPPORTED) if(CONFIG_SOC_TOUCH_SENSOR_SUPPORTED)
if(CONFIG_SOC_TOUCH_SENSOR_VERSION EQUAL 3) set(version_folder "hw_ver${CONFIG_SOC_TOUCH_SENSOR_VERSION}")
list(APPEND srcs "hw_ver3/touch_version_specific.c" if(CONFIG_SOC_TOUCH_SENSOR_VERSION GREATER 1)
"common/touch_sens_common.c") list(APPEND srcs "common/touch_sens_common.c"
list(APPEND public_inc "include" "hw_ver3/include") "${version_folder}/touch_version_specific.c")
list(APPEND public_inc "include" "${version_folder}/include")
endif() endif()
endif() endif()

View File

@@ -21,12 +21,14 @@
#include "soc/interrupts.h" #include "soc/interrupts.h"
#include "esp_intr_alloc.h" #include "esp_intr_alloc.h"
#endif #endif
#include "esp_private/touch_sens_helper.h"
#if CONFIG_TOUCH_ENABLE_DEBUG_LOG #if CONFIG_TOUCH_ENABLE_DEBUG_LOG
// The local log level must be defined before including esp_log.h // The local log level must be defined before including esp_log.h
// Set the maximum log level for this source file // Set the maximum log level for this source file
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG #define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
#endif #endif
#include "esp_log.h"
#include "esp_check.h" #include "esp_check.h"
#include "touch_sens_private.h" #include "touch_sens_private.h"
@@ -72,7 +74,7 @@ esp_err_t touch_sensor_new_controller(const touch_sensor_config_t *sens_cfg, tou
g_touch = (touch_sensor_handle_t)heap_caps_calloc(1, sizeof(struct touch_sensor_s), TOUCH_MEM_ALLOC_CAPS); g_touch = (touch_sensor_handle_t)heap_caps_calloc(1, sizeof(struct touch_sensor_s), TOUCH_MEM_ALLOC_CAPS);
ESP_RETURN_ON_FALSE(g_touch, ESP_ERR_NO_MEM, TAG, "No memory for touch sensor struct"); ESP_RETURN_ON_FALSE(g_touch, ESP_ERR_NO_MEM, TAG, "No memory for touch sensor struct");
g_touch->mutex = xSemaphoreCreateMutexWithCaps(TOUCH_MEM_ALLOC_CAPS); g_touch->mutex = xSemaphoreCreateRecursiveMutexWithCaps(TOUCH_MEM_ALLOC_CAPS);
ESP_GOTO_ON_FALSE(g_touch->mutex, ESP_ERR_NO_MEM, err, TAG, "No memory for mutex semaphore"); ESP_GOTO_ON_FALSE(g_touch->mutex, ESP_ERR_NO_MEM, err, TAG, "No memory for mutex semaphore");
touch_priv_enable_module(true); touch_priv_enable_module(true);
@@ -99,7 +101,7 @@ esp_err_t touch_sensor_del_controller(touch_sensor_handle_t sens_handle)
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
// Take the semaphore to make sure the touch has stopped // Take the semaphore to make sure the touch has stopped
xSemaphoreTake(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Touch sensor has not disabled"); ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Touch sensor has not disabled");
FOR_EACH_TOUCH_CHANNEL(i) { FOR_EACH_TOUCH_CHANNEL(i) {
ESP_GOTO_ON_FALSE(!sens_handle->ch[i], ESP_ERR_INVALID_STATE, err, TAG, "There are still some touch channels not deleted"); ESP_GOTO_ON_FALSE(!sens_handle->ch[i], ESP_ERR_INVALID_STATE, err, TAG, "There are still some touch channels not deleted");
@@ -112,7 +114,7 @@ esp_err_t touch_sensor_del_controller(touch_sensor_handle_t sens_handle)
ESP_GOTO_ON_ERROR(esp_intr_free(sens_handle->intr_handle), err, TAG, "Failed to deregister the interrupt handler"); ESP_GOTO_ON_ERROR(esp_intr_free(sens_handle->intr_handle), err, TAG, "Failed to deregister the interrupt handler");
#endif #endif
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
touch_ll_intr_disable(TOUCH_LL_INTR_MASK_ALL); touch_ll_interrupt_disable(TOUCH_LL_INTR_MASK_ALL);
touch_ll_clear_active_channel_status(); touch_ll_clear_active_channel_status();
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
@@ -120,7 +122,7 @@ esp_err_t touch_sensor_del_controller(touch_sensor_handle_t sens_handle)
s_touch_free_resource(sens_handle); s_touch_free_resource(sens_handle);
err: err:
if (g_touch && g_touch->mutex) { if (g_touch && g_touch->mutex) {
xSemaphoreGive(g_touch->mutex); xSemaphoreGiveRecursive(g_touch->mutex);
} }
return ret; return ret;
} }
@@ -133,10 +135,11 @@ esp_err_t touch_sensor_new_channel(touch_sensor_handle_t sens_handle, int chan_i
TOUCH_NULL_POINTER_CHECK(chan_cfg); TOUCH_NULL_POINTER_CHECK(chan_cfg);
TOUCH_NULL_POINTER_CHECK(ret_chan_handle); TOUCH_NULL_POINTER_CHECK(ret_chan_handle);
TOUCH_CHANNEL_CHECK(chan_id); TOUCH_CHANNEL_CHECK(chan_id);
ESP_RETURN_ON_FALSE(g_touch == sens_handle, ESP_ERR_INVALID_ARG, TAG, "The input touch sensor handle is unmatched"); ESP_RETURN_ON_FALSE(g_touch == sens_handle, ESP_ERR_INVALID_ARG, TAG, "The input touch sensor handle is unmatched");
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTake(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err2, TAG, "Please disable the touch sensor first"); ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err2, TAG, "Please disable the touch sensor first");
ESP_GOTO_ON_FALSE(!sens_handle->ch[chan_id], ESP_ERR_INVALID_STATE, err2, TAG, "The channel %d has been registered", chan_id); ESP_GOTO_ON_FALSE(!sens_handle->ch[chan_id], ESP_ERR_INVALID_STATE, err2, TAG, "The channel %d has been registered", chan_id);
@@ -145,29 +148,29 @@ esp_err_t touch_sensor_new_channel(touch_sensor_handle_t sens_handle, int chan_i
ESP_GOTO_ON_FALSE(sens_handle->ch[chan_id], ESP_ERR_NO_MEM, err2, TAG, "No memory for touch channel"); ESP_GOTO_ON_FALSE(sens_handle->ch[chan_id], ESP_ERR_NO_MEM, err2, TAG, "No memory for touch channel");
sens_handle->ch[chan_id]->id = chan_id; sens_handle->ch[chan_id]->id = chan_id;
sens_handle->ch[chan_id]->base = sens_handle; sens_handle->ch[chan_id]->base = sens_handle;
sens_handle->ch[chan_id]->is_prox_chan = false; sens_handle->ch[chan_id]->prox_id = 0;
/* Init the channel */ /* Init the channel */
ESP_GOTO_ON_ERROR(touch_priv_config_channel(sens_handle->ch[chan_id], chan_cfg), ESP_GOTO_ON_ERROR(touch_priv_config_channel(sens_handle->ch[chan_id], chan_cfg),
err1, TAG, "Failed to configure the touch channel %d", chan_id); err1, TAG, "Failed to configure the touch channel %d", chan_id);
touch_channel_pin_init(chan_id); touch_channel_pin_init(chan_id);
touch_chan_benchmark_config_t bm_cfg = {.do_reset = true};
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
#if SOC_TOUCH_SENSOR_VERSION == 2
touch_ll_reset_chan_benchmark(1 << chan_id);
#endif
sens_handle->chan_mask |= 1 << chan_id; sens_handle->chan_mask |= 1 << chan_id;
touch_ll_set_channel_mask(sens_handle->chan_mask); /* Reset the benchmark to overwrite the legacy benchmark during the deep sleep */
touch_priv_config_benchmark(sens_handle->ch[chan_id], &bm_cfg);
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
*ret_chan_handle = sens_handle->ch[chan_id]; *ret_chan_handle = sens_handle->ch[chan_id];
xSemaphoreGive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
err1: err1:
free(sens_handle->ch[chan_id]); free(sens_handle->ch[chan_id]);
sens_handle->ch[chan_id] = NULL; sens_handle->ch[chan_id] = NULL;
err2: err2:
xSemaphoreGive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
} }
@@ -177,27 +180,41 @@ esp_err_t touch_sensor_del_channel(touch_channel_handle_t chan_handle)
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
touch_sensor_handle_t sens_handle = chan_handle->base; touch_sensor_handle_t sens_handle = chan_handle->base;
xSemaphoreTake(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first"); ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
#if SOC_TOUCH_SENSOR_VERSION == 2 #if SOC_TOUCH_SUPPORT_WATERPROOF
if (sens_handle->guard_chan == chan_handle || (BIT(chan_handle->id) & sens_handle->shield_chan_mask)) { if (sens_handle->shield_chan == chan_handle) {
ESP_GOTO_ON_ERROR(touch_sensor_config_waterproof(sens_handle, NULL), err, TAG, "Failed to disable waterproof on this channel"); ESP_GOTO_ON_ERROR(touch_sensor_config_waterproof(sens_handle, NULL), err, TAG, "Failed to disable waterproof on this channel");
} else if (sens_handle->guard_chan == chan_handle) {
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
touch_ll_waterproof_set_guard_chan(TOUCH_LL_NULL_CHANNEL);
sens_handle->guard_chan = NULL;
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
} }
if (sens_handle->sleep_chan == chan_handle) { #endif // SOC_TOUCH_SUPPORT_WATERPROOF
ESP_GOTO_ON_ERROR(touch_sensor_config_sleep_channel(sens_handle, NULL), err, TAG, "Failed to disable sleep function on this channel"); #if SOC_TOUCH_SUPPORT_SLEEP_WAKEUP
if (sens_handle->deep_slp_chan == chan_handle) {
ESP_GOTO_ON_ERROR(touch_sensor_config_sleep_wakeup(sens_handle, NULL), err, TAG, "Failed to disable sleep function on this channel");
}
#endif
#if SOC_TOUCH_SUPPORT_PROX_SENSING
if (chan_handle->prox_id > 0) {
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
chan_handle->prox_id = 0;
touch_ll_set_proximity_sensing_channel(chan_handle->prox_id - 1, TOUCH_LL_NULL_CHANNEL);
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
} }
#endif #endif
int id = chan_handle->id; int id = chan_handle->id;
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
sens_handle->chan_mask &= ~(1UL << id); sens_handle->chan_mask &= ~(1UL << id);
touch_ll_set_channel_mask(sens_handle->chan_mask);
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
free(g_touch->ch[id]); free(g_touch->ch[id]);
g_touch->ch[id] = NULL; g_touch->ch[id] = NULL;
err: err:
xSemaphoreGive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
} }
@@ -208,13 +225,13 @@ esp_err_t touch_sensor_reconfig_controller(touch_sensor_handle_t sens_handle, co
ESP_RETURN_ON_FALSE(sens_cfg->meas_interval_us >= 0, ESP_ERR_INVALID_ARG, TAG, "interval_us should be a positive value"); ESP_RETURN_ON_FALSE(sens_cfg->meas_interval_us >= 0, ESP_ERR_INVALID_ARG, TAG, "interval_us should be a positive value");
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTake(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first"); ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
ESP_GOTO_ON_ERROR(touch_priv_config_controller(sens_handle, sens_cfg), err, TAG, "Configure touch controller failed"); ESP_GOTO_ON_ERROR(touch_priv_config_controller(sens_handle, sens_cfg), err, TAG, "Configure touch controller failed");
err: err:
xSemaphoreGive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
} }
@@ -230,13 +247,14 @@ esp_err_t touch_sensor_enable(touch_sensor_handle_t sens_handle)
sens_handle->is_enabled = true; sens_handle->is_enabled = true;
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
touch_ll_intr_clear(TOUCH_LL_INTR_MASK_ALL); touch_ll_enable_channel_mask(sens_handle->chan_mask);
touch_ll_intr_enable(TOUCH_LL_INTR_MASK_ALL); touch_ll_interrupt_clear(TOUCH_LL_INTR_MASK_ALL);
touch_ll_interrupt_enable(TOUCH_LL_INTR_MASK_ALL);
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
#if SOC_TOUCH_SUPPORT_PROX_SENSING #if SOC_TOUCH_SUPPORT_PROX_SENSING
/* Reset the cached data of proximity channel */ /* Reset the cached data of proximity channel */
FOR_EACH_TOUCH_CHANNEL(i) { FOR_EACH_TOUCH_CHANNEL(i) {
if (sens_handle->ch[i] && sens_handle->ch[i]->is_prox_chan) { if (sens_handle->ch[i] && sens_handle->ch[i]->prox_id > 0) {
sens_handle->ch[i]->prox_cnt = 0; sens_handle->ch[i]->prox_cnt = 0;
memset(sens_handle->ch[i]->prox_val, 0, sizeof(sens_handle->ch[i]->prox_val[0]) * TOUCH_SAMPLE_CFG_NUM); memset(sens_handle->ch[i]->prox_val, 0, sizeof(sens_handle->ch[i]->prox_val[0]) * TOUCH_SAMPLE_CFG_NUM);
} }
@@ -253,16 +271,17 @@ esp_err_t touch_sensor_disable(touch_sensor_handle_t sens_handle)
TOUCH_NULL_POINTER_CHECK(sens_handle); TOUCH_NULL_POINTER_CHECK(sens_handle);
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTake(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Touch sensor has not enabled"); ESP_GOTO_ON_FALSE(sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Touch sensor has not enabled");
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
touch_ll_intr_disable(TOUCH_LL_INTR_MASK_ALL); touch_ll_interrupt_disable(TOUCH_LL_INTR_MASK_ALL);
touch_ll_enable_channel_mask(0);
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
sens_handle->is_enabled = false; sens_handle->is_enabled = false;
err: err:
xSemaphoreGive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
} }
@@ -273,13 +292,13 @@ esp_err_t touch_sensor_reconfig_channel(touch_channel_handle_t chan_handle, cons
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
touch_sensor_handle_t sens_handle = chan_handle->base; touch_sensor_handle_t sens_handle = chan_handle->base;
xSemaphoreTake(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first"); ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
ESP_GOTO_ON_ERROR(touch_priv_config_channel(chan_handle, chan_cfg), err, TAG, "Configure touch channel failed"); ESP_GOTO_ON_ERROR(touch_priv_config_channel(chan_handle, chan_cfg), err, TAG, "Configure touch channel failed");
err: err:
xSemaphoreGive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
} }
@@ -294,13 +313,8 @@ esp_err_t touch_sensor_start_continuous_scanning(touch_sensor_handle_t sens_hand
TOUCH_ENTER_CRITICAL_SAFE(TOUCH_PERIPH_LOCK); TOUCH_ENTER_CRITICAL_SAFE(TOUCH_PERIPH_LOCK);
sens_handle->is_started = true; sens_handle->is_started = true;
#if SOC_TOUCH_SENSOR_VERSION <= 2
touch_ll_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
touch_ll_start_fsm();
#else
touch_ll_enable_fsm_timer(true); touch_ll_enable_fsm_timer(true);
touch_ll_start_fsm_repeated_timer(false); touch_ll_start_fsm_repeated_timer();
#endif
TOUCH_EXIT_CRITICAL_SAFE(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL_SAFE(TOUCH_PERIPH_LOCK);
err: err:
@@ -316,13 +330,8 @@ esp_err_t touch_sensor_stop_continuous_scanning(touch_sensor_handle_t sens_handl
ESP_GOTO_ON_FALSE_ISR(sens_handle->is_started, ESP_ERR_INVALID_STATE, err, TAG, "Continuous scanning not started yet"); ESP_GOTO_ON_FALSE_ISR(sens_handle->is_started, ESP_ERR_INVALID_STATE, err, TAG, "Continuous scanning not started yet");
TOUCH_ENTER_CRITICAL_SAFE(TOUCH_PERIPH_LOCK); TOUCH_ENTER_CRITICAL_SAFE(TOUCH_PERIPH_LOCK);
#if SOC_TOUCH_SENSOR_VERSION <= 2 touch_ll_stop_fsm_repeated_timer();
touch_ll_stop_fsm();
touch_ll_set_fsm_mode(TOUCH_FSM_MODE_SW);
#else
touch_ll_stop_fsm_repeated_timer(false);
touch_ll_enable_fsm_timer(false); touch_ll_enable_fsm_timer(false);
#endif
sens_handle->is_started = false; sens_handle->is_started = false;
TOUCH_EXIT_CRITICAL_SAFE(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL_SAFE(TOUCH_PERIPH_LOCK);
@@ -349,9 +358,8 @@ esp_err_t touch_sensor_trigger_oneshot_scanning(touch_sensor_handle_t sens_handl
ticks = 1; ticks = 1;
} }
} }
xSemaphoreTake(sens_handle->mutex, ticks); xSemaphoreTakeRecursive(sens_handle->mutex, ticks);
TickType_t end_tick = xTaskGetTickCount() + ticks; TickType_t end_tick = xTaskGetTickCount() + ticks;
// TODO: extract the following implementation into version specific source file when supporting other targets
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
touch_ll_enable_fsm_timer(false); touch_ll_enable_fsm_timer(false);
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
@@ -379,7 +387,7 @@ esp_err_t touch_sensor_trigger_oneshot_scanning(touch_sensor_handle_t sens_handl
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
err: err:
xSemaphoreGive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
sens_handle->is_started = false; sens_handle->is_started = false;
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
@@ -400,7 +408,7 @@ esp_err_t touch_sensor_register_callbacks(touch_sensor_handle_t sens_handle, con
#endif #endif
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTake(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first"); ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
@@ -408,7 +416,7 @@ esp_err_t touch_sensor_register_callbacks(touch_sensor_handle_t sens_handle, con
sens_handle->user_ctx = user_ctx; sens_handle->user_ctx = user_ctx;
err: err:
xSemaphoreGive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
} }
@@ -426,3 +434,21 @@ esp_err_t touch_channel_config_benchmark(touch_channel_handle_t chan_handle, con
touch_priv_config_benchmark(chan_handle, benchmark_cfg); touch_priv_config_benchmark(chan_handle, benchmark_cfg);
return ESP_OK; return ESP_OK;
} }
/******************************************************************************/
/* Scope: Private APIs */
/******************************************************************************/
esp_err_t touch_sensor_get_channel_info(touch_channel_handle_t chan_handle, touch_chan_info_t *chan_info)
{
TOUCH_NULL_POINTER_CHECK(chan_handle);
TOUCH_NULL_POINTER_CHECK(chan_info);
xSemaphoreTakeRecursive(chan_handle->base->mutex, portMAX_DELAY);
chan_info->chan_id = chan_handle->id;
chan_info->chan_gpio = touch_sensor_channel_io_map[chan_handle->id];
chan_info->flags.can_wake_dp_slp = chan_handle == chan_handle->base->deep_slp_chan;
chan_info->flags.is_proxi = chan_handle->prox_id > 0;
chan_info->flags.is_guard = chan_handle == chan_handle->base->guard_chan;
chan_info->flags.is_shield = chan_handle == chan_handle->base->shield_chan;
xSemaphoreGiveRecursive(chan_handle->base->mutex);
return ESP_OK;
}

View File

@@ -14,7 +14,7 @@
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/semphr.h" #include "freertos/semphr.h"
#include "soc/soc_caps.h" #include "soc/soc_caps.h"
#include "hal/touch_sensor_hal.h" #include "hal/touch_sens_hal.h"
#include "driver/touch_sens_types.h" #include "driver/touch_sens_types.h"
#include "esp_memory_utils.h" #include "esp_memory_utils.h"
#include "esp_check.h" #include "esp_check.h"
@@ -32,13 +32,19 @@ extern "C" {
/* IRAM safe caps */ /* IRAM safe caps */
#if CONFIG_TOUCH_ISR_IRAM_SAFE || CONFIG_TOUCH_CTRL_FUNC_IN_IRAM #if CONFIG_TOUCH_ISR_IRAM_SAFE || CONFIG_TOUCH_CTRL_FUNC_IN_IRAM
#define TOUCH_INTR_ALLOC_FLAGS (ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_SHARED | ESP_INTR_FLAG_LOWMED) #define _TOUCH_INTR_ALLOC_FLAGS (ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_LOWMED)
#define TOUCH_MEM_ALLOC_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT) #define TOUCH_MEM_ALLOC_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)
#else #else
#define TOUCH_INTR_ALLOC_FLAGS (ESP_INTR_FLAG_SHARED | ESP_INTR_FLAG_LOWMED) #define _TOUCH_INTR_ALLOC_FLAGS (ESP_INTR_FLAG_LOWMED)
#define TOUCH_MEM_ALLOC_CAPS MALLOC_CAP_DEFAULT #define TOUCH_MEM_ALLOC_CAPS MALLOC_CAP_DEFAULT
#endif //CONFIG_TOUCH_ISR_IRAM_SAFE #endif //CONFIG_TOUCH_ISR_IRAM_SAFE
#if SOC_TOUCH_SENSOR_VERSION == 3
#define TOUCH_INTR_ALLOC_FLAGS (_TOUCH_INTR_ALLOC_FLAGS)
#else
#define TOUCH_INTR_ALLOC_FLAGS (_TOUCH_INTR_ALLOC_FLAGS | ESP_INTR_FLAG_SHARED)
#endif
/* DMA caps */ /* DMA caps */
#define TOUCH_DMA_ALLOC_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA) #define TOUCH_DMA_ALLOC_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA)
@@ -85,6 +91,7 @@ struct touch_sensor_s {
bool immersion_proof; /*!< Flag to indicate whether to disable scanning when the guard ring is triggered */ bool immersion_proof; /*!< Flag to indicate whether to disable scanning when the guard ring is triggered */
bool proximity_en; /*!< Flag to indicate whether the proximity sensing feature is enabled */ bool proximity_en; /*!< Flag to indicate whether the proximity sensing feature is enabled */
bool timeout_en; /*!< Flag to indicate whether the measurement timeout feature (hardware timeout) is enabled */ bool timeout_en; /*!< Flag to indicate whether the measurement timeout feature (hardware timeout) is enabled */
bool denoise_en; /*!< Flag to indicate whether the denoise channel feature is enabled */
}; };
/** /**
@@ -94,7 +101,7 @@ struct touch_sensor_s {
struct touch_channel_s { struct touch_channel_s {
touch_sensor_handle_t base; /*!< The touch sensor controller handle */ touch_sensor_handle_t base; /*!< The touch sensor controller handle */
int id; /*!< Touch channel id, the range is target-specific */ int id; /*!< Touch channel id, the range is target-specific */
bool is_prox_chan; /*!< Flag to indicate whether this is a proximity channel */ int prox_id; /*!< The proximity channel id + 1. It is 0 if not a proximity channel */
uint32_t prox_cnt; /*!< Cache the proximity measurement count, only takes effect when the channel is a proximity channel. uint32_t prox_cnt; /*!< Cache the proximity measurement count, only takes effect when the channel is a proximity channel.
* When this count reaches `touch_proximity_config_t::scan_times`, * When this count reaches `touch_proximity_config_t::scan_times`,
* this field will be cleared and call the `on_proximity_meas_done` callback. * this field will be cleared and call the `on_proximity_meas_done` callback.

View File

@@ -9,4 +9,375 @@
* Version 2 includes ESP32-S2 and ESP32-S3 * Version 2 includes ESP32-S2 and ESP32-S3
*/ */
#error "'esp_driver_touch_sens' does not support for ESP32-S2 and ESP32-S3 yet" #pragma once
#include "soc/soc_caps.h"
#include "driver/touch_sens_types.h"
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
#define TOUCH_MIN_CHAN_ID 1 /*!< The minimum available channel id of the touch pad */
#define TOUCH_MAX_CHAN_ID 14 /*!< The maximum available channel id of the touch pad */
#define TOUCH_SHIELD_CHAN_ID 14 /*!< The touch channel that can be used as the shield channel */
/**
* @brief Helper macro to the default configurations of the touch sensor controller
*
* @param[in] sample_cfg_number The number of the sample configurations, which can only be 1 here because there is only one sample configuration
* @param[in] sample_cfg_ptr The pointer to the sample configurations
*/
#define TOUCH_SENSOR_DEFAULT_BASIC_CONFIG(sample_cfg_number, sample_cfg_ptr) { \
.power_on_wait_us = 256, \
.meas_interval_us = 32.0, \
.max_meas_time_us = 0, \
.sample_cfg_num = sample_cfg_number, \
.sample_cfg = sample_cfg_ptr, \
}
/**
* @brief Helper macro to the default sample configurations
* @note This default configuration uses `sample frequency = clock frequency / 1`
*
* @param[in] chg_times The charge times of the touch channel
* @param[in] volt_low The low voltage limit of the touch channel
* @param[in] volt_high The high voltage limit of the touch channel
*/
#define TOUCH_SENSOR_V2_DEFAULT_SAMPLE_CONFIG(chg_times, volt_low, volt_high) { \
.charge_times = chg_times, \
.charge_volt_lim_h = volt_high, \
.charge_volt_lim_l = volt_low, \
.idle_conn = TOUCH_IDLE_CONN_GND, \
.bias_type = TOUCH_BIAS_TYPE_SELF, \
}
/**
* @brief Helper macro to the default filter configurations
*
*/
#define TOUCH_SENSOR_DEFAULT_FILTER_CONFIG() { \
.benchmark = { \
.filter_mode = TOUCH_BM_IIR_FILTER_4, \
.jitter_step = 4, \
.denoise_lvl = 1, \
}, \
.data = { \
.smooth_filter = TOUCH_SMOOTH_IIR_FILTER_2, \
.active_hysteresis = 2, \
.debounce_cnt = 2, \
}, \
}
/**
* @brief The data type of the touch channel
*
*/
typedef enum {
TOUCH_CHAN_DATA_TYPE_RAW, /*!< The raw data of the touch channel */
TOUCH_CHAN_DATA_TYPE_SMOOTH, /*!< The smooth data of the touch channel */
TOUCH_CHAN_DATA_TYPE_BENCHMARK, /*!< The benchmark of the touch channel */
TOUCH_CHAN_DATA_TYPE_PROXIMITY, /*!< The proximity data of the proximity channel */
} touch_chan_data_type_t;
/**
* @brief Sample configurations of the touch sensor
*
*/
typedef struct {
uint32_t charge_times; /*!< The charge and discharge times of this sample configuration, the read data are positive correlation to the charge_times */
touch_volt_lim_h_t charge_volt_lim_h; /*!< The upper voltage limit while charging a touch pad. i.e., the touch controller won't charge the touch pad higher than this high voltage limitation. */
touch_volt_lim_l_t charge_volt_lim_l; /*!< The lower voltage limit while discharging a touch pad. i.e., the touch controller won't discharge the touch pad lower than this low voltage limitation. */
touch_idle_conn_t idle_conn; /*!< The connection of the idle touch channels.
* The idle touch channel is a channel which is enabled and power-on but not under measuring.
*/
touch_bias_type_t bias_type; /*!< The type of the touch sensor bias. Which affects the charge/discharge stability and power consumption */
} touch_sensor_sample_config_t;
/**
* @brief Configurations of the touch sensor controller
*
*/
typedef struct {
uint32_t power_on_wait_us; /*!< The waiting time between the channels power on and able to measure, to ensure the data stability */
float meas_interval_us; /*!< Measurement interval of each channels */
uint32_t max_meas_time_us; /*!< The maximum time of measuring one channel, if the time exceeds this value, the timeout interrupt will be triggered.
* Set to '0' to ignore the measurement time limitation, otherwise please set a proper time considering the configurations
* of this sample configurations below.
*/
/* Touch sensor sample configuration */
uint32_t sample_cfg_num; /*!< The sample configuration number that used for sampling, CANNOT exceed TOUCH_SAMPLE_CFG_NUM */
touch_sensor_sample_config_t *sample_cfg; /*!< The array of this sample configuration configurations, the length should be specified in `touch_sensor_config_t::sample_cfg_num` */
} touch_sensor_config_t;
/**
* @brief Configurations of the touch sensor channel
*
*/
typedef struct {
uint32_t active_thresh[TOUCH_SAMPLE_CFG_NUM]; /*!< The active threshold of each sample configuration,
* while the touch channel smooth value minus benchmark value exceed this threshold,
* will be regarded as activated
*/
touch_charge_speed_t charge_speed; /*!< The speed of charging and discharging the touch pad, the higher the speed, the faster charging and discharging */
touch_init_charge_volt_t init_charge_volt; /*!< The initial voltage before charging/discharging a touch pad */
} touch_channel_config_t;
/**
* @brief Configurations of the touch sensor filter
*
*/
typedef struct {
/**
* @brief Benchmark configuration
*/
struct {
touch_benchmark_filter_mode_t filter_mode; /*!< Benchmark filter mode. IIR filter and Jitter filter can be selected,
* TOUCH_BM_IIR_FILTER_16 is recommended
*/
uint32_t jitter_step; /*!< Jitter filter step size, only takes effect when the `filter_mode` is TOUCH_BM_JITTER_FILTER. Range: [0 ~ 15] */
int denoise_lvl; /*!< The denoise level, which determines the noise bouncing range that won't trigger benchmark update.
* Range: [0 ~ 4]. The greater the denoise_lvl is, more noise resistance will be. Specially, `0` stands for no denoise
* Typically, recommend to set this field to 1.
*/
} benchmark; /*!< Benchmark filter */
/**
* @brief Data configuration
*/
struct {
touch_smooth_filter_mode_t smooth_filter; /*!< Smooth data IIR filter mode */
uint32_t active_hysteresis; /*!< The hysteresis threshold to judge whether the touch channel is active
* If the channel data exceed the 'touch_channel_config_t::active_thresh + active_hysteresis'
* The channel will be activated. If the channel data is below to
* 'touch_channel_config_t::active_thresh - active_hysteresis' the channel will be inactivated.
*/
uint32_t debounce_cnt; /*!< The debounce count of the touch channel.
* Only when the channel data exceed the `touch_channel_config_t::active_thresh + active_hysteresis` for `debounce_cnt` times
* The channel will be activated. And only if the channel data is below to the `touch_channel_config_t::active_thresh - active_hysteresis`
* for `debounce_cnt` times, the channel will be inactivated.
* (The unit of `debounce_cnt` is the tick of the slow clock source)
*/
} data; /*!< Channel data filter */
} touch_sensor_filter_config_t;
/**
* @brief Touch sensor configuration during the deep sleep
* @note Currently it is the same as the normal controller configuration.
* The deep sleep configuration only takes effect when the chip entered sleep,
* so that to update a more power efficient configuration.
*
*/
typedef touch_sensor_config_t touch_sensor_config_dslp_t;
/**
* @brief Configuration of the touch sensor sleep function
*
*/
typedef struct {
touch_sleep_wakeup_level_t slp_wakeup_lvl; /*!< The sleep level that can be woke up by touch sensor. */
touch_channel_handle_t deep_slp_chan; /*!< The touch channel handle that supposed to work in the deep sleep. It can wake up the chip
* from deep sleep when this channel is activated.
* Only effective when the `touch_sleep_config_t::slp_wakeup_lvl` is `TOUCH_DEEP_SLEEP_WAKEUP`
*/
uint32_t deep_slp_thresh[TOUCH_SAMPLE_CFG_NUM]; /*!< The active threshold of the deep sleep channel during deep sleep,
* while the sleep channel exceed this threshold, it will be regarded as activated
* Only effective when the `touch_sleep_config_t::slp_wakeup_lvl` is `TOUCH_DEEP_SLEEP_WAKEUP`
*/
touch_sensor_config_dslp_t *deep_slp_sens_cfg; /*!< Specify the touch sensor configuration during the deep sleep.
* Note that these configurations will no take effect immediately,
* they will be set automatically while the chip prepare to enter sleep.
* Set NULL to not change the configurations before entering sleep.
* The sleep configuration mainly aims at lower down the charging and measuring times,
* so that to save power consumption during the sleep.
* Only effective when the `touch_sleep_config_t::slp_wakeup_lvl` is `TOUCH_DEEP_SLEEP_WAKEUP`
*/
} touch_sleep_config_t;
/**
* @brief Configuration of the touch sensor waterproof function
*
*/
typedef struct {
touch_channel_handle_t guard_chan; /*!< The guard channel of that used for immersion detect. Set NULL if you don't need the guard channel.
* Typically, the guard channel is a ring that surrounds the touch panels,
* it is used to detect the large area that covered by water.
* While large area of water covers the touch panel, the guard channel will be activated.
*/
touch_channel_handle_t shield_chan; /*!< The shield channel that used for water droplets shield, can't be NULL.
* The shield channel can only be the No.14 channel on touch version 2.
* Typically, the shield channel uses grid layout which covers the touch area,
* it is used to shield the influence of water droplets covering both the touch panel and the shield channel.
* The shield channel will be paralleled to the current measuring channel (except the guard channel) to reduce the influence of water droplets.
*/
uint32_t shield_drv; /*!< The shield channel driver, which controls the drive capability of shield channel, range: 0 ~ 7
* The larger the parasitic capacitance on the shielding channel, the higher the drive capability needs to be set.
*/
struct {
uint32_t immersion_proof: 1; /*!< Enable to protect the touch sensor pad when immersion detected.
* It will temporary disable the touch scanning if the guard channel triggered, and enable again if guard channel released.
* So that to avoid the fake touch when the touch panel is immersed in water.
*/
} flags; /*!< Flags of the water proof function */
} touch_waterproof_config_t;
/**
* @brief Configuration of the touch sensor proximity function
*
*/
typedef struct {
touch_channel_handle_t proximity_chan[TOUCH_PROXIMITY_CHAN_NUM]; /*!< The touch channel handles that will be configured as proximity sensing channels */
uint32_t scan_times; /*!< The total scan times of EACH sample configuration, all sample configurations share a same `scan_times`.
* The measurement result of each scanning will be accumulated together to get the final result.
*/
} touch_proximity_config_t;
/**
* @brief Configuration of denoise channel
*
*/
typedef struct {
touch_charge_speed_t charge_speed; /*!< The speed of charging and discharging the denoise touch channel, the higher the speed, the faster charging and discharging */
touch_init_charge_volt_t init_charge_volt; /*!< The initial voltage before starting charging/discharging the denoise channel */
touch_denoise_chan_cap_t ref_cap; /*!< The reference capacitance of the denoise channel. */
touch_denoise_chan_resolution_t resolution; /*!< The noise suppression resolution of the denoise channel.
* The higher the resolution, the better the suppression effect,
* but at the same time, the attenuation of other touch channel sampling values also increases.
*/
} touch_denoise_chan_config_t;
/**
* @brief Base event structure used in touch event queue
*/
typedef struct {
touch_channel_handle_t chan; /*!< the current triggered touch channel handle */
int chan_id; /*!< the current triggered touch channel number */
uint32_t status_mask; /*!< the current channel triggered status.
* For the bits in the status mask,
* if the bit is set, the corresponding channel is active
* if the bit is cleared, the corresponding channel is inactive
*/
} touch_base_event_data_t;
/**
* @brief Measure done event data
* @note Currently same as base event data
*
*/
typedef touch_base_event_data_t touch_meas_done_event_data_t;
/**
* @brief Scan done event data
* @note Currently same as base event data
*
*/
typedef touch_base_event_data_t touch_scan_done_event_data_t;
/**
* @brief Active event data
* @note Currently same as base event data
*
*/
typedef touch_base_event_data_t touch_active_event_data_t;
/**
* @brief Inactive event data
* @note Currently same as base event data
*
*/
typedef touch_base_event_data_t touch_inactive_event_data_t;
/**
* @brief Proximity sensing measure done event data
* @note Currently same as base event data
*
*/
typedef touch_base_event_data_t touch_prox_done_event_data_t;
/**
* @brief Timeout event data
* @note Currently same as base event data
*
*/
typedef touch_base_event_data_t touch_timeout_event_data_t;
/**
* @brief Touch sensor callbacks
* @note Set NULL for the used callbacks.
*
*/
typedef struct {
/**
* @brief Touch sensor on active event callback.
* Callback when any touch channel is activated.
* @param[in] sens_handle Touch sensor controller handle, created from `touch_sensor_new_controller()`
* @param[in] event Touch sensor active event data
* @param[in] user_ctx User registered context, passed from `touch_sensor_register_callbacks()`
*
* @return Whether a high priority task has been waken up by this callback function
*/
bool (*on_active)(touch_sensor_handle_t sens_handle, const touch_active_event_data_t *event, void *user_ctx);
/**
* @brief Touch sensor on inactive event callback.
* Callback when any touch channel is inactivated.
* @param[in] sens_handle Touch sensor controller handle, created from `touch_sensor_new_controller()`
* @param[in] event Touch sensor inactive event data
* @param[in] user_ctx User registered context, passed from `touch_sensor_register_callbacks()`
*
* @return Whether a high priority task has been waken up by this callback function
*/
bool (*on_inactive)(touch_sensor_handle_t sens_handle, const touch_inactive_event_data_t *event, void *user_ctx);
/**
* @brief Touch sensor on measure done event callback.
* Callback when the measurement of all the sample configurations on the current touch channel is done.
* @param[in] sens_handle Touch sensor controller handle, created from `touch_sensor_new_controller()`
* @param[in] event Touch sensor measure done event data
* @param[in] user_ctx User registered context, passed from `touch_sensor_register_callbacks()`
*
* @return Whether a high priority task has been waken up by this callback function
*/
bool (*on_measure_done)(touch_sensor_handle_t sens_handle, const touch_meas_done_event_data_t *event, void *user_ctx);
/**
* @brief Touch sensor on scan done event callback.
* Callback when finished scanning all the registered touch channels.
* @param[in] sens_handle Touch sensor controller handle, created from `touch_sensor_new_controller()`
* @param[in] event Touch sensor scan done event data
* @param[in] user_ctx User registered context, passed from `touch_sensor_register_callbacks()`
*
* @return Whether a high priority task has been waken up by this callback function
*/
bool (*on_scan_done)(touch_sensor_handle_t sens_handle, const touch_scan_done_event_data_t *event, void *user_ctx);
/**
* @brief Touch sensor on measurement timeout event callback.
* Callback when measure the current touch channel timeout.
* @param[in] sens_handle Touch sensor controller handle, created from `touch_sensor_new_controller()`
* @param[in] event Touch sensor timeout event data
* @param[in] user_ctx User registered context, passed from `touch_sensor_register_callbacks()`
*
* @return Whether a high priority task has been waken up by this callback function
*/
bool (*on_timeout)(touch_sensor_handle_t sens_handle, const touch_timeout_event_data_t *event, void *user_ctx);
/**
* @brief Touch sensor on proximity sensing measurement done event callback.
* Callback when proximity sensing measurement of the current channel is done.
* @param[in] sens_handle Touch sensor controller handle, created from `touch_sensor_new_controller()`
* @param[in] event Touch sensor proximity sensing measure done event data
* @param[in] user_ctx User registered context, passed from `touch_sensor_register_callbacks()`
*
* @return Whether a high priority task has been waken up by this callback function
*/
bool (*on_proximity_meas_done)(touch_sensor_handle_t sens_handle, const touch_prox_done_event_data_t *event, void *user_ctx);
} touch_event_callbacks_t;
/**
* @brief Touch sensor benchmark configurations, to set or reset the benchmark of the channel
*
*/
typedef struct {
bool do_reset; /*!< Whether to reset the benchmark to the channel's latest smooth data */
} touch_chan_benchmark_config_t;
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,471 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @brief This file is only applicable to the touch hardware version2
* Version 2 includes ESP32-S2 and ESP32-S3
*/
#include <inttypes.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "soc/soc_caps.h"
#include "soc/clk_tree_defs.h"
#include "soc/touch_sensor_periph.h"
#include "soc/rtc.h"
#include "hal/hal_utils.h"
#include "driver/touch_sens.h"
#include "esp_private/rtc_ctrl.h"
#include "esp_private/periph_ctrl.h"
#include "esp_clk_tree.h"
#include "esp_sleep.h"
#include "../../common/touch_sens_private.h"
#if CONFIG_TOUCH_ENABLE_DEBUG_LOG
// The local log level must be defined before including esp_log.h
// Set the maximum log level for this source file
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
#endif
#include "esp_log.h"
#include "esp_check.h"
#define TOUCH_DENOISE_CHAN_ID 0 /*!< The touch channel that can be used as the denoise channel */
static const char *TAG = "touch";
portMUX_TYPE g_touch_spinlock = portMUX_INITIALIZER_UNLOCKED;
/******************************************************************************
* Scope: touch driver private *
******************************************************************************/
void touch_priv_enable_module(bool enable)
{
TOUCH_ENTER_CRITICAL(TOUCH_RTC_LOCK);
touch_ll_enable_clock_gate(enable);
// Reset the benchmark after finished the scanning
touch_ll_reset_chan_benchmark(TOUCH_LL_FULL_CHANNEL_MASK);
TOUCH_EXIT_CRITICAL(TOUCH_RTC_LOCK);
}
void IRAM_ATTR touch_priv_default_intr_handler(void *arg)
{
/* If the touch controller object has not been allocated, return directly */
if (!g_touch) {
return;
}
bool need_yield = false;
uint32_t status = touch_ll_get_intr_status_mask();
g_touch->is_meas_timeout = false;
touch_ll_interrupt_clear(status);
touch_base_event_data_t data;
touch_ll_get_active_channel_mask(&data.status_mask);
data.chan = g_touch->ch[touch_ll_get_current_meas_channel()];
/* If the channel is not registered, return directly */
if (!data.chan) {
return;
}
data.chan_id = data.chan->id;
if (status & TOUCH_LL_INTR_MASK_DONE) {
#if !SOC_TOUCH_PROXIMITY_MEAS_DONE_SUPPORTED
/* For the target like ESP32-S2 that don't support proximity done interrupt,
Simulate the interrupt by software by judge the scan times. */
if (data.chan->prox_id > 0 &&
touch_ll_proximity_get_total_scan_times() == touch_ll_proximity_get_curr_scan_cnt(data.chan_id)) {
/* Set the proximity scan done flag to simulate a proximity done interrupt */
status |= TOUCH_LL_INTR_MASK_PROX_DONE;
}
#endif
if (g_touch->cbs.on_measure_done) {
need_yield |= g_touch->cbs.on_measure_done(g_touch, &data, g_touch->user_ctx);
}
}
if (status & TOUCH_LL_INTR_MASK_SCAN_DONE) {
#if CONFIG_IDF_TARGET_ESP32S2
/* Workaround for the fake scan done interrupt.
(Only happens when both channel 13 and 14 are enabled)
The scan done interrupt will be triggered twice for channel 13 and 14,
but we only hope it be triggered after channel 14 measurement done. */
bool fake_scan_done = data.chan_id == 13 && (g_touch->chan_mask >> 13 == 0x03);
if (g_touch->cbs.on_scan_done && !fake_scan_done)
#else
if (g_touch->cbs.on_scan_done)
#endif
{
need_yield |= g_touch->cbs.on_scan_done(g_touch, &data, g_touch->user_ctx);
}
}
if (status & TOUCH_LL_INTR_MASK_PROX_DONE) {
/* Accumulated proximity sensing data is stored in the benchmark data register.
Read it out to latch the last proximity sensing data. */
touch_ll_read_chan_data(data.chan_id, TOUCH_LL_READ_BENCHMARK, &data.chan->prox_val[0]);
// TODO: support to judge by software if the proximity channel triggered
if (g_touch->cbs.on_proximity_meas_done) {
need_yield |= g_touch->cbs.on_proximity_meas_done(g_touch, &data, g_touch->user_ctx);
}
}
if (status & TOUCH_LL_INTR_MASK_ACTIVE) {
/* When the guard ring activated, disable the scanning of other channels to avoid fake touch */
TOUCH_ENTER_CRITICAL_SAFE(TOUCH_PERIPH_LOCK);
if (g_touch->waterproof_en && data.chan == g_touch->guard_chan) {
touch_ll_enable_scan_mask(~BIT(data.chan->id), false);
}
TOUCH_EXIT_CRITICAL_SAFE(TOUCH_PERIPH_LOCK);
if (g_touch->cbs.on_active) {
need_yield |= g_touch->cbs.on_active(g_touch, &data, g_touch->user_ctx);
}
}
if (status & TOUCH_LL_INTR_MASK_INACTIVE) {
/* When the guard ring inactivated, enable the scanning of other channels again */
TOUCH_ENTER_CRITICAL_SAFE(TOUCH_PERIPH_LOCK);
if (g_touch->waterproof_en && data.chan == g_touch->guard_chan) {
touch_ll_enable_scan_mask(g_touch->chan_mask & (~BIT(g_touch->shield_chan->id)), true);
}
TOUCH_EXIT_CRITICAL_SAFE(TOUCH_PERIPH_LOCK);
if (g_touch->cbs.on_inactive) {
need_yield |= g_touch->cbs.on_inactive(g_touch, &data, g_touch->user_ctx);
}
}
if (status & TOUCH_LL_INTR_MASK_TIMEOUT) {
g_touch->is_meas_timeout = true;
touch_ll_force_done_curr_measurement();
if ((g_touch->cbs.on_timeout)) {
need_yield |= g_touch->cbs.on_timeout(g_touch, &data, g_touch->user_ctx);
}
}
if (need_yield) {
portYIELD_FROM_ISR();
}
}
static esp_err_t s_touch_convert_to_hal_config(touch_sensor_handle_t sens_handle, const touch_sensor_config_t *sens_cfg, touch_hal_config_t *hal_cfg)
{
TOUCH_NULL_POINTER_CHECK(sens_cfg);
TOUCH_NULL_POINTER_CHECK(hal_cfg);
ESP_RETURN_ON_FALSE(sens_cfg->sample_cfg_num && sens_cfg->sample_cfg, ESP_ERR_INVALID_ARG, TAG,
"at least one sample configuration required");
ESP_RETURN_ON_FALSE(sens_cfg->sample_cfg_num <= TOUCH_SAMPLE_CFG_NUM, ESP_ERR_INVALID_ARG, TAG,
"at most %d sample configurations supported", (int)(TOUCH_SAMPLE_CFG_NUM));
/* Get the source clock frequency for the first time */
if (!sens_handle->src_freq_hz) {
/* Touch sensor actually uses dynamic fast clock LP_DYN_FAST_CLK, but it will only switch to the slow clock during sleep,
* This driver only designed for wakeup case (sleep case should use ULP driver), so we only need to consider RTC_FAST here */
esp_clk_tree_src_get_freq_hz(SOC_MOD_CLK_RTC_FAST, ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED, &sens_handle->src_freq_hz);
ESP_LOGD(TAG, "touch rtc clock source: RTC_FAST, frequency: %"PRIu32" Hz", sens_handle->src_freq_hz);
}
uint32_t src_freq_mhz = sens_handle->src_freq_hz / 1000000;
hal_cfg->power_on_wait_ticks = (uint32_t)sens_cfg->power_on_wait_us * src_freq_mhz;
hal_cfg->power_on_wait_ticks = hal_cfg->power_on_wait_ticks > TOUCH_LL_PAD_MEASURE_WAIT_MAX ?
TOUCH_LL_PAD_MEASURE_WAIT_MAX : hal_cfg->power_on_wait_ticks;
hal_cfg->meas_interval_ticks = (uint32_t)(sens_cfg->meas_interval_us * src_freq_mhz);
hal_cfg->timeout_ticks = (uint32_t)sens_cfg->max_meas_time_us * src_freq_mhz;
ESP_RETURN_ON_FALSE(hal_cfg->timeout_ticks <= TOUCH_LL_TIMEOUT_MAX, ESP_ERR_INVALID_ARG, TAG,
"max_meas_time_ms should within %"PRIu32, TOUCH_LL_TIMEOUT_MAX / src_freq_mhz);
hal_cfg->sample_cfg_num = sens_cfg->sample_cfg_num; // Only one sample cfg
hal_cfg->sample_cfg = (touch_hal_sample_config_t *)sens_cfg->sample_cfg;
return ESP_OK;
}
esp_err_t touch_priv_config_controller(touch_sensor_handle_t sens_handle, const touch_sensor_config_t *sens_cfg)
{
#if CONFIG_TOUCH_ENABLE_DEBUG_LOG
esp_log_level_set(TAG, ESP_LOG_DEBUG);
#endif
/* Check and convert the configuration to hal configurations */
touch_hal_config_t hal_cfg = {};
ESP_RETURN_ON_ERROR(s_touch_convert_to_hal_config(sens_handle, sens_cfg, &hal_cfg),
TAG, "parse the configuration failed due to the invalid configuration");
sens_handle->sample_cfg_num = 1; // Only have one set of sampling configuration
/* Configure the hardware */
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
touch_hal_config_controller(&hal_cfg);
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
return ESP_OK;
}
esp_err_t touch_priv_config_channel(touch_channel_handle_t chan_handle, const touch_channel_config_t *chan_cfg)
{
// Check the validation of the channel active threshold
ESP_RETURN_ON_FALSE(chan_cfg->active_thresh[0] <= TOUCH_LL_ACTIVE_THRESH_MAX, ESP_ERR_INVALID_ARG,
TAG, "the active threshold out of range 0~%d", TOUCH_LL_ACTIVE_THRESH_MAX);
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
touch_ll_set_chan_active_threshold(chan_handle->id, chan_cfg->active_thresh[0]);
touch_ll_set_charge_speed(chan_handle->id, chan_cfg->charge_speed);
touch_ll_set_init_charge_voltage(chan_handle->id, chan_cfg->init_charge_volt);
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
return ESP_OK;
}
esp_err_t touch_priv_deinit_controller(touch_sensor_handle_t sens_handle)
{
/* Disable the additional functions */
if (sens_handle->proximity_en) {
touch_sensor_config_proximity_sensing(sens_handle, NULL);
}
if (sens_handle->sleep_en) {
touch_sensor_config_sleep_wakeup(sens_handle, NULL);
}
if (sens_handle->waterproof_en) {
touch_sensor_config_waterproof(sens_handle, NULL);
}
if (sens_handle->denoise_en) {
touch_sensor_config_denoise_channel(sens_handle, NULL);
}
return ESP_OK;
}
esp_err_t touch_priv_channel_read_data(touch_channel_handle_t chan_handle, touch_chan_data_type_t type, uint32_t *data)
{
ESP_RETURN_ON_FALSE_ISR(type >= TOUCH_CHAN_DATA_TYPE_RAW && type <= TOUCH_CHAN_DATA_TYPE_PROXIMITY,
ESP_ERR_INVALID_ARG, TAG, "The channel data type is invalid");
ESP_RETURN_ON_FALSE_ISR(type != TOUCH_CHAN_DATA_TYPE_PROXIMITY || chan_handle->prox_id > 0, ESP_ERR_INVALID_ARG, TAG, "This is not a proximity sensing channel");
TOUCH_ENTER_CRITICAL_SAFE(TOUCH_PERIPH_LOCK);
switch (type) {
default: // fall through
case TOUCH_CHAN_DATA_TYPE_RAW:
touch_ll_read_chan_data(chan_handle->id, TOUCH_LL_READ_RAW, data);
break;
case TOUCH_CHAN_DATA_TYPE_SMOOTH:
touch_ll_read_chan_data(chan_handle->id, TOUCH_LL_READ_SMOOTH, data);
break;
case TOUCH_CHAN_DATA_TYPE_BENCHMARK:
touch_ll_read_chan_data(chan_handle->id, TOUCH_LL_READ_BENCHMARK, data);
break;
case TOUCH_CHAN_DATA_TYPE_PROXIMITY:
/* Get the proximity value from the stored data.
* The proximity value are updated in the isr when proximity scanning is done */
*data = chan_handle->prox_val[0];
break;
}
TOUCH_EXIT_CRITICAL_SAFE(TOUCH_PERIPH_LOCK);
return ESP_OK;
}
void touch_priv_config_benchmark(touch_channel_handle_t chan_handle, const touch_chan_benchmark_config_t *benchmark_cfg)
{
if (benchmark_cfg->do_reset) {
touch_ll_reset_chan_benchmark(BIT(chan_handle->id));
}
}
/******************************************************************************
* Scope: public APIs *
******************************************************************************/
esp_err_t touch_sensor_config_filter(touch_sensor_handle_t sens_handle, const touch_sensor_filter_config_t *filter_cfg)
{
TOUCH_NULL_POINTER_CHECK(sens_handle);
if (filter_cfg) {
ESP_RETURN_ON_FALSE(filter_cfg->benchmark.denoise_lvl >= 0 && filter_cfg->benchmark.denoise_lvl <= 4,
ESP_ERR_INVALID_ARG, TAG, "denoise_lvl is out of range");
}
esp_err_t ret = ESP_OK;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
if (filter_cfg) {
touch_ll_filter_enable(true);
/* Configure the benchmark filter and update strategy */
touch_ll_filter_set_filter_mode(filter_cfg->benchmark.filter_mode);
if (filter_cfg->benchmark.filter_mode == TOUCH_BM_JITTER_FILTER) {
touch_ll_filter_set_jitter_step(filter_cfg->benchmark.jitter_step);
}
touch_ll_filter_set_denoise_level(filter_cfg->benchmark.denoise_lvl);
/* Configure the touch data filter */
touch_ll_filter_set_smooth_mode(filter_cfg->data.smooth_filter);
touch_ll_filter_set_active_hysteresis(filter_cfg->data.active_hysteresis);
touch_ll_filter_set_debounce(filter_cfg->data.debounce_cnt);
} else {
touch_ll_filter_enable(false);
}
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
xSemaphoreGiveRecursive(sens_handle->mutex);
return ret;
}
esp_err_t touch_sensor_config_sleep_wakeup(touch_sensor_handle_t sens_handle, const touch_sleep_config_t *sleep_cfg)
{
TOUCH_NULL_POINTER_CHECK(sens_handle);
esp_err_t ret = ESP_OK;
int dp_slp_chan_id = -1;
touch_hal_config_t hal_cfg = {};
touch_hal_config_t *hal_cfg_ptr = NULL;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
if (sleep_cfg) {
ESP_GOTO_ON_FALSE(sleep_cfg->slp_wakeup_lvl == TOUCH_LIGHT_SLEEP_WAKEUP || sleep_cfg->slp_wakeup_lvl == TOUCH_DEEP_SLEEP_WAKEUP,
ESP_ERR_INVALID_ARG, err, TAG, "Invalid sleep level");
/* Enabled touch sensor as wake-up source */
esp_sleep_enable_touchpad_wakeup();
#if SOC_PM_SUPPORT_RTC_PERIPH_PD
// Keep ESP_PD_DOMAIN_RTC_PERIPH power domain on during the light/deep sleep, so that to keep the touch sensor working
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
#endif // SOC_PM_SUPPORT_RC_FAST_PD
/* If set the deep sleep channel (i.e., enable deep sleep wake-up),
configure the deep sleep related settings. */
if (sleep_cfg->slp_wakeup_lvl == TOUCH_DEEP_SLEEP_WAKEUP) {
ESP_GOTO_ON_FALSE(sleep_cfg->deep_slp_chan, ESP_ERR_INVALID_ARG, err, TAG, "deep sleep waken channel can't be NULL");
dp_slp_chan_id = sleep_cfg->deep_slp_chan->id;
/* Check and convert the configuration to hal configurations */
if (sleep_cfg->deep_slp_sens_cfg) {
hal_cfg_ptr = &hal_cfg;
ESP_GOTO_ON_ERROR(s_touch_convert_to_hal_config(sens_handle, sleep_cfg->deep_slp_sens_cfg, hal_cfg_ptr),
err, TAG, "parse the configuration failed due to the invalid configuration");
}
sens_handle->sleep_en = true;
sens_handle->deep_slp_chan = sleep_cfg->deep_slp_chan;
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
touch_ll_sleep_set_threshold(sleep_cfg->deep_slp_thresh[0]);
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
}
} else {
/* Disable the touch sensor as wake-up source */
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TOUCHPAD);
#if SOC_PM_SUPPORT_RTC_PERIPH_PD
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_AUTO);
#endif // SOC_PM_SUPPORT_RC_FAST_PD
sens_handle->deep_slp_chan = NULL;
sens_handle->sleep_en = false;
}
/* Save or update the sleep config */
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
touch_hal_save_sleep_config(dp_slp_chan_id, hal_cfg_ptr);
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
err:
xSemaphoreGiveRecursive(sens_handle->mutex);
return ret;
}
// Water proof can be enabled separately
esp_err_t touch_sensor_config_waterproof(touch_sensor_handle_t sens_handle, const touch_waterproof_config_t *wp_cfg)
{
TOUCH_NULL_POINTER_CHECK(sens_handle);
esp_err_t ret = ESP_OK;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
if (wp_cfg) {
ESP_GOTO_ON_FALSE(wp_cfg->shield_chan && wp_cfg->shield_chan->id == 14, ESP_ERR_INVALID_ARG, err, TAG, "Shield channel must be channel 14");
// Check the validation of the waterproof configuration
TOUCH_NULL_POINTER_CHECK(wp_cfg->shield_chan);
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
sens_handle->waterproof_en = true;
sens_handle->guard_chan = wp_cfg->guard_chan;
sens_handle->shield_chan = wp_cfg->shield_chan;
touch_ll_waterproof_set_guard_chan(wp_cfg->guard_chan ? wp_cfg->guard_chan->id : TOUCH_LL_NULL_CHANNEL);
// need to disable the scanning of the shield channel
touch_ll_enable_scan_mask(BIT(wp_cfg->shield_chan->id), false);
touch_ll_waterproof_set_shield_driver(wp_cfg->shield_drv);
touch_ll_waterproof_enable(true);
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
} else {
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
touch_ll_waterproof_enable(false);
touch_ll_waterproof_set_guard_chan(TOUCH_LL_NULL_CHANNEL);
touch_ll_enable_scan_mask(BIT(sens_handle->shield_chan->id), true);
touch_ll_waterproof_set_shield_driver(0);
sens_handle->guard_chan = NULL;
sens_handle->shield_chan = NULL;
sens_handle->waterproof_en = false;
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
}
err:
xSemaphoreGiveRecursive(sens_handle->mutex);
return ret;
}
esp_err_t touch_sensor_config_proximity_sensing(touch_sensor_handle_t sens_handle, const touch_proximity_config_t *prox_cfg)
{
TOUCH_NULL_POINTER_CHECK(sens_handle);
esp_err_t ret = ESP_OK;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
/* Reset proximity sensing part of all channels */
FOR_EACH_TOUCH_CHANNEL(i) {
if (sens_handle->ch[i]) {
sens_handle->ch[i]->prox_id = 0;
sens_handle->ch[i]->prox_cnt = 0;
memset(sens_handle->ch[i]->prox_val, 0, sizeof(sens_handle->ch[i]->prox_val[0]) * TOUCH_SAMPLE_CFG_NUM);
}
}
if (prox_cfg) {
sens_handle->proximity_en = true;
for (int i = 0; i < TOUCH_PROXIMITY_CHAN_NUM; i++) {
if (prox_cfg->proximity_chan[i]) {
prox_cfg->proximity_chan[i]->prox_id = i + 1;
touch_ll_set_proximity_sensing_channel(i, prox_cfg->proximity_chan[i]->id);
} else {
touch_ll_set_proximity_sensing_channel(i, TOUCH_LL_NULL_CHANNEL);
}
}
touch_ll_proximity_set_total_scan_times(prox_cfg->scan_times);
} else {
for (int i = 0; i < TOUCH_PROXIMITY_CHAN_NUM; i++) {
touch_ll_set_proximity_sensing_channel(i, TOUCH_LL_NULL_CHANNEL);
}
sens_handle->proximity_en = false;
}
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
err:
xSemaphoreGiveRecursive(sens_handle->mutex);
return ret;
}
esp_err_t touch_sensor_config_denoise_channel(touch_sensor_handle_t sens_handle, const touch_denoise_chan_config_t *denoise_cfg)
{
TOUCH_NULL_POINTER_CHECK(sens_handle);
esp_err_t ret = ESP_OK;
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
if (denoise_cfg) {
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
sens_handle->denoise_en = true;
sens_handle->chan_mask |= BIT(TOUCH_DENOISE_CHAN_ID);
touch_ll_set_charge_speed(TOUCH_DENOISE_CHAN_ID, denoise_cfg->charge_speed);
touch_ll_set_init_charge_voltage(TOUCH_DENOISE_CHAN_ID, denoise_cfg->init_charge_volt);
touch_ll_denoise_set_reference_cap(denoise_cfg->ref_cap);
touch_ll_denoise_set_resolution(denoise_cfg->resolution);
touch_ll_denoise_enable(true);
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
} else {
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
sens_handle->denoise_en = false;
sens_handle->chan_mask &= ~BIT(TOUCH_DENOISE_CHAN_ID);
touch_ll_denoise_enable(false);
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
}
err:
xSemaphoreGiveRecursive(sens_handle->mutex);
return ret;
}

View File

@@ -25,6 +25,9 @@ extern "C" {
/** /**
* @brief Helper macro to the default configurations of the touch sensor controller * @brief Helper macro to the default configurations of the touch sensor controller
* *
* @param[in] sample_cfg_number The number of sample configurations, which should be less than or equal to `SOC_TOUCH_SAMPLE_CFG_NUM`
* Given multiple sample configurations to enable the frequency hopping
* @param[in] sample_cfg_array The pointer to the sample configurations array
*/ */
#define TOUCH_SENSOR_DEFAULT_BASIC_CONFIG(sample_cfg_number, sample_cfg_array) { \ #define TOUCH_SENSOR_DEFAULT_BASIC_CONFIG(sample_cfg_number, sample_cfg_array) { \
.power_on_wait_us = 256, \ .power_on_wait_us = 256, \
@@ -39,6 +42,9 @@ extern "C" {
* @brief Helper macro to the default sample configurations * @brief Helper macro to the default sample configurations
* @note This default configuration uses `sample frequency = clock frequency / 1` * @note This default configuration uses `sample frequency = clock frequency / 1`
* *
* @param[in] _div_num The division of the final data, used to scaling the final data
* @param[in] coarse_freq_tune The coarse frequency tuning value
* @param[in] fine_freq_tune The fine frequency tuning value
*/ */
#define TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG(_div_num, coarse_freq_tune, fine_freq_tune) { \ #define TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG(_div_num, coarse_freq_tune, fine_freq_tune) { \
.div_num = _div_num, \ .div_num = _div_num, \
@@ -51,6 +57,10 @@ extern "C" {
.bypass_shield_output = false, \ .bypass_shield_output = false, \
} }
/**
* @brief Helper macro to the default filter configurations
*
*/
#define TOUCH_SENSOR_DEFAULT_FILTER_CONFIG() { \ #define TOUCH_SENSOR_DEFAULT_FILTER_CONFIG() { \
.benchmark = { \ .benchmark = { \
.filter_mode = TOUCH_BM_IIR_FILTER_4, \ .filter_mode = TOUCH_BM_IIR_FILTER_4, \
@@ -60,6 +70,7 @@ extern "C" {
.data = { \ .data = { \
.smooth_filter = TOUCH_SMOOTH_IIR_FILTER_2, \ .smooth_filter = TOUCH_SMOOTH_IIR_FILTER_2, \
.active_hysteresis = 2, \ .active_hysteresis = 2, \
.debounce_cnt = 2, \
}, \ }, \
} }
@@ -73,74 +84,14 @@ typedef enum {
TOUCH_CHAN_DATA_TYPE_PROXIMITY, /*!< The proximity data of the proximity channel */ TOUCH_CHAN_DATA_TYPE_PROXIMITY, /*!< The proximity data of the proximity channel */
} touch_chan_data_type_t; } touch_chan_data_type_t;
/**
* @brief The chip sleep level that allows the touch sensor to wake-up
*
*/
typedef enum {
TOUCH_LIGHT_SLEEP_WAKEUP, /*!< Only enable the touch sensor to wake up the chip from light sleep */
TOUCH_DEEP_SLEEP_WAKEUP, /*!< Enable the touch sensor to wake up the chip from deep sleep or light sleep */
} touch_sleep_wakeup_level_t;
/**
* @brief Touch sensor shield channel drive capability level
*
*/
typedef enum {
TOUCH_SHIELD_CAP_40PF, /*!< The max equivalent capacitance in shield channel is 40pf */
TOUCH_SHIELD_CAP_80PF, /*!< The max equivalent capacitance in shield channel is 80pf */
TOUCH_SHIELD_CAP_120PF, /*!< The max equivalent capacitance in shield channel is 120pf */
TOUCH_SHIELD_CAP_160PF, /*!< The max equivalent capacitance in shield channel is 160pf */
TOUCH_SHIELD_CAP_200PF, /*!< The max equivalent capacitance in shield channel is 200pf */
TOUCH_SHIELD_CAP_240PF, /*!< The max equivalent capacitance in shield channel is 240pf */
TOUCH_SHIELD_CAP_280PF, /*!< The max equivalent capacitance in shield channel is 280pf */
TOUCH_SHIELD_CAP_320PF, /*!< The max equivalent capacitance in shield channel is 320pf */
} touch_chan_shield_cap_t;
/**
* @brief Touch channel Infinite Impulse Response (IIR) filter or Jitter filter for benchmark
* @note Recommended filter coefficient selection is `IIR_16`.
*/
typedef enum {
TOUCH_BM_IIR_FILTER_4, /*!< IIR Filter for benchmark, 1/4 raw_value + 3/4 benchmark */
TOUCH_BM_IIR_FILTER_8, /*!< IIR Filter for benchmark, 1/8 raw_value + 7/8 benchmark */
TOUCH_BM_IIR_FILTER_16, /*!< IIR Filter for benchmark, 1/16 raw_value + 15/16 benchmark (typical) */
TOUCH_BM_IIR_FILTER_32, /*!< IIR Filter for benchmark, 1/32 raw_value + 31/32 benchmark */
TOUCH_BM_IIR_FILTER_64, /*!< IIR Filter for benchmark, 1/64 raw_value + 63/64 benchmark */
TOUCH_BM_IIR_FILTER_128, /*!< IIR Filter for benchmark, 1/128 raw_value + 127/128 benchmark */
TOUCH_BM_JITTER_FILTER, /*!< Jitter Filter for benchmark, raw value +/- jitter_step */
} touch_benchmark_filter_mode_t;
/**
* @brief Touch channel Infinite Impulse Response (IIR) filter for smooth data
*
*/
typedef enum {
TOUCH_SMOOTH_NO_FILTER, /*!< No filter adopted for smooth data, smooth data equals raw data */
TOUCH_SMOOTH_IIR_FILTER_2, /*!< IIR filter adopted for smooth data, smooth data equals 1/2 raw data + 1/2 last smooth data (typical) */
TOUCH_SMOOTH_IIR_FILTER_4, /*!< IIR filter adopted for smooth data, smooth data equals 1/4 raw data + 3/4 last smooth data */
TOUCH_SMOOTH_IIR_FILTER_8, /*!< IIR filter adopted for smooth data, smooth data equals 1/8 raw data + 7/8 last smooth data */
} touch_smooth_filter_mode_t;
/**
* @brief Interrupt events
*
*/
typedef enum {
TOUCH_INTR_EVENT_ACTIVE, /*!< Touch channel active event */
TOUCH_INTR_EVENT_INACTIVE, /*!< Touch channel inactive event */
TOUCH_INTR_EVENT_MEASURE_DONE, /*!< Touch channel measure done event */
TOUCH_INTR_EVENT_SCAN_DONE, /*!< All touch channels scan done event */
TOUCH_INTR_EVENT_TIMEOUT, /*!< Touch channel measurement timeout event */
TOUCH_INTR_EVENT_PROXIMITY_DONE, /*!< Proximity channel measurement done event */
} touch_intr_event_t;
/** /**
* @brief Sample configurations of the touch sensor * @brief Sample configurations of the touch sensor
* *
*/ */
typedef struct { typedef struct {
uint32_t div_num; /*!< Division of the touch output pulse, `touch_out_pulse / div_num = charge_times` */ uint32_t div_num; /*!< Division of the touch output pulse.
* It is proportional to the gain of the read data, the greater the div_num, the higher gain of the read data.
* If the read data is exceeded the maximum range, please reduce the div_num. */
uint32_t charge_times; /*!< The charge and discharge times of this sample configuration, the read data are positive correlation to the charge_times */ uint32_t charge_times; /*!< The charge and discharge times of this sample configuration, the read data are positive correlation to the charge_times */
uint8_t rc_filter_res; /*!< The resistance of the RC filter of this sample configuration, range [0, 3], while 0 = 0K, 1 = 1.5K, 2 = 3K, 3 = 4.5K */ uint8_t rc_filter_res; /*!< The resistance of the RC filter of this sample configuration, range [0, 3], while 0 = 0K, 1 = 1.5K, 2 = 3K, 3 = 4.5K */
uint8_t rc_filter_cap; /*!< The capacitance of the RC filter of this sample configuration, range [0, 127], while 0 = 0pF, 1 = 20fF, ..., 127 = 2.54pF */ uint8_t rc_filter_cap; /*!< The capacitance of the RC filter of this sample configuration, range [0, 127], while 0 = 0pF, 1 = 20fF, ..., 127 = 2.54pF */
@@ -162,7 +113,7 @@ typedef struct {
* of this sample configurations below. * of this sample configurations below.
*/ */
touch_out_mode_t output_mode; /*!< Touch channel counting mode of the binarized touch output */ touch_out_mode_t output_mode; /*!< Touch channel counting mode of the binarized touch output */
uint32_t sample_cfg_num; /*!< The sample configuration number that used for sampling */ uint32_t sample_cfg_num; /*!< The sample configuration number that used for sampling, CANNOT exceed TOUCH_SAMPLE_CFG_NUM */
touch_sensor_sample_config_t *sample_cfg; /*!< The array of this sample configuration configurations, the length should be specified in `touch_sensor_config_t::sample_cfg_num` */ touch_sensor_sample_config_t *sample_cfg; /*!< The array of this sample configuration configurations, the length should be specified in `touch_sensor_config_t::sample_cfg_num` */
} touch_sensor_config_t; } touch_sensor_config_t;
@@ -224,7 +175,7 @@ typedef struct {
typedef touch_sensor_config_t touch_sensor_config_dslp_t; typedef touch_sensor_config_t touch_sensor_config_dslp_t;
/** /**
* @brief Configure the touch sensor sleep function * @brief Configuration of the touch sensor sleep function
* *
*/ */
typedef struct { typedef struct {
@@ -248,7 +199,7 @@ typedef struct {
} touch_sleep_config_t; } touch_sleep_config_t;
/** /**
* @brief Configure the touch sensor waterproof function * @brief Configuration of the touch sensor waterproof function
* *
*/ */
typedef struct { typedef struct {
@@ -274,7 +225,7 @@ typedef struct {
} touch_waterproof_config_t; } touch_waterproof_config_t;
/** /**
* @brief Configure the touch sensor proximity function * @brief Configuration of the touch sensor proximity function
* *
*/ */
typedef struct { typedef struct {

View File

@@ -29,6 +29,7 @@
// Set the maximum log level for this source file // Set the maximum log level for this source file
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG #define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
#endif #endif
#include "esp_log.h"
#include "esp_check.h" #include "esp_check.h"
static const char *TAG = "touch"; static const char *TAG = "touch";
@@ -44,10 +45,6 @@ void touch_priv_enable_module(bool enable)
TOUCH_ENTER_CRITICAL(TOUCH_RTC_LOCK); TOUCH_ENTER_CRITICAL(TOUCH_RTC_LOCK);
touch_ll_enable_module_clock(enable); touch_ll_enable_module_clock(enable);
touch_ll_enable_out_gate(enable); touch_ll_enable_out_gate(enable);
#if SOC_TOUCH_SENSOR_VERSION >= 2
// Reset the benchmark after finished the scanning
touch_ll_reset_chan_benchmark(TOUCH_LL_FULL_CHANNEL_MASK);
#endif
TOUCH_EXIT_CRITICAL(TOUCH_RTC_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_RTC_LOCK);
} }
@@ -60,7 +57,7 @@ void IRAM_ATTR touch_priv_default_intr_handler(void *arg)
bool need_yield = false; bool need_yield = false;
uint32_t status = touch_ll_get_intr_status_mask(); uint32_t status = touch_ll_get_intr_status_mask();
g_touch->is_meas_timeout = false; g_touch->is_meas_timeout = false;
touch_ll_intr_clear(status); touch_ll_interrupt_clear(status);
touch_base_event_data_t data; touch_base_event_data_t data;
touch_ll_get_active_channel_mask(&data.status_mask); touch_ll_get_active_channel_mask(&data.status_mask);
data.chan = g_touch->ch[touch_ll_get_current_meas_channel()]; data.chan = g_touch->ch[touch_ll_get_current_meas_channel()];
@@ -253,7 +250,7 @@ esp_err_t touch_priv_channel_read_data(touch_channel_handle_t chan_handle, touch
TOUCH_EXIT_CRITICAL_SAFE(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL_SAFE(TOUCH_PERIPH_LOCK);
} }
} else { } else {
if (!chan_handle->is_prox_chan) { if (!chan_handle->prox_id) {
ESP_EARLY_LOGW(TAG, "This is not a proximity sensing channel"); ESP_EARLY_LOGW(TAG, "This is not a proximity sensing channel");
} }
TOUCH_ENTER_CRITICAL_SAFE(TOUCH_PERIPH_LOCK); TOUCH_ENTER_CRITICAL_SAFE(TOUCH_PERIPH_LOCK);
@@ -287,7 +284,7 @@ esp_err_t touch_sensor_config_filter(touch_sensor_handle_t sens_handle, const to
} }
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTake(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
if (filter_cfg) { if (filter_cfg) {
@@ -307,7 +304,7 @@ esp_err_t touch_sensor_config_filter(touch_sensor_handle_t sens_handle, const to
} }
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
xSemaphoreGive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
} }
@@ -323,7 +320,7 @@ esp_err_t touch_sensor_config_sleep_wakeup(touch_sensor_handle_t sens_handle, co
}; };
touch_hal_config_t *hal_cfg_ptr = NULL; touch_hal_config_t *hal_cfg_ptr = NULL;
xSemaphoreTake(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first"); ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
if (sleep_cfg) { if (sleep_cfg) {
@@ -374,7 +371,7 @@ esp_err_t touch_sensor_config_sleep_wakeup(touch_sensor_handle_t sens_handle, co
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
err: err:
xSemaphoreGive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
} }
@@ -384,7 +381,7 @@ esp_err_t touch_sensor_config_waterproof(touch_sensor_handle_t sens_handle, cons
TOUCH_NULL_POINTER_CHECK(sens_handle); TOUCH_NULL_POINTER_CHECK(sens_handle);
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTake(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first"); ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
@@ -419,7 +416,7 @@ esp_err_t touch_sensor_config_waterproof(touch_sensor_handle_t sens_handle, cons
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
} }
err: err:
xSemaphoreGive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
} }
@@ -428,7 +425,7 @@ esp_err_t touch_sensor_config_proximity_sensing(touch_sensor_handle_t sens_handl
TOUCH_NULL_POINTER_CHECK(sens_handle); TOUCH_NULL_POINTER_CHECK(sens_handle);
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
xSemaphoreTake(sens_handle->mutex, portMAX_DELAY); xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first"); ESP_GOTO_ON_FALSE(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err, TAG, "Please disable the touch sensor first");
@@ -436,8 +433,8 @@ esp_err_t touch_sensor_config_proximity_sensing(touch_sensor_handle_t sens_handl
/* Reset proximity sensing part of all channels */ /* Reset proximity sensing part of all channels */
FOR_EACH_TOUCH_CHANNEL(i) { FOR_EACH_TOUCH_CHANNEL(i) {
if (sens_handle->ch[i] && sens_handle->ch[i]->is_prox_chan) { if (sens_handle->ch[i] && sens_handle->ch[i]->prox_id > 0) {
sens_handle->ch[i]->is_prox_chan = false; sens_handle->ch[i]->prox_id = 0;
sens_handle->ch[i]->prox_cnt = 0; sens_handle->ch[i]->prox_cnt = 0;
for (int i = 0; i < TOUCH_SAMPLE_CFG_NUM; i++) { for (int i = 0; i < TOUCH_SAMPLE_CFG_NUM; i++) {
sens_handle->ch[i]->prox_val[i] = 0; sens_handle->ch[i]->prox_val[i] = 0;
@@ -450,7 +447,7 @@ esp_err_t touch_sensor_config_proximity_sensing(touch_sensor_handle_t sens_handl
uint8_t sample_cfg_num = sens_handle->sample_cfg_num; uint8_t sample_cfg_num = sens_handle->sample_cfg_num;
for (int i = 0; i < TOUCH_PROXIMITY_CHAN_NUM; i++) { for (int i = 0; i < TOUCH_PROXIMITY_CHAN_NUM; i++) {
if (prox_cfg->proximity_chan[i]) { if (prox_cfg->proximity_chan[i]) {
prox_cfg->proximity_chan[i]->is_prox_chan = true; prox_cfg->proximity_chan[i]->prox_id = i + 1;
touch_ll_set_proximity_sensing_channel(i, prox_cfg->proximity_chan[i]->id); touch_ll_set_proximity_sensing_channel(i, prox_cfg->proximity_chan[i]->id);
} else { } else {
touch_ll_set_proximity_sensing_channel(i, TOUCH_LL_NULL_CHANNEL); touch_ll_set_proximity_sensing_channel(i, TOUCH_LL_NULL_CHANNEL);
@@ -469,6 +466,6 @@ esp_err_t touch_sensor_config_proximity_sensing(touch_sensor_handle_t sens_handl
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK); TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
err: err:
xSemaphoreGive(sens_handle->mutex); xSemaphoreGiveRecursive(sens_handle->mutex);
return ret; return ret;
} }

View File

@@ -61,6 +61,8 @@ esp_err_t touch_sensor_new_channel(touch_sensor_handle_t sens_handle, int chan_i
/** /**
* @brief Delete the touch channel * @brief Delete the touch channel
* @note This function can be called when the touch sensor controller is NOT enabled (i.e. INIT state). * @note This function can be called when the touch sensor controller is NOT enabled (i.e. INIT state).
* @note If the channel has been enabled other sub-features like proximity sensing, sleep wakeup, waterproof, denoise.
* The attached sub-features will be disabled while deleting the channel.
* *
* @param[in] chan_handle Touch channel handle * @param[in] chan_handle Touch channel handle
* @return * @return
@@ -289,6 +291,24 @@ esp_err_t touch_sensor_config_proximity_sensing(touch_sensor_handle_t sens_handl
esp_err_t touch_sensor_config_sleep_wakeup(touch_sensor_handle_t sens_handle, const touch_sleep_config_t *sleep_cfg); esp_err_t touch_sensor_config_sleep_wakeup(touch_sensor_handle_t sens_handle, const touch_sleep_config_t *sleep_cfg);
#endif #endif
#if SOC_TOUCH_SUPPORT_DENOISE_CHAN
/**
* @brief Configure the touch denoise channel
* @note The denoise channel is used to suppress the internal background noise.
* Once the denoise channel enabled, the measured data of the other touch channels
* will minus the data of the denoise channel automatically.
* So the channel data will be attenuated after enabling the denoise channel.
*
* @param[in] sens_handle Touch sensor controller handle
* @param[in] denoise_cfg Denoise channel configurations, set NULL to disable the touch channel
* @return
* - ESP_OK: Configure the denoise channel success
* - ESP_ERR_INVALID_ARG: The sensor handle is NULL or invalid denoise configuration
* - ESP_ERR_INVALID_STATE: The touch sensor is enabled
*/
esp_err_t touch_sensor_config_denoise_channel(touch_sensor_handle_t sens_handle, const touch_denoise_chan_config_t *denoise_cfg);
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -10,7 +10,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include "soc/soc_caps.h" #include "soc/soc_caps.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sens_types.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -22,6 +22,15 @@ extern "C" {
#define TOUCH_PROXIMITY_CHAN_NUM SOC_TOUCH_PROXIMITY_CHANNEL_NUM /*!< The supported proximity channel number in proximity sensing mode */ #define TOUCH_PROXIMITY_CHAN_NUM SOC_TOUCH_PROXIMITY_CHANNEL_NUM /*!< The supported proximity channel number in proximity sensing mode */
#endif #endif
/**
* @brief The chip sleep level that allows the touch sensor to wake-up
*
*/
typedef enum {
TOUCH_LIGHT_SLEEP_WAKEUP, /*!< Only enable the touch sensor to wake up the chip from light sleep */
TOUCH_DEEP_SLEEP_WAKEUP, /*!< Enable the touch sensor to wake up the chip from deep sleep or light sleep */
} touch_sleep_wakeup_level_t;
typedef struct touch_sensor_s *touch_sensor_handle_t; /*!< The handle of touch sensor controller */ typedef struct touch_sensor_s *touch_sensor_handle_t; /*!< The handle of touch sensor controller */
typedef struct touch_channel_s *touch_channel_handle_t; /*!< The handle of touch channel */ typedef struct touch_channel_s *touch_channel_handle_t; /*!< The handle of touch channel */

View File

@@ -0,0 +1,45 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include "esp_err.h"
#include "driver/touch_sens_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Touch channel information
*
*/
typedef struct {
int chan_id; /*!< Touch channel number */
int chan_gpio; /*!< Corresponding GPIO of this channel */
struct {
uint32_t can_wake_dp_slp: 1;/*!< Whether this channel can wakeup from deep sleep */
uint32_t is_proxi: 1; /*!< Whether this channel is used for proximity sensing */
uint32_t is_guard: 1; /*!< Whether this channel is used for waterproof guard channel */
uint32_t is_shield: 1; /*!< Whether this channel is used for waterproof shield channel */
} flags; /*!< Channel sub-feature flags */
} touch_chan_info_t;
/**
* @brief Get the touch channel information by the channel handle
*
* @param[in] chan_handle Touch channel handle
* @param[out] chan_info Touch channel information
* @return
* - ESP_OK: Success to get the channel information
* - ESP_ERR_INVALID_ARG: NULL pointer
*/
esp_err_t touch_sensor_get_channel_info(touch_channel_handle_t chan_handle, touch_chan_info_t *chan_info);
#ifdef __cplusplus
}
#endif

View File

@@ -1,6 +1,8 @@
components/esp_driver_touch_sens/test_apps/touch_sens: components/esp_driver_touch_sens/test_apps/touch_sens:
disable: disable:
- if: SOC_TOUCH_SENSOR_VERSION != 3 - if: SOC_TOUCH_SENSOR_SUPPORTED != 1
temporary: currently driver ng only support version 3 - if: SOC_TOUCH_SENSOR_VERSION == 1
temporary: true
reason: currently driver ng does not support version 1
depends_components: depends_components:
- esp_driver_touch_sens - esp_driver_touch_sens

View File

@@ -1,3 +1,3 @@
| Supported Targets | ESP32-P4 | | Supported Targets | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | -------- | | ----------------- | -------- | -------- | -------- |

View File

@@ -10,29 +10,36 @@
#include "unity.h" #include "unity.h"
#include "driver/touch_sens.h" #include "driver/touch_sens.h"
#include "hal/touch_sensor_ll.h" #include "hal/touch_sensor_ll.h"
#include "esp_private/touch_sens_helper.h"
#include "esp_log.h" #include "esp_log.h"
#include "esp_attr.h" #include "esp_attr.h"
static touch_sensor_sample_config_t s_sample_cfg[TOUCH_SAMPLE_CFG_NUM] = { static touch_sensor_sample_config_t s_sample_cfg[TOUCH_SAMPLE_CFG_NUM] = {
#if SOC_TOUCH_SENSOR_VERSION == 2
TOUCH_SENSOR_V2_DEFAULT_SAMPLE_CONFIG(500, TOUCH_VOLT_LIM_L_0V5, TOUCH_VOLT_LIM_H_2V2),
#elif SOC_TOUCH_SENSOR_VERSION == 3
TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG(1, 1, 1), TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG(1, 1, 1),
#if TOUCH_SAMPLE_CFG_NUM > 1
TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG(2, 1, 1), TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG(2, 1, 1),
#endif
#if TOUCH_SAMPLE_CFG_NUM > 2
TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG(4, 1, 1), TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG(4, 1, 1),
#else
#error "Target not support"
#endif #endif
}; };
static touch_channel_config_t s_chan_cfg = { static touch_channel_config_t s_chan_cfg = {
#if SOC_TOUCH_SENSOR_VERSION == 2
.active_thresh = {
2000,
},
.charge_speed = TOUCH_CHARGE_SPEED_7,
.init_charge_volt = TOUCH_INIT_CHARGE_VOLT_LOW,
#elif SOC_TOUCH_SENSOR_VERSION == 3
.active_thresh = { .active_thresh = {
5000, 5000,
#if TOUCH_SAMPLE_CFG_NUM > 1
2500, 2500,
#endif
#if TOUCH_SAMPLE_CFG_NUM > 2
1000, 1000,
#endif
}, },
#endif
}; };
TEST_CASE("touch_sens_install_uninstall_test", "[touch]") TEST_CASE("touch_sens_install_uninstall_test", "[touch]")
@@ -48,20 +55,20 @@ TEST_CASE("touch_sens_install_uninstall_test", "[touch]")
touch_sensor_filter_config_t filter_cfg = TOUCH_SENSOR_DEFAULT_FILTER_CONFIG(); touch_sensor_filter_config_t filter_cfg = TOUCH_SENSOR_DEFAULT_FILTER_CONFIG();
TEST_ESP_OK(touch_sensor_config_filter(touch, &filter_cfg)); TEST_ESP_OK(touch_sensor_config_filter(touch, &filter_cfg));
for (int i = 0; i < TOUCH_TOTAL_CHAN_NUM; i++) { for (int i = TOUCH_MIN_CHAN_ID; i <= TOUCH_MAX_CHAN_ID; i++) {
TEST_ESP_OK(touch_sensor_new_channel(touch, i, &s_chan_cfg, &touch_chan[i])); TEST_ESP_OK(touch_sensor_new_channel(touch, i, &s_chan_cfg, &touch_chan[i]));
} }
touch_channel_handle_t fault_chan = NULL; touch_channel_handle_t fault_chan = NULL;
TEST_ASSERT(touch_sensor_new_channel(touch, TOUCH_TOTAL_CHAN_NUM, &s_chan_cfg, &fault_chan) == ESP_ERR_INVALID_ARG); TEST_ASSERT(touch_sensor_new_channel(touch, TOUCH_TOTAL_CHAN_NUM, &s_chan_cfg, &fault_chan) == ESP_ERR_INVALID_ARG);
TEST_ASSERT(touch_sensor_new_channel(touch, 0, &s_chan_cfg, &fault_chan) == ESP_ERR_INVALID_STATE); TEST_ASSERT(touch_sensor_new_channel(touch, TOUCH_MIN_CHAN_ID, &s_chan_cfg, &fault_chan) == ESP_ERR_INVALID_STATE);
TEST_ESP_OK(touch_sensor_enable(touch)); TEST_ESP_OK(touch_sensor_enable(touch));
TEST_ASSERT(touch_sensor_del_channel(touch_chan[0]) == ESP_ERR_INVALID_STATE); TEST_ASSERT(touch_sensor_del_channel(touch_chan[TOUCH_MIN_CHAN_ID]) == ESP_ERR_INVALID_STATE);
TEST_ESP_OK(touch_sensor_disable(touch)); TEST_ESP_OK(touch_sensor_disable(touch));
TEST_ASSERT(touch_sensor_del_controller(touch) == ESP_ERR_INVALID_STATE); TEST_ASSERT(touch_sensor_del_controller(touch) == ESP_ERR_INVALID_STATE);
for (int i = 0; i < TOUCH_TOTAL_CHAN_NUM; i++) { for (int i = TOUCH_MIN_CHAN_ID; i <= TOUCH_MAX_CHAN_ID; i++) {
TEST_ESP_OK(touch_sensor_del_channel(touch_chan[i])); TEST_ESP_OK(touch_sensor_del_channel(touch_chan[i]));
} }
TEST_ESP_OK(touch_sensor_del_controller(touch)); TEST_ESP_OK(touch_sensor_del_controller(touch));
@@ -119,7 +126,13 @@ static bool TEST_TCH_IRAM_ATTR s_test_touch_on_inactive_callback(touch_sensor_ha
static void s_test_touch_simulate_touch(touch_sensor_handle_t touch, touch_channel_handle_t touch_chan, bool active) static void s_test_touch_simulate_touch(touch_sensor_handle_t touch, touch_channel_handle_t touch_chan, bool active)
{ {
#if SOC_TOUCH_SENSOR_VERSION == 2
touch_chan_info_t chan_info = {};
touch_sensor_get_channel_info(touch_chan, &chan_info);
touch_ll_set_charge_speed(chan_info.chan_id, active ? TOUCH_CHARGE_SPEED_4 : TOUCH_CHARGE_SPEED_7);
#elif SOC_TOUCH_SENSOR_VERSION == 3
touch_ll_set_internal_capacitor(active ? 0x7f : 0); touch_ll_set_internal_capacitor(active ? 0x7f : 0);
#endif
} }
static void s_test_touch_log_data(touch_channel_handle_t touch_chan, uint32_t sample_cfg_num, const char *tag) static void s_test_touch_log_data(touch_channel_handle_t touch_chan, uint32_t sample_cfg_num, const char *tag)
@@ -146,15 +159,21 @@ TEST_CASE("touch_sens_active_inactive_test", "[touch]")
/* Configuring the filter */ /* Configuring the filter */
touch_sensor_filter_config_t filter_cfg = TOUCH_SENSOR_DEFAULT_FILTER_CONFIG(); touch_sensor_filter_config_t filter_cfg = TOUCH_SENSOR_DEFAULT_FILTER_CONFIG();
TEST_ESP_OK(touch_sensor_config_filter(touch, &filter_cfg)); TEST_ESP_OK(touch_sensor_config_filter(touch, &filter_cfg));
TEST_ESP_OK(touch_sensor_new_channel(touch, 0, &s_chan_cfg, &touch_chan)); TEST_ESP_OK(touch_sensor_new_channel(touch, TOUCH_MIN_CHAN_ID, &s_chan_cfg, &touch_chan));
#if SOC_TOUCH_SENSOR_VERSION == 3
/* Connect the touch channels to the internal capacitor */ /* Connect the touch channels to the internal capacitor */
touch_ll_enable_internal_capacitor(true); touch_ll_enable_internal_capacitor(true);
#endif // SOC_TOUCH_SENSOR_VERSION == 3
s_test_touch_do_initial_scanning(touch, 3); s_test_touch_do_initial_scanning(touch, 3);
/* Read benchmark */ /* Read benchmark */
uint32_t benchmark[TOUCH_SAMPLE_CFG_NUM] = {0}; uint32_t benchmark[TOUCH_SAMPLE_CFG_NUM] = {0};
TEST_ESP_OK(touch_channel_read_data(touch_chan, TOUCH_CHAN_DATA_TYPE_BENCHMARK, benchmark)); TEST_ESP_OK(touch_channel_read_data(touch_chan, TOUCH_CHAN_DATA_TYPE_BENCHMARK, benchmark));
/* Test whether success to finish the initial scanning */
for (int i = 0; i < TOUCH_SAMPLE_CFG_NUM; i++) {
TEST_ASSERT_GREATER_THAN(0, benchmark[i]);
}
/* Re-configure the threshold according to the benchmark */ /* Re-configure the threshold according to the benchmark */
touch_channel_config_t chan_cfg = s_test_get_chan_cfg_by_benchmark(benchmark, TOUCH_SAMPLE_CFG_NUM, TEST_ACTIVE_THRESH_RATIO); touch_channel_config_t chan_cfg = s_test_get_chan_cfg_by_benchmark(benchmark, TOUCH_SAMPLE_CFG_NUM, TEST_ACTIVE_THRESH_RATIO);
TEST_ESP_OK(touch_sensor_reconfig_channel(touch_chan, &chan_cfg)); TEST_ESP_OK(touch_sensor_reconfig_channel(touch_chan, &chan_cfg));

View File

@@ -4,8 +4,9 @@ import pytest
from pytest_embedded import Dut from pytest_embedded import Dut
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.esp32p4 @pytest.mark.esp32p4
@pytest.mark.temp_skip_ci(targets=['esp32p4'], reason='esp32p4 runners do not support touch pins')
@pytest.mark.generic @pytest.mark.generic
@pytest.mark.parametrize( @pytest.mark.parametrize(
'config', 'config',

View File

@@ -9,7 +9,7 @@
#include <stdint.h> #include <stdint.h>
#include "esp_err.h" #include "esp_err.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sensor_legacy_types.h"
#include "hal/gpio_types.h" #include "hal/gpio_types.h"
#include "soc/soc_caps.h" #include "soc/soc_caps.h"

View File

@@ -62,6 +62,7 @@
#include "hal/uart_hal.h" #include "hal/uart_hal.h"
#if SOC_TOUCH_SENSOR_SUPPORTED #if SOC_TOUCH_SENSOR_SUPPORTED
#include "hal/touch_sensor_hal.h" #include "hal/touch_sensor_hal.h"
#include "hal/touch_sens_hal.h"
#endif #endif
#if CONFIG_SPIRAM && CONFIG_ESP_LDO_RESERVE_PSRAM #if CONFIG_SPIRAM && CONFIG_ESP_LDO_RESERVE_PSRAM
@@ -301,7 +302,7 @@ static void ext0_wakeup_prepare(void);
static void ext1_wakeup_prepare(void); static void ext1_wakeup_prepare(void);
#endif #endif
static esp_err_t timer_wakeup_prepare(int64_t sleep_duration); static esp_err_t timer_wakeup_prepare(int64_t sleep_duration);
#if SOC_TOUCH_SENSOR_SUPPORTED && SOC_TOUCH_SENSOR_VERSION != 1 #if SOC_TOUCH_SENSOR_VERSION >= 2
static void touch_wakeup_prepare(void); static void touch_wakeup_prepare(void);
#endif #endif
#if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP && SOC_DEEP_SLEEP_SUPPORTED #if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP && SOC_DEEP_SLEEP_SUPPORTED
@@ -881,11 +882,7 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
/* In light sleep, the RTC_PERIPH power domain should be in the power-on state (Power on the touch circuit in light sleep), /* In light sleep, the RTC_PERIPH power domain should be in the power-on state (Power on the touch circuit in light sleep),
* otherwise the touch sensor FSM will be cleared, causing touch sensor false triggering. * otherwise the touch sensor FSM will be cleared, causing touch sensor false triggering.
*/ */
#if SOC_TOUCH_SENSOR_VERSION == 3
bool keep_rtc_power_on = touch_ll_is_fsm_repeated_timer_enabled(); bool keep_rtc_power_on = touch_ll_is_fsm_repeated_timer_enabled();
#else
bool keep_rtc_power_on = touch_ll_get_fsm_state();
#endif
if (keep_rtc_power_on) { // Check if the touch sensor is working properly. if (keep_rtc_power_on) { // Check if the touch sensor is working properly.
pd_flags &= ~RTC_SLEEP_PD_RTC_PERIPH; pd_flags &= ~RTC_SLEEP_PD_RTC_PERIPH;
} }
@@ -1712,26 +1709,7 @@ static esp_err_t timer_wakeup_prepare(int64_t sleep_duration)
return ESP_OK; return ESP_OK;
} }
#if SOC_TOUCH_SENSOR_VERSION == 2 #if SOC_TOUCH_SENSOR_VERSION >= 2
/* In deep sleep mode, only the sleep channel is supported, and other touch channels should be turned off. */
static void touch_wakeup_prepare(void)
{
uint16_t sleep_cycle = 0;
uint16_t meas_times = 0;
touch_pad_t touch_num = TOUCH_PAD_NUM0;
touch_ll_sleep_get_channel_num(&touch_num); // Check if the sleep pad is enabled.
if ((touch_num > TOUCH_PAD_NUM0) && (touch_num < TOUCH_PAD_MAX) && touch_ll_get_fsm_state()) {
touch_ll_stop_fsm();
touch_ll_clear_channel_mask(TOUCH_PAD_BIT_MASK_ALL);
touch_ll_intr_clear(TOUCH_PAD_INTR_MASK_ALL); // Clear state from previous wakeup
touch_hal_sleep_channel_get_work_time(&sleep_cycle, &meas_times);
touch_ll_set_meas_times(meas_times);
touch_ll_set_sleep_time(sleep_cycle);
touch_ll_set_channel_mask(BIT(touch_num));
touch_ll_start_fsm();
}
}
#elif SOC_TOUCH_SENSOR_VERSION == 3
static void touch_wakeup_prepare(void) static void touch_wakeup_prepare(void)
{ {
touch_hal_prepare_deep_sleep(); touch_hal_prepare_deep_sleep();

View File

@@ -282,10 +282,15 @@ if(NOT BOOTLOADER_BUILD)
endif() endif()
if(CONFIG_SOC_TOUCH_SENSOR_SUPPORTED) if(CONFIG_SOC_TOUCH_SENSOR_SUPPORTED)
list(APPEND srcs "${target}/touch_sensor_hal.c") # Source files for legacy touch driver
if(CONFIG_SOC_TOUCH_SENSOR_VERSION LESS 3) if(CONFIG_SOC_TOUCH_SENSOR_VERSION LESS 3)
list(APPEND srcs "${target}/touch_sensor_hal.c")
list(APPEND srcs "touch_sensor_hal.c") list(APPEND srcs "touch_sensor_hal.c")
endif() endif()
# Source files for touch driver-ng (currently only support ver2 & ver3)
if(CONFIG_SOC_TOUCH_SENSOR_VERSION GREATER 1)
list(APPEND srcs "touch_sens_hal.c")
endif()
endif() endif()
if(${target} STREQUAL "esp32") if(${target} STREQUAL "esp32")

View File

@@ -15,7 +15,7 @@
#pragma once #pragma once
#include "hal/touch_sensor_ll.h" #include "hal/touch_sensor_ll.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sensor_legacy_types.h"
#include_next "hal/touch_sensor_hal.h" #include_next "hal/touch_sensor_hal.h"

View File

@@ -21,7 +21,7 @@
#include "soc/sens_struct.h" #include "soc/sens_struct.h"
#include "soc/rtc_io_struct.h" #include "soc/rtc_io_struct.h"
#include "soc/rtc_cntl_struct.h" #include "soc/rtc_cntl_struct.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sensor_legacy_types.h"
#ifdef __cplusplus #ifdef __cplusplus

View File

@@ -7,7 +7,7 @@
// The HAL layer for Touch sensor (common part) // The HAL layer for Touch sensor (common part)
#include "hal/touch_sensor_hal.h" #include "hal/touch_sensor_hal.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sensor_legacy_types.h"
void touch_hal_init(void) void touch_hal_init(void)
{ {

View File

@@ -24,7 +24,7 @@
#include "soc/touch_struct.h" #include "soc/touch_struct.h"
#include "soc/pmu_struct.h" #include "soc/pmu_struct.h"
#include "soc/soc_caps.h" #include "soc/soc_caps.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sens_types.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -173,17 +173,6 @@ static inline void touch_ll_enable_fsm_timer(bool enable)
LP_ANA_PERI.touch_mux0.touch_start_force = !enable; LP_ANA_PERI.touch_mux0.touch_start_force = !enable;
} }
/**
* Get touch sensor FSM mode.
* The measurement action can be triggered by the hardware timer, as well as by the software instruction.
*
* @param mode FSM mode.
*/
static inline void touch_ll_get_fsm_mode(touch_fsm_mode_t *mode)
{
*mode = (touch_fsm_mode_t)LP_ANA_PERI.touch_mux0.touch_fsm_en;
}
/** /**
* Is touch sensor FSM using hardware timer to trigger scanning. * Is touch sensor FSM using hardware timer to trigger scanning.
* The measurement action can be triggered by the hardware timer, as well as by the software instruction. * The measurement action can be triggered by the hardware timer, as well as by the software instruction.
@@ -222,10 +211,9 @@ static inline void touch_ll_force_done_curr_measurement(void)
* The measurement action can be triggered by the hardware timer, as well as by the software instruction. * The measurement action can be triggered by the hardware timer, as well as by the software instruction.
* @note * @note
* The timer should be triggered * The timer should be triggered
* @param is_sleep Whether in sleep state
*/ */
__attribute__((always_inline)) __attribute__((always_inline))
static inline void touch_ll_start_fsm_repeated_timer(bool is_sleep) static inline void touch_ll_start_fsm_repeated_timer(void)
{ {
/** /**
* Touch timer trigger measurement and always wait measurement done. * Touch timer trigger measurement and always wait measurement done.
@@ -238,10 +226,9 @@ static inline void touch_ll_start_fsm_repeated_timer(bool is_sleep)
/** /**
* Stop touch sensor FSM timer. * Stop touch sensor FSM timer.
* The measurement action can be triggered by the hardware timer, as well as by the software instruction. * The measurement action can be triggered by the hardware timer, as well as by the software instruction.
* @param is_sleep Whether in sleep state
*/ */
__attribute__((always_inline)) __attribute__((always_inline))
static inline void touch_ll_stop_fsm_repeated_timer(bool is_sleep) static inline void touch_ll_stop_fsm_repeated_timer(void)
{ {
PMU.touch_pwr_cntl.sleep_timer_en = 0; PMU.touch_pwr_cntl.sleep_timer_en = 0;
touch_ll_force_done_curr_measurement(); touch_ll_force_done_curr_measurement();
@@ -255,6 +242,7 @@ static inline void touch_ll_stop_fsm_repeated_timer(bool is_sleep)
* - true: enabled * - true: enabled
* - true: disabled * - true: disabled
*/ */
__attribute__((always_inline))
static inline bool touch_ll_is_fsm_repeated_timer_enabled(void) static inline bool touch_ll_is_fsm_repeated_timer_enabled(void)
{ {
return (bool)(PMU.touch_pwr_cntl.sleep_timer_en); return (bool)(PMU.touch_pwr_cntl.sleep_timer_en);
@@ -305,7 +293,7 @@ __attribute__((always_inline))
static inline void touch_ll_enable_scan_mask(uint16_t chan_mask, bool enable) static inline void touch_ll_enable_scan_mask(uint16_t chan_mask, bool enable)
{ {
// Channel shift workaround: the lowest bit takes no effect // Channel shift workaround: the lowest bit takes no effect
uint16_t mask = (chan_mask << 1) & TOUCH_PAD_BIT_MASK_ALL; uint16_t mask = (chan_mask << 1) & TOUCH_LL_FULL_CHANNEL_MASK;
uint16_t prev_mask = LP_ANA_PERI.touch_scan_ctrl1.touch_scan_pad_map; uint16_t prev_mask = LP_ANA_PERI.touch_scan_ctrl1.touch_scan_pad_map;
if (enable) { if (enable) {
LP_ANA_PERI.touch_scan_ctrl1.touch_scan_pad_map = prev_mask | mask; LP_ANA_PERI.touch_scan_ctrl1.touch_scan_pad_map = prev_mask | mask;
@@ -326,10 +314,10 @@ static inline void touch_ll_enable_scan_mask(uint16_t chan_mask, bool enable)
* @return * @return
* - ESP_OK on success * - ESP_OK on success
*/ */
static inline void touch_ll_set_channel_mask(uint16_t enable_mask) static inline void touch_ll_enable_channel_mask(uint16_t enable_mask)
{ {
// Channel shift workaround: the lowest bit takes no effect // Channel shift workaround: the lowest bit takes no effect
uint16_t mask = (enable_mask << 1) & TOUCH_PAD_BIT_MASK_ALL; uint16_t mask = (enable_mask << 1) & TOUCH_LL_FULL_CHANNEL_MASK;
LP_ANA_PERI.touch_scan_ctrl1.touch_scan_pad_map = mask; LP_ANA_PERI.touch_scan_ctrl1.touch_scan_pad_map = mask;
LP_ANA_PERI.touch_filter2.touch_outen = mask; LP_ANA_PERI.touch_filter2.touch_outen = mask;
} }
@@ -479,7 +467,7 @@ static inline void touch_ll_set_clock_div(uint8_t sample_cfg_id, uint32_t div_nu
* *
* @param type Select idle channel connect to high resistance state or ground. (No effect) * @param type Select idle channel connect to high resistance state or ground. (No effect)
*/ */
static inline void touch_ll_set_idle_channel_connect(touch_pad_conn_type_t type) static inline void touch_ll_set_idle_channel_connect(touch_idle_conn_t type)
{ {
(void)type; (void)type;
} }
@@ -502,7 +490,7 @@ static inline uint32_t touch_ll_get_current_meas_channel(void)
* *
* @param int_mask interrupt mask * @param int_mask interrupt mask
*/ */
static inline void touch_ll_intr_enable(uint32_t int_mask) static inline void touch_ll_interrupt_enable(uint32_t int_mask)
{ {
uint32_t mask = LP_TOUCH.int_ena.val; uint32_t mask = LP_TOUCH.int_ena.val;
mask |= (int_mask & TOUCH_LL_INTR_MASK_ALL); mask |= (int_mask & TOUCH_LL_INTR_MASK_ALL);
@@ -514,7 +502,7 @@ static inline void touch_ll_intr_enable(uint32_t int_mask)
* *
* @param int_mask interrupt mask * @param int_mask interrupt mask
*/ */
static inline void touch_ll_intr_disable(uint32_t int_mask) static inline void touch_ll_interrupt_disable(uint32_t int_mask)
{ {
uint32_t mask = LP_TOUCH.int_ena.val; uint32_t mask = LP_TOUCH.int_ena.val;
mask &= ~(int_mask & TOUCH_LL_INTR_MASK_ALL); mask &= ~(int_mask & TOUCH_LL_INTR_MASK_ALL);
@@ -527,7 +515,7 @@ static inline void touch_ll_intr_disable(uint32_t int_mask)
* @param int_mask Pad mask to clear interrupts * @param int_mask Pad mask to clear interrupts
*/ */
__attribute__((always_inline)) __attribute__((always_inline))
static inline void touch_ll_intr_clear(touch_pad_intr_mask_t int_mask) static inline void touch_ll_interrupt_clear(uint32_t int_mask)
{ {
LP_TOUCH.int_clr.val = int_mask; LP_TOUCH.int_clr.val = int_mask;
} }
@@ -545,29 +533,24 @@ static inline uint32_t touch_ll_get_intr_status_mask(void)
} }
/** /**
* Enable the timeout check for all touch sensor channels measurements. * Set the timeout to enable or disable the check for all touch sensor channels measurements.
* When the touch reading of a touch channel exceeds the measurement threshold, * When the touch reading of a touch channel exceeds the measurement threshold,
* If enable: a timeout interrupt will be generated and it will go to the next channel measurement. * If enable: a timeout interrupt will be generated and it will go to the next channel measurement.
* If disable: the FSM is always on the channel, until the measurement of this channel is over. * If disable: the FSM is always on the channel, until the measurement of this channel is over.
* *
* @param timeout_cycles The maximum time cycles of the measurement on one channel. * @param timeout_cycles The maximum time cycles of the measurement on one channel.
* Set to 0 to disable the timeout.
* Set to non-zero to enable the timeout and set the timeout cycles.
*/ */
static inline void touch_ll_timeout_enable(uint32_t timeout_cycles) static inline void touch_ll_set_timeout(uint32_t timeout_cycles)
{ {
if (timeout_cycles) {
LP_ANA_PERI.touch_scan_ctrl2.touch_timeout_num = timeout_cycles; LP_ANA_PERI.touch_scan_ctrl2.touch_timeout_num = timeout_cycles;
LP_ANA_PERI.touch_scan_ctrl2.touch_timeout_en = 1; LP_ANA_PERI.touch_scan_ctrl2.touch_timeout_en = 1;
} } else {
/**
* Disable the timeout check for all touch sensor channels measurements.
* When the touch reading of a touch channel exceeds the measurement threshold,
* If enable: a timeout interrupt will be generated and it will go to the next channel measurement.
* If disable: the FSM is always on the channel, until the measurement of this channel is over.
*/
static inline void touch_ll_timeout_disable(void)
{
LP_ANA_PERI.touch_scan_ctrl2.touch_timeout_en = 0; LP_ANA_PERI.touch_scan_ctrl2.touch_timeout_en = 0;
} }
}
/** /**
* Set the engaged sample configuration number * Set the engaged sample configuration number
@@ -665,9 +648,9 @@ static inline void touch_ll_reset_chan_benchmark(uint32_t chan_mask)
* Set filter mode. The input of the filter is the raw value of touch reading, * Set filter mode. The input of the filter is the raw value of touch reading,
* and the output of the filter is involved in the judgment of the touch state. * and the output of the filter is involved in the judgment of the touch state.
* *
* @param mode Filter mode type. Refer to ``touch_filter_mode_t``. * @param mode Filter mode type. Refer to ``touch_benchmark_filter_mode_t``.
*/ */
static inline void touch_ll_filter_set_filter_mode(touch_filter_mode_t mode) static inline void touch_ll_filter_set_filter_mode(touch_benchmark_filter_mode_t mode)
{ {
LP_ANA_PERI.touch_filter1.touch_filter_mode = mode; LP_ANA_PERI.touch_filter1.touch_filter_mode = mode;
} }
@@ -676,9 +659,9 @@ static inline void touch_ll_filter_set_filter_mode(touch_filter_mode_t mode)
* Set filter mode. The input to the filter is raw data and the output is the smooth data. * Set filter mode. The input to the filter is raw data and the output is the smooth data.
* The smooth data is used to determine the touch status. * The smooth data is used to determine the touch status.
* *
* @param mode Filter mode type. Refer to ``touch_smooth_mode_t``. * @param mode Filter mode type. Refer to ``touch_smooth_filter_mode_t``.
*/ */
static inline void touch_ll_filter_set_smooth_mode(touch_smooth_mode_t mode) static inline void touch_ll_filter_set_smooth_mode(touch_smooth_filter_mode_t mode)
{ {
LP_ANA_PERI.touch_filter1.touch_smooth_lvl = mode; LP_ANA_PERI.touch_filter1.touch_smooth_lvl = mode;
} }
@@ -803,7 +786,7 @@ static inline void touch_ll_waterproof_set_shield_chan_mask(uint32_t mask)
* *
* @param driver_level The driver level of the touch buff * @param driver_level The driver level of the touch buff
*/ */
static inline void touch_ll_waterproof_set_shield_driver(touch_pad_shield_driver_t driver_level) static inline void touch_ll_waterproof_set_shield_driver(touch_chan_shield_cap_t driver_level)
{ {
LP_ANA_PERI.touch_ana_para.touch_touch_buf_drv = driver_level; LP_ANA_PERI.touch_ana_para.touch_touch_buf_drv = driver_level;
} }

View File

@@ -15,7 +15,7 @@
#pragma once #pragma once
#include "hal/touch_sensor_ll.h" #include "hal/touch_sensor_ll.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sensor_legacy_types.h"
#include_next "hal/touch_sensor_hal.h" #include_next "hal/touch_sensor_hal.h"
@@ -278,14 +278,10 @@ void touch_hal_filter_get_config(touch_filter_config_t *filter_info);
/** /**
* Enable touch sensor filter and detection algorithm. * Enable touch sensor filter and detection algorithm.
* For more details on the detection algorithm, please refer to the application documentation. * For more details on the detection algorithm, please refer to the application documentation.
*
* @param enable set true to enable the filter
*/ */
#define touch_hal_filter_enable() touch_ll_filter_enable() #define touch_hal_filter_enable(enable) touch_ll_filter_enable(enable)
/**
* Disable touch sensor filter and detection algorithm.
* For more details on the detection algorithm, please refer to the application documentation.
*/
#define touch_hal_filter_disable() touch_ll_filter_disable()
/************************ Denoise register setting ************************/ /************************ Denoise register setting ************************/
@@ -326,7 +322,7 @@ void touch_hal_denoise_enable(void);
* This denoise function filters out interference introduced on all channels, * This denoise function filters out interference introduced on all channels,
* such as noise introduced by the power supply and external EMI. * such as noise introduced by the power supply and external EMI.
*/ */
#define touch_hal_denoise_disable() touch_ll_denoise_disable() #define touch_hal_denoise_disable() touch_ll_denoise_enable(false)
/** /**
* Set internal reference capacitance of denoise channel. * Set internal reference capacitance of denoise channel.
@@ -391,7 +387,7 @@ void touch_hal_denoise_enable(void);
* *
* @param pad_num Touch sensor channel number. * @param pad_num Touch sensor channel number.
*/ */
#define touch_hal_waterproof_set_sheild_driver(driver_level) touch_ll_waterproof_set_sheild_driver(driver_level) #define touch_hal_waterproof_set_sheild_driver(driver_level) touch_ll_waterproof_set_shield_driver(driver_level)
/** /**
* Get max equivalent capacitance for shield channel. * Get max equivalent capacitance for shield channel.
@@ -400,7 +396,7 @@ void touch_hal_denoise_enable(void);
* *
* @param pad_num Touch sensor channel number. * @param pad_num Touch sensor channel number.
*/ */
#define touch_hal_waterproof_get_sheild_driver(driver_level) touch_ll_waterproof_get_sheild_driver(driver_level) #define touch_hal_waterproof_get_sheild_driver(driver_level) touch_ll_waterproof_get_shield_driver(driver_level)
/** /**
* Set parameter of waterproof function. * Set parameter of waterproof function.
@@ -430,7 +426,7 @@ void touch_hal_waterproof_enable(void);
/** /**
* Disable parameter of waterproof function. * Disable parameter of waterproof function.
*/ */
#define touch_hal_waterproof_disable() touch_ll_waterproof_disable() #define touch_hal_waterproof_disable() touch_ll_waterproof_enable(false)
/************************ Proximity register setting ************************/ /************************ Proximity register setting ************************/
@@ -550,13 +546,9 @@ void touch_hal_sleep_channel_enable(touch_pad_t pad_num, bool enable);
/** /**
* Enable proximity function for sleep pad. * Enable proximity function for sleep pad.
* @param enable the proximity sensing
*/ */
#define touch_hal_sleep_enable_approach() touch_ll_sleep_enable_proximity_sensing() #define touch_hal_sleep_enable_approach(enable) touch_ll_sleep_enable_proximity_sensing(enable)
/**
* Disable proximity function for sleep pad.
*/
#define touch_hal_sleep_disable_approach() touch_ll_sleep_disable_proximity_sensing()
/** /**
* Read benchmark of touch sensor for sleep pad. * Read benchmark of touch sensor for sleep pad.

File diff suppressed because it is too large Load Diff

View File

@@ -9,7 +9,7 @@
#include "soc/soc_pins.h" #include "soc/soc_pins.h"
#include "soc/touch_sensor_pins.h" #include "soc/touch_sensor_pins.h"
#include "hal/touch_sensor_hal.h" #include "hal/touch_sensor_hal.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sensor_legacy_types.h"
static int s_sleep_cycle = -1; static int s_sleep_cycle = -1;
static int s_meas_times = -1; static int s_meas_times = -1;
@@ -48,12 +48,12 @@ void touch_hal_deinit(void)
touch_ll_clear_trigger_status_mask(); touch_ll_clear_trigger_status_mask();
touch_ll_intr_disable(TOUCH_PAD_INTR_MASK_ALL); touch_ll_intr_disable(TOUCH_PAD_INTR_MASK_ALL);
touch_ll_timeout_disable(); touch_ll_timeout_disable();
touch_ll_waterproof_disable(); touch_ll_waterproof_enable(false);
touch_ll_denoise_disable(); touch_ll_denoise_enable(false);
touch_pad_t prox_pad[SOC_TOUCH_PROXIMITY_CHANNEL_NUM] = {[0 ... (SOC_TOUCH_PROXIMITY_CHANNEL_NUM - 1)] = 0}; touch_pad_t prox_pad[SOC_TOUCH_PROXIMITY_CHANNEL_NUM] = {[0 ... (SOC_TOUCH_PROXIMITY_CHANNEL_NUM - 1)] = 0};
touch_ll_proximity_set_channel_num((const touch_pad_t *)prox_pad); touch_ll_proximity_set_channel_num((const touch_pad_t *)prox_pad);
touch_ll_sleep_set_channel_num(0); touch_ll_sleep_set_channel_num(0);
touch_ll_sleep_disable_proximity_sensing(); touch_ll_sleep_enable_proximity_sensing(false);
touch_ll_reset(); // Reset the touch sensor FSM. touch_ll_reset(); // Reset the touch sensor FSM.
} }
@@ -90,25 +90,25 @@ void touch_hal_denoise_get_config(touch_pad_denoise_t *denoise)
void touch_hal_denoise_enable(void) void touch_hal_denoise_enable(void)
{ {
touch_ll_clear_channel_mask(1U << SOC_TOUCH_DENOISE_CHANNEL); touch_ll_clear_channel_mask(1U << SOC_TOUCH_DENOISE_CHANNEL);
touch_ll_denoise_enable(); touch_ll_denoise_enable(true);
} }
void touch_hal_waterproof_set_config(const touch_pad_waterproof_t *waterproof) void touch_hal_waterproof_set_config(const touch_pad_waterproof_t *waterproof)
{ {
touch_ll_waterproof_set_guard_pad(waterproof->guard_ring_pad); touch_ll_waterproof_set_guard_pad(waterproof->guard_ring_pad);
touch_ll_waterproof_set_sheild_driver(waterproof->shield_driver); touch_ll_waterproof_set_shield_driver(waterproof->shield_driver);
} }
void touch_hal_waterproof_get_config(touch_pad_waterproof_t *waterproof) void touch_hal_waterproof_get_config(touch_pad_waterproof_t *waterproof)
{ {
touch_ll_waterproof_get_guard_pad(&waterproof->guard_ring_pad); touch_ll_waterproof_get_guard_pad(&waterproof->guard_ring_pad);
touch_ll_waterproof_get_sheild_driver(&waterproof->shield_driver); touch_ll_waterproof_get_shield_driver(&waterproof->shield_driver);
} }
void touch_hal_waterproof_enable(void) void touch_hal_waterproof_enable(void)
{ {
touch_ll_clear_channel_mask(1U << SOC_TOUCH_SHIELD_CHANNEL); touch_ll_clear_channel_mask(1U << SOC_TOUCH_SHIELD_CHANNEL);
touch_ll_waterproof_enable(); touch_ll_waterproof_enable(true);
} }
bool touch_hal_enable_proximity(touch_pad_t touch_num, bool enabled) bool touch_hal_enable_proximity(touch_pad_t touch_num, bool enabled)

View File

@@ -15,7 +15,7 @@
#pragma once #pragma once
#include "hal/touch_sensor_ll.h" #include "hal/touch_sensor_ll.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sensor_legacy_types.h"
#include_next "hal/touch_sensor_hal.h" #include_next "hal/touch_sensor_hal.h"
@@ -278,14 +278,10 @@ void touch_hal_filter_get_config(touch_filter_config_t *filter_info);
/** /**
* Enable touch sensor filter and detection algorithm. * Enable touch sensor filter and detection algorithm.
* For more details on the detection algorithm, please refer to the application documentation. * For more details on the detection algorithm, please refer to the application documentation.
*
* @param enable set true to enable the filter
*/ */
#define touch_hal_filter_enable() touch_ll_filter_enable() #define touch_hal_filter_enable(enable) touch_ll_filter_enable(enable)
/**
* Disable touch sensor filter and detection algorithm.
* For more details on the detection algorithm, please refer to the application documentation.
*/
#define touch_hal_filter_disable() touch_ll_filter_disable()
/************************ Denoise register setting ************************/ /************************ Denoise register setting ************************/
@@ -326,7 +322,7 @@ void touch_hal_denoise_enable(void);
* This denoise function filters out interference introduced on all channels, * This denoise function filters out interference introduced on all channels,
* such as noise introduced by the power supply and external EMI. * such as noise introduced by the power supply and external EMI.
*/ */
#define touch_hal_denoise_disable() touch_ll_denoise_disable() #define touch_hal_denoise_disable() touch_ll_denoise_enable(false)
/** /**
* Set internal reference capacitance of denoise channel. * Set internal reference capacitance of denoise channel.
@@ -391,7 +387,7 @@ void touch_hal_denoise_enable(void);
* *
* @param pad_num Touch sensor channel number. * @param pad_num Touch sensor channel number.
*/ */
#define touch_hal_waterproof_set_sheild_driver(driver_level) touch_ll_waterproof_set_sheild_driver(driver_level) #define touch_hal_waterproof_set_sheild_driver(driver_level) touch_ll_waterproof_set_shield_driver(driver_level)
/** /**
* Get max equivalent capacitance for shield channel. * Get max equivalent capacitance for shield channel.
@@ -400,7 +396,7 @@ void touch_hal_denoise_enable(void);
* *
* @param pad_num Touch sensor channel number. * @param pad_num Touch sensor channel number.
*/ */
#define touch_hal_waterproof_get_sheild_driver(driver_level) touch_ll_waterproof_get_sheild_driver(driver_level) #define touch_hal_waterproof_get_sheild_driver(driver_level) touch_ll_waterproof_get_shield_driver(driver_level)
/** /**
* Set parameter of waterproof function. * Set parameter of waterproof function.
@@ -430,7 +426,7 @@ void touch_hal_waterproof_enable(void);
/** /**
* Disable parameter of waterproof function. * Disable parameter of waterproof function.
*/ */
#define touch_hal_waterproof_disable() touch_ll_waterproof_disable() #define touch_hal_waterproof_disable() touch_ll_waterproof_enable(false)
/************************ Proximity register setting ************************/ /************************ Proximity register setting ************************/
@@ -550,13 +546,9 @@ void touch_hal_sleep_channel_enable(touch_pad_t pad_num, bool enable);
/** /**
* Enable proximity function for sleep pad. * Enable proximity function for sleep pad.
* @param enable the proximity sensing
*/ */
#define touch_hal_sleep_enable_approach() touch_ll_sleep_enable_proximity_sensing() #define touch_hal_sleep_enable_approach(enable) touch_ll_sleep_enable_proximity_sensing(enable)
/**
* Disable proximity function for sleep pad.
*/
#define touch_hal_sleep_disable_approach() touch_ll_sleep_disable_proximity_sensing()
/** /**
* Read benchmark of touch sensor for sleep pad. * Read benchmark of touch sensor for sleep pad.

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,8 @@
#include "soc/soc_pins.h" #include "soc/soc_pins.h"
#include "hal/touch_sensor_hal.h" #include "hal/touch_sensor_hal.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sensor_ll.h"
#include "hal/touch_sensor_legacy_types.h"
#include "soc/soc_caps.h" #include "soc/soc_caps.h"
static int s_sleep_cycle = -1; static int s_sleep_cycle = -1;
@@ -48,12 +49,12 @@ void touch_hal_deinit(void)
touch_ll_clear_trigger_status_mask(); touch_ll_clear_trigger_status_mask();
touch_ll_intr_disable(TOUCH_PAD_INTR_MASK_ALL); touch_ll_intr_disable(TOUCH_PAD_INTR_MASK_ALL);
touch_ll_timeout_disable(); touch_ll_timeout_disable();
touch_ll_waterproof_disable(); touch_ll_waterproof_enable(false);
touch_ll_denoise_disable(); touch_ll_denoise_enable(false);
touch_pad_t prox_pad[SOC_TOUCH_PROXIMITY_CHANNEL_NUM] = {[0 ... (SOC_TOUCH_PROXIMITY_CHANNEL_NUM - 1)] = 0}; touch_pad_t prox_pad[SOC_TOUCH_PROXIMITY_CHANNEL_NUM] = {[0 ... (SOC_TOUCH_PROXIMITY_CHANNEL_NUM - 1)] = 0};
touch_ll_proximity_set_channel_num((const touch_pad_t *)prox_pad); touch_ll_proximity_set_channel_num((const touch_pad_t *)prox_pad);
touch_ll_sleep_set_channel_num(0); touch_ll_sleep_set_channel_num(0);
touch_ll_sleep_disable_proximity_sensing(); touch_ll_sleep_enable_proximity_sensing(false);
touch_ll_reset(); // Reset the touch sensor FSM. touch_ll_reset(); // Reset the touch sensor FSM.
} }
@@ -90,25 +91,25 @@ void touch_hal_denoise_get_config(touch_pad_denoise_t *denoise)
void touch_hal_denoise_enable(void) void touch_hal_denoise_enable(void)
{ {
touch_ll_clear_channel_mask(1U << SOC_TOUCH_DENOISE_CHANNEL); touch_ll_clear_channel_mask(1U << SOC_TOUCH_DENOISE_CHANNEL);
touch_ll_denoise_enable(); touch_ll_denoise_enable(true);
} }
void touch_hal_waterproof_set_config(const touch_pad_waterproof_t *waterproof) void touch_hal_waterproof_set_config(const touch_pad_waterproof_t *waterproof)
{ {
touch_ll_waterproof_set_guard_pad(waterproof->guard_ring_pad); touch_ll_waterproof_set_guard_pad(waterproof->guard_ring_pad);
touch_ll_waterproof_set_sheild_driver(waterproof->shield_driver); touch_ll_waterproof_set_shield_driver(waterproof->shield_driver);
} }
void touch_hal_waterproof_get_config(touch_pad_waterproof_t *waterproof) void touch_hal_waterproof_get_config(touch_pad_waterproof_t *waterproof)
{ {
touch_ll_waterproof_get_guard_pad(&waterproof->guard_ring_pad); touch_ll_waterproof_get_guard_pad(&waterproof->guard_ring_pad);
touch_ll_waterproof_get_sheild_driver(&waterproof->shield_driver); touch_ll_waterproof_get_shield_driver(&waterproof->shield_driver);
} }
void touch_hal_waterproof_enable(void) void touch_hal_waterproof_enable(void)
{ {
touch_ll_clear_channel_mask(1U << SOC_TOUCH_SHIELD_CHANNEL); touch_ll_clear_channel_mask(1U << SOC_TOUCH_SHIELD_CHANNEL);
touch_ll_waterproof_enable(); touch_ll_waterproof_enable(true);
} }
bool touch_hal_enable_proximity(touch_pad_t touch_num, bool enabled) bool touch_hal_enable_proximity(touch_pad_t touch_num, bool enabled)

View File

@@ -10,23 +10,48 @@
* See readme.md in hal/include/hal/readme.md * See readme.md in hal/include/hal/readme.md
******************************************************************************/ ******************************************************************************/
// The HAL layer for touch sensor (ESP32-P4 specific part)
#pragma once #pragma once
#include "soc/soc_caps.h"
#if SOC_TOUCH_SENSOR_VERSION > 1
#include "hal/touch_sensor_ll.h" #include "hal/touch_sensor_ll.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sens_types.h"
#endif // SOC_TOUCH_SENSOR_SUPPORTED
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#if SOC_TOUCH_SENSOR_VERSION > 1
#if SOC_TOUCH_SENSOR_VERSION == 2
/** /**
* @brief Sample configurations of the touch sensor * @brief Sample configurations of the touch sensor V2
*
*/ */
typedef struct { typedef struct {
uint32_t div_num; /*!< The division from the source clock to the sampling frequency */ uint32_t charge_times; /*!< The charge and discharge times of this sample configuration, the read data are positive correlation to the charge_times */
touch_volt_lim_h_t charge_volt_lim_h; /*!< The upper voltage limit while charging a touch pad. i.e., the touch controller won't charge the touch pad higher than this high voltage limitation. */
touch_volt_lim_l_t charge_volt_lim_l; /*!< The lower voltage limit while discharging a touch pad. i.e., the touch controller won't discharge the touch pad lower than this low voltage limitation. */
touch_idle_conn_t idle_conn; /*!< The connection of the idle touch channels.
* The idle touch channel is a channel which is enabled and power-on but not under measuring.
*/
touch_bias_type_t bias_type; /*!< The type of the touch sensor bias. Which affects the charge/discharge stability and power consumption */
} touch_hal_sample_config_v2_t;
/**
* @brief Alias of touch_hal_sample_config_v2_t for compatibility
*/
typedef touch_hal_sample_config_v2_t touch_hal_sample_config_t;
#elif SOC_TOUCH_SENSOR_VERSION == 3
/**
* @brief Sample configurations of the touch sensor V3
*/
typedef struct {
uint32_t div_num; /*!< The division of the touch output signal. It is proportional to the gain of the read data */
uint32_t charge_times; /*!< The charge and discharge times of the sample configuration, the read data are positive correlation to the charge_times */ uint32_t charge_times; /*!< The charge and discharge times of the sample configuration, the read data are positive correlation to the charge_times */
uint8_t rc_filter_res; /*!< The resistance of the RC filter of the sample configuration, range [0, 3], while 0 = 0K, 1 = 1.5K, 2 = 3K, 3 = 4.5K */ uint8_t rc_filter_res; /*!< The resistance of the RC filter of the sample configuration, range [0, 3], while 0 = 0K, 1 = 1.5K, 2 = 3K, 3 = 4.5K */
uint8_t rc_filter_cap; /*!< The capacitance of the RC filter of the sample configuration, range [0, 127], while 0 = 0pF, 1 = 20fF, ..., 127 = 2.54pF */ uint8_t rc_filter_cap; /*!< The capacitance of the RC filter of the sample configuration, range [0, 127], while 0 = 0pF, 1 = 20fF, ..., 127 = 2.54pF */
@@ -34,7 +59,16 @@ typedef struct {
uint8_t high_drv; /*!< High speed touch driver */ uint8_t high_drv; /*!< High speed touch driver */
uint8_t bias_volt; /*!< The Internal LDO voltage, which decide the bias voltage of the sample wave, range [0,15] */ uint8_t bias_volt; /*!< The Internal LDO voltage, which decide the bias voltage of the sample wave, range [0,15] */
bool bypass_shield_output; /*!< Whether to bypass the shield output */ bool bypass_shield_output; /*!< Whether to bypass the shield output */
} touch_hal_sample_config_t; } touch_hal_sample_config_v3_t;
/**
* @brief Alias of touch_hal_sample_config_v3_t for compatibility
*/
typedef touch_hal_sample_config_v3_t touch_hal_sample_config_t;
#else
#error "Unsupported touch sensor version"
#endif
/** /**
* @brief Configurations of the touch sensor controller * @brief Configurations of the touch sensor controller
@@ -47,7 +81,9 @@ typedef struct {
* Set to '0' to ignore the measurement time limitation, otherwise please set a proper time considering the configurations * Set to '0' to ignore the measurement time limitation, otherwise please set a proper time considering the configurations
* of the sample configurations below. * of the sample configurations below.
*/ */
#if SOC_TOUCH_SENSOR_VERSION == 3
touch_out_mode_t output_mode; /*!< Touch channel counting mode of the binarized touch output */ touch_out_mode_t output_mode; /*!< Touch channel counting mode of the binarized touch output */
#endif // SOC_TOUCH_SENSOR_VERSION == 3
uint32_t sample_cfg_num; /*!< The sample configuration number that used for sampling */ uint32_t sample_cfg_num; /*!< The sample configuration number that used for sampling */
touch_hal_sample_config_t *sample_cfg; /*!< The array of the sample configuration configurations, the length should be specified in `touch_hal_sample_config_t::sample_cfg_num` */ touch_hal_sample_config_t *sample_cfg; /*!< The array of the sample configuration configurations, the length should be specified in `touch_hal_sample_config_t::sample_cfg_num` */
} touch_hal_config_t; } touch_hal_config_t;
@@ -74,6 +110,8 @@ void touch_hal_save_sleep_config(int deep_slp_chan, const touch_hal_config_t *de
*/ */
void touch_hal_prepare_deep_sleep(void); void touch_hal_prepare_deep_sleep(void);
#endif // SOC_TOUCH_SENSOR_SUPPORTED
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -0,0 +1,171 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "soc/soc_caps.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Touch sensor shield channel drive capability level
*
*/
typedef enum {
TOUCH_SHIELD_CAP_40PF, /*!< The max equivalent capacitance in shield channel is 40pf */
TOUCH_SHIELD_CAP_80PF, /*!< The max equivalent capacitance in shield channel is 80pf */
TOUCH_SHIELD_CAP_120PF, /*!< The max equivalent capacitance in shield channel is 120pf */
TOUCH_SHIELD_CAP_160PF, /*!< The max equivalent capacitance in shield channel is 160pf */
TOUCH_SHIELD_CAP_200PF, /*!< The max equivalent capacitance in shield channel is 200pf */
TOUCH_SHIELD_CAP_240PF, /*!< The max equivalent capacitance in shield channel is 240pf */
TOUCH_SHIELD_CAP_280PF, /*!< The max equivalent capacitance in shield channel is 280pf */
TOUCH_SHIELD_CAP_320PF, /*!< The max equivalent capacitance in shield channel is 320pf */
} touch_chan_shield_cap_t;
/**
* @brief Touch channel Infinite Impulse Response (IIR) filter or Jitter filter for benchmark
* @note Recommended filter coefficient selection is `IIR_16`.
*/
typedef enum {
TOUCH_BM_IIR_FILTER_4, /*!< IIR Filter for benchmark, 1/4 raw_value + 3/4 benchmark */
TOUCH_BM_IIR_FILTER_8, /*!< IIR Filter for benchmark, 1/8 raw_value + 7/8 benchmark */
TOUCH_BM_IIR_FILTER_16, /*!< IIR Filter for benchmark, 1/16 raw_value + 15/16 benchmark (typical) */
TOUCH_BM_IIR_FILTER_32, /*!< IIR Filter for benchmark, 1/32 raw_value + 31/32 benchmark */
TOUCH_BM_IIR_FILTER_64, /*!< IIR Filter for benchmark, 1/64 raw_value + 63/64 benchmark */
TOUCH_BM_IIR_FILTER_128, /*!< IIR Filter for benchmark, 1/128 raw_value + 127/128 benchmark */
#if SOC_TOUCH_SENSOR_VERSION == 2
TOUCH_BM_IIR_FILTER_256, /*!< IIR Filter for benchmark, 1/256 raw_value + 255/256 benchmark */
#endif
TOUCH_BM_JITTER_FILTER, /*!< Jitter Filter for benchmark, raw value +/- jitter_step */
} touch_benchmark_filter_mode_t;
/**
* @brief Touch channel Infinite Impulse Response (IIR) filter for smooth data
*
*/
typedef enum {
TOUCH_SMOOTH_NO_FILTER, /*!< No filter adopted for smooth data, smooth data equals raw data */
TOUCH_SMOOTH_IIR_FILTER_2, /*!< IIR filter adopted for smooth data, smooth data equals 1/2 raw data + 1/2 last smooth data (typical) */
TOUCH_SMOOTH_IIR_FILTER_4, /*!< IIR filter adopted for smooth data, smooth data equals 1/4 raw data + 3/4 last smooth data */
TOUCH_SMOOTH_IIR_FILTER_8, /*!< IIR filter adopted for smooth data, smooth data equals 1/8 raw data + 7/8 last smooth data */
} touch_smooth_filter_mode_t;
/**
* @brief Touch sensor upper charging voltage limit
*/
typedef enum {
TOUCH_VOLT_LIM_H_0V9, /*!< Touch sensor upper voltage limit is 0.9V while charging a touch pad */
TOUCH_VOLT_LIM_H_1V0, /*!< Touch sensor upper voltage limit is 1.0V while charging a touch pad */
TOUCH_VOLT_LIM_H_1V1, /*!< Touch sensor upper voltage limit is 1.1V while charging a touch pad */
TOUCH_VOLT_LIM_H_1V2, /*!< Touch sensor upper voltage limit is 1.2V while charging a touch pad */
// No 1V3
TOUCH_VOLT_LIM_H_1V4, /*!< Touch sensor upper voltage limit is 1.4V while charging a touch pad */
TOUCH_VOLT_LIM_H_1V5, /*!< Touch sensor upper voltage limit is 1.5V while charging a touch pad */
TOUCH_VOLT_LIM_H_1V6, /*!< Touch sensor upper voltage limit is 1.6V while charging a touch pad */
TOUCH_VOLT_LIM_H_1V7, /*!< Touch sensor upper voltage limit is 1.7V while charging a touch pad */
// No 1V8
TOUCH_VOLT_LIM_H_1V9, /*!< Touch sensor upper voltage limit is 1.9V while charging a touch pad */
TOUCH_VOLT_LIM_H_2V0, /*!< Touch sensor upper voltage limit is 2.0V while charging a touch pad */
TOUCH_VOLT_LIM_H_2V1, /*!< Touch sensor upper voltage limit is 2.1V while charging a touch pad */
TOUCH_VOLT_LIM_H_2V2, /*!< Touch sensor upper voltage limit is 2.2V while charging a touch pad */
// No 2V3
TOUCH_VOLT_LIM_H_2V4, /*!< Touch sensor upper voltage limit is 2.4V while charging a touch pad */
TOUCH_VOLT_LIM_H_2V5, /*!< Touch sensor upper voltage limit is 2.5V while charging a touch pad */
TOUCH_VOLT_LIM_H_2V6, /*!< Touch sensor upper voltage limit is 2.6V while charging a touch pad */
TOUCH_VOLT_LIM_H_2V7, /*!< Touch sensor upper voltage limit is 2.7V while charging a touch pad */
} touch_volt_lim_h_t;
/**
* @brief Touch sensor lower discharging voltage limit
*/
typedef enum {
TOUCH_VOLT_LIM_L_0V5, /*!< Touch sensor lower voltage limit is 0.5V while discharging a touch pad */
TOUCH_VOLT_LIM_L_0V6, /*!< Touch sensor lower voltage limit is 0.6V while discharging a touch pad */
TOUCH_VOLT_LIM_L_0V7, /*!< Touch sensor lower voltage limit is 0.7V while discharging a touch pad */
TOUCH_VOLT_LIM_L_0V8, /*!< Touch sensor lower voltage limit is 0.8V while discharging a touch pad */
} touch_volt_lim_l_t;
/**
* @brief Touch sensor charge and discharge speed
*/
typedef enum {
TOUCH_CHARGE_SPEED_0 = 0, /*!< Touch sensor charge and discharge speed, no charge, always zero */
TOUCH_CHARGE_SPEED_1 = 1, /*!< Touch sensor charge and discharge speed, slowest */
TOUCH_CHARGE_SPEED_2 = 2, /*!< Touch sensor charge and discharge speed */
TOUCH_CHARGE_SPEED_3 = 3, /*!< Touch sensor charge and discharge speed */
TOUCH_CHARGE_SPEED_4 = 4, /*!< Touch sensor charge and discharge speed */
TOUCH_CHARGE_SPEED_5 = 5, /*!< Touch sensor charge and discharge speed */
TOUCH_CHARGE_SPEED_6 = 6, /*!< Touch sensor charge and discharge speed */
TOUCH_CHARGE_SPEED_7 = 7, /*!< Touch sensor charge and discharge speed, fastest */
} touch_charge_speed_t;
/**
* @brief Touch sensor initial voltage before charging
*/
typedef enum {
TOUCH_INIT_CHARGE_VOLT_LOW = 0, /*!< Tie the initial charge voltage to low */
TOUCH_INIT_CHARGE_VOLT_HIGH = 1,/*!< Tie the initial charge voltage to high */
} touch_init_charge_volt_t;
/**
* @brief Touch channel idle state configuration
*/
typedef enum {
TOUCH_IDLE_CONN_HIGHZ = 0, /*!< The idle (enabled but not measuring) touch channel is at high resistance state */
TOUCH_IDLE_CONN_GND = 1, /*!< The idle (enabled but not measuring) touch channel is connected to the ground */
} touch_idle_conn_t;
/**
* @brief Touch sensor denoise channel internal reference capacitance
*/
typedef enum {
TOUCH_DENOISE_CHAN_CAP_5PF = 0, /*!< Denoise channel internal reference capacitance is 5.0pf */
TOUCH_DENOISE_CHAN_CAP_6PF = 1, /*!< Denoise channel internal reference capacitance is 6.4pf */
TOUCH_DENOISE_CHAN_CAP_7PF = 2, /*!< Denoise channel internal reference capacitance is 7.8pf */
TOUCH_DENOISE_CHAN_CAP_9PF = 3, /*!< Denoise channel internal reference capacitance is 9.2pf */
TOUCH_DENOISE_CHAN_CAP_10PF = 4, /*!< Denoise channel internal reference capacitance is 10.6pf */
TOUCH_DENOISE_CHAN_CAP_12PF = 5, /*!< Denoise channel internal reference capacitance is 12.0pf */
TOUCH_DENOISE_CHAN_CAP_13PF = 6, /*!< Denoise channel internal reference capacitance is 13.4pf */
TOUCH_DENOISE_CHAN_CAP_14PF = 7, /*!< Denoise channel internal reference capacitance is 14.8pf */
} touch_denoise_chan_cap_t;
/**
* @brief Touch sensor denoise channel noise suppression resolution
*/
typedef enum {
TOUCH_DENOISE_CHAN_RESOLUTION_BIT12 = 0, /*!< Denoise channel noise suppression resolution is 12bit */
TOUCH_DENOISE_CHAN_RESOLUTION_BIT10 = 1, /*!< Denoise channel noise suppression resolution is 10bit */
TOUCH_DENOISE_CHAN_RESOLUTION_BIT8 = 2, /*!< Denoise channel noise suppression resolution is 8bit */
TOUCH_DENOISE_CHAN_RESOLUTION_BIT4 = 3, /*!< Denoise channel noise suppression resolution is 4bit */
} touch_denoise_chan_resolution_t;
/**
* @brief Touch sensor bias type
*/
typedef enum {
TOUCH_BIAS_TYPE_BANDGAP, /*!< Use bandgap-bias to charge/discharge the touch channel, which is more stable but power-consuming */
TOUCH_BIAS_TYPE_SELF, /*!< Use self-bias to charge/discharge the touch channel, which is less stable but power-saving */
} touch_bias_type_t;
/**
* @brief Touch channel binarized output counting mode
*/
typedef enum {
TOUCH_PAD_OUT_AS_DATA, /*!< Counting the output of touch channel as data.
* The value will be smaller than actual value but more sensitive when the frequency of touch_out is close to the source clock
* Normally we treat the output as data when it is lower than the sample clock
*/
TOUCH_PAD_OUT_AS_CLOCK, /*!< Counting the output of touch channel as clock.
* The value is accurate but less sensitive when the frequency of touch_out is close to the source clock
* Normally we treat the output as clock when it is higher than the sample clock
*/
} touch_out_mode_t;
#ifdef __cplusplus
}
#endif

View File

@@ -10,13 +10,14 @@
* See readme.md in hal/include/hal/readme.md * See readme.md in hal/include/hal/readme.md
******************************************************************************/ ******************************************************************************/
// The HAL layer for touch sensor (common part) // The legacy HAL layer for touch sensor (common part)
#pragma once #pragma once
#include "soc/soc_caps.h"
#if SOC_TOUCH_SENSOR_SUPPORTED #if SOC_TOUCH_SENSOR_SUPPORTED
#include "hal/touch_sensor_ll.h" #include "hal/touch_sensor_ll.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sensor_legacy_types.h"
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -275,23 +275,6 @@ typedef enum {
TOUCH_PAD_SMOOTH_MAX, TOUCH_PAD_SMOOTH_MAX,
} touch_smooth_mode_t; } touch_smooth_mode_t;
#if SOC_TOUCH_SENSOR_VERSION == 3
/**
* @brief Touch channel counting mode of the binarized touch output
*
*/
typedef enum {
TOUCH_PAD_OUT_AS_DATA, /*!< Counting the output of touch channel as data.
* The value will be smaller than actual value but more sensitive when the frequency of touch_out is close to the source clock
* Normally we treat the output as data when it is lower than the sample clock
*/
TOUCH_PAD_OUT_AS_CLOCK, /*!< Counting the output of touch channel as clock.
* The value is accurate but less sensitive when the frequency of touch_out is close to the source clock
* Normally we treat the output as clock when it is higher than the sample clock
*/
} touch_out_mode_t;
#endif
/** Touch sensor filter configuration */ /** Touch sensor filter configuration */
typedef struct touch_filter_config { typedef struct touch_filter_config {
touch_filter_mode_t mode; /*!<Set filter mode. The input of the filter is the raw value of touch reading, touch_filter_mode_t mode; /*!<Set filter mode. The input of the filter is the raw value of touch reading,

View File

@@ -5,11 +5,11 @@
*/ */
#include <string.h> #include <string.h>
#include "soc/soc_pins.h"
#include "hal/touch_sensor_ll.h"
#include "hal/touch_sensor_hal.h"
#include "hal/touch_sensor_types.h"
#include "soc/soc_caps.h" #include "soc/soc_caps.h"
#include "hal/touch_sensor_ll.h"
#include "hal/touch_sens_hal.h"
#include "hal/touch_sens_types.h"
typedef struct { typedef struct {
int deep_slp_chan; int deep_slp_chan;
@@ -26,16 +26,19 @@ void touch_hal_config_controller(const touch_hal_config_t *cfg)
{ {
HAL_ASSERT(cfg); HAL_ASSERT(cfg);
touch_ll_sleep_set_channel_num(TOUCH_LL_NULL_CHANNEL); touch_ll_sleep_set_channel_num(TOUCH_LL_NULL_CHANNEL);
touch_ll_set_out_mode(cfg->output_mode);
touch_ll_set_power_on_wait_cycle(cfg->power_on_wait_ticks); touch_ll_set_power_on_wait_cycle(cfg->power_on_wait_ticks);
touch_ll_set_measure_interval_ticks(cfg->meas_interval_ticks); touch_ll_set_measure_interval_ticks(cfg->meas_interval_ticks);
if (cfg->timeout_ticks) { touch_ll_set_timeout(cfg->timeout_ticks);
touch_ll_timeout_enable(cfg->timeout_ticks);
} else {
touch_ll_timeout_disable();
}
#if SOC_TOUCH_SENSOR_VERSION == 2
touch_ll_set_charge_times(cfg->sample_cfg->charge_times);
touch_ll_set_charge_voltage_high_limit(cfg->sample_cfg->charge_volt_lim_h);
touch_ll_set_charge_voltage_low_limit(cfg->sample_cfg->charge_volt_lim_l);
touch_ll_set_idle_channel_connection(cfg->sample_cfg->idle_conn);
touch_ll_set_bias_type(cfg->sample_cfg->bias_type);
#elif SOC_TOUCH_SENSOR_VERSION == 3
touch_ll_sample_cfg_set_engaged_num(cfg->sample_cfg_num); touch_ll_sample_cfg_set_engaged_num(cfg->sample_cfg_num);
touch_ll_set_out_mode(cfg->output_mode);
for (int i = 0; i < cfg->sample_cfg_num; i++) { for (int i = 0; i < cfg->sample_cfg_num; i++) {
touch_ll_set_clock_div(i, cfg->sample_cfg[i].div_num); touch_ll_set_clock_div(i, cfg->sample_cfg[i].div_num);
touch_ll_set_charge_times(i, cfg->sample_cfg[i].charge_times); touch_ll_set_charge_times(i, cfg->sample_cfg[i].charge_times);
@@ -44,6 +47,9 @@ void touch_hal_config_controller(const touch_hal_config_t *cfg)
touch_ll_sample_cfg_bypass_shield_output(i, cfg->sample_cfg[i].bypass_shield_output); touch_ll_sample_cfg_bypass_shield_output(i, cfg->sample_cfg[i].bypass_shield_output);
touch_ll_sample_cfg_set_bias_voltage(i, cfg->sample_cfg[i].bias_volt); touch_ll_sample_cfg_set_bias_voltage(i, cfg->sample_cfg[i].bias_volt);
} }
#else
HAL_ASSERT(0); // Unsupported touch sensor version
#endif
} }
void touch_hal_save_sleep_config(int deep_slp_chan, const touch_hal_config_t *deep_slp_cfg) void touch_hal_save_sleep_config(int deep_slp_chan, const touch_hal_config_t *deep_slp_cfg)
@@ -68,7 +74,7 @@ static void s_touch_hal_apply_sleep_config(void)
/* Whether to enable touch sensor wake-up the chip from deep sleep */ /* Whether to enable touch sensor wake-up the chip from deep sleep */
if (s_touch_slp_obj.deep_slp_chan >= 0) { if (s_touch_slp_obj.deep_slp_chan >= 0) {
touch_ll_sleep_set_channel_num(s_touch_slp_obj.deep_slp_chan); touch_ll_sleep_set_channel_num(s_touch_slp_obj.deep_slp_chan);
touch_ll_set_channel_mask(BIT(s_touch_slp_obj.deep_slp_chan)); touch_ll_enable_channel_mask(BIT(s_touch_slp_obj.deep_slp_chan));
} else { } else {
touch_ll_sleep_set_channel_num(TOUCH_LL_NULL_CHANNEL); touch_ll_sleep_set_channel_num(TOUCH_LL_NULL_CHANNEL);
} }
@@ -78,5 +84,5 @@ void touch_hal_prepare_deep_sleep(void)
{ {
s_touch_hal_apply_sleep_config(); s_touch_hal_apply_sleep_config();
touch_ll_sleep_reset_benchmark(); touch_ll_sleep_reset_benchmark();
touch_ll_intr_clear(TOUCH_LL_INTR_MASK_ALL); touch_ll_interrupt_clear(TOUCH_LL_INTR_MASK_ALL);
} }

View File

@@ -7,7 +7,7 @@
// The HAL layer for Touch Sensor (common part) // The HAL layer for Touch Sensor (common part)
#include "hal/touch_sensor_hal.h" #include "hal/touch_sensor_hal.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sensor_legacy_types.h"
#include "soc/soc_caps.h" #include "soc/soc_caps.h"
void touch_hal_config(touch_pad_t touch_num) void touch_hal_config(touch_pad_t touch_num)

View File

@@ -827,6 +827,10 @@ config SOC_TOUCH_SUPPORT_PROX_SENSING
bool bool
default y default y
config SOC_TOUCH_SUPPORT_DENOISE_CHAN
bool
default y
config SOC_TOUCH_PROXIMITY_CHANNEL_NUM config SOC_TOUCH_PROXIMITY_CHANNEL_NUM
int int
default 3 default 3

View File

@@ -345,6 +345,7 @@
#define SOC_TOUCH_SUPPORT_SLEEP_WAKEUP (1) /*!< Touch sensor supports sleep awake */ #define SOC_TOUCH_SUPPORT_SLEEP_WAKEUP (1) /*!< Touch sensor supports sleep awake */
#define SOC_TOUCH_SUPPORT_WATERPROOF (1) /*!< Touch sensor supports waterproof */ #define SOC_TOUCH_SUPPORT_WATERPROOF (1) /*!< Touch sensor supports waterproof */
#define SOC_TOUCH_SUPPORT_PROX_SENSING (1) /*!< Touch sensor supports proximity sensing */ #define SOC_TOUCH_SUPPORT_PROX_SENSING (1) /*!< Touch sensor supports proximity sensing */
#define SOC_TOUCH_SUPPORT_DENOISE_CHAN (1) /*!< Touch sensor supports denoise channel */
#define SOC_TOUCH_PROXIMITY_CHANNEL_NUM (3) /*!< Support touch proximity channel number. */ #define SOC_TOUCH_PROXIMITY_CHANNEL_NUM (3) /*!< Support touch proximity channel number. */
#define SOC_TOUCH_SAMPLE_CFG_NUM (1U) /*!< The sample configuration number in total, each sampler can be used to sample on one frequency */ #define SOC_TOUCH_SAMPLE_CFG_NUM (1U) /*!< The sample configuration number in total, each sampler can be used to sample on one frequency */

View File

@@ -1003,6 +1003,10 @@ config SOC_TOUCH_SUPPORT_PROX_SENSING
bool bool
default y default y
config SOC_TOUCH_SUPPORT_DENOISE_CHAN
bool
default y
config SOC_TOUCH_PROXIMITY_CHANNEL_NUM config SOC_TOUCH_PROXIMITY_CHANNEL_NUM
int int
default 3 default 3

View File

@@ -385,6 +385,7 @@
#define SOC_TOUCH_SUPPORT_SLEEP_WAKEUP (1) /*!< Touch sensor supports sleep awake */ #define SOC_TOUCH_SUPPORT_SLEEP_WAKEUP (1) /*!< Touch sensor supports sleep awake */
#define SOC_TOUCH_SUPPORT_WATERPROOF (1) /*!< Touch sensor supports waterproof */ #define SOC_TOUCH_SUPPORT_WATERPROOF (1) /*!< Touch sensor supports waterproof */
#define SOC_TOUCH_SUPPORT_PROX_SENSING (1) /*!< Touch sensor supports proximity sensing */ #define SOC_TOUCH_SUPPORT_PROX_SENSING (1) /*!< Touch sensor supports proximity sensing */
#define SOC_TOUCH_SUPPORT_DENOISE_CHAN (1) /*!< Touch sensor supports denoise channel */
#define SOC_TOUCH_PROXIMITY_CHANNEL_NUM (3) /*!< Support touch proximity sensing channel number. */ #define SOC_TOUCH_PROXIMITY_CHANNEL_NUM (3) /*!< Support touch proximity sensing channel number. */
#define SOC_TOUCH_PROXIMITY_MEAS_DONE_SUPPORTED (1) /*!< Support touch proximity sensing measure done interrupt type. */ #define SOC_TOUCH_PROXIMITY_MEAS_DONE_SUPPORTED (1) /*!< Support touch proximity sensing measure done interrupt type. */

View File

@@ -3061,12 +3061,12 @@ ork.*/
#define RTC_CNTL_TOUCH_BYPASS_NOISE_THRES_M (BIT(8)) #define RTC_CNTL_TOUCH_BYPASS_NOISE_THRES_M (BIT(8))
#define RTC_CNTL_TOUCH_BYPASS_NOISE_THRES_V 0x1 #define RTC_CNTL_TOUCH_BYPASS_NOISE_THRES_V 0x1
#define RTC_CNTL_TOUCH_BYPASS_NOISE_THRES_S 8 #define RTC_CNTL_TOUCH_BYPASS_NOISE_THRES_S 8
/* RTC_CNTL_TOUCH_BYPASS_NEG_THRES : R/W ;bitpos:[7] ;default: 1'b0 ; */ /* RTC_CNTL_TOUCH_BYPASS_NN_THRES : R/W ;bitpos:[7] ;default: 1'b0 ; */
/*description: */ /*description: */
#define RTC_CNTL_TOUCH_BYPASS_NEG_THRES (BIT(7)) #define RTC_CNTL_TOUCH_BYPASS_NN_THRES (BIT(7))
#define RTC_CNTL_TOUCH_BYPASS_NEG_THRES_M (BIT(7)) #define RTC_CNTL_TOUCH_BYPASS_NN_THRES_M (BIT(7))
#define RTC_CNTL_TOUCH_BYPASS_NEG_THRES_V 0x1 #define RTC_CNTL_TOUCH_BYPASS_NN_THRES_V 0x1
#define RTC_CNTL_TOUCH_BYPASS_NEG_THRES_S 7 #define RTC_CNTL_TOUCH_BYPASS_NN_THRES_S 7
#define RTC_CNTL_USB_CONF_REG (DR_REG_RTCCNTL_BASE + 0x120) #define RTC_CNTL_USB_CONF_REG (DR_REG_RTCCNTL_BASE + 0x120)
/* RTC_CNTL_SW_HW_USB_PHY_SEL : R/W ;bitpos:[20] ;default: 1'b0 ; */ /* RTC_CNTL_SW_HW_USB_PHY_SEL : R/W ;bitpos:[20] ;default: 1'b0 ; */

View File

@@ -798,7 +798,7 @@ typedef volatile struct rtc_cntl_dev_s {
union { union {
struct { struct {
uint32_t reserved0 : 7; uint32_t reserved0 : 7;
uint32_t touch_bypass_neg_noise_thres : 1; uint32_t touch_bypass_nn_thres : 1;
uint32_t touch_bypass_noise_thres : 1; uint32_t touch_bypass_noise_thres : 1;
uint32_t touch_smooth_lvl : 2; uint32_t touch_smooth_lvl : 2;
uint32_t touch_jitter_step : 4; /*touch jitter step*/ uint32_t touch_jitter_step : 4; /*touch jitter step*/

View File

@@ -1,12 +1,12 @@
/* /*
* SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2016-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#pragma once #pragma once
#include "driver/touch_sensor.h" #include "driver/touch_sensor_legacy.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -274,9 +274,9 @@ esp_err_t touch_element_waterproof_remove(touch_elem_handle_t element_handle);
* @return * @return
* - ESP_OK: Successfully initialized touch sleep * - ESP_OK: Successfully initialized touch sleep
* - ESP_ERR_INVALID_STATE: Touch element is not installed or touch sleep has been installed * - ESP_ERR_INVALID_STATE: Touch element is not installed or touch sleep has been installed
* - ESP_ERR_INVALID_ARG: inputed argument is NULL * - ESP_ERR_INVALID_ARG: inputted argument is NULL
* - ESP_ERR_NO_MEM: no memory for touch sleep struct * - ESP_ERR_NO_MEM: no memory for touch sleep struct
* - ESP_ERR_NOT_SUPPORTED: inputed wakeup_elem_handle is not touch_button_handle_t type, currently only touch_button_handle_t supported * - ESP_ERR_NOT_SUPPORTED: inputted wakeup_elem_handle is not touch_button_handle_t type, currently only touch_button_handle_t supported
*/ */
esp_err_t touch_element_enable_light_sleep(const touch_elem_sleep_config_t *sleep_config); esp_err_t touch_element_enable_light_sleep(const touch_elem_sleep_config_t *sleep_config);
@@ -305,9 +305,9 @@ esp_err_t touch_element_disable_light_sleep(void);
* @return * @return
* - ESP_OK: Successfully initialized touch sleep * - ESP_OK: Successfully initialized touch sleep
* - ESP_ERR_INVALID_STATE: Touch element is not installed or touch sleep has been installed * - ESP_ERR_INVALID_STATE: Touch element is not installed or touch sleep has been installed
* - ESP_ERR_INVALID_ARG: inputed argument is NULL * - ESP_ERR_INVALID_ARG: inputted argument is NULL
* - ESP_ERR_NO_MEM: no memory for touch sleep struct * - ESP_ERR_NO_MEM: no memory for touch sleep struct
* - ESP_ERR_NOT_SUPPORTED: inputed wakeup_elem_handle is not touch_button_handle_t type, currently only touch_button_handle_t supported * - ESP_ERR_NOT_SUPPORTED: inputted wakeup_elem_handle is not touch_button_handle_t type, currently only touch_button_handle_t supported
*/ */
esp_err_t touch_element_enable_deep_sleep(touch_elem_handle_t wakeup_elem_handle, const touch_elem_sleep_config_t *sleep_config); esp_err_t touch_element_enable_deep_sleep(touch_elem_handle_t wakeup_elem_handle, const touch_elem_sleep_config_t *sleep_config);

View File

@@ -8,7 +8,7 @@
#include "esp_err.h" #include "esp_err.h"
#include "ulp_riscv_register_ops.h" #include "ulp_riscv_register_ops.h"
#include "hal/touch_sensor_types.h" #include "hal/touch_sensor_legacy_types.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@@ -207,7 +207,7 @@ ESP32S2_DOCS = ['hw-reference/esp32s2/**',
'api-reference/peripherals/ds.rst', 'api-reference/peripherals/ds.rst',
'api-reference/peripherals/temp_sensor.rst', 'api-reference/peripherals/temp_sensor.rst',
'api-reference/system/async_memcpy.rst', 'api-reference/system/async_memcpy.rst',
'api-reference/peripherals/touch_pad.rst', 'api-reference/peripherals/cap_touch_sens.rst',
'api-reference/peripherals/touch_element.rst', 'api-reference/peripherals/touch_element.rst',
'api-guides/RF_calibration.rst', 'api-guides/RF_calibration.rst',
'api-guides/phy.rst'] + FTDI_JTAG_DOCS + USB_OTG_DFU_DOCS + USB_OTG_CONSOLE_DOCS 'api-guides/phy.rst'] + FTDI_JTAG_DOCS + USB_OTG_DFU_DOCS + USB_OTG_CONSOLE_DOCS
@@ -215,7 +215,7 @@ ESP32S2_DOCS = ['hw-reference/esp32s2/**',
ESP32S3_DOCS = ['hw-reference/esp32s3/**', ESP32S3_DOCS = ['hw-reference/esp32s3/**',
'api-reference/system/ipc.rst', 'api-reference/system/ipc.rst',
'api-guides/flash_psram_config.rst', 'api-guides/flash_psram_config.rst',
'api-reference/peripherals/touch_pad.rst', 'api-reference/peripherals/cap_touch_sens.rst',
'api-reference/peripherals/sd_pullup_requirements.rst', 'api-reference/peripherals/sd_pullup_requirements.rst',
'api-guides/RF_calibration.rst', 'api-guides/RF_calibration.rst',
'api-guides/phy.rst'] + USB_OTG_DFU_DOCS + USB_OTG_CONSOLE_DOCS + QEMU_DOCS 'api-guides/phy.rst'] + USB_OTG_DFU_DOCS + USB_OTG_CONSOLE_DOCS + QEMU_DOCS

View File

@@ -6,8 +6,6 @@ api-guides/usb-otg-console.rst
api-guides/esp-wifi-mesh.rst api-guides/esp-wifi-mesh.rst
api-guides/dfu.rst api-guides/dfu.rst
api-guides/wifi-security.rst api-guides/wifi-security.rst
api-reference/peripherals/touch_element.rst
api-reference/peripherals/touch_pad.rst
api-reference/peripherals/adc_calibration.rst api-reference/peripherals/adc_calibration.rst
api-reference/peripherals/parlio.rst api-reference/peripherals/parlio.rst
api-reference/peripherals/sd_pullup_requirements.rst api-reference/peripherals/sd_pullup_requirements.rst

View File

@@ -261,7 +261,6 @@ INPUT = \
$(PROJECT_PATH)/components/hal/include/hal/spi_types.h \ $(PROJECT_PATH)/components/hal/include/hal/spi_types.h \
$(PROJECT_PATH)/components/hal/include/hal/temperature_sensor_types.h \ $(PROJECT_PATH)/components/hal/include/hal/temperature_sensor_types.h \
$(PROJECT_PATH)/components/hal/include/hal/timer_types.h \ $(PROJECT_PATH)/components/hal/include/hal/timer_types.h \
$(PROJECT_PATH)/components/hal/include/hal/touch_sensor_types.h \
$(PROJECT_PATH)/components/hal/include/hal/twai_types.h \ $(PROJECT_PATH)/components/hal/include/hal/twai_types.h \
$(PROJECT_PATH)/components/hal/include/hal/uart_types.h \ $(PROJECT_PATH)/components/hal/include/hal/uart_types.h \
$(PROJECT_PATH)/components/hal/include/hal/efuse_hal.h \ $(PROJECT_PATH)/components/hal/include/hal/efuse_hal.h \

View File

@@ -1,5 +1,6 @@
INPUT += \ INPUT += \
$(PROJECT_PATH)/components/driver/touch_sensor/$(IDF_TARGET)/include/driver/touch_sensor.h \ $(PROJECT_PATH)/components/driver/touch_sensor/$(IDF_TARGET)/include/driver/touch_sensor.h \
$(PROJECT_PATH)/components/hal/include/hal/touch_sensor_legacy_types.h \
$(PROJECT_PATH)/components/esp_psram/include/esp32/himem.h \ $(PROJECT_PATH)/components/esp_psram/include/esp32/himem.h \
$(PROJECT_PATH)/components/soc/$(IDF_TARGET)/include/soc/dac_channel.h \ $(PROJECT_PATH)/components/soc/$(IDF_TARGET)/include/soc/dac_channel.h \
$(PROJECT_PATH)/components/soc/$(IDF_TARGET)/include/soc/rtc_io_channel.h \ $(PROJECT_PATH)/components/soc/$(IDF_TARGET)/include/soc/rtc_io_channel.h \

View File

@@ -1,8 +1,9 @@
INPUT += \ INPUT += \
$(PROJECT_PATH)/components/driver/touch_sensor/$(IDF_TARGET)/include/driver/touch_sensor.h \ $(PROJECT_PATH)/components/esp_driver_touch_sens/include/driver/touch_sens.h \
$(PROJECT_PATH)/components/esp_driver_touch_sens/include/driver/touch_sens_types.h \
$(PROJECT_PATH)/components/esp_driver_touch_sens/hw_ver2/include/driver/touch_version_types.h \
$(PROJECT_PATH)/components/soc/$(IDF_TARGET)/include/soc/dac_channel.h \ $(PROJECT_PATH)/components/soc/$(IDF_TARGET)/include/soc/dac_channel.h \
$(PROJECT_PATH)/components/soc/$(IDF_TARGET)/include/soc/rtc_io_channel.h \ $(PROJECT_PATH)/components/soc/$(IDF_TARGET)/include/soc/rtc_io_channel.h \
$(PROJECT_PATH)/components/soc/$(IDF_TARGET)/include/soc/touch_sensor_channel.h \
$(PROJECT_PATH)/components/ulp/ulp_fsm/include/$(IDF_TARGET)/ulp.h \ $(PROJECT_PATH)/components/ulp/ulp_fsm/include/$(IDF_TARGET)/ulp.h \
$(PROJECT_PATH)/components/touch_element/include/touch_element/touch_button.h \ $(PROJECT_PATH)/components/touch_element/include/touch_element/touch_button.h \
$(PROJECT_PATH)/components/touch_element/include/touch_element/touch_element.h \ $(PROJECT_PATH)/components/touch_element/include/touch_element/touch_element.h \

View File

@@ -1,7 +1,8 @@
INPUT += \ INPUT += \
$(PROJECT_PATH)/components/driver/touch_sensor/$(IDF_TARGET)/include/driver/touch_sensor.h \ $(PROJECT_PATH)/components/esp_driver_touch_sens/include/driver/touch_sens.h \
$(PROJECT_PATH)/components/esp_driver_touch_sens/include/driver/touch_sens_types.h \
$(PROJECT_PATH)/components/esp_driver_touch_sens/hw_ver2/include/driver/touch_version_types.h \
$(PROJECT_PATH)/components/esp_lcd/rgb/include/esp_lcd_panel_rgb.h \ $(PROJECT_PATH)/components/esp_lcd/rgb/include/esp_lcd_panel_rgb.h \
$(PROJECT_PATH)/components/soc/$(IDF_TARGET)/include/soc/touch_sensor_channel.h \
$(PROJECT_PATH)/components/ulp/ulp_fsm/include/$(IDF_TARGET)/ulp.h \ $(PROJECT_PATH)/components/ulp/ulp_fsm/include/$(IDF_TARGET)/ulp.h \
$(PROJECT_PATH)/components/touch_element/include/touch_element/touch_button.h \ $(PROJECT_PATH)/components/touch_element/include/touch_element/touch_button.h \
$(PROJECT_PATH)/components/touch_element/include/touch_element/touch_element.h \ $(PROJECT_PATH)/components/touch_element/include/touch_element/touch_element.h \

View File

@@ -3,7 +3,7 @@ Capacitive Touch Sensor
:link_to_translation:`zh_CN:[中文]` :link_to_translation:`zh_CN:[中文]`
{IDF_TARGET_TOUCH_SENSOR_VERSION:default="NOT_UPDATED", esp32p4="v3"} {IDF_TARGET_TOUCH_SENSOR_VERSION:default="NOT_UPDATED", esp32s2="v2", esp32s3="v2", esp32p4="v3"}
Introduction Introduction
--------------- ---------------
@@ -35,59 +35,9 @@ Overview of Capacitive Touch Sensor Versions
Overview of Touch Sensor Channels Overview of Touch Sensor Channels
------------------------------------ ------------------------------------
.. only:: esp32p4 .. include:: cap_touch_sens/{IDF_TARGET_PATH_NAME}.inc
:start-after: touch-chan-mapping
.. list-table:: :end-before: ---
:header-rows: 1
:widths: 20 20
* - Channel
- GPIO
* - CH0
- IO2
* - CH1
- IO3
* - CH2
- IO4
* - CH3
- IO5
* - CH4
- IO6
* - CH5
- IO7
* - CH6
- IO8
* - CH7
- IO9
* - CH8
- IO10
* - CH9
- IO11
* - CH10
- IO12
* - CH11
- IO13
* - CH12
- IO14
* - CH13
- IO15
* - CH14
- Internal
Terminology in the Driver Terminology in the Driver
---------------------------- ----------------------------
@@ -148,6 +98,7 @@ Categorized by functionality, the APIs of Capacitive Touch Sensor mainly include
:SOC_TOUCH_SUPPORT_WATERPROOF: - `Waterproof Configuration <#touch-waterproof>`__ :SOC_TOUCH_SUPPORT_WATERPROOF: - `Waterproof Configuration <#touch-waterproof>`__
:SOC_TOUCH_SUPPORT_PROX_SENSING: - `Proximity Sensing Configuration <#touch-prox-sensing>`__ :SOC_TOUCH_SUPPORT_PROX_SENSING: - `Proximity Sensing Configuration <#touch-prox-sensing>`__
:SOC_TOUCH_SUPPORT_SLEEP_WAKEUP: - `Sleep Wake-up Configuration <#touch-sleep-wakeup>`__ :SOC_TOUCH_SUPPORT_SLEEP_WAKEUP: - `Sleep Wake-up Configuration <#touch-sleep-wakeup>`__
:SOC_TOUCH_SUPPORT_DENOISE_CHAN: - `Denoise Channel Configuration <#touch-denoise-chan>`__
.. _touch-ctrl: .. _touch-ctrl:
@@ -385,8 +336,14 @@ Call :cpp:func:`touch_channel_read_data` to read the data with different types.
The {IDF_TARGET_NAME} supports proximity sensing. Proximity sensing can be registered by calling :cpp:func:`touch_sensor_config_proximity_sensing` and specify the configurations :cpp:type:`touch_proximity_config_t`. The {IDF_TARGET_NAME} supports proximity sensing. Proximity sensing can be registered by calling :cpp:func:`touch_sensor_config_proximity_sensing` and specify the configurations :cpp:type:`touch_proximity_config_t`.
.. only:: esp32p4
Since the capacitance change caused by proximity sensing is far less than that caused by physical touch, large area of copper foil is often used on PCB to increase the sensing area. In addition, multiple rounds of scans are needed and the result of each scan will be accumulated in the driver to improve the measurement sensitivity. The scan times (rounds) can be determined by :cpp:member:`touch_proximity_config_t::scan_times` and the charging times of the proximity channel in one scan can be determined by :cpp:member:`touch_proximity_config_t::charge_times`. Generally, the larger the scan times and charging times is, the higher the sensitivity will be, however, the read data will be unstable if the sensitivity is too high. Proper parameters should be determined regarding the application. Since the capacitance change caused by proximity sensing is far less than that caused by physical touch, large area of copper foil is often used on PCB to increase the sensing area. In addition, multiple rounds of scans are needed and the result of each scan will be accumulated in the driver to improve the measurement sensitivity. The scan times (rounds) can be determined by :cpp:member:`touch_proximity_config_t::scan_times` and the charging times of the proximity channel in one scan can be determined by :cpp:member:`touch_proximity_config_t::charge_times`. Generally, the larger the scan times and charging times is, the higher the sensitivity will be, however, the read data will be unstable if the sensitivity is too high. Proper parameters should be determined regarding the application.
.. only:: not esp32p4
Since the capacitance change caused by proximity sensing is far less than that caused by physical touch, large area of copper foil is often used on PCB to increase the sensing area. In addition, multiple rounds of scans are needed and the result of each scan will be accumulated in the driver to improve the measurement sensitivity. The scan times (rounds) can be determined by :cpp:member:`touch_proximity_config_t::scan_times`. Generally, the larger the scan times and charging times is, the higher the sensitivity will be, however, the read data will be unstable if the sensitivity is too high. Proper parameters should be determined regarding the application.
The accumulated proximity data can be read by :cpp:func:`touch_channel_read_data` with the data type :cpp:enumerator:`TOUCH_CHAN_DATA_TYPE_PROXIMITY` The accumulated proximity data can be read by :cpp:func:`touch_channel_read_data` with the data type :cpp:enumerator:`TOUCH_CHAN_DATA_TYPE_PROXIMITY`
To deregister the proximity sensing, you can call :cpp:func:`touch_sensor_config_proximity_sensing` again, and set the second parameter (i.e. :cpp:type:`touch_proximity_config_t` pointer) to ``NULL``. To deregister the proximity sensing, you can call :cpp:func:`touch_sensor_config_proximity_sensing` again, and set the second parameter (i.e. :cpp:type:`touch_proximity_config_t` pointer) to ``NULL``.
@@ -421,7 +378,7 @@ Call :cpp:func:`touch_channel_read_data` to read the data with different types.
If you want to read or configure the touch sensor during the sleep, you can turn to the driver ``components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_touch_ulp_core.h`` which based on the :doc:`Ultra Low Power (ULP) Coprocessor <../system/ulp>`. If you want to read or configure the touch sensor during the sleep, you can turn to the driver ``components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_touch_ulp_core.h`` which based on the :doc:`Ultra Low Power (ULP) Coprocessor <../system/ulp>`.
- Light sleep wake-up: you need to set :cpp:member:`slp_wakeup_lvl` to :cpp:enumerator:`TOUCH_LIGHT_SLEEP_WAKEUP` to enable the light sleep wake-up by touch sensor. Note that any registered touch channel can wake-up the chip from light sleep. - Light sleep wake-up: you need to set :cpp:member:`slp_wakeup_lvl` to :cpp:enumerator:`TOUCH_LIGHT_SLEEP_WAKEUP` to enable the light sleep wake-up by touch sensor. Note that any registered touch channel can wake-up the chip from light sleep.
- Deep sleep wake-up: beside setting :cpp:member:`slp_wakeup_lvl` to :cpp:enumerator:`TOUCH_DEEP_SLEEP_WAKEUP`, you need to specify :cpp:member:`deep_slp_chan` additionally. Only the specified channel can wake-up the chip from the deep sleep, in order to reduce the power consumption. And also, the driver supports to store another set of configurations for the deep sleep via :cpp:member:`deep_slp_sens_cfg`, this set of configurations only takes effect during the deep sleep, you can customize the configurations to save more power. The configurations will be reset to the previous set after waking-up from the deep sleep. Please be aware that, not only deep sleep wake-up, but also light sleep wake-up will be enabled when the :cpp:member:`slp_wakeup_lvl` is :cpp:enumerator:`TOUCH_DEEP_SLEEP_WAKEUP`. - Deep sleep wake-up: beside setting :cpp:member:`slp_wakeup_lvl` to :cpp:enumerator:`TOUCH_DEEP_SLEEP_WAKEUP`, you need to specify :cpp:member:`deep_slp_chan` additionally. In order to reduce the power consumption, only the specified channel can wake-up the chip from the deep sleep when RTC_PREI power domain off. And also, the driver supports to store another set of configurations for the deep sleep via :cpp:member:`deep_slp_sens_cfg`, this set of configurations only takes effect during the deep sleep, you can customize the configurations to save more power. The configurations will be reset to the previous set after waking-up from the deep sleep. Please be aware that, not only deep sleep wake-up, but also light sleep wake-up will be enabled when the :cpp:member:`slp_wakeup_lvl` is :cpp:enumerator:`TOUCH_DEEP_SLEEP_WAKEUP`.
To deregister the sleep wake-up function, you can call :cpp:func:`touch_sensor_config_sleep_wakeup` again, and set the second parameter (i.e. :cpp:type:`touch_sleep_config_t` pointer) to ``NULL``. To deregister the sleep wake-up function, you can call :cpp:func:`touch_sensor_config_sleep_wakeup` again, and set the second parameter (i.e. :cpp:type:`touch_sleep_config_t` pointer) to ``NULL``.
@@ -444,15 +401,44 @@ Call :cpp:func:`touch_channel_read_data` to read the data with different types.
// Register the deep sleep wake-up // Register the deep sleep wake-up
ESP_ERROR_CHECK(touch_sensor_config_sleep_wakeup(sens_handle, &deep_slp_cfg)); ESP_ERROR_CHECK(touch_sensor_config_sleep_wakeup(sens_handle, &deep_slp_cfg));
.. _touch-denoise-chan:
.. only:: SOC_TOUCH_SUPPORT_DENOISE_CHAN
Denoise Channel Configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The {IDF_TARGET_NAME} supports the internal background noise suppression by the denoise channel. Denoise channel can be registered by calling :cpp:func:`touch_sensor_config_denoise_channel` and specify the configurations :cpp:type:`touch_denoise_chan_config_t`.
Denoise channel is an internal channel that not fanned out. After the denoise channel is enabled, the sampled data of the other touch channels will minus the data of the denoise channel automatically, so the final measurement result of the touch channels will be attenuated compare to the original data.
Aside of the common touch channel configuration, the reference capacitance that attached to the denoise channel can be set by :cpp:member:`touch_denoise_chan_config_t::ref_cap`. And the noise suppression resolution can be set by :cpp:member:`touch_denoise_chan_config_t::resolution`. The higher the resolution, the greater and more accuracy the denoise channel sample data will be, and the better suppression effect it takes. But at the same time, the attenuation of other touch channel sampling values also increases.
For example, the denoise channel resolution is :cpp:enumerator:`touch_denoise_chan_resolution_t::TOUCH_DENOISE_CHAN_RESOLUTION_BIT8`, i.e., maximum sample data is ``255``. Assuming the actual sample data of a normal touch channel is ``10000``, and the denoise channel sample data is ``100``, then the final measurement result of the touch channel will be ``10000 - 100 = 9900``; If we increase the resolution to :cpp:enumerator:`touch_denoise_chan_resolution_t::TOUCH_DENOISE_CHAN_RESOLUTION_BIT12`, i.e., maximum sample data is ``4095``, the resolution is ``16`` times greater. So the denoise channel sample data will be about ``100 * 16 = 1600``, then the final measurement result of this touch channel will be ``10000 - 1600 = 8400.``
To deregister the denoise channel, you can call :cpp:func:`touch_sensor_config_denoise_channel` again, and set the second parameter (i.e. :cpp:type:`touch_denoise_chan_config_t` pointer) to ``NULL``.
.. code-block:: c
touch_denoise_chan_config_t denoise_cfg = {
// Denoise channel configurations
// ...
}
// Register the denoise channel
ESP_ERROR_CHECK(touch_sensor_config_denoise_channel(sens_handle, &denoise_cfg));
// ...
// Deregister the denoise channel
ESP_ERROR_CHECK(touch_sensor_config_denoise_channel(sens_handle, NULL));
Application Examples Application Examples
------------------------ ------------------------
- :example:`peripherals/touch_sensor/touch_sensor_v3` demonstrates how to register touch channels and read the data, including hardware requirements and project configuration instructions. - :example:`peripherals/touch_sensor/touch_sens_basic` demonstrates how to register touch channels and read the data, including hardware requirements and project configuration instructions.
API Reference API Reference
------------- -------------
.. only:: esp32p4 .. only:: esp32p4 or esp32s2 or esp32s3
.. include-build-file:: inc/touch_sens.inc .. include-build-file:: inc/touch_sens.inc
.. include-build-file:: inc/touch_sens_types.inc .. include-build-file:: inc/touch_sens_types.inc

View File

@@ -0,0 +1,64 @@
.. This file gets included from other .rst files in this folder.
.. It contains target-specific snippets.
.. Comments and '---' lines act as delimiters.
..
.. This is necessary mainly because RST doesn't support substitutions
.. (defined in RST, not in Python) inside code blocks. If that is ever implemented,
.. These code blocks can be moved back to the main .rst files, with target-specific
.. file names being replaced by substitutions.
.. touch-chan-mapping
.. list-table::
:header-rows: 1
:widths: 20 20
* - Channel
- GPIO
* - CH0
- IO2
* - CH1
- IO3
* - CH2
- IO4
* - CH3
- IO5
* - CH4
- IO6
* - CH5
- IO7
* - CH6
- IO8
* - CH7
- IO9
* - CH8
- IO10
* - CH9
- IO11
* - CH10
- IO12
* - CH11
- IO13
* - CH12
- IO14
* - CH13
- IO15
* - CH14
- Internal
---

View File

@@ -0,0 +1,64 @@
.. This file gets included from other .rst files in this folder.
.. It contains target-specific snippets.
.. Comments and '---' lines act as delimiters.
..
.. This is necessary mainly because RST doesn't support substitutions
.. (defined in RST, not in Python) inside code blocks. If that is ever implemented,
.. These code blocks can be moved back to the main .rst files, with target-specific
.. file names being replaced by substitutions.
.. touch-chan-mapping
.. list-table::
:header-rows: 1
:widths: 20 20
* - Channel
- GPIO
* - CH0
- Internal
* - CH1
- IO1
* - CH2
- IO2
* - CH3
- IO3
* - CH4
- IO4
* - CH5
- IO5
* - CH6
- IO6
* - CH7
- IO7
* - CH8
- IO8
* - CH9
- IO9
* - CH10
- IO10
* - CH11
- IO11
* - CH12
- IO12
* - CH13
- IO13
* - CH14
- IO14
---

View File

@@ -0,0 +1,64 @@
.. This file gets included from other .rst files in this folder.
.. It contains target-specific snippets.
.. Comments and '---' lines act as delimiters.
..
.. This is necessary mainly because RST doesn't support substitutions
.. (defined in RST, not in Python) inside code blocks. If that is ever implemented,
.. These code blocks can be moved back to the main .rst files, with target-specific
.. file names being replaced by substitutions.
.. touch-chan-mapping
.. list-table::
:header-rows: 1
:widths: 20 20
* - Channel
- GPIO
* - CH0
- Internal
* - CH1
- IO1
* - CH2
- IO2
* - CH3
- IO3
* - CH4
- IO4
* - CH5
- IO5
* - CH6
- IO6
* - CH7
- IO7
* - CH8
- IO8
* - CH9
- IO9
* - CH10
- IO10
* - CH11
- IO11
* - CH12
- IO12
* - CH13
- IO13
* - CH14
- IO14
---

View File

@@ -42,8 +42,8 @@ Peripherals API
:SOC_GPSPI_SUPPORTED: spi_slave :SOC_GPSPI_SUPPORTED: spi_slave
:SOC_SPI_SUPPORT_SLAVE_HD_VER2: spi_slave_hd :SOC_SPI_SUPPORT_SLAVE_HD_VER2: spi_slave_hd
:SOC_TEMP_SENSOR_SUPPORTED: temp_sensor :SOC_TEMP_SENSOR_SUPPORTED: temp_sensor
:SOC_TOUCH_SENSOR_SUPPORTED and not esp32p4: touch_pad :esp32: touch_pad
:esp32p4: cap_touch_sens :SOC_TOUCH_SENSOR_SUPPORTED and not esp32: cap_touch_sens
:esp32s2: touch_element :esp32s2: touch_element
:SOC_TWAI_SUPPORTED: twai :SOC_TWAI_SUPPORTED: twai
uart uart

View File

@@ -6,7 +6,11 @@ Touch Element
Overview Overview
-------- --------
The Touch Element Library is a highly abstracted element library designed on the basis of the touch sensor driver. The library provides a unified and user-friendly software interface to quickly build capacitive touch sensor applications. For more information about the touch sensor driver API, see :doc:`../peripherals/touch_pad`. The Touch Element Library is a highly abstracted element library designed on the basis of the touch sensor driver. The library provides a unified and user-friendly software interface to quickly build capacitive touch sensor applications.
.. warning::
The Touch Element Library currently is still based on the legacy touch driver. Please refer to the :doc:`new driver of Capacitive Touch Sensor </api-reference/peripherals/cap_touch_sens>` if you don't need the Touch Element Library.
Architecture Architecture
^^^^^^^^^^^^ ^^^^^^^^^^^^

View File

@@ -5,6 +5,12 @@ Touch Sensor
{IDF_TARGET_TOUCH_SENSOR_VERSION:default="v2", esp32="v1"} {IDF_TARGET_TOUCH_SENSOR_VERSION:default="v2", esp32="v1"}
.. only:: esp32s2 or esp32s3
.. warning::
The touch driver in this document has been deprecated, please move to the new document for the latest touch driver: :doc:`Capacitive Touch Sensor </api-reference/peripherals/cap_touch_sens>`.
Introduction Introduction
------------ ------------
@@ -146,8 +152,6 @@ 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. 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_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_read`.
Method of Measurements Method of Measurements
^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^
@@ -250,7 +254,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. 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_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/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.
Touch Triggered Interrupts Touch Triggered Interrupts
^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -300,9 +304,9 @@ Application Examples
.. only:: esp32s2 or esp32s3 .. only:: esp32s2 or esp32s3
- :example:`peripherals/touch_sensor/touch_sensor_v2/touch_pad_read` demonstrates how to read and display raw values from capacitive touch pad sensors on {IDF_TARGET_NAME}, including how to calibrate the sensors and detect touch actions. .. warning::
- :example:`peripherals/touch_sensor/touch_sensor_v2/touch_pad_interrupt` demonstrates how to set up {IDF_TARGET_NAME}'s capacitive touch pad peripheral to trigger an interrupt when a pad is touched, and how to detect the touch event by the software for sensor designs when greater touch detection sensitivity is required.
The example that uses legacy driver is removed, please see :example:`peripherals/touch_sensor/touch_sens_basic` for the usage of the new driver.
.. _touch_pad-api-reference: .. _touch_pad-api-reference:
@@ -321,4 +325,4 @@ Some useful macros can be used to specified the GPIO number of a touch pad chann
2. ``TOUCH_PAD_GPIO4_CHANNEL`` is the channel number of GPIO 4 (channel 0). 2. ``TOUCH_PAD_GPIO4_CHANNEL`` is the channel number of GPIO 4 (channel 0).
.. include-build-file:: inc/touch_sensor_channel.inc .. include-build-file:: inc/touch_sensor_channel.inc
.. include-build-file:: inc/touch_sensor_types.inc .. include-build-file:: inc/touch_sensor_legacy_types.inc

View File

@@ -3,7 +3,7 @@
:link_to_translation:`en:[English]` :link_to_translation:`en:[English]`
{IDF_TARGET_TOUCH_SENSOR_VERSION:default="NOT_UPDATED", esp32p4="v3"} {IDF_TARGET_TOUCH_SENSOR_VERSION:default="NOT_UPDATED", esp32s2="v2", esp32s3="v2", esp32p4="v3"}
概述 概述
------ ------
@@ -35,59 +35,9 @@
触摸通道概览 触摸通道概览
---------------------- ----------------------
.. only:: esp32p4 .. include:: cap_touch_sens/{IDF_TARGET_PATH_NAME}.inc
:start-after: touch-chan-mapping
.. list-table:: :end-before: ---
:header-rows: 1
:widths: 20 20
* - 通道
- GPIO
* - CH0
- IO2
* - CH1
- IO3
* - CH2
- IO4
* - CH3
- IO5
* - CH4
- IO6
* - CH5
- IO7
* - CH6
- IO8
* - CH7
- IO9
* - CH8
- IO10
* - CH9
- IO11
* - CH10
- IO12
* - CH11
- IO13
* - CH12
- IO14
* - CH13
- IO15
* - CH14
- 未引出
驱动中的术语介绍 驱动中的术语介绍
------------------------- -------------------------
@@ -148,6 +98,7 @@
:SOC_TOUCH_SUPPORT_WATERPROOF: - `防水防潮配置 <#touch-waterproof>`__ :SOC_TOUCH_SUPPORT_WATERPROOF: - `防水防潮配置 <#touch-waterproof>`__
:SOC_TOUCH_SUPPORT_PROX_SENSING: - `接近感应配置 <#touch-prox-sensing>`__ :SOC_TOUCH_SUPPORT_PROX_SENSING: - `接近感应配置 <#touch-prox-sensing>`__
:SOC_TOUCH_SUPPORT_SLEEP_WAKEUP: - `睡眠唤醒配置 <#touch-sleep-wakeup>`__ :SOC_TOUCH_SUPPORT_SLEEP_WAKEUP: - `睡眠唤醒配置 <#touch-sleep-wakeup>`__
:SOC_TOUCH_SUPPORT_DENOISE_CHAN: - `去噪通道配置 <#touch-denoise-chan>`__
.. _touch-ctrl: .. _touch-ctrl:
@@ -385,8 +336,14 @@
{IDF_TARGET_NAME} 支持接近感应功能。可通过调用 :cpp:func:`touch_sensor_config_proximity_sensing` 并配置 :cpp:type:`touch_proximity_config_t` 来注册接近感应功能。 {IDF_TARGET_NAME} 支持接近感应功能。可通过调用 :cpp:func:`touch_sensor_config_proximity_sensing` 并配置 :cpp:type:`touch_proximity_config_t` 来注册接近感应功能。
.. only:: esp32p4
由于接近感应引起的电容变化远小于物理触摸PCB 上常用较大面积的铺铜来增大触摸通道的感应面积,另外需要在硬件上对接近感应通道进行多轮扫描并在驱动中进行累加来提高测量灵敏度。接近感应的灵敏度由测量轮数 :cpp:member:`touch_proximity_config_t::scan_times` 以及单次测量的充放电次数 :cpp:member:`touch_proximity_config_t::charge_times` 决定。测量轮数以及充放电次数越高,灵敏度越高,但是过高的灵敏度容易导致误触发,请选择适当的灵敏度来保证触发的稳定性。 由于接近感应引起的电容变化远小于物理触摸PCB 上常用较大面积的铺铜来增大触摸通道的感应面积,另外需要在硬件上对接近感应通道进行多轮扫描并在驱动中进行累加来提高测量灵敏度。接近感应的灵敏度由测量轮数 :cpp:member:`touch_proximity_config_t::scan_times` 以及单次测量的充放电次数 :cpp:member:`touch_proximity_config_t::charge_times` 决定。测量轮数以及充放电次数越高,灵敏度越高,但是过高的灵敏度容易导致误触发,请选择适当的灵敏度来保证触发的稳定性。
.. only:: not esp32p4
由于接近感应引起的电容变化远小于物理触摸PCB 上常用较大面积的铺铜来增大触摸通道的感应面积,另外需要在硬件上对接近感应通道进行多轮扫描并在驱动中进行累加来提高测量灵敏度。接近感应的灵敏度由测量轮数 :cpp:member:`touch_proximity_config_t::scan_times` 决定。测量轮数以及充放电次数越高,灵敏度越高,但是过高的灵敏度容易导致误触发,请选择适当的灵敏度来保证触发的稳定性。
接近感应通道多次测量的累加值也可通过 :cpp:func:`touch_channel_read_data` 获取,数据类型 :cpp:type:`touch_chan_data_type_t`:cpp:enumerator:`TOUCH_CHAN_DATA_TYPE_PROXIMITY` 接近感应通道多次测量的累加值也可通过 :cpp:func:`touch_channel_read_data` 获取,数据类型 :cpp:type:`touch_chan_data_type_t`:cpp:enumerator:`TOUCH_CHAN_DATA_TYPE_PROXIMITY`
若需要注销接近感应功能,可再次调用 :cpp:func:`touch_sensor_config_proximity_sensing` 并将第二个参数(即 :cpp:type:`touch_proximity_config_t` 的配置结构体指针)设为 ``NULL`` 来注销接近感应功能。 若需要注销接近感应功能,可再次调用 :cpp:func:`touch_sensor_config_proximity_sensing` 并将第二个参数(即 :cpp:type:`touch_proximity_config_t` 的配置结构体指针)设为 ``NULL`` 来注销接近感应功能。
@@ -410,7 +367,7 @@
睡眠唤醒配置 睡眠唤醒配置
^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
{IDF_TARGET_NAME} 支持触摸传感器将芯片从浅睡眠或深睡眠状态中唤醒。可通过调用 :cpp:func:`touch_sensor_config_sleep_wakeup` 并配置 :cpp:type:`touch_sleep_config_t` 来注册接近感应功能。 {IDF_TARGET_NAME} 支持触摸传感器将芯片从 Light-sleep 或 Deep-sleep 状态中唤醒。可通过调用 :cpp:func:`touch_sensor_config_sleep_wakeup` 并配置 :cpp:type:`touch_sleep_config_t` 来注册接近感应功能。
注册触摸传感器的睡眠唤醒功能后,处于睡眠状态下的芯片仍将继续保持对触摸传感器的采样,这将会导致芯片睡眠后的功耗增加,可通过减少充放电次数、增加采样间隔等方式来降低功耗。 注册触摸传感器的睡眠唤醒功能后,处于睡眠状态下的芯片仍将继续保持对触摸传感器的采样,这将会导致芯片睡眠后的功耗增加,可通过减少充放电次数、增加采样间隔等方式来降低功耗。
@@ -420,8 +377,8 @@
若需要在睡眠过程中进行读数、配置等操作,可通过运行在 :doc:`超低功耗协处理器 ULP <../system/ulp>` 上的触摸传感器驱动 ``components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_touch_ulp_core.h`` 实现。 若需要在睡眠过程中进行读数、配置等操作,可通过运行在 :doc:`超低功耗协处理器 ULP <../system/ulp>` 上的触摸传感器驱动 ``components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_touch_ulp_core.h`` 实现。
- 浅睡眠状态唤醒:通过指定 :cpp:member:`slp_wakeup_lvl`:cpp:enumerator:`TOUCH_LIGHT_SLEEP_WAKEUP` 即可启用触摸传感器浅睡眠唤醒功能。注意任何已注册的触摸传感器通道都会在浅睡眠状态下保持采样并支持唤醒浅睡眠 - Light-sleep 状态唤醒:通过指定 :cpp:member:`slp_wakeup_lvl`:cpp:enumerator:`TOUCH_LIGHT_SLEEP_WAKEUP` 即可启用触摸传感器 Light-sleep 唤醒功能。注意任何已注册的触摸传感器通道都会在 Light-sleep 状态下保持采样并支持唤醒 Light-sleep
- 深睡眠状态唤醒:启用触摸传感器深睡眠唤醒功能除了指定 :cpp:member:`slp_wakeup_lvl`:cpp:enumerator:`TOUCH_DEEP_SLEEP_WAKEUP` 外,还需要指定深睡眠唤醒通道 :cpp:member:`deep_slp_chan`,注意只有该指定的通道才会在深睡眠状态下保持采样以及唤醒,以此降低在深睡眠状态下的功耗。此外,若需要在深度睡眠下使用另一套低功耗的配置来进一步降低功耗,可以通过 :cpp:member:`deep_slp_sens_cfg` 额外指定一套低功耗配置,在进入深睡眠前,驱动会应用这套配置,从深睡眠状态唤醒后,则会重新配置到之前的配置。请注意当 :cpp:member:`slp_wakeup_lvl` 配置为 :cpp:enumerator:`TOUCH_DEEP_SLEEP_WAKEUP` 后,触摸传感器不仅能唤醒深睡眠状态,还能唤醒浅睡眠状态。 - Deep-sleep 状态唤醒:启用触摸传感器 Deep-sleep 唤醒功能除了指定 :cpp:member:`slp_wakeup_lvl`:cpp:enumerator:`TOUCH_DEEP_SLEEP_WAKEUP` 外,还需要指定 Deep-sleep 唤醒通道 :cpp:member:`deep_slp_chan`,注意只有该指定的通道才会在 Deep-sleep 状态下保持采样以及唤醒,以此降低在 Deep-sleep 状态下的功耗。此外,若需要在深度睡眠下使用另一套低功耗的配置来进一步降低功耗,可以通过 :cpp:member:`deep_slp_sens_cfg` 额外指定一套低功耗配置,在进入 Deep-sleep 前,驱动会应用这套配置,从 Deep-sleep 状态唤醒后,则会重新配置到之前的配置。请注意当 :cpp:member:`slp_wakeup_lvl` 配置为 :cpp:enumerator:`TOUCH_DEEP_SLEEP_WAKEUP` 后,触摸传感器不仅能唤醒 Deep-sleep 状态,还能唤醒 Light-sleep 状态。
若需要注销睡眠唤醒功能,可再次调用 :cpp:func:`touch_sensor_config_sleep_wakeup` 并将第二个参数(即 :cpp:type:`touch_sleep_config_t` 的配置结构体指针)设为 ``NULL`` 来注销睡眠唤醒功能。 若需要注销睡眠唤醒功能,可再次调用 :cpp:func:`touch_sensor_config_sleep_wakeup` 并将第二个参数(即 :cpp:type:`touch_sleep_config_t` 的配置结构体指针)设为 ``NULL`` 来注销睡眠唤醒功能。
@@ -430,7 +387,7 @@
touch_sleep_config_t light_slp_cfg = { touch_sleep_config_t light_slp_cfg = {
.slp_wakeup_lvl = TOUCH_LIGHT_SLEEP_WAKEUP, .slp_wakeup_lvl = TOUCH_LIGHT_SLEEP_WAKEUP,
}; };
// 注册浅睡眠唤醒功能 // 注册 Light-sleep 唤醒功能
ESP_ERROR_CHECK(touch_sensor_config_sleep_wakeup(sens_handle, &light_slp_cfg)); ESP_ERROR_CHECK(touch_sensor_config_sleep_wakeup(sens_handle, &light_slp_cfg));
// ... // ...
// 注销睡眠唤醒功能 // 注销睡眠唤醒功能
@@ -438,21 +395,50 @@
touch_sleep_config_t deep_slp_cfg = { touch_sleep_config_t deep_slp_cfg = {
.slp_wakeup_lvl = TOUCH_DEEP_SLEEP_WAKEUP, .slp_wakeup_lvl = TOUCH_DEEP_SLEEP_WAKEUP,
.deep_slp_chan = dslp_chan_handle, .deep_slp_chan = dslp_chan_handle,
// 其他深睡眠唤醒配置 // 其他 Deep-sleep 唤醒配置
// ... // ...
}; };
// 注册深睡眠唤醒功能 // 注册 Deep-sleep 唤醒功能
ESP_ERROR_CHECK(touch_sensor_config_sleep_wakeup(sens_handle, &deep_slp_cfg)); ESP_ERROR_CHECK(touch_sensor_config_sleep_wakeup(sens_handle, &deep_slp_cfg));
.. _touch-denoise-chan:
.. only:: SOC_TOUCH_SUPPORT_DENOISE_CHAN
去噪通道配置
^^^^^^^^^^^^
{IDF_TARGET_NAME} 支持通过去噪通道抑制内部背景噪声。可通过调用 :cpp:func:`touch_sensor_config_denoise_channel` 并配置 :cpp:type:`touch_denoise_chan_config_t` 来注册去噪通道。
去噪通道是一个没有引出的内部触摸通道。去噪通道使能之后,其他触摸通道的采样值会自动减去去噪通道的采样值,从而实现去噪。因此最终测量结果相比去噪前会有一定衰减。
除了常规的触摸通道配置,去噪通道还可以配置 :cpp:member:`touch_denoise_chan_config_t::ref_cap` 来指定连接到该通道上的参考电容大小,以及 :cpp:member:`touch_denoise_chan_config_t::resolution` 来指定噪声抑制的分辨率。分辨率越高,去噪通道采样值越大越精确,抑制效果越好,但同时其他触摸通道在自动扣除去噪通道采样值后的测量值衰减也越大。
例如,去噪通道分辨率为 :cpp:enumerator:`touch_denoise_chan_resolution_t::TOUCH_DENOISE_CHAN_RESOLUTION_BIT8`,即去噪通道采样值最大为 ``255``。假设此时一个常规通道实际采样值为 ``10000``,去噪通道采样值假设为 ``100``,则该常规通道扣除去噪通道采样值后的读数为 ``10000 - 100 = 9900``;若分辨率改为 :cpp:enumerator:`touch_denoise_chan_resolution_t::TOUCH_DENOISE_CHAN_RESOLUTION_BIT12`,即去噪通道采样值最大为 ``4095``,去噪通道分辨率提升 ``16`` 倍,去噪通道采样值大概为 ``100 * 16 = 1600``。此时该常规通道扣除去噪通道采样值后的读数为 ``10000 - 1600 = 8400``
若需要注销去噪通道功能,可再次调用 :cpp:func:`touch_sensor_config_denoise_channel` 并将第二个参数(即 :cpp:type:`touch_denoise_chan_config_t` 的配置结构体指针)设为 ``NULL`` 来注销去噪通道功能。
.. code-block:: c
touch_denoise_chan_config_t denoise_cfg = {
// 去噪通道配置
// ...
}
// 注册去噪通道
ESP_ERROR_CHECK(touch_sensor_config_denoise_channel(sens_handle, &denoise_cfg));
// ...
// 注销去噪通道
ESP_ERROR_CHECK(touch_sensor_config_denoise_channel(sens_handle, NULL));
应用示例 应用示例
-------- --------
- :example:`peripherals/touch_sensor/touch_sensor_v3` 演示了如何注册触摸通道并读取数据,并说明了硬件要求及项目配置。 - :example:`peripherals/touch_sensor/touch_sens_basic` 演示了如何注册触摸通道并读取数据,并说明了硬件要求及项目配置。
API 参考 API 参考
---------- ----------
.. only:: esp32p4 .. only:: esp32p4 or esp32s2 or esp32s3
.. include-build-file:: inc/touch_sens.inc .. include-build-file:: inc/touch_sens.inc
.. include-build-file:: inc/touch_sens_types.inc .. include-build-file:: inc/touch_sens_types.inc

View File

@@ -0,0 +1,64 @@
.. This file gets included from other .rst files in this folder.
.. It contains target-specific snippets.
.. Comments and '---' lines act as delimiters.
..
.. This is necessary mainly because RST doesn't support substitutions
.. (defined in RST, not in Python) inside code blocks. If that is ever implemented,
.. These code blocks can be moved back to the main .rst files, with target-specific
.. file names being replaced by substitutions.
.. touch-chan-mapping
.. list-table::
:header-rows: 1
:widths: 20 20
* - 通道
- GPIO
* - CH0
- IO2
* - CH1
- IO3
* - CH2
- IO4
* - CH3
- IO5
* - CH4
- IO6
* - CH5
- IO7
* - CH6
- IO8
* - CH7
- IO9
* - CH8
- IO10
* - CH9
- IO11
* - CH10
- IO12
* - CH11
- IO13
* - CH12
- IO14
* - CH13
- IO15
* - CH14
- 未引出
---

View File

@@ -0,0 +1,64 @@
.. This file gets included from other .rst files in this folder.
.. It contains target-specific snippets.
.. Comments and '---' lines act as delimiters.
..
.. This is necessary mainly because RST doesn't support substitutions
.. (defined in RST, not in Python) inside code blocks. If that is ever implemented,
.. These code blocks can be moved back to the main .rst files, with target-specific
.. file names being replaced by substitutions.
.. touch-chan-mapping
.. list-table::
:header-rows: 1
:widths: 20 20
* - 通道
- GPIO
* - CH0
- 未引出
* - CH1
- IO1
* - CH2
- IO2
* - CH3
- IO3
* - CH4
- IO4
* - CH5
- IO5
* - CH6
- IO6
* - CH7
- IO7
* - CH8
- IO8
* - CH9
- IO9
* - CH10
- IO10
* - CH11
- IO11
* - CH12
- IO12
* - CH13
- IO13
* - CH14
- IO14
---

View File

@@ -0,0 +1,64 @@
.. This file gets included from other .rst files in this folder.
.. It contains target-specific snippets.
.. Comments and '---' lines act as delimiters.
..
.. This is necessary mainly because RST doesn't support substitutions
.. (defined in RST, not in Python) inside code blocks. If that is ever implemented,
.. These code blocks can be moved back to the main .rst files, with target-specific
.. file names being replaced by substitutions.
.. touch-chan-mapping
.. list-table::
:header-rows: 1
:widths: 20 20
* - 通道
- GPIO
* - CH0
- 未引出
* - CH1
- IO1
* - CH2
- IO2
* - CH3
- IO3
* - CH4
- IO4
* - CH5
- IO5
* - CH6
- IO6
* - CH7
- IO7
* - CH8
- IO8
* - CH9
- IO9
* - CH10
- IO10
* - CH11
- IO11
* - CH12
- IO12
* - CH13
- IO13
* - CH14
- IO14
---

View File

@@ -42,8 +42,8 @@
:SOC_SPI_SUPPORT_SLAVE_HD_VER2: spi_slave_hd :SOC_SPI_SUPPORT_SLAVE_HD_VER2: spi_slave_hd
:SOC_JPEG_CODEC_SUPPORTED: jpeg :SOC_JPEG_CODEC_SUPPORTED: jpeg
:SOC_TEMP_SENSOR_SUPPORTED: temp_sensor :SOC_TEMP_SENSOR_SUPPORTED: temp_sensor
:SOC_TOUCH_SENSOR_SUPPORTED and not esp32p4: touch_pad :esp32: touch_pad
:esp32p4: cap_touch_sens :SOC_TOUCH_SENSOR_SUPPORTED and not esp32: cap_touch_sens
:esp32s2: touch_element :esp32s2: touch_element
:SOC_TWAI_SUPPORTED: twai :SOC_TWAI_SUPPORTED: twai
uart uart

View File

@@ -6,7 +6,11 @@
概述 概述
-------- --------
触摸元件库是基于触摸传感器驱动设计的高度抽象的元件库,该库提供了统一且友好的软件接口,可以快速构建电容式触摸传感器的应用。有关触摸传感器驱动 API 的更多信息,请参阅 :doc:`../peripherals/touch_pad` 触摸元件库是基于触摸传感器驱动设计的高度抽象的元件库,该库提供了统一且友好的软件接口,可以快速构建电容式触摸传感器的应用。
.. warning::
目前的触摸元件库仍然基于旧的触摸传感器驱动。如您不需要使用触摸元件库,请参考新的 :doc:`电容式触摸传感器 </api-reference/peripherals/cap_touch_sens>` 驱动。
架构 架构
^^^^^^^^^^^^ ^^^^^^^^^^^^

View File

@@ -5,6 +5,12 @@
{IDF_TARGET_TOUCH_SENSOR_VERSION:default="v2", esp32="v1"} {IDF_TARGET_TOUCH_SENSOR_VERSION:default="v2", esp32="v1"}
.. only:: esp32s2 or esp32s3
.. warning::
该文档所演示的 Touch 驱动已弃用, 请移步新文档查看最新的 Touch 驱动: :doc:`Capacitive Touch Sensor </api-reference/peripherals/cap_touch_sens>`.
概述 概述
------------ ------------
@@ -146,8 +152,6 @@
该函数也可以用于检查触碰和释放触摸传感器时传感器读数变化范围,然后根据这些信息设定触摸传感器的触摸阈值。 该函数也可以用于检查触碰和释放触摸传感器时传感器读数变化范围,然后根据这些信息设定触摸传感器的触摸阈值。
请参考应用示例 :example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_read`,查看如何使用读取触摸传感器数据。
测量方式 测量方式
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -250,7 +254,7 @@
也可以将硬件触摸监测连接至中断,详细介绍见下一章节。 也可以将硬件触摸监测连接至中断,详细介绍见下一章节。
如果测量中存在噪声,且电容变化幅度较小,硬件触摸监测结果可能就不太理想。如需解决这一问题,不建议使用硬件监测或中断信号,建议在自己的应用程序中进行采样滤波,并执行触摸监测。请参考 :example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_interrupt`,查看以上两种触摸监测的实现方式。 如果测量中存在噪声,且电容变化幅度较小,硬件触摸监测结果可能就不太理想。如需解决这一问题,不建议使用硬件监测或中断信号,建议在自己的应用程序中进行采样滤波,并执行触摸监测。
中断触发 中断触发
^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -300,9 +304,9 @@
.. only:: esp32s2 or esp32s3 .. only:: esp32s2 or esp32s3
- :example:`peripherals/touch_sensor/touch_sensor_v2/touch_pad_read` 演示了如何在 {IDF_TARGET_NAME} 上读取并显示电容触摸传感器的原始值,包括如何校准传感器以及监测触摸动作。 .. warning::
- :example:`peripherals/touch_sensor/touch_sensor_v2/touch_pad_interrupt` 演示了如何设置 {IDF_TARGET_NAME} 的电容触摸板外设,使其在被触摸时触发中断,以及在需要更高触摸监测灵敏度的传感器设计中,如何通过软件来监测触摸事件。
使用老驱动的例程已移除,新驱动用法请参考 :example:`peripherals/touch_sensor/touch_sens_basic`
.. _touch_pad-api-reference: .. _touch_pad-api-reference:
@@ -321,4 +325,4 @@ GPIO 宏查找表
2. ``TOUCH_PAD_GPIO4_CHANNEL`` 定义了 GPIO 4 的通道(即通道 0 2. ``TOUCH_PAD_GPIO4_CHANNEL`` 定义了 GPIO 4 的通道(即通道 0
.. include-build-file:: inc/touch_sensor_channel.inc .. include-build-file:: inc/touch_sensor_channel.inc
.. include-build-file:: inc/touch_sensor_types.inc .. include-build-file:: inc/touch_sensor_legacy_types.inc

View File

@@ -420,24 +420,19 @@ examples/peripherals/touch_sensor/touch_element:
- if: IDF_TARGET in ["esp32s2", "esp32s3"] - if: IDF_TARGET in ["esp32s2", "esp32s3"]
reason: only supports esp32s2 and esp32s3 reason: only supports esp32s2 and esp32s3
examples/peripherals/touch_sensor/touch_sens_basic:
disable:
- if: SOC_TOUCH_SENSOR_SUPPORTED != 1
- if: SOC_TOUCH_SENSOR_VERSION == 1
temporary: true
reason: not supported yet
depends_components:
- esp_driver_touch_sens
examples/peripherals/touch_sensor/touch_sensor_v1: examples/peripherals/touch_sensor/touch_sensor_v1:
disable: disable:
- if: SOC_TOUCH_SENSOR_VERSION != 1 - if: SOC_TOUCH_SENSOR_VERSION != 1
examples/peripherals/touch_sensor/touch_sensor_v2:
disable:
- if: SOC_TOUCH_SENSOR_VERSION != 2
examples/peripherals/touch_sensor/touch_sensor_v3:
disable:
- if: SOC_TOUCH_SENSOR_VERSION != 3
disable_test:
- if: IDF_TARGET == "esp32p4"
temporary: true
reason: the runners do not support the pins for touch sensor
depends_components:
- esp_driver_touch_sens
examples/peripherals/twai/twai_alert_and_recovery: examples/peripherals/twai/twai_alert_and_recovery:
disable: disable:
- if: SOC_TWAI_SUPPORTED != 1 - if: SOC_TWAI_SUPPORTED != 1

View File

@@ -1,5 +1,5 @@
| Supported Targets | ESP32-P4 | | Supported Targets | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | -------- | | ----------------- | -------- | -------- | -------- |
# Capacity Touch Sensor Example (for hardware version 3) # Capacity Touch Sensor Example (for hardware version 3)

View File

@@ -1,3 +1,3 @@
idf_component_register(SRCS "touch_sens_v3_example_main.c" idf_component_register(SRCS "touch_sens_basic_example_main.c"
REQUIRES esp_driver_touch_sens REQUIRES esp_driver_touch_sens
INCLUDE_DIRS ".") INCLUDE_DIRS ".")

View File

@@ -10,11 +10,7 @@
#include "freertos/task.h" #include "freertos/task.h"
#include "driver/touch_sens.h" #include "driver/touch_sens.h"
#include "esp_check.h" #include "esp_check.h"
#include "touch_sens_example_config.h"
// Touch version 3 supports multiple sample configurations
#define EXAMPLE_TOUCH_SAMPLE_CFG_NUM 1 // Up to 'TOUCH_SAMPLE_CFG_NUM'
#define EXAMPLE_TOUCH_CHANNEL_NUM 4
#define EXAMPLE_TOUCH_CHAN_INIT_SCAN_TIMES 3
static touch_sensor_handle_t s_sens_handle = NULL; static touch_sensor_handle_t s_sens_handle = NULL;
static touch_channel_handle_t s_chan_handle[EXAMPLE_TOUCH_CHANNEL_NUM] = {}; static touch_channel_handle_t s_chan_handle[EXAMPLE_TOUCH_CHANNEL_NUM] = {};
@@ -22,6 +18,13 @@ static touch_channel_handle_t s_chan_handle[EXAMPLE_TOUCH_CHANNEL_NUM] = {};
static float s_thresh2bm_ratio[EXAMPLE_TOUCH_CHANNEL_NUM] = { static float s_thresh2bm_ratio[EXAMPLE_TOUCH_CHANNEL_NUM] = {
[0 ... EXAMPLE_TOUCH_CHANNEL_NUM - 1] = 0.015f, // 1.5% [0 ... EXAMPLE_TOUCH_CHANNEL_NUM - 1] = 0.015f, // 1.5%
}; };
// The touch channel IDs that used in this example
static int s_channel_id[EXAMPLE_TOUCH_CHANNEL_NUM] = {
TOUCH_MIN_CHAN_ID,
TOUCH_MIN_CHAN_ID + 1,
TOUCH_MIN_CHAN_ID + 2,
TOUCH_MIN_CHAN_ID + 3,
};
bool example_touch_on_active_callback(touch_sensor_handle_t sens_handle, const touch_active_event_data_t *event, void *user_ctx) bool example_touch_on_active_callback(touch_sensor_handle_t sens_handle, const touch_active_event_data_t *event, void *user_ctx)
{ {
@@ -56,7 +59,7 @@ static void example_touch_do_initial_scanning(void)
ESP_ERROR_CHECK(touch_channel_read_data(s_chan_handle[i], TOUCH_CHAN_DATA_TYPE_BENCHMARK, benchmark)); ESP_ERROR_CHECK(touch_channel_read_data(s_chan_handle[i], TOUCH_CHAN_DATA_TYPE_BENCHMARK, benchmark));
/* Calculate the proper active thresholds regarding the initial benchmark */ /* Calculate the proper active thresholds regarding the initial benchmark */
printf("[CH %d]", i); printf("[CH %d]", i);
touch_channel_config_t chan_cfg = {}; touch_channel_config_t chan_cfg = EXAMPLE_TOUCH_CHAN_CFG_DEFAULT();
for (int j = 0; j < EXAMPLE_TOUCH_SAMPLE_CFG_NUM; j++) { for (int j = 0; j < EXAMPLE_TOUCH_SAMPLE_CFG_NUM; j++) {
chan_cfg.active_thresh[j] = (uint32_t)(benchmark[j] * s_thresh2bm_ratio[i]); chan_cfg.active_thresh[j] = (uint32_t)(benchmark[j] * s_thresh2bm_ratio[i]);
printf(" %d: %"PRIu32", %"PRIu32"\t", j, benchmark[j], chan_cfg.active_thresh[j]); printf(" %d: %"PRIu32", %"PRIu32"\t", j, benchmark[j], chan_cfg.active_thresh[j]);
@@ -70,15 +73,7 @@ static void example_touch_do_initial_scanning(void)
void app_main(void) void app_main(void)
{ {
/* Use the default sample configurations */ /* Use the default sample configurations */
touch_sensor_sample_config_t sample_cfg[EXAMPLE_TOUCH_SAMPLE_CFG_NUM] = { touch_sensor_sample_config_t sample_cfg[EXAMPLE_TOUCH_SAMPLE_CFG_NUM] = EXAMPLE_TOUCH_SAMPLE_CFG_DEFAULT();
TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG(1, 1, 1),
#if EXAMPLE_TOUCH_SAMPLE_CFG_NUM > 1
TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG(2, 1, 1),
#endif
#if EXAMPLE_TOUCH_SAMPLE_CFG_NUM > 2
TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG(4, 1, 1),
#endif
};
/* Allocate new touch controller handle */ /* Allocate new touch controller handle */
touch_sensor_config_t sens_cfg = TOUCH_SENSOR_DEFAULT_BASIC_CONFIG(EXAMPLE_TOUCH_SAMPLE_CFG_NUM, sample_cfg); touch_sensor_config_t sens_cfg = TOUCH_SENSOR_DEFAULT_BASIC_CONFIG(EXAMPLE_TOUCH_SAMPLE_CFG_NUM, sample_cfg);
ESP_ERROR_CHECK(touch_sensor_new_controller(&sens_cfg, &s_sens_handle)); ESP_ERROR_CHECK(touch_sensor_new_controller(&sens_cfg, &s_sens_handle));
@@ -87,9 +82,7 @@ void app_main(void)
touch_sensor_filter_config_t filter_cfg = TOUCH_SENSOR_DEFAULT_FILTER_CONFIG(); touch_sensor_filter_config_t filter_cfg = TOUCH_SENSOR_DEFAULT_FILTER_CONFIG();
ESP_ERROR_CHECK(touch_sensor_config_filter(s_sens_handle, &filter_cfg)); ESP_ERROR_CHECK(touch_sensor_config_filter(s_sens_handle, &filter_cfg));
/* Allocate new touch channel on the touch controller */ /** Following is about setting the touch channel active threshold of each sample configuration.
touch_channel_config_t chan_cfg = {
/** Set the touch channel active threshold of each sample configuration.
* *
* @How to Determine: * @How to Determine:
* As the actual threshold is affected by various factors in real application, * As the actual threshold is affected by various factors in real application,
@@ -106,18 +99,10 @@ void app_main(void)
* Step2: then reconfig the threshold after the initial scanning.(see `example_touch_do_initial_scanning`) * Step2: then reconfig the threshold after the initial scanning.(see `example_touch_do_initial_scanning`)
* Step3: adjust the `s_thresh2bm_ratio` to a proper value to trigger the active callback * Step3: adjust the `s_thresh2bm_ratio` to a proper value to trigger the active callback
*/ */
.active_thresh = { touch_channel_config_t chan_cfg = EXAMPLE_TOUCH_CHAN_CFG_DEFAULT();
1000, // estimated active threshold of sample configuration 0 /* Allocate new touch channel on the touch controller */
#if EXAMPLE_TOUCH_SAMPLE_CFG_NUM > 1
2500, // estimated active threshold of sample configuration 1
#endif
#if EXAMPLE_TOUCH_SAMPLE_CFG_NUM > 2
5000, // estimated active threshold of sample configuration 2
#endif
},
};
for (int i = 0; i < EXAMPLE_TOUCH_CHANNEL_NUM; i++) { for (int i = 0; i < EXAMPLE_TOUCH_CHANNEL_NUM; i++) {
ESP_ERROR_CHECK(touch_sensor_new_channel(s_sens_handle, i, &chan_cfg, &s_chan_handle[i])); ESP_ERROR_CHECK(touch_sensor_new_channel(s_sens_handle, s_channel_id[i], &chan_cfg, &s_chan_handle[i]));
} }
/* Do the initial scanning to initialize the touch channel data /* Do the initial scanning to initialize the touch channel data
@@ -149,14 +134,14 @@ void app_main(void)
for (int i = 0; i < EXAMPLE_TOUCH_CHANNEL_NUM; i++) { for (int i = 0; i < EXAMPLE_TOUCH_CHANNEL_NUM; i++) {
/* Read and print the benchmark of each sample configuration */ /* Read and print the benchmark of each sample configuration */
ESP_ERROR_CHECK(touch_channel_read_data(s_chan_handle[i], TOUCH_CHAN_DATA_TYPE_BENCHMARK, benchmark)); ESP_ERROR_CHECK(touch_channel_read_data(s_chan_handle[i], TOUCH_CHAN_DATA_TYPE_BENCHMARK, benchmark));
printf("benchmark [CH %d]:", i); printf("benchmark [CH %d]:", s_channel_id[i]);
for (int j = 0; j < EXAMPLE_TOUCH_SAMPLE_CFG_NUM; j++) { for (int j = 0; j < EXAMPLE_TOUCH_SAMPLE_CFG_NUM; j++) {
printf(" %"PRIu32, benchmark[j]); printf(" %"PRIu32, benchmark[j]);
} }
printf("\n"); printf("\n");
/* Read and print the channel data of each sample configuration */ /* Read and print the channel data of each sample configuration */
ESP_ERROR_CHECK(touch_channel_read_data(s_chan_handle[i], TOUCH_CHAN_DATA_TYPE_SMOOTH, chan_data)); ESP_ERROR_CHECK(touch_channel_read_data(s_chan_handle[i], TOUCH_CHAN_DATA_TYPE_SMOOTH, chan_data));
printf("chan_data [CH %d]:", i); printf("chan_data [CH %d]:", s_channel_id[i]);
for (int j = 0; j < EXAMPLE_TOUCH_SAMPLE_CFG_NUM; j++) { for (int j = 0; j < EXAMPLE_TOUCH_SAMPLE_CFG_NUM; j++) {
printf(" %"PRIu32, chan_data[j]); printf(" %"PRIu32, chan_data[j]);
} }

View File

@@ -0,0 +1,54 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#pragma once
#include "driver/touch_sens.h"
#include "esp_assert.h"
#ifdef __cplusplus
extern "C" {
#endif
// Touch version 3 supports multiple sample configurations
#define EXAMPLE_TOUCH_SAMPLE_CFG_NUM TOUCH_SAMPLE_CFG_NUM // Up to 'TOUCH_SAMPLE_CFG_NUM'
#define EXAMPLE_TOUCH_CHANNEL_NUM 4
#define EXAMPLE_TOUCH_CHAN_INIT_SCAN_TIMES 3
ESP_STATIC_ASSERT(EXAMPLE_TOUCH_SAMPLE_CFG_NUM <= TOUCH_SAMPLE_CFG_NUM, "sample configuration number exceed the supported number");
ESP_STATIC_ASSERT(EXAMPLE_TOUCH_CHANNEL_NUM <= (TOUCH_MAX_CHAN_ID - TOUCH_MIN_CHAN_ID + 1), "touch channel number exceed the max supported number ");
#if SOC_TOUCH_SENSOR_VERSION == 2
#define EXAMPLE_TOUCH_SAMPLE_CFG_DEFAULT() {TOUCH_SENSOR_V2_DEFAULT_SAMPLE_CONFIG(500, TOUCH_VOLT_LIM_L_0V5, TOUCH_VOLT_LIM_H_2V2)}
#define EXAMPLE_TOUCH_CHAN_CFG_DEFAULT() { \
.active_thresh = {2000}, \
.charge_speed = TOUCH_CHARGE_SPEED_7, \
.init_charge_volt = TOUCH_INIT_CHARGE_VOLT_LOW, \
}
#elif SOC_TOUCH_SENSOR_VERSION == 3
#define EXAMPLE_TOUCH_SAMPLE_CFG(res, cap, coarse_freq_tune, fine_freq_tune) { \
.div_num = 8, \
.charge_times = 500, \
.rc_filter_res = res, \
.rc_filter_cap = cap, \
.low_drv = fine_freq_tune, \
.high_drv = coarse_freq_tune, \
.bias_volt = 5, \
.bypass_shield_output = false, \
}
#define EXAMPLE_TOUCH_SAMPLE_CFG_DEFAULT() {EXAMPLE_TOUCH_SAMPLE_CFG(3, 29, 8, 3),\
EXAMPLE_TOUCH_SAMPLE_CFG(2, 88, 31, 7), \
EXAMPLE_TOUCH_SAMPLE_CFG(3, 10, 31, 7)}
#define EXAMPLE_TOUCH_CHAN_CFG_DEFAULT() { \
.active_thresh = {1000, 2500, 5000}, \
}
#else
#error "Target not supported"
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -4,8 +4,9 @@ import pytest
from pytest_embedded import Dut from pytest_embedded import Dut
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.esp32p4 @pytest.mark.esp32p4
@pytest.mark.temp_skip_ci(targets=['esp32p4'], reason='esp32p4 runners do not support touch pins')
@pytest.mark.generic @pytest.mark.generic
def test_touch_sens_v3(dut: Dut) -> None: def test_touch_sens_v3(dut: Dut) -> None:
dut.expect_exact('Initial benchmark and new threshold are:') dut.expect_exact('Initial benchmark and new threshold are:')

View File

@@ -1,6 +0,0 @@
# 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.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(touch_pad_interrupt)

View File

@@ -1,60 +0,0 @@
| Supported Targets | ESP32-S2 | ESP32-S3 |
| ----------------- | -------- | -------- |
# Touch Pad Interrupt Example
(See the README.md file in the upper level 'examples' directory for more information about examples.)
This example demonstrates how to set up ESP32-S2/S3'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.
- The hardware interrupt mode occupies less CPU resources, but we can only apply fixed threshold and software algorithms are also impossibile.
- The polling mode is flexible and supports various software algorithms. However, it comsumes more CPU.
ESP32-S2/S3 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.
For a simpler example how to configure and read capacitive touch pads, please refer to [touch_pad_read](../touch_pad_read).
## How to use example
### Hardware Required
* A development board with ESP32-S2 or ESP32-S3 chip
* A touch extension board like [esp32-s2-touch-devkit-1](https://docs.espressif.com/projects/espressif-esp-dev-kits/en/latest/esp32s2/esp32-s2-touch-devkit-1/user_guide.html)
### Build and Flash
Build the project and flash it to the board, then run monitor tool to view serial output:
```
idf.py -p PORT flash monitor
```
(Replace PORT with the name of the serial port to use.)
(To exit the serial monitor, type ``Ctrl-]``.)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
## Example Output
The application cycles between the interrupt mode and the pooling mode with a filter, to compare performance of the touch sensor system between 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
```
## Troubleshooting
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.

View File

@@ -1,2 +0,0 @@
idf_component_register(SRCS "tp_interrupt_main.c"
INCLUDE_DIRS ".")

View File

@@ -1,211 +0,0 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#include <stdio.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "esp_log.h"
#include "driver/touch_pad.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_num;
uint32_t pad_status;
uint32_t pad_val;
} 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 = touch_pad_get_status();
evt.pad_num = 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 %"PRIu32", thresh %"PRIu32, \
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)
{
touch_event_t evt = {0};
static uint8_t guard_mode_flag = 0;
/* Wait touch sensor init done */
vTaskDelay(50 / portTICK_PERIOD_MS);
tp_example_set_thresholds();
while (1) {
int ret = xQueueReceive(que_touch, &evt, (TickType_t)portMAX_DELAY);
if (ret != pdTRUE) {
continue;
}
if (evt.intr_mask & TOUCH_PAD_INTR_MASK_ACTIVE) {
/* if guard pad be touched, other pads no response. */
if (evt.pad_num == button[3]) {
guard_mode_flag = 1;
ESP_LOGW(TAG, "TouchSensor [%"PRIu32"] be activated, enter guard mode", evt.pad_num);
} else {
if (guard_mode_flag == 0) {
ESP_LOGI(TAG, "TouchSensor [%"PRIu32"] be activated, status mask 0x%"PRIu32"", evt.pad_num, evt.pad_status);
} else {
ESP_LOGW(TAG, "In guard mode. No response");
}
}
}
if (evt.intr_mask & TOUCH_PAD_INTR_MASK_INACTIVE) {
/* if guard pad be touched, other pads no response. */
if (evt.pad_num == button[3]) {
guard_mode_flag = 0;
ESP_LOGW(TAG, "TouchSensor [%"PRIu32"] be inactivated, exit guard mode", evt.pad_num);
} else {
if (guard_mode_flag == 0) {
ESP_LOGI(TAG, "TouchSensor [%"PRIu32"] be inactivated, status mask 0x%"PRIu32, evt.pad_num, evt.pad_status);
}
}
}
if (evt.intr_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) {
ESP_LOGI(TAG, "The touch sensor group measurement is done [%"PRIu32"].", evt.pad_num);
}
if (evt.intr_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) {
/* Add your exception handling in here. */
ESP_LOGI(TAG, "Touch sensor channel %"PRIu32" measure timeout. Skip this exception channel!!", evt.pad_num);
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_measurement_interval(TOUCH_PAD_SLEEP_CYCLE_DEFAULT);
touch_pad_set_charge_discharge_times(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(button[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, 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);
/* 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", 4096, NULL, 5, NULL);
}

View File

@@ -1,15 +0,0 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import pytest
from pytest_embedded import Dut
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.generic
def test_touch_pad_interrupt_v2(dut: Dut) -> None:
dut.expect_exact('Touch pad: Initializing touch pad')
dut.expect_exact('Touch pad: Denoise function init')
dut.expect_exact('Touch pad: touch pad waterproof init')
dut.expect_exact('Touch pad: touch pad filter init')
dut.expect(r'touch pad \[\d+\] base \d+, thresh \d+')

View File

@@ -1,6 +0,0 @@
# 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.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(touch_pad_read)

View File

@@ -1,50 +0,0 @@
| Supported Targets | ESP32-S2 | ESP32-S3 |
| ----------------- | -------- | -------- |
# Touch Pad Read Example
(See the README.md file in the upper level 'examples' directory for more information about examples.)
Read and display raw values from capacitive touch pad sensors.
Once configured, ESP32S2/S3 will continuously measure capacitance of touch pad sensors. Measurement is reflected as numeric value inversely related to sensor's capacitance. With a finger touched on a pad, its capacitance will get larger meanwhile the measured value gets smaller, and vice versa.
To detect if a sensor is touched or not, each particular design should be calibrated by obtaining both measurements for each individual sensor. Then a threshold between both values can be established. With specific threshold, API is then able to distinguish whether specific sensor is touched or released. For ESP32-S2/S3, the hardware integrates the edge detection algorithm, which can achieve the purpose of detecting touch actions by configuring appropriate parameters. There is another similar example that demonstrates how to perform simple calibration and trigger an interrupt when a pad is touched - see [touch_pad_interrupt](../touch_pad_interrupt).
## How to use example
### Hardware Required
* A development board with ESP32-S2 or ESP32-S3 chip
* A touch extension board like [esp32-s2-touch-devkit-1](https://docs.espressif.com/projects/espressif-esp-dev-kits/en/latest/esp32s2/esp32-s2-touch-devkit-1/user_guide.html)
### Build and Flash
Build the project and flash it to the board, then run monitor tool to view serial output:
```
idf.py -p PORT flash monitor
```
(Replace PORT with the name of the serial port to use.)
(To exit the serial monitor, type ``Ctrl-]``.)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
## Example Output
ESP32-S2/S3 supports up to 14 capacitive touch pads, T1 - T14, which are connected to the specific GPIO pins. For the information of available pins please refer to ESP32-S2/S3 Technical Reference Manual. Note that T0 is an internal channel with no corresponding GPIO, it is mainly used for de-noise. This example will initialize all the 14 touch pads. The raw values of each pad can be monitored in the terminal:
```
Touch Sensor read, the output format is:
Touchpad num:[raw data]
T1: [6473] T2: [6507] T3: [6638] T4: [8917] T5: [9053] T6: [7190] T7: [7176] T8: [7416] T9: [7145] T10: [7387] T11: [7973] T12: [7776] T13: [8151] T14: [8190]
T1: [6463] T2: [6512] T3: [6643] T4: [8920] T5: [9050] T6: [7191] T7: [7176] T8: [7416] T9: [7143] T10: [7387] T11: [7974] T12: [7778] T13: [8152] T14: [8192]
T1: [6476] T2: [6508] T3: [6641] T4: [8919] T5: [9053] T6: [7190] T7: [7177] T8: [7416] T9: [7143] T10: [7386] T11: [7974] T12: [7776] T13: [8153] T14: [8193]
```
## Troubleshooting
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.

View File

@@ -1,2 +0,0 @@
idf_component_register(SRCS "tp_read_main.c"
INCLUDE_DIRS ".")

View File

@@ -1,90 +0,0 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#include <stdio.h>
#include <inttypes.h>
#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_PERIOD_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: [%4"PRIu32"] ", 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_measurement_interval(TOUCH_PAD_SLEEP_CYCLE_DEFAULT);
touch_pad_set_charge_discharge_times(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(button[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", 4096, NULL, 5, NULL);
}

View File

@@ -1,13 +0,0 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import pytest
from pytest_embedded import Dut
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.generic
def test_touch_pad_read_v2(dut: Dut) -> None:
dut.expect_exact('touch read: Denoise function init')
dut.expect(r'T1: \[\d+\] T2: \[\d+\] T3: \[\d+\] T4: \[\d+\] T5: \[\d+\] T6: \[\d+\] T7: \[\d+\] T8: \[\d+\] T9: \[\d+\]'
r' T10: \[\d+\] T11: \[\d+\] T12: \[\d+\] T13: \[\d+\] T14: \[\d+\]')

View File

@@ -3,7 +3,7 @@ menu "Example Configuration"
config EXAMPLE_TOUCH_WAKEUP config EXAMPLE_TOUCH_WAKEUP
bool "Enable touch wake up" bool "Enable touch wake up"
default y default y
depends on SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP depends on SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP && !IDF_TARGET_ESP32P4
help help
This option enables wake up from deep sleep using touch pads. This option enables wake up from deep sleep using touch pads.
ESP32 - TOUCH8 and TOUCH9, which correspond to GPIO33 and GPIO32. ESP32 - TOUCH8 and TOUCH9, which correspond to GPIO33 and GPIO32.

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */

View File

@@ -6,3 +6,4 @@ CONFIG_NEWLIB_TIME_SYSCALL_USE_RTC_HRT=y
CONFIG_RTC_CLK_SRC_INT_RC=y CONFIG_RTC_CLK_SRC_INT_RC=y
CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP=y CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP=y
CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_TOUCH_SUPPRESS_DEPRECATE_WARN=y

View File

@@ -10,7 +10,7 @@
#include "esp_sleep.h" #include "esp_sleep.h"
#include "ulp_riscv.h" #include "ulp_riscv.h"
#include "ulp_main.h" #include "ulp_main.h"
#include "driver/touch_pad.h" #include "driver/touch_sensor.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"

View File

@@ -7,3 +7,4 @@ CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
CONFIG_BOOTLOADER_LOG_LEVEL=2 CONFIG_BOOTLOADER_LOG_LEVEL=2
CONFIG_LOG_DEFAULT_LEVEL_WARN=y CONFIG_LOG_DEFAULT_LEVEL_WARN=y
CONFIG_LOG_DEFAULT_LEVEL=2 CONFIG_LOG_DEFAULT_LEVEL=2
CONFIG_TOUCH_SUPPRESS_DEPRECATE_WARN=y