Merge branch 'feature/touch_sensor_driver_support_for_esp32s3' into 'master'

driver(touch): support touch sensor for esp32s3 platform

Closes IDF-1784 and IDF-3302

See merge request espressif/esp-idf!14102
This commit is contained in:
Kevin (Lao Kaiyao) 2021-10-12 05:50:58 +00:00
commit a9faafee3c
82 changed files with 1237 additions and 577 deletions

View File

@ -60,7 +60,9 @@ if(${target} STREQUAL "esp32s3")
"mcpwm.c"
"usb_serial_jtag.c"
"spi_slave_hd.c"
"touch_sensor_common.c")
"touch_sensor_common.c"
"esp32s3/touch_sensor.c"
)
endif()
if(IDF_TARGET STREQUAL "esp32c3")

View File

@ -21,6 +21,7 @@
#include "driver/touch_pad.h"
#include "driver/rtc_cntl.h"
#include "driver/gpio.h"
#include "esp_check.h"
#ifndef NDEBUG
// Enable built-in checks in queue.h in debug builds
@ -49,13 +50,9 @@ static SemaphoreHandle_t rtc_touch_mux = NULL;
#define TOUCH_PAD_SHIFT_ROUND_DEFAULT (8) // ROUND = 2^(n-1); rounding off for fractional.
static const char *TOUCH_TAG = "TOUCH_SENSOR";
#define TOUCH_CHECK(a, str, ret_val) ({ \
if (!(a)) { \
ESP_LOGE(TOUCH_TAG,"%s(%d): %s", __FUNCTION__, __LINE__, str); \
return (ret_val); \
} \
})
#define TOUCH_CHANNEL_CHECK(channel) TOUCH_CHECK(channel < SOC_TOUCH_SENSOR_NUM, "Touch channel error", ESP_ERR_INVALID_ARG)
#define TOUCH_CHANNEL_CHECK(channel) ESP_RETURN_ON_FALSE(channel < SOC_TOUCH_SENSOR_NUM, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch channel error");
#define TOUCH_NULL_POINTER_CHECK(p, name) ESP_RETURN_ON_FALSE((p), ESP_ERR_INVALID_ARG, TOUCH_TAG, "input param '"name"' is NULL")
#define TOUCH_PARAM_CHECK_STR(s) ""s" parameter error"
extern portMUX_TYPE rtc_spinlock; //TODO: Will be placed in the appropriate position after the rtc module is finished.
@ -72,13 +69,13 @@ static esp_err_t _touch_pad_read(touch_pad_t touch_num, uint16_t *touch_value, t
esp_err_t touch_pad_isr_handler_register(void (*fn)(void *), void *arg, int no_use, intr_handle_t *handle_no_use)
{
TOUCH_CHECK(fn, "Touch_Pad ISR null", ESP_ERR_INVALID_ARG);
ESP_RETURN_ON_FALSE(fn, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch_Pad ISR null");
return rtc_isr_register(fn, arg, RTC_CNTL_TOUCH_INT_ST_M);
}
esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg)
{
TOUCH_CHECK(fn, "Touch_Pad ISR null", ESP_ERR_INVALID_ARG);
ESP_RETURN_ON_FALSE(fn, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch_Pad ISR null");
return rtc_isr_register(fn, arg, RTC_CNTL_TOUCH_INT_ST_M);
}
@ -121,7 +118,7 @@ static void touch_pad_filter_cb(void *arg)
}
xTimerReset(s_touch_pad_filter->timer, portMAX_DELAY);
xSemaphoreGive(rtc_touch_mux);
if (s_filter_cb != NULL) {
if (s_filter_cb) {
//return the raw data and filtered data.
s_filter_cb(s_touch_pad_filter->raw_val, s_touch_pad_filter->filtered_val);
}
@ -139,6 +136,8 @@ esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_cycle)
esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_cycle)
{
TOUCH_NULL_POINTER_CHECK(sleep_cycle, "sleep_cycle");
TOUCH_NULL_POINTER_CHECK(meas_cycle, "meas_cycle");
TOUCH_ENTER_CRITICAL();
touch_hal_get_meas_time(meas_cycle);
touch_hal_get_sleep_time(sleep_cycle);
@ -149,7 +148,7 @@ esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_cycle)
esp_err_t touch_pad_set_trigger_mode(touch_trigger_mode_t mode)
{
TOUCH_CHECK((mode < TOUCH_TRIGGER_MAX), TOUCH_PARAM_CHECK_STR("mode"), ESP_ERR_INVALID_ARG);
ESP_RETURN_ON_FALSE((mode < TOUCH_TRIGGER_MAX), ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("mode"));
TOUCH_ENTER_CRITICAL();
touch_hal_set_trigger_mode(mode);
TOUCH_EXIT_CRITICAL();
@ -158,13 +157,14 @@ esp_err_t touch_pad_set_trigger_mode(touch_trigger_mode_t mode)
esp_err_t touch_pad_get_trigger_mode(touch_trigger_mode_t *mode)
{
TOUCH_NULL_POINTER_CHECK(mode, "mode");
touch_hal_get_trigger_mode(mode);
return ESP_OK;
}
esp_err_t touch_pad_set_trigger_source(touch_trigger_src_t src)
{
TOUCH_CHECK((src < TOUCH_TRIGGER_SOURCE_MAX), TOUCH_PARAM_CHECK_STR("src"), ESP_ERR_INVALID_ARG);
ESP_RETURN_ON_FALSE((src < TOUCH_TRIGGER_SOURCE_MAX), ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("src"));
TOUCH_ENTER_CRITICAL();
touch_hal_set_trigger_source(src);
TOUCH_EXIT_CRITICAL();
@ -173,15 +173,16 @@ esp_err_t touch_pad_set_trigger_source(touch_trigger_src_t src)
esp_err_t touch_pad_get_trigger_source(touch_trigger_src_t *src)
{
TOUCH_NULL_POINTER_CHECK(src, "src");
touch_hal_get_trigger_source(src);
return ESP_OK;
}
esp_err_t touch_pad_set_group_mask(uint16_t set1_mask, uint16_t set2_mask, uint16_t en_mask)
{
TOUCH_CHECK((set1_mask <= TOUCH_PAD_BIT_MASK_ALL), "touch set1 bitmask error", ESP_ERR_INVALID_ARG);
TOUCH_CHECK((set2_mask <= TOUCH_PAD_BIT_MASK_ALL), "touch set2 bitmask error", ESP_ERR_INVALID_ARG);
TOUCH_CHECK((en_mask <= TOUCH_PAD_BIT_MASK_ALL), "touch work_en bitmask error", ESP_ERR_INVALID_ARG);
ESP_RETURN_ON_FALSE((set1_mask <= TOUCH_PAD_BIT_MASK_ALL), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch set1 bitmask error");
ESP_RETURN_ON_FALSE((set2_mask <= TOUCH_PAD_BIT_MASK_ALL), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch set2 bitmask error");
ESP_RETURN_ON_FALSE((en_mask <= TOUCH_PAD_BIT_MASK_ALL), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch work_en bitmask error");
TOUCH_ENTER_CRITICAL();
touch_hal_set_group_mask(set1_mask, set2_mask);
@ -193,6 +194,9 @@ esp_err_t touch_pad_set_group_mask(uint16_t set1_mask, uint16_t set2_mask, uint1
esp_err_t touch_pad_get_group_mask(uint16_t *set1_mask, uint16_t *set2_mask, uint16_t *en_mask)
{
TOUCH_NULL_POINTER_CHECK(set1_mask, "set1_mask");
TOUCH_NULL_POINTER_CHECK(set2_mask, "set2_mask");
TOUCH_NULL_POINTER_CHECK(en_mask, "en_mask");
TOUCH_ENTER_CRITICAL();
touch_hal_get_channel_mask(en_mask);
touch_hal_get_group_mask(set1_mask, set2_mask);
@ -203,9 +207,9 @@ esp_err_t touch_pad_get_group_mask(uint16_t *set1_mask, uint16_t *set2_mask, uin
esp_err_t touch_pad_clear_group_mask(uint16_t set1_mask, uint16_t set2_mask, uint16_t en_mask)
{
TOUCH_CHECK((set1_mask <= TOUCH_PAD_BIT_MASK_ALL), "touch set1 bitmask error", ESP_ERR_INVALID_ARG);
TOUCH_CHECK((set2_mask <= TOUCH_PAD_BIT_MASK_ALL), "touch set2 bitmask error", ESP_ERR_INVALID_ARG);
TOUCH_CHECK((en_mask <= TOUCH_PAD_BIT_MASK_ALL), "touch work_en bitmask error", ESP_ERR_INVALID_ARG);
ESP_RETURN_ON_FALSE((set1_mask <= TOUCH_PAD_BIT_MASK_ALL), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch set1 bitmask error");
ESP_RETURN_ON_FALSE((set2_mask <= TOUCH_PAD_BIT_MASK_ALL), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch set2 bitmask error");
ESP_RETURN_ON_FALSE((en_mask <= TOUCH_PAD_BIT_MASK_ALL), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch work_en bitmask error");
TOUCH_ENTER_CRITICAL();
touch_hal_clear_channel_mask(en_mask);
@ -245,7 +249,7 @@ bool touch_pad_meas_is_done(void)
esp_err_t touch_pad_config(touch_pad_t touch_num, uint16_t threshold)
{
TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL);
ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_FAIL, TOUCH_TAG, "Touch pad not initialized");
TOUCH_CHANNEL_CHECK(touch_num);
touch_fsm_mode_t mode;
touch_pad_io_init(touch_num);
@ -297,8 +301,8 @@ esp_err_t touch_pad_init(void)
esp_err_t touch_pad_deinit(void)
{
TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL);
if (s_touch_pad_filter != NULL) {
ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_FAIL, TOUCH_TAG, "Touch pad not initialized");
if (s_touch_pad_filter) {
touch_pad_filter_stop();
touch_pad_filter_delete();
}
@ -337,8 +341,8 @@ static esp_err_t _touch_pad_read(touch_pad_t touch_num, uint16_t *touch_value, t
esp_err_t touch_pad_read(touch_pad_t touch_num, uint16_t *touch_value)
{
TOUCH_CHANNEL_CHECK(touch_num);
TOUCH_CHECK(touch_value != NULL, "touch_value", ESP_ERR_INVALID_ARG);
TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL);
TOUCH_NULL_POINTER_CHECK(touch_value, "touch_value");
ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_FAIL, TOUCH_TAG, "Touch pad not initialized");
esp_err_t res = ESP_OK;
touch_fsm_mode_t mode;
@ -351,10 +355,10 @@ esp_err_t touch_pad_read(touch_pad_t touch_num, uint16_t *touch_value)
IRAM_ATTR esp_err_t touch_pad_read_raw_data(touch_pad_t touch_num, uint16_t *touch_value)
{
TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL);
ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_FAIL, TOUCH_TAG, "Touch pad not initialized");
TOUCH_CHANNEL_CHECK(touch_num);
TOUCH_CHECK(touch_value != NULL, "touch_value", ESP_ERR_INVALID_ARG);
TOUCH_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_FAIL);
TOUCH_NULL_POINTER_CHECK(touch_value, "touch_value");
ESP_RETURN_ON_FALSE(s_touch_pad_filter, ESP_FAIL, TOUCH_TAG, "Touch pad filter not initialized");
*touch_value = s_touch_pad_filter->raw_val[touch_num];
if (*touch_value == 0) {
return ESP_ERR_INVALID_STATE;
@ -364,10 +368,10 @@ IRAM_ATTR esp_err_t touch_pad_read_raw_data(touch_pad_t touch_num, uint16_t *tou
IRAM_ATTR esp_err_t touch_pad_read_filtered(touch_pad_t touch_num, uint16_t *touch_value)
{
TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL);
ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_FAIL, TOUCH_TAG, "Touch pad not initialized");
TOUCH_CHANNEL_CHECK(touch_num);
TOUCH_CHECK(touch_value != NULL, "touch_value", ESP_ERR_INVALID_ARG);
TOUCH_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_FAIL);
TOUCH_NULL_POINTER_CHECK(touch_value, "touch_value");
ESP_RETURN_ON_FALSE(s_touch_pad_filter, ESP_FAIL, TOUCH_TAG, "Touch pad filter not initialized");
*touch_value = (s_touch_pad_filter->filtered_val[touch_num]);
if (*touch_value == 0) {
return ESP_ERR_INVALID_STATE;
@ -377,13 +381,13 @@ IRAM_ATTR esp_err_t touch_pad_read_filtered(touch_pad_t touch_num, uint16_t *tou
esp_err_t touch_pad_set_filter_period(uint32_t new_period_ms)
{
TOUCH_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE);
TOUCH_CHECK(new_period_ms > 0, "Touch pad filter period error", ESP_ERR_INVALID_ARG);
TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_ERR_INVALID_STATE);
ESP_RETURN_ON_FALSE(s_touch_pad_filter, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad filter not initialized");
ESP_RETURN_ON_FALSE(new_period_ms > 0, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch pad filter period error");
ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad not initialized");
esp_err_t ret = ESP_OK;
xSemaphoreTake(rtc_touch_mux, portMAX_DELAY);
if (s_touch_pad_filter != NULL) {
if (s_touch_pad_filter) {
xTimerChangePeriod(s_touch_pad_filter->timer, new_period_ms / portTICK_PERIOD_MS, portMAX_DELAY);
s_touch_pad_filter->period = new_period_ms;
} else {
@ -396,13 +400,13 @@ esp_err_t touch_pad_set_filter_period(uint32_t new_period_ms)
esp_err_t touch_pad_get_filter_period(uint32_t *p_period_ms)
{
TOUCH_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE);
TOUCH_CHECK(p_period_ms != NULL, "Touch pad period pointer error", ESP_ERR_INVALID_ARG);
TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_ERR_INVALID_STATE);
ESP_RETURN_ON_FALSE(s_touch_pad_filter, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad filter not initialized");
TOUCH_NULL_POINTER_CHECK(p_period_ms, "p_period_ms");
ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad not initialized");
esp_err_t ret = ESP_OK;
xSemaphoreTake(rtc_touch_mux, portMAX_DELAY);
if (s_touch_pad_filter != NULL) {
if (s_touch_pad_filter) {
*p_period_ms = s_touch_pad_filter->period;
} else {
ESP_LOGE(TOUCH_TAG, "Touch pad filter deleted");
@ -414,8 +418,8 @@ esp_err_t touch_pad_get_filter_period(uint32_t *p_period_ms)
esp_err_t touch_pad_filter_start(uint32_t filter_period_ms)
{
TOUCH_CHECK(filter_period_ms >= portTICK_PERIOD_MS, "Touch pad filter period error", ESP_ERR_INVALID_ARG);
TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_ERR_INVALID_STATE);
ESP_RETURN_ON_FALSE(filter_period_ms >= portTICK_PERIOD_MS, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch pad filter period error");
ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad not initialized");
xSemaphoreTake(rtc_touch_mux, portMAX_DELAY);
if (s_touch_pad_filter == NULL) {
@ -445,11 +449,11 @@ err_no_mem:
esp_err_t touch_pad_filter_stop(void)
{
TOUCH_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE);
TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_ERR_INVALID_STATE);
ESP_RETURN_ON_FALSE(s_touch_pad_filter, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad filter not initialized");
ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad not initialized");
esp_err_t ret = ESP_OK;
xSemaphoreTake(rtc_touch_mux, portMAX_DELAY);
if (s_touch_pad_filter != NULL) {
if (s_touch_pad_filter) {
xTimerStop(s_touch_pad_filter->timer, portMAX_DELAY);
} else {
ESP_LOGE(TOUCH_TAG, "Touch pad filter deleted");
@ -461,11 +465,11 @@ esp_err_t touch_pad_filter_stop(void)
esp_err_t touch_pad_filter_delete(void)
{
TOUCH_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE);
TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_ERR_INVALID_STATE);
ESP_RETURN_ON_FALSE(s_touch_pad_filter, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad filter not initialized");
ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_ERR_INVALID_STATE, TOUCH_TAG, "Touch pad not initialized");
xSemaphoreTake(rtc_touch_mux, portMAX_DELAY);
if (s_touch_pad_filter != NULL) {
if (s_touch_pad_filter->timer != NULL) {
if (s_touch_pad_filter) {
if (s_touch_pad_filter->timer) {
xTimerStop(s_touch_pad_filter->timer, portMAX_DELAY);
xTimerDelete(s_touch_pad_filter->timer, portMAX_DELAY);
s_touch_pad_filter->timer = NULL;

View File

@ -293,7 +293,7 @@ esp_err_t touch_pad_reset_benchmark(touch_pad_t touch_num);
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_filter_set_config(touch_filter_config_t *filter_info);
esp_err_t touch_pad_filter_set_config(const touch_filter_config_t *filter_info);
/**
* @brief get parameter of touch sensor filter and detection algorithm.
@ -331,7 +331,7 @@ esp_err_t touch_pad_filter_disable(void);
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_set_config(touch_pad_denoise_t *denoise);
esp_err_t touch_pad_denoise_set_config(const touch_pad_denoise_t *denoise);
/**
* @brief get parameter of denoise pad (TOUCH_PAD_NUM0).
@ -380,7 +380,7 @@ esp_err_t touch_pad_denoise_read_data(uint32_t *data);
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_set_config(touch_pad_waterproof_t *waterproof);
esp_err_t touch_pad_waterproof_set_config(const touch_pad_waterproof_t *waterproof);
/**
* @brief get parameter of waterproof function.

View File

@ -20,6 +20,7 @@
#include "driver/rtc_cntl.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
#include "esp_check.h"
#include "hal/touch_sensor_types.h"
#include "hal/touch_sensor_hal.h"
@ -36,18 +37,14 @@
#define TOUCH_PAD_MEASURE_WAIT_DEFAULT (0xFF) // The timer frequency is 8Mhz, the max value is 0xff
static const char *TOUCH_TAG = "TOUCH_SENSOR";
#define TOUCH_CHECK(a, str, ret_val) ({ \
if (!(a)) { \
ESP_LOGE(TOUCH_TAG,"%s(%d): %s", __FUNCTION__, __LINE__, str); \
return (ret_val); \
} \
})
#define TOUCH_CHANNEL_CHECK(channel) do { \
TOUCH_CHECK(channel < SOC_TOUCH_SENSOR_NUM && channel >= 0, "Touch channel error", ESP_ERR_INVALID_ARG); \
TOUCH_CHECK(channel != SOC_TOUCH_DENOISE_CHANNEL, "TOUCH0 is internal denoise channel", ESP_ERR_INVALID_ARG); \
ESP_RETURN_ON_FALSE(channel < SOC_TOUCH_SENSOR_NUM && channel >= 0, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch channel error"); \
ESP_RETURN_ON_FALSE(channel != SOC_TOUCH_DENOISE_CHANNEL, ESP_ERR_INVALID_ARG, TOUCH_TAG, "TOUCH0 is internal denoise channel"); \
} while (0);
#define TOUCH_CH_MASK_CHECK(mask) TOUCH_CHECK((mask <= TOUCH_PAD_BIT_MASK_ALL), "touch channel bitmask error", ESP_ERR_INVALID_ARG)
#define TOUCH_INTR_MASK_CHECK(mask) TOUCH_CHECK(mask & TOUCH_PAD_INTR_MASK_ALL, "intr mask error", ESP_ERR_INVALID_ARG)
#define TOUCH_CH_MASK_CHECK(mask) ESP_RETURN_ON_FALSE((mask <= TOUCH_PAD_BIT_MASK_ALL), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch channel bitmask error");
#define TOUCH_INTR_MASK_CHECK(mask) ESP_RETURN_ON_FALSE(mask & TOUCH_PAD_INTR_MASK_ALL, ESP_ERR_INVALID_ARG, TOUCH_TAG, "intr mask error");
#define TOUCH_NULL_POINTER_CHECK(p, name) ESP_RETURN_ON_FALSE((p), ESP_ERR_INVALID_ARG, TOUCH_TAG, "input param '"name"' is NULL")
#define TOUCH_PARAM_CHECK_STR(s) ""s" parameter error"
extern portMUX_TYPE rtc_spinlock; //TODO: Will be placed in the appropriate position after the rtc module is finished.
@ -85,7 +82,7 @@ static void touch_pad_workaround_isr_internal(void *arg)
esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_mask_t intr_mask)
{
static bool reg_flag = false;
TOUCH_CHECK(fn != NULL, TOUCH_PARAM_CHECK_STR("intr_mask"), ESP_ERR_INVALID_ARG);
ESP_RETURN_ON_FALSE(fn, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("intr_mask"));
TOUCH_INTR_MASK_CHECK(intr_mask);
uint32_t en_msk = 0;
@ -104,6 +101,11 @@ esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_ma
if (intr_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) {
en_msk |= RTC_CNTL_TOUCH_TIMEOUT_INT_ST_M;
}
#if SOC_TOUCH_PROXIMITY_MEAS_DONE_SUPPORTED
if (intr_mask & TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE) {
en_msk |= RTC_CNTL_TOUCH_APPROACH_LOOP_DONE_INT_ST_M;
}
#endif
esp_err_t ret = rtc_isr_register(fn, arg, en_msk);
/* Must ensure: After being registered, it is executed first. */
if ( (ret == ESP_OK) && (reg_flag == false) && (intr_mask & (TOUCH_PAD_INTR_MASK_SCAN_DONE | TOUCH_PAD_INTR_MASK_TIMEOUT)) ) {
@ -136,7 +138,7 @@ esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_times)
esp_err_t touch_pad_set_idle_channel_connect(touch_pad_conn_type_t type)
{
TOUCH_CHECK(type < TOUCH_PAD_CONN_MAX, TOUCH_PARAM_CHECK_STR("type"), ESP_ERR_INVALID_ARG);
ESP_RETURN_ON_FALSE(type < TOUCH_PAD_CONN_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("type"));
TOUCH_ENTER_CRITICAL();
touch_hal_set_idle_channel_connect(type);
TOUCH_EXIT_CRITICAL();
@ -145,6 +147,7 @@ esp_err_t touch_pad_set_idle_channel_connect(touch_pad_conn_type_t type)
esp_err_t touch_pad_get_idle_channel_connect(touch_pad_conn_type_t *type)
{
TOUCH_NULL_POINTER_CHECK(type, "type");
touch_hal_get_idle_channel_connect(type);
return ESP_OK;
}
@ -166,6 +169,7 @@ esp_err_t touch_pad_set_channel_mask(uint16_t enable_mask)
esp_err_t touch_pad_get_channel_mask(uint16_t *enable_mask)
{
TOUCH_NULL_POINTER_CHECK(enable_mask, "enable_mask");
TOUCH_ENTER_CRITICAL();
touch_hal_get_channel_mask(enable_mask);
TOUCH_EXIT_CRITICAL();
@ -238,6 +242,7 @@ esp_err_t touch_pad_timeout_set(bool enable, uint32_t threshold)
esp_err_t touch_pad_timeout_get_threshold(uint32_t *threshold)
{
TOUCH_NULL_POINTER_CHECK(threshold, "threshold");
TOUCH_ENTER_CRITICAL();
touch_hal_timeout_get_threshold(threshold);
TOUCH_EXIT_CRITICAL();
@ -281,7 +286,7 @@ esp_err_t touch_pad_init(void)
esp_err_t touch_pad_deinit(void)
{
TOUCH_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL);
ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_FAIL, TOUCH_TAG, "Touch pad not initialized");
xSemaphoreTake(rtc_touch_mux, portMAX_DELAY);
TOUCH_ENTER_CRITICAL();
touch_hal_deinit();
@ -302,7 +307,8 @@ esp_err_t touch_pad_reset(void)
esp_err_t IRAM_ATTR touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data)
{
TOUCH_CHECK(touch_num < TOUCH_PAD_MAX && touch_num >= 0, "Touch channel error", ESP_ERR_INVALID_ARG);
ESP_RETURN_ON_FALSE(touch_num < TOUCH_PAD_MAX && touch_num >= 0, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch channel error");
TOUCH_NULL_POINTER_CHECK(raw_data, "raw_data");
TOUCH_ENTER_CRITICAL_SAFE();
*raw_data = touch_hal_read_raw_data(touch_num);
TOUCH_EXIT_CRITICAL_SAFE();
@ -311,6 +317,7 @@ esp_err_t IRAM_ATTR touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw
esp_err_t IRAM_ATTR touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth_data)
{
TOUCH_NULL_POINTER_CHECK(smooth_data, "smooth_data");
TOUCH_CHANNEL_CHECK(touch_num);
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_filter_read_smooth(touch_num, smooth_data);
@ -320,6 +327,7 @@ esp_err_t IRAM_ATTR touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t
esp_err_t IRAM_ATTR touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark)
{
TOUCH_NULL_POINTER_CHECK(benchmark, "benchmark");
TOUCH_CHANNEL_CHECK(touch_num);
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_read_benchmark(touch_num, benchmark);
@ -330,20 +338,21 @@ esp_err_t IRAM_ATTR touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *be
/* Should be call after clk enable and filter enable. */
esp_err_t touch_pad_reset_benchmark(touch_pad_t touch_num)
{
TOUCH_CHECK(touch_num <= TOUCH_PAD_MAX && touch_num >= 0, "Touch channel error", ESP_ERR_INVALID_ARG);
ESP_RETURN_ON_FALSE(touch_num <= TOUCH_PAD_MAX && touch_num >= 0, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch channel error");
TOUCH_ENTER_CRITICAL();
touch_hal_reset_benchmark(touch_num);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_filter_set_config(touch_filter_config_t *filter_info)
esp_err_t touch_pad_filter_set_config(const touch_filter_config_t *filter_info)
{
TOUCH_CHECK(filter_info->mode < TOUCH_PAD_FILTER_MAX, TOUCH_PARAM_CHECK_STR("mode"), ESP_ERR_INVALID_ARG);
TOUCH_CHECK(filter_info->debounce_cnt <= TOUCH_DEBOUNCE_CNT_MAX, TOUCH_PARAM_CHECK_STR("debounce"), ESP_ERR_INVALID_ARG);
TOUCH_CHECK(filter_info->noise_thr <= TOUCH_NOISE_THR_MAX, TOUCH_PARAM_CHECK_STR("noise"), ESP_ERR_INVALID_ARG);
TOUCH_CHECK(filter_info->jitter_step <= TOUCH_JITTER_STEP_MAX, TOUCH_PARAM_CHECK_STR("jitter_step"), ESP_ERR_INVALID_ARG);
TOUCH_CHECK(filter_info->smh_lvl < TOUCH_PAD_SMOOTH_MAX, TOUCH_PARAM_CHECK_STR("smooth level"), ESP_ERR_INVALID_ARG);
TOUCH_NULL_POINTER_CHECK(filter_info, "filter_info");
ESP_RETURN_ON_FALSE(filter_info->mode < TOUCH_PAD_FILTER_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("mode"));
ESP_RETURN_ON_FALSE(filter_info->debounce_cnt <= TOUCH_DEBOUNCE_CNT_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("debounce"));
ESP_RETURN_ON_FALSE(filter_info->noise_thr <= TOUCH_NOISE_THR_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("noise"));
ESP_RETURN_ON_FALSE(filter_info->jitter_step <= TOUCH_JITTER_STEP_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("jitter_step"));
ESP_RETURN_ON_FALSE(filter_info->smh_lvl < TOUCH_PAD_SMOOTH_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("smooth level"));
TOUCH_ENTER_CRITICAL();
touch_hal_filter_set_config(filter_info);
@ -354,6 +363,7 @@ esp_err_t touch_pad_filter_set_config(touch_filter_config_t *filter_info)
esp_err_t touch_pad_filter_get_config(touch_filter_config_t *filter_info)
{
TOUCH_NULL_POINTER_CHECK(filter_info, "filter_info");
TOUCH_ENTER_CRITICAL();
touch_hal_filter_get_config(filter_info);
TOUCH_EXIT_CRITICAL();
@ -393,10 +403,11 @@ esp_err_t touch_pad_denoise_disable(void)
return ESP_OK;
}
esp_err_t touch_pad_denoise_set_config(touch_pad_denoise_t *denoise)
esp_err_t touch_pad_denoise_set_config(const touch_pad_denoise_t *denoise)
{
TOUCH_CHECK(denoise->grade < TOUCH_PAD_DENOISE_MAX, TOUCH_PARAM_CHECK_STR("grade"), ESP_ERR_INVALID_ARG);
TOUCH_CHECK(denoise->cap_level < TOUCH_PAD_DENOISE_CAP_MAX, TOUCH_PARAM_CHECK_STR("cap_level"), ESP_ERR_INVALID_ARG);
TOUCH_NULL_POINTER_CHECK(denoise, "denoise");
ESP_RETURN_ON_FALSE(denoise->grade < TOUCH_PAD_DENOISE_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("grade"));
ESP_RETURN_ON_FALSE(denoise->cap_level < TOUCH_PAD_DENOISE_CAP_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("cap_level"));
const touch_hal_meas_mode_t meas = {
.slope = TOUCH_PAD_SLOPE_DEFAULT,
@ -412,6 +423,7 @@ esp_err_t touch_pad_denoise_set_config(touch_pad_denoise_t *denoise)
esp_err_t touch_pad_denoise_get_config(touch_pad_denoise_t *denoise)
{
TOUCH_NULL_POINTER_CHECK(denoise, "denoise");
TOUCH_ENTER_CRITICAL();
touch_hal_denoise_get_config(denoise);
TOUCH_EXIT_CRITICAL();
@ -420,14 +432,16 @@ esp_err_t touch_pad_denoise_get_config(touch_pad_denoise_t *denoise)
esp_err_t touch_pad_denoise_read_data(uint32_t *data)
{
TOUCH_NULL_POINTER_CHECK(data, "data");
touch_hal_denoise_read_data(data);
return ESP_OK;
}
esp_err_t touch_pad_waterproof_set_config(touch_pad_waterproof_t *waterproof)
esp_err_t touch_pad_waterproof_set_config(const touch_pad_waterproof_t *waterproof)
{
TOUCH_CHECK(waterproof->guard_ring_pad < SOC_TOUCH_SENSOR_NUM, TOUCH_PARAM_CHECK_STR("pad"), ESP_ERR_INVALID_ARG);
TOUCH_CHECK(waterproof->shield_driver < TOUCH_PAD_SHIELD_DRV_MAX, TOUCH_PARAM_CHECK_STR("shield_driver"), ESP_ERR_INVALID_ARG);
TOUCH_NULL_POINTER_CHECK(waterproof, "waterproof");
ESP_RETURN_ON_FALSE(waterproof->guard_ring_pad < SOC_TOUCH_SENSOR_NUM, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("pad"));
ESP_RETURN_ON_FALSE(waterproof->shield_driver < TOUCH_PAD_SHIELD_DRV_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("shield_driver"));
TOUCH_ENTER_CRITICAL();
touch_hal_waterproof_set_config(waterproof);
@ -437,6 +451,7 @@ esp_err_t touch_pad_waterproof_set_config(touch_pad_waterproof_t *waterproof)
esp_err_t touch_pad_waterproof_get_config(touch_pad_waterproof_t *waterproof)
{
TOUCH_NULL_POINTER_CHECK(waterproof, "waterproof");
TOUCH_ENTER_CRITICAL();
touch_hal_waterproof_get_config(waterproof);
TOUCH_EXIT_CRITICAL();
@ -463,7 +478,7 @@ esp_err_t touch_pad_waterproof_disable(void)
esp_err_t touch_pad_proximity_enable(touch_pad_t touch_num, bool enabled)
{
esp_err_t ret = ESP_OK;
TOUCH_CHECK(touch_num < TOUCH_PAD_MAX, "Touch channel error", ESP_ERR_INVALID_ARG);
ESP_RETURN_ON_FALSE(touch_num < TOUCH_PAD_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch channel error");
TOUCH_ENTER_CRITICAL();
if (!touch_hal_enable_proximity(touch_num, enabled)) {
@ -475,7 +490,7 @@ esp_err_t touch_pad_proximity_enable(touch_pad_t touch_num, bool enabled)
esp_err_t touch_pad_proximity_set_count(touch_pad_t touch_num, uint32_t count)
{
TOUCH_CHECK(count <= TOUCH_PROXIMITY_MEAS_NUM_MAX, TOUCH_PARAM_CHECK_STR("measure count"), ESP_ERR_INVALID_ARG);
ESP_RETURN_ON_FALSE(count <= TOUCH_PROXIMITY_MEAS_NUM_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("measure count"));
TOUCH_ENTER_CRITICAL();
touch_hal_proximity_set_meas_times(count);
@ -485,7 +500,7 @@ esp_err_t touch_pad_proximity_set_count(touch_pad_t touch_num, uint32_t count)
esp_err_t touch_pad_proximity_get_count(touch_pad_t touch_num, uint32_t *count)
{
TOUCH_CHECK(count != NULL, TOUCH_PARAM_CHECK_STR("measure count"), ESP_ERR_INVALID_ARG);
ESP_RETURN_ON_FALSE(count, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("measure count"));
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_proximity_get_meas_times(count);
@ -504,7 +519,8 @@ esp_err_t touch_pad_proximity_get_count(touch_pad_t touch_num, uint32_t *count)
*/
esp_err_t touch_pad_proximity_read_meas_cnt(touch_pad_t touch_num, uint32_t *cnt)
{
TOUCH_CHECK(touch_hal_proximity_pad_check(touch_num), "touch num is not proximity", ESP_ERR_INVALID_ARG);
TOUCH_NULL_POINTER_CHECK(cnt, "cnt");
ESP_RETURN_ON_FALSE(touch_hal_proximity_pad_check(touch_num), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch num is not proximity");
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_proximity_read_meas_cnt(touch_num, cnt);
TOUCH_EXIT_CRITICAL_SAFE();
@ -513,7 +529,8 @@ esp_err_t touch_pad_proximity_read_meas_cnt(touch_pad_t touch_num, uint32_t *cnt
esp_err_t touch_pad_proximity_get_data(touch_pad_t touch_num, uint32_t *measure_out)
{
TOUCH_CHECK(touch_hal_proximity_pad_check(touch_num), "touch num is not proximity", ESP_ERR_INVALID_ARG);
ESP_RETURN_ON_FALSE(touch_hal_proximity_pad_check(touch_num), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch num is not proximity");
TOUCH_NULL_POINTER_CHECK(measure_out, "measure_out");
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_read_benchmark(touch_num, measure_out);
TOUCH_EXIT_CRITICAL_SAFE();
@ -524,6 +541,7 @@ esp_err_t touch_pad_proximity_get_data(touch_pad_t touch_num, uint32_t *measure_
esp_err_t touch_pad_sleep_channel_get_info(touch_pad_sleep_channel_t *slp_config)
{
TOUCH_NULL_POINTER_CHECK(slp_config, "slp_config");
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_sleep_channel_get_config(slp_config);
TOUCH_EXIT_CRITICAL_SAFE();
@ -556,6 +574,7 @@ esp_err_t touch_pad_sleep_channel_enable_proximity(touch_pad_t pad_num, bool ena
esp_err_t touch_pad_sleep_get_channel_num(touch_pad_t *pad_num)
{
TOUCH_NULL_POINTER_CHECK(pad_num, "pad_num");
TOUCH_ENTER_CRITICAL();
touch_hal_sleep_get_channel_num(pad_num);
TOUCH_EXIT_CRITICAL();
@ -572,6 +591,7 @@ esp_err_t touch_pad_sleep_set_threshold(touch_pad_t pad_num, uint32_t touch_thre
esp_err_t touch_pad_sleep_get_threshold(touch_pad_t pad_num, uint32_t *touch_thres)
{
TOUCH_NULL_POINTER_CHECK(touch_thres, "touch_thres");
TOUCH_ENTER_CRITICAL();
touch_hal_sleep_get_threshold(touch_thres);
TOUCH_EXIT_CRITICAL();
@ -580,6 +600,7 @@ esp_err_t touch_pad_sleep_get_threshold(touch_pad_t pad_num, uint32_t *touch_thr
esp_err_t touch_pad_sleep_channel_read_benchmark(touch_pad_t pad_num, uint32_t *benchmark)
{
TOUCH_NULL_POINTER_CHECK(benchmark, "benchmark");
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_sleep_read_benchmark(benchmark);
TOUCH_EXIT_CRITICAL_SAFE();
@ -588,6 +609,7 @@ esp_err_t touch_pad_sleep_channel_read_benchmark(touch_pad_t pad_num, uint32_t *
esp_err_t touch_pad_sleep_channel_read_smooth(touch_pad_t pad_num, uint32_t *smooth_data)
{
TOUCH_NULL_POINTER_CHECK(smooth_data, "smooth_data");
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_sleep_read_smooth(smooth_data);
TOUCH_EXIT_CRITICAL_SAFE();
@ -596,6 +618,7 @@ esp_err_t touch_pad_sleep_channel_read_smooth(touch_pad_t pad_num, uint32_t *smo
esp_err_t touch_pad_sleep_channel_read_data(touch_pad_t pad_num, uint32_t *raw_data)
{
TOUCH_NULL_POINTER_CHECK(raw_data, "raw_data");
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_sleep_read_data(raw_data);
TOUCH_EXIT_CRITICAL_SAFE();
@ -612,12 +635,14 @@ esp_err_t touch_pad_sleep_channel_reset_benchmark(void)
esp_err_t touch_pad_sleep_channel_read_debounce(touch_pad_t pad_num, uint32_t *debounce)
{
TOUCH_NULL_POINTER_CHECK(debounce, "debounce");
touch_hal_sleep_read_debounce(debounce);
return ESP_OK;
}
esp_err_t touch_pad_sleep_channel_read_proximity_cnt(touch_pad_t pad_num, uint32_t *approach_cnt)
{
TOUCH_NULL_POINTER_CHECK(approach_cnt, "approach_cnt");
touch_hal_sleep_read_proximity_cnt(approach_cnt);
return ESP_OK;
}

View File

@ -6,12 +6,12 @@
#pragma once
#include "driver/touch_sensor_common.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "driver/touch_sensor_common.h"
/**
* @brief Set touch sensor FSM start
* @note Start FSM after the touch sensor FSM mode is set.
@ -180,6 +180,7 @@ uint32_t touch_pad_read_intr_status_mask(void);
/**
* @brief Enable touch sensor interrupt by bitmask.
* @note This API can be called in ISR handler.
* @param int_mask Pad mask to enable interrupts
* @return
* - ESP_OK on success
@ -188,6 +189,7 @@ esp_err_t touch_pad_intr_enable(touch_pad_intr_mask_t int_mask);
/**
* @brief Disable touch sensor interrupt by bitmask.
* @note This API can be called in ISR handler.
* @param int_mask Pad mask to disable interrupts
* @return
* - ESP_OK on success
@ -291,7 +293,7 @@ esp_err_t touch_pad_reset_benchmark(touch_pad_t touch_num);
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_filter_set_config(touch_filter_config_t *filter_info);
esp_err_t touch_pad_filter_set_config(const touch_filter_config_t *filter_info);
/**
* @brief get parameter of touch sensor filter and detection algorithm.
@ -329,7 +331,7 @@ esp_err_t touch_pad_filter_disable(void);
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_denoise_set_config(touch_pad_denoise_t *denoise);
esp_err_t touch_pad_denoise_set_config(const touch_pad_denoise_t *denoise);
/**
* @brief get parameter of denoise pad (TOUCH_PAD_NUM0).
@ -378,7 +380,7 @@ esp_err_t touch_pad_denoise_read_data(uint32_t *data);
* @return
* - ESP_OK Success
*/
esp_err_t touch_pad_waterproof_set_config(touch_pad_waterproof_t *waterproof);
esp_err_t touch_pad_waterproof_set_config(const touch_pad_waterproof_t *waterproof);
/**
* @brief get parameter of waterproof function.

View File

@ -0,0 +1,628 @@
/*
* SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <esp_types.h>
#include <stdlib.h>
#include <ctype.h>
#include "esp_log.h"
#include "sys/lock.h"
#include "soc/soc_pins.h"
#include "freertos/FreeRTOS.h"
#include "freertos/xtensa_api.h"
#include "freertos/semphr.h"
#include "freertos/timers.h"
#include "esp_intr_alloc.h"
#include "driver/rtc_io.h"
#include "driver/touch_pad.h"
#include "driver/rtc_cntl.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
#include "esp_check.h"
#include "hal/touch_sensor_types.h"
#include "hal/touch_sensor_hal.h"
#ifndef NDEBUG
// Enable built-in checks in queue.h in debug builds
#define INVARIANTS
#endif
#include "sys/queue.h"
#define TOUCH_PAD_FILTER_FACTOR_DEFAULT (4) // IIR filter coefficient.
#define TOUCH_PAD_SHIFT_DEFAULT (4) // Increase computing accuracy.
#define TOUCH_PAD_SHIFT_ROUND_DEFAULT (8) // ROUND = 2^(n-1); rounding off for fractional.
#define TOUCH_PAD_MEASURE_WAIT_DEFAULT (0xFF) // The timer frequency is 8Mhz, the max value is 0xff
static const char *TOUCH_TAG = "TOUCH_SENSOR";
#define TOUCH_CHANNEL_CHECK(channel) do { \
ESP_RETURN_ON_FALSE(channel < SOC_TOUCH_SENSOR_NUM && channel >= 0, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch channel error"); \
ESP_RETURN_ON_FALSE(channel != SOC_TOUCH_DENOISE_CHANNEL, ESP_ERR_INVALID_ARG, TOUCH_TAG, "TOUCH0 is internal denoise channel"); \
} while (0);
#define TOUCH_CH_MASK_CHECK(mask) ESP_RETURN_ON_FALSE((mask <= TOUCH_PAD_BIT_MASK_ALL), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch channel bitmask error");
#define TOUCH_INTR_MASK_CHECK(mask) ESP_RETURN_ON_FALSE(mask & TOUCH_PAD_INTR_MASK_ALL, ESP_ERR_INVALID_ARG, TOUCH_TAG, "intr mask error");
#define TOUCH_NULL_POINTER_CHECK(p, name) ESP_RETURN_ON_FALSE((p), ESP_ERR_INVALID_ARG, TOUCH_TAG, "input param '"name"' is NULL")
#define TOUCH_PARAM_CHECK_STR(s) ""s" parameter error"
extern portMUX_TYPE rtc_spinlock; //TODO: Will be placed in the appropriate position after the rtc module is finished.
#define TOUCH_ENTER_CRITICAL_SAFE() portENTER_CRITICAL_SAFE(&rtc_spinlock) // Can be called in isr and task.
#define TOUCH_EXIT_CRITICAL_SAFE() portEXIT_CRITICAL_SAFE(&rtc_spinlock)
#define TOUCH_ENTER_CRITICAL() portENTER_CRITICAL(&rtc_spinlock)
#define TOUCH_EXIT_CRITICAL() portEXIT_CRITICAL(&rtc_spinlock)
static SemaphoreHandle_t rtc_touch_mux = NULL;
/*---------------------------------------------------------------
Touch Pad
---------------------------------------------------------------*/
esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_mask_t intr_mask)
{
ESP_RETURN_ON_FALSE(fn, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("intr_mask"));
TOUCH_INTR_MASK_CHECK(intr_mask);
uint32_t en_msk = 0;
if (intr_mask & TOUCH_PAD_INTR_MASK_DONE) {
en_msk |= RTC_CNTL_TOUCH_DONE_INT_ST_M;
}
if (intr_mask & TOUCH_PAD_INTR_MASK_ACTIVE) {
en_msk |= RTC_CNTL_TOUCH_ACTIVE_INT_ST_M;
}
if (intr_mask & TOUCH_PAD_INTR_MASK_INACTIVE) {
en_msk |= RTC_CNTL_TOUCH_INACTIVE_INT_ST_M;
}
if (intr_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) {
en_msk |= RTC_CNTL_TOUCH_SCAN_DONE_INT_ST_M;
}
if (intr_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) {
en_msk |= RTC_CNTL_TOUCH_TIMEOUT_INT_ST_M;
}
#if SOC_TOUCH_PROXIMITY_MEAS_DONE_SUPPORTED
if (intr_mask & TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE) {
en_msk |= RTC_CNTL_TOUCH_APPROACH_LOOP_DONE_INT_ST_M;
}
#endif
esp_err_t ret = rtc_isr_register(fn, arg, en_msk);
return ret;
}
esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_times)
{
TOUCH_ENTER_CRITICAL();
touch_hal_set_meas_times(meas_times);
touch_hal_set_sleep_time(sleep_cycle);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_times)
{
TOUCH_NULL_POINTER_CHECK(sleep_cycle, "sleep_cycle");
TOUCH_NULL_POINTER_CHECK(meas_times, "meas_times");
TOUCH_ENTER_CRITICAL();
touch_hal_get_measure_times(meas_times);
touch_hal_get_sleep_time(sleep_cycle);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_set_idle_channel_connect(touch_pad_conn_type_t type)
{
ESP_RETURN_ON_FALSE(type < TOUCH_PAD_CONN_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("type"));
TOUCH_ENTER_CRITICAL();
touch_hal_set_idle_channel_connect(type);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_get_idle_channel_connect(touch_pad_conn_type_t *type)
{
TOUCH_NULL_POINTER_CHECK(type, "type");
touch_hal_get_idle_channel_connect(type);
return ESP_OK;
}
bool touch_pad_meas_is_done(void)
{
return touch_hal_meas_is_done();
}
esp_err_t touch_pad_set_channel_mask(uint16_t enable_mask)
{
TOUCH_CH_MASK_CHECK(enable_mask);
TOUCH_ENTER_CRITICAL();
touch_hal_set_channel_mask(enable_mask);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_get_channel_mask(uint16_t *enable_mask)
{
TOUCH_NULL_POINTER_CHECK(enable_mask, "enable_mask");
TOUCH_ENTER_CRITICAL();
touch_hal_get_channel_mask(enable_mask);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_clear_channel_mask(uint16_t enable_mask)
{
TOUCH_CH_MASK_CHECK(enable_mask);
TOUCH_ENTER_CRITICAL();
touch_hal_clear_channel_mask(enable_mask);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
touch_pad_t IRAM_ATTR touch_pad_get_current_meas_channel(void)
{
return (touch_pad_t)touch_hal_get_current_meas_channel();
}
esp_err_t touch_pad_intr_enable(touch_pad_intr_mask_t int_mask)
{
if (!(int_mask & TOUCH_PAD_INTR_MASK_ALL)) {
return ESP_ERR_INVALID_ARG;
}
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_intr_enable(int_mask);
TOUCH_EXIT_CRITICAL_SAFE();
return ESP_OK;
}
esp_err_t touch_pad_intr_disable(touch_pad_intr_mask_t int_mask)
{
if (!(int_mask & TOUCH_PAD_INTR_MASK_ALL)) {
return ESP_ERR_INVALID_ARG;
}
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_intr_disable(int_mask);
TOUCH_EXIT_CRITICAL_SAFE();
return ESP_OK;
}
esp_err_t touch_pad_intr_clear(touch_pad_intr_mask_t int_mask)
{
TOUCH_INTR_MASK_CHECK(int_mask);
TOUCH_ENTER_CRITICAL();
touch_hal_intr_clear(int_mask);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
uint32_t touch_pad_read_intr_status_mask(void)
{
return touch_hal_read_intr_status_mask();
}
esp_err_t touch_pad_timeout_set(bool enable, uint32_t threshold)
{
TOUCH_ENTER_CRITICAL();
if (enable) {
touch_hal_timeout_enable();
} else {
touch_hal_timeout_disable();
}
touch_hal_timeout_set_threshold(threshold);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_timeout_get_threshold(uint32_t *threshold)
{
TOUCH_NULL_POINTER_CHECK(threshold, "threshold");
TOUCH_ENTER_CRITICAL();
touch_hal_timeout_get_threshold(threshold);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_timeout_resume(void)
{
TOUCH_ENTER_CRITICAL();
touch_hal_timer_force_done();
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_config(touch_pad_t touch_num)
{
TOUCH_CHANNEL_CHECK(touch_num);
touch_pad_io_init(touch_num);
TOUCH_ENTER_CRITICAL();
touch_hal_config(touch_num);
touch_hal_set_channel_mask(BIT(touch_num));
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_init(void)
{
if (rtc_touch_mux == NULL) {
rtc_touch_mux = xSemaphoreCreateMutex();
}
if (rtc_touch_mux == NULL) {
return ESP_ERR_NO_MEM;
}
TOUCH_ENTER_CRITICAL();
touch_hal_init();
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_deinit(void)
{
ESP_RETURN_ON_FALSE(rtc_touch_mux, ESP_FAIL, TOUCH_TAG, "Touch pad not initialized");
xSemaphoreTake(rtc_touch_mux, portMAX_DELAY);
TOUCH_ENTER_CRITICAL();
touch_hal_deinit();
TOUCH_EXIT_CRITICAL();
xSemaphoreGive(rtc_touch_mux);
vSemaphoreDelete(rtc_touch_mux);
rtc_touch_mux = NULL;
return ESP_OK;
}
esp_err_t touch_pad_reset(void)
{
TOUCH_ENTER_CRITICAL();
touch_hal_reset();
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t IRAM_ATTR touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data)
{
TOUCH_CHANNEL_CHECK(touch_num);
TOUCH_NULL_POINTER_CHECK(raw_data, "raw_data");
TOUCH_ENTER_CRITICAL_SAFE();
*raw_data = touch_hal_read_raw_data(touch_num);
TOUCH_EXIT_CRITICAL_SAFE();
return ESP_OK;
}
esp_err_t IRAM_ATTR touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth_data)
{
TOUCH_CHANNEL_CHECK(touch_num);
TOUCH_NULL_POINTER_CHECK(smooth_data, "smooth_data");
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_filter_read_smooth(touch_num, smooth_data);
TOUCH_EXIT_CRITICAL_SAFE();
return ESP_OK;
}
esp_err_t IRAM_ATTR touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark)
{
TOUCH_CHANNEL_CHECK(touch_num);
TOUCH_NULL_POINTER_CHECK(benchmark, "benchmark");
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_read_benchmark(touch_num, benchmark);
TOUCH_EXIT_CRITICAL_SAFE();
return ESP_OK;
}
/* Should be call after clk enable and filter enable. */
esp_err_t touch_pad_reset_benchmark(touch_pad_t touch_num)
{
ESP_RETURN_ON_FALSE(touch_num <= TOUCH_PAD_MAX && touch_num >= 0, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch channel error");
TOUCH_ENTER_CRITICAL();
touch_hal_reset_benchmark(touch_num);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_filter_set_config(const touch_filter_config_t *filter_info)
{
TOUCH_NULL_POINTER_CHECK(filter_info, "filter_info");
ESP_RETURN_ON_FALSE(filter_info->mode < TOUCH_PAD_FILTER_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("mode"));
ESP_RETURN_ON_FALSE(filter_info->debounce_cnt <= TOUCH_DEBOUNCE_CNT_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("debounce"));
ESP_RETURN_ON_FALSE(filter_info->noise_thr <= TOUCH_NOISE_THR_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("noise"));
ESP_RETURN_ON_FALSE(filter_info->jitter_step <= TOUCH_JITTER_STEP_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("jitter_step"));
ESP_RETURN_ON_FALSE(filter_info->smh_lvl < TOUCH_PAD_SMOOTH_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("smooth level"));
TOUCH_ENTER_CRITICAL();
touch_hal_filter_set_config(filter_info);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_filter_get_config(touch_filter_config_t *filter_info)
{
TOUCH_NULL_POINTER_CHECK(filter_info, "filter_info");
TOUCH_ENTER_CRITICAL();
touch_hal_filter_get_config(filter_info);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_filter_enable(void)
{
TOUCH_ENTER_CRITICAL();
touch_hal_filter_enable();
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_filter_disable(void)
{
TOUCH_ENTER_CRITICAL();
touch_hal_filter_disable();
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_denoise_enable(void)
{
TOUCH_ENTER_CRITICAL();
touch_hal_clear_channel_mask(BIT(SOC_TOUCH_DENOISE_CHANNEL));
touch_hal_denoise_enable();
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_denoise_disable(void)
{
TOUCH_ENTER_CRITICAL();
touch_hal_denoise_disable();
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_denoise_set_config(const touch_pad_denoise_t *denoise)
{
TOUCH_NULL_POINTER_CHECK(denoise, "denoise");
ESP_RETURN_ON_FALSE(denoise->grade < TOUCH_PAD_DENOISE_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("grade"));
ESP_RETURN_ON_FALSE(denoise->cap_level < TOUCH_PAD_DENOISE_CAP_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("cap_level"));
const touch_hal_meas_mode_t meas = {
.slope = TOUCH_PAD_SLOPE_DEFAULT,
.tie_opt = TOUCH_PAD_TIE_OPT_DEFAULT,
};
TOUCH_ENTER_CRITICAL();
touch_hal_set_meas_mode(SOC_TOUCH_DENOISE_CHANNEL, &meas);
touch_hal_denoise_set_config(denoise);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_denoise_get_config(touch_pad_denoise_t *denoise)
{
TOUCH_NULL_POINTER_CHECK(denoise, "denoise");
TOUCH_ENTER_CRITICAL();
touch_hal_denoise_get_config(denoise);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_denoise_read_data(uint32_t *data)
{
touch_hal_denoise_read_data(data);
return ESP_OK;
}
esp_err_t touch_pad_waterproof_set_config(const touch_pad_waterproof_t *waterproof)
{
TOUCH_NULL_POINTER_CHECK(waterproof, "waterproof");
ESP_RETURN_ON_FALSE(waterproof->guard_ring_pad < SOC_TOUCH_SENSOR_NUM, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("pad"));
ESP_RETURN_ON_FALSE(waterproof->shield_driver < TOUCH_PAD_SHIELD_DRV_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("shield_driver"));
TOUCH_ENTER_CRITICAL();
touch_hal_waterproof_set_config(waterproof);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_waterproof_get_config(touch_pad_waterproof_t *waterproof)
{
TOUCH_NULL_POINTER_CHECK(waterproof, "waterproof");
TOUCH_ENTER_CRITICAL();
touch_hal_waterproof_get_config(waterproof);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_waterproof_enable(void)
{
touch_pad_io_init(SOC_TOUCH_SHIELD_CHANNEL);
TOUCH_ENTER_CRITICAL();
touch_hal_waterproof_enable();
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_waterproof_disable(void)
{
TOUCH_ENTER_CRITICAL();
touch_hal_waterproof_disable();
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_proximity_enable(touch_pad_t touch_num, bool enabled)
{
esp_err_t ret = ESP_OK;
ESP_RETURN_ON_FALSE(touch_num < TOUCH_PAD_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, "Touch channel error");
TOUCH_ENTER_CRITICAL();
if (!touch_hal_enable_proximity(touch_num, enabled)) {
ret = ESP_ERR_NOT_SUPPORTED;
}
TOUCH_EXIT_CRITICAL();
return ret;
}
esp_err_t touch_pad_proximity_set_count(touch_pad_t touch_num, uint32_t count)
{
ESP_RETURN_ON_FALSE(count <= TOUCH_PROXIMITY_MEAS_NUM_MAX, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("measure count"));
TOUCH_ENTER_CRITICAL();
touch_hal_proximity_set_meas_times(count);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_proximity_get_count(touch_pad_t touch_num, uint32_t *count)
{
ESP_RETURN_ON_FALSE(count, ESP_ERR_INVALID_ARG, TOUCH_TAG, TOUCH_PARAM_CHECK_STR("measure count"));
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_proximity_get_meas_times(count);
TOUCH_EXIT_CRITICAL_SAFE();
return ESP_OK;
}
/**
* @brief Get measure count of proximity channel.
* The proximity sensor measurement is the accumulation of touch channel measurements.
* @param touch_num touch pad index
* @param cnt Pointer to receive proximity channel measurement count
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG parameter is NULL
*/
esp_err_t touch_pad_proximity_read_meas_cnt(touch_pad_t touch_num, uint32_t *cnt)
{
TOUCH_NULL_POINTER_CHECK(cnt, "cnt");
ESP_RETURN_ON_FALSE(touch_hal_proximity_pad_check(touch_num), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch num is not proximity");
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_proximity_read_meas_cnt(touch_num, cnt);
TOUCH_EXIT_CRITICAL_SAFE();
return ESP_OK;
}
esp_err_t touch_pad_proximity_get_data(touch_pad_t touch_num, uint32_t *measure_out)
{
TOUCH_NULL_POINTER_CHECK(measure_out, "measure_out");
ESP_RETURN_ON_FALSE(touch_hal_proximity_pad_check(touch_num), ESP_ERR_INVALID_ARG, TOUCH_TAG, "touch num is not proximity");
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_read_benchmark(touch_num, measure_out);
TOUCH_EXIT_CRITICAL_SAFE();
return ESP_OK;
}
/************** sleep pad setting ***********************/
esp_err_t touch_pad_sleep_channel_get_info(touch_pad_sleep_channel_t *slp_config)
{
TOUCH_NULL_POINTER_CHECK(slp_config, "slp_config");
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_sleep_channel_get_config(slp_config);
TOUCH_EXIT_CRITICAL_SAFE();
return ESP_OK;
}
esp_err_t touch_pad_sleep_channel_enable(touch_pad_t pad_num, bool enable)
{
TOUCH_CHANNEL_CHECK(pad_num);
TOUCH_ENTER_CRITICAL();
touch_hal_sleep_channel_enable(pad_num, enable);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_sleep_channel_enable_proximity(touch_pad_t pad_num, bool enable)
{
TOUCH_CHANNEL_CHECK(pad_num);
TOUCH_ENTER_CRITICAL();
if (enable) {
touch_hal_sleep_enable_approach();
} else {
touch_hal_sleep_disable_approach();
}
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_sleep_get_channel_num(touch_pad_t *pad_num)
{
TOUCH_NULL_POINTER_CHECK(pad_num, "pad_num");
TOUCH_ENTER_CRITICAL();
touch_hal_sleep_get_channel_num(pad_num);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_sleep_set_threshold(touch_pad_t pad_num, uint32_t touch_thres)
{
TOUCH_ENTER_CRITICAL();
touch_hal_sleep_set_threshold(touch_thres);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_sleep_get_threshold(touch_pad_t pad_num, uint32_t *touch_thres)
{
TOUCH_ENTER_CRITICAL();
touch_hal_sleep_get_threshold(touch_thres);
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_sleep_channel_read_benchmark(touch_pad_t pad_num, uint32_t *benchmark)
{
TOUCH_NULL_POINTER_CHECK(benchmark, "benchmark");
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_sleep_read_benchmark(benchmark);
TOUCH_EXIT_CRITICAL_SAFE();
return ESP_OK;
}
esp_err_t touch_pad_sleep_channel_read_smooth(touch_pad_t pad_num, uint32_t *smooth_data)
{
TOUCH_NULL_POINTER_CHECK(smooth_data, "smooth_data");
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_sleep_read_smooth(smooth_data);
TOUCH_EXIT_CRITICAL_SAFE();
return ESP_OK;
}
esp_err_t touch_pad_sleep_channel_read_data(touch_pad_t pad_num, uint32_t *raw_data)
{
TOUCH_NULL_POINTER_CHECK(raw_data, "raw_data");
TOUCH_ENTER_CRITICAL_SAFE();
touch_hal_sleep_read_data(raw_data);
TOUCH_EXIT_CRITICAL_SAFE();
return ESP_OK;
}
esp_err_t touch_pad_sleep_channel_reset_benchmark(void)
{
TOUCH_ENTER_CRITICAL();
touch_hal_sleep_reset_benchmark();
TOUCH_EXIT_CRITICAL();
return ESP_OK;
}
esp_err_t touch_pad_sleep_channel_read_debounce(touch_pad_t pad_num, uint32_t *debounce)
{
TOUCH_NULL_POINTER_CHECK(debounce, "debounce");
touch_hal_sleep_read_debounce(debounce);
return ESP_OK;
}
esp_err_t touch_pad_sleep_channel_read_proximity_cnt(touch_pad_t pad_num, uint32_t *approach_cnt)
{
TOUCH_NULL_POINTER_CHECK(approach_cnt, "approach_cnt");
touch_hal_sleep_read_proximity_cnt(approach_cnt);
return ESP_OK;
}
esp_err_t touch_pad_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times)
{
touch_hal_sleep_channel_set_work_time(sleep_cycle, meas_times);
return ESP_OK;
}

View File

@ -5,10 +5,10 @@
*/
/*
Tests for the touch sensor device driver for ESP32-S2 only
Tests for the touch sensor device driver for ESP32-S2 & ESP32-S3
*/
#include "sdkconfig.h"
#if CONFIG_IDF_TARGET_ESP32S2
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
#include <string.h>
#include "esp_system.h"
@ -64,9 +64,9 @@ void test_pxp_deinit_io(void)
#define TOUCH_EXCEED_TIME_MS (1000)
#define TOUCH_REG_BASE_TEST() ({ \
TEST_ASSERT_EQUAL_UINT32(REG_GET_FIELD(RTC_CNTL_DATE_REG, RTC_CNTL_CNTL_DATE), RTCCNTL.date.date); \
TEST_ASSERT_EQUAL_UINT32(REG_GET_FIELD(SENS_SARDATE_REG, SENS_SAR_DATE), SENS.sardate.sar_date); \
TEST_ASSERT_EQUAL_UINT32(REG_GET_FIELD(RTC_IO_DATE_REG, RTC_IO_IO_DATE), RTCIO.date.date); \
TEST_ASSERT_EQUAL_UINT32(REG_READ(RTC_CNTL_DATE_REG), RTCCNTL.date.date); \
TEST_ASSERT_EQUAL_UINT32(REG_READ(SENS_SARDATE_REG), SENS.sardate.sar_date); \
TEST_ASSERT_EQUAL_UINT32(REG_READ(RTC_IO_DATE_REG), RTCIO.date.date); \
})
#define TEST_TOUCH_COUNT_NUM (5)
@ -1158,15 +1158,34 @@ esp_err_t test_touch_filter_parameter_reset(int reset_cnt)
printf_touch_hw_read("[raw ] cnt:");
printf_touch_benchmark_read("[base] cnt:");
test_touch_measure_step(1);
/* ESP32S2 reset benchmark to raw data */
/*The benchmark on S2 will track the raw data in real time while the channel is not active.
But on S3, it track the smooth data. And due to the latency of the smooth data,
the benchmark will be updated to the last smooth data. Thus we have to read smooth data here
but read benchmark after one measurement step. */
#if CONFIG_IDF_TARGET_ESP32S3
uint32_t smooth_data[TEST_TOUCH_CHANNEL] = {0};
for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) {
TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_value) );
TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &base_value) );
TEST_ASSERT_EQUAL_UINT32(base_value, touch_value);
TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &(smooth_data[i])) );
}
#endif
/* Run 1 time measurement, the benchmark will update after finishing the channel scan*/
test_touch_measure_step(1);
printf_touch_hw_read("[raw ] cnt+1:");
printf_touch_smooth_read("[smooth]cnt+1:");
printf_touch_benchmark_read("[base] cnt+1:");
for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) {
TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &base_value) );
#if CONFIG_IDF_TARGET_ESP32S2
/* In ESP32S3, benchmark will update to the raw data. */
TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_value) );
/* Here we compare the benchmark with raw data directly */
TEST_ASSERT_EQUAL_UINT32(base_value, touch_value);
#elif CONFIG_IDF_TARGET_ESP32S3
/* In ESP32S3, benchmark will update to the smooth data. Smooth data is filtered from raw data by IIR.
Here we compare the benchmark with the previous smooth data*/
TEST_ASSERT_EQUAL_UINT32(base_value, smooth_data[i]);
#endif
}
int test_cnt = 2;
while (test_cnt--) {
@ -2115,4 +2134,4 @@ void test_touch_slope_debug(int pad_num)
TEST_ESP_OK( touch_pad_deinit() );
}
#endif // CONFIG_IDF_TARGET_ESP32S2
#endif // CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3

View File

@ -364,10 +364,12 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags)
if (deep_sleep) {
if (s_config.wakeup_triggers & RTC_TOUCH_TRIG_EN) {
touch_wakeup_prepare();
#if CONFIG_IDF_TARGET_ESP32S2
/* Workaround: In deep sleep, for ESP32S2, Power down the RTC_PERIPH will change the slope configuration of Touch sensor sleep pad.
* The configuration change will change the reading of the sleep pad, which will cause the touch wake-up sensor to trigger falsely.
*/
pd_flags &= ~RTC_SLEEP_PD_RTC_PERIPH;
#endif
}
} else {
/* In light sleep, the RTC_PERIPH power domain should be in the power-on state (Power on the touch circuit in light sleep),
@ -702,7 +704,7 @@ esp_err_t esp_sleep_disable_wakeup_source(esp_sleep_source_t source)
s_config.ext1_trigger_mode = 0;
s_config.wakeup_triggers &= ~RTC_EXT1_TRIG_EN;
#endif
#if SOC_TOUCH_PAD_WAKE_SUPPORTED
#if SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP
} else if (CHECK_SOURCE(source, ESP_SLEEP_WAKEUP_TOUCHPAD, RTC_TOUCH_TRIG_EN)) {
s_config.wakeup_triggers &= ~RTC_TOUCH_TRIG_EN;
#endif
@ -1065,7 +1067,7 @@ esp_sleep_wakeup_cause_t esp_sleep_get_wakeup_cause(void)
} else if (wakeup_cause & RTC_EXT1_TRIG_EN) {
return ESP_SLEEP_WAKEUP_EXT1;
#endif
#if SOC_TOUCH_PAD_WAKE_SUPPORTED
#if SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP
} else if (wakeup_cause & RTC_TOUCH_TRIG_EN) {
return ESP_SLEEP_WAKEUP_TOUCHPAD;
#endif
@ -1137,7 +1139,7 @@ static uint32_t get_power_down_flags(void)
// RTC_PERIPH is needed for EXT0 wakeup and GPIO wakeup.
// If RTC_PERIPH is auto, and EXT0/GPIO aren't enabled, power down RTC_PERIPH.
if (s_config.pd_options[ESP_PD_DOMAIN_RTC_PERIPH] == ESP_PD_OPTION_AUTO) {
#if SOC_TOUCH_PAD_WAKE_SUPPORTED
#if SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP
uint32_t wakeup_source = RTC_TOUCH_TRIG_EN;
#if SOC_ULP_SUPPORTED
wakeup_source |= RTC_ULP_TRIG_EN;
@ -1155,7 +1157,7 @@ static uint32_t get_power_down_flags(void)
} else {
s_config.pd_options[ESP_PD_DOMAIN_RTC_PERIPH] = ESP_PD_OPTION_OFF;
}
#endif // SOC_TOUCH_PAD_WAKE_SUPPORTED
#endif // SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP
}
#if SOC_PM_SUPPORT_CPU_PD

View File

@ -1,16 +1,8 @@
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/*******************************************************************************
* NOTICE
@ -56,14 +48,14 @@ typedef enum {
static inline void rtcio_ll_function_select(int rtcio_num, rtcio_ll_func_t func)
{
if (func == RTCIO_FUNC_RTC) {
// SENS.sar_io_mux_conf.iomux_clk_gate_en = 1;
SENS.sar_peri_clk_gate_conf.iomux_clk_en = 1;
// 0: GPIO connected to digital GPIO module. 1: GPIO connected to analog RTC module.
SET_PERI_REG_MASK(rtc_io_desc[rtcio_num].reg, (rtc_io_desc[rtcio_num].mux));
//0:RTC FUNCTION 1,2,3:Reserved
SET_PERI_REG_BITS(rtc_io_desc[rtcio_num].reg, RTC_IO_TOUCH_PAD1_FUN_SEL_V, RTCIO_LL_PIN_FUNC, rtc_io_desc[rtcio_num].func);
} else if (func == RTCIO_FUNC_DIGITAL) {
CLEAR_PERI_REG_MASK(rtc_io_desc[rtcio_num].reg, (rtc_io_desc[rtcio_num].mux));
// SENS.sar_io_mux_conf.iomux_clk_gate_en = 0;
SENS.sar_peri_clk_gate_conf.iomux_clk_en = 0;
}
}
@ -276,6 +268,7 @@ static inline void rtcio_ll_force_unhold_all(void)
*/
static inline void rtcio_ll_wakeup_enable(int rtcio_num, rtcio_ll_wake_type_t type)
{
SENS.sar_peri_clk_gate_conf.iomux_clk_en = 1;
RTCIO.pin[rtcio_num].wakeup_enable = 0x1;
RTCIO.pin[rtcio_num].int_type = type;
}

View File

@ -1,16 +1,8 @@
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/*******************************************************************************
* NOTICE
@ -18,7 +10,7 @@
* See readme.md in hal/include/hal/readme.md
******************************************************************************/
// The HAL layer for touch sensor (esp32s2 specific part)
// The HAL layer for touch sensor (ESP32-S3 specific part)
#pragma once

View File

@ -1,16 +1,8 @@
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/*******************************************************************************
* NOTICE
@ -174,7 +166,11 @@ static inline void touch_ll_get_voltage_attenuation(touch_volt_atten_t *atten)
*/
static inline void touch_ll_set_slope(touch_pad_t touch_num, touch_cnt_slope_t slope)
{
abort();//IDF-3417
if (touch_num < TOUCH_PAD_NUM10) {
SET_PERI_REG_BITS(RTC_CNTL_TOUCH_DAC_REG, RTC_CNTL_TOUCH_PAD0_DAC_V, slope, (RTC_CNTL_TOUCH_PAD0_DAC_S - touch_num * 3));
} else {
SET_PERI_REG_BITS(RTC_CNTL_TOUCH_DAC1_REG, RTC_CNTL_TOUCH_PAD10_DAC_V, slope, (RTC_CNTL_TOUCH_PAD10_DAC_S - (touch_num - TOUCH_PAD_NUM10) * 3));
}
}
/**
@ -189,7 +185,11 @@ static inline void touch_ll_set_slope(touch_pad_t touch_num, touch_cnt_slope_t s
*/
static inline void touch_ll_get_slope(touch_pad_t touch_num, touch_cnt_slope_t *slope)
{
abort();//IDF-3417
if (touch_num < TOUCH_PAD_NUM10) {
*slope = GET_PERI_REG_BITS2(RTC_CNTL_TOUCH_DAC_REG, RTC_CNTL_TOUCH_PAD0_DAC_V, (RTC_CNTL_TOUCH_PAD0_DAC_S - touch_num * 3));
} else {
*slope = GET_PERI_REG_BITS2(RTC_CNTL_TOUCH_DAC1_REG, RTC_CNTL_TOUCH_PAD10_DAC_V, (RTC_CNTL_TOUCH_PAD10_DAC_S - (touch_num - TOUCH_PAD_NUM10) * 3));
}
}
/**
@ -413,7 +413,7 @@ static inline void touch_ll_clear_trigger_status_mask(void)
static inline uint32_t IRAM_ATTR touch_ll_read_raw_data(touch_pad_t touch_num)
{
SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_RAW;
return SENS.sar_touch_status[touch_num - 1].touch_pad1_data;
return SENS.sar_touch_status[touch_num - 1].touch_pad_data;
}
/**
@ -490,19 +490,22 @@ static inline touch_pad_t IRAM_ATTR touch_ll_get_current_meas_channel(void)
static inline void touch_ll_intr_enable(touch_pad_intr_mask_t int_mask)
{
if (int_mask & TOUCH_PAD_INTR_MASK_DONE) {
RTCCNTL.int_ena.rtc_touch_done = 1;
RTCCNTL.int_ena_w1ts.rtc_touch_done_w1ts = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_ACTIVE) {
RTCCNTL.int_ena.rtc_touch_active = 1;
RTCCNTL.int_ena_w1ts.rtc_touch_active_w1ts = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_INACTIVE) {
RTCCNTL.int_ena.rtc_touch_inactive = 1;
RTCCNTL.int_ena_w1ts.rtc_touch_inactive_w1ts = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) {
RTCCNTL.int_ena.rtc_touch_scan_done = 1;
RTCCNTL.int_ena_w1ts.rtc_touch_scan_done_w1ts = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) {
RTCCNTL.int_ena.rtc_touch_timeout = 1;
RTCCNTL.int_ena_w1ts.rtc_touch_timeout_w1ts = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE) {
RTCCNTL.int_ena_w1ts.rtc_touch_approach_loop_done_w1ts = 1;
}
}
@ -514,19 +517,22 @@ static inline void touch_ll_intr_enable(touch_pad_intr_mask_t int_mask)
static inline void touch_ll_intr_disable(touch_pad_intr_mask_t int_mask)
{
if (int_mask & TOUCH_PAD_INTR_MASK_DONE) {
RTCCNTL.int_ena.rtc_touch_done = 0;
RTCCNTL.int_ena_w1tc.rtc_touch_done_w1tc = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_ACTIVE) {
RTCCNTL.int_ena.rtc_touch_active = 0;
RTCCNTL.int_ena_w1tc.rtc_touch_active_w1tc = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_INACTIVE) {
RTCCNTL.int_ena.rtc_touch_inactive = 0;
RTCCNTL.int_ena_w1tc.rtc_touch_inactive_w1tc = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) {
RTCCNTL.int_ena.rtc_touch_scan_done = 0;
RTCCNTL.int_ena_w1tc.rtc_touch_scan_done_w1tc = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) {
RTCCNTL.int_ena.rtc_touch_timeout = 0;
RTCCNTL.int_ena_w1tc.rtc_touch_timeout_w1tc = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE) {
RTCCNTL.int_ena_w1tc.rtc_touch_approach_loop_done_w1tc = 1;
}
}
@ -552,6 +558,9 @@ static inline void touch_ll_intr_clear(touch_pad_intr_mask_t int_mask)
if (int_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) {
RTCCNTL.int_clr.rtc_touch_timeout = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE) {
RTCCNTL.int_clr.rtc_touch_approach_loop_done = 1;
}
}
/**
@ -579,6 +588,9 @@ static inline uint32_t touch_ll_read_intr_status_mask(void)
if (intr_st & RTC_CNTL_TOUCH_TIMEOUT_INT_ST_M) {
intr_msk |= TOUCH_PAD_INTR_MASK_TIMEOUT;
}
if (intr_st & RTC_CNTL_TOUCH_APPROACH_LOOP_DONE_INT_ST_M) {
intr_msk |= TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE;
}
return (intr_msk & TOUCH_PAD_INTR_MASK_ALL);
}
@ -641,7 +653,7 @@ static inline void touch_ll_timeout_get_threshold(uint32_t *threshold)
static inline void IRAM_ATTR touch_ll_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth_data)
{
SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_SMOOTH;
*smooth_data = SENS.sar_touch_status[touch_num - 1].touch_pad1_data;
*smooth_data = SENS.sar_touch_status[touch_num - 1].touch_pad_data;
}
/**
@ -654,7 +666,7 @@ static inline void IRAM_ATTR touch_ll_filter_read_smooth(touch_pad_t touch_num,
static inline void IRAM_ATTR touch_ll_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark)
{
SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_BENCHMARK;
*benchmark = SENS.sar_touch_status[touch_num - 1].touch_pad1_data;
*benchmark = SENS.sar_touch_status[touch_num - 1].touch_pad_data;
}
/**
@ -749,9 +761,9 @@ static inline void touch_ll_filter_get_debounce(uint32_t *dbc_cnt)
static inline void touch_ll_filter_set_noise_thres(uint32_t noise_thr)
{
RTCCNTL.touch_filter_ctrl.touch_noise_thres = noise_thr;
RTCCNTL.touch_filter_ctrl.touch_neg_noise_thres = noise_thr;
RTCCNTL.touch_filter_ctrl.touch_neg_noise_limit = 0xF;
RTCCNTL.touch_filter_ctrl.touch_hysteresis = 2;
RTCCNTL.touch_filter_ctrl.config2 = noise_thr;
RTCCNTL.touch_filter_ctrl.config1 = 0xF;
RTCCNTL.touch_filter_ctrl.config3 = 2;
}
/**
@ -889,7 +901,7 @@ static inline void touch_ll_denoise_get_grade(touch_pad_denoise_grade_t *grade)
*/
static inline void touch_ll_denoise_read_data(uint32_t *data)
{
*data = SENS.sar_touch_status0.touch_denoise_data;
*data = SENS.sar_touch_denoise.touch_denoise_data;
}
/************************ Waterproof register setting ************************/
@ -1014,6 +1026,13 @@ static inline void touch_ll_proximity_get_meas_times(uint32_t *times)
*/
static inline void touch_ll_proximity_read_meas_cnt(touch_pad_t touch_num, uint32_t *cnt)
{
if (SENS.sar_touch_conf.touch_approach_pad0 == touch_num) {
*cnt = SENS.sar_touch_appr_status.touch_approach_pad0_cnt;
} else if (SENS.sar_touch_conf.touch_approach_pad1 == touch_num) {
*cnt = SENS.sar_touch_appr_status.touch_approach_pad1_cnt;
} else if (SENS.sar_touch_conf.touch_approach_pad2 == touch_num) {
*cnt = SENS.sar_touch_appr_status.touch_approach_pad2_cnt;
}
}
/**
@ -1111,17 +1130,22 @@ static inline bool touch_ll_sleep_get_approach_status(void)
*/
static inline void touch_ll_sleep_read_benchmark(uint32_t *benchmark)
{
SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_BENCHMARK;
*benchmark = SENS.sar_touch_slp_status.touch_slp_data;
}
static inline void touch_ll_sleep_read_smooth(uint32_t *smooth_data)
{
SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_SMOOTH;
*smooth_data = SENS.sar_touch_slp_status.touch_slp_data;
}
/* Workaround: Note: sleep pad raw data is not in `sar_touch_slp_status` */
static inline void touch_ll_sleep_read_data(uint32_t *raw_data)
{
uint32_t touch_num = RTCCNTL.touch_slp_thres.touch_slp_pad;
SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_RAW;
*raw_data = SENS.sar_touch_status[touch_num - 1].touch_pad1_data;
*raw_data = SENS.sar_touch_status[touch_num - 1].touch_pad_data;
}
static inline void touch_ll_sleep_reset_benchmark(void)
@ -1146,6 +1170,7 @@ static inline void touch_ll_sleep_low_power(bool is_low_power)
*/
static inline void touch_ll_sleep_read_debounce(uint32_t *debounce)
{
*debounce = SENS.sar_touch_slp_status.touch_slp_debounce;
}
/**
@ -1154,6 +1179,7 @@ static inline void touch_ll_sleep_read_debounce(uint32_t *debounce)
*/
static inline void touch_ll_sleep_read_proximity_cnt(uint32_t *approach_cnt)
{
*approach_cnt = SENS.sar_touch_appr_status.touch_slp_approach_cnt;
}
/**

View File

@ -1,19 +1,12 @@
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
// The HAL layer for Touch Sensor (common part)
#include "soc/soc_pins.h"
#include "hal/touch_sensor_hal.h"
#include "hal/touch_sensor_types.h"
#include "soc/soc_caps.h"

View File

@ -1,16 +1,8 @@
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
@ -155,12 +147,23 @@ typedef enum {
TOUCH_PAD_INTR_MASK_INACTIVE = BIT(2), /*!<Inactive for one of the enabled channels. */
TOUCH_PAD_INTR_MASK_SCAN_DONE = BIT(3), /*!<Measurement done for all the enabled channels. */
TOUCH_PAD_INTR_MASK_TIMEOUT = BIT(4), /*!<Timeout for one of the enabled channels. */
#if SOC_TOUCH_PROXIMITY_MEAS_DONE_SUPPORTED
TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE = BIT(5), /*!<For proximity sensor, when the number of measurements reaches the set count of measurements, an interrupt will be generated. */
TOUCH_PAD_INTR_MASK_MAX
#define TOUCH_PAD_INTR_MASK_ALL (TOUCH_PAD_INTR_MASK_TIMEOUT \
| TOUCH_PAD_INTR_MASK_SCAN_DONE \
| TOUCH_PAD_INTR_MASK_INACTIVE \
| TOUCH_PAD_INTR_MASK_ACTIVE \
| TOUCH_PAD_INTR_MASK_DONE \
| TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE) /*!<All touch interrupt type enable. */
#else
TOUCH_PAD_INTR_MASK_MAX
#define TOUCH_PAD_INTR_MASK_ALL (TOUCH_PAD_INTR_MASK_TIMEOUT \
| TOUCH_PAD_INTR_MASK_SCAN_DONE \
| TOUCH_PAD_INTR_MASK_INACTIVE \
| TOUCH_PAD_INTR_MASK_ACTIVE \
| TOUCH_PAD_INTR_MASK_DONE) /*!<All touch interrupt type enable. */
#endif
} touch_pad_intr_mask_t;
FLAG_ATTR(touch_pad_intr_mask_t)

View File

@ -1,16 +1,8 @@
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* Soc capabilities file, describing the following chip attributes:
@ -239,11 +231,11 @@
#define SOC_TIMER_GROUP_TOTAL_TIMERS (SOC_TIMER_GROUPS * SOC_TIMER_GROUP_TIMERS_PER_GROUP)
/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/
#define SOC_TOUCH_VERSION_1 (1) /*!<Hardware version of touch sensor */
#define SOC_TOUCH_SENSOR_NUM (10)
#define SOC_TOUCH_PAD_MEASURE_WAIT_MAX (0xFF) /*!<The timer frequency is 8Mhz, the max value is 0xff */
#define SOC_TOUCH_PAD_THRESHOLD_MAX (0) /*!<If set touch threshold max value, The touch sensor can't be in touched status */
#define SOC_TOUCH_PAD_WAKE_SUPPORTED (1) /*!<Supports waking up from touch pad trigger */
/*-------------------------- TWAI CAPS ---------------------------------------*/
#define SOC_TWAI_BRP_MIN 2
@ -295,6 +287,7 @@
/*-------------------------- Power Management CAPS ---------------------------*/
#define SOC_PM_SUPPORT_EXT_WAKEUP (1)
#define SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP (1) /*!<Supports waking up from touch pad trigger */
/* ---------------------------- Compatibility ------------------------------- */
#define SOC_CAN_SUPPORTED SOC_TWAI_SUPPORTED

View File

@ -234,12 +234,12 @@
#define SOC_TIMER_GROUP_TOTAL_TIMERS (SOC_TIMER_GROUPS * SOC_TIMER_GROUP_TIMERS_PER_GROUP)
/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/
#define SOC_TOUCH_SENSOR_NUM (15) /*! 15 Touch channels */
#define SOC_TOUCH_PROXIMITY_CHANNEL_NUM (3) /* Sopport touch proximity channel number. */
#define SOC_TOUCH_VERSION_2 (1) /*!<Hardware version of touch sensor */
#define SOC_TOUCH_SENSOR_NUM (15) /*!<15 Touch channels */
#define SOC_TOUCH_PROXIMITY_CHANNEL_NUM (3) /* Sopport touch proximity channel number. */
#define SOC_TOUCH_PAD_THRESHOLD_MAX (0x1FFFFF) /*!<If set touch threshold max value, The touch sensor can't be in touched status */
#define SOC_TOUCH_PAD_MEASURE_WAIT_MAX (0xFF) /*!<The timer frequency is 8Mhz, the max value is 0xff */
#define SOC_TOUCH_PAD_WAKE_SUPPORTED (1) /*!<Supports waking up from touch pad trigger */
/*-------------------------- TWAI CAPS ---------------------------------------*/
#define SOC_TWAI_BRP_MIN 2
@ -330,5 +330,7 @@
#define SOC_PM_SUPPORT_WIFI_PD (1)
#define SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP (1) /*!<Supports waking up from touch pad trigger */
/* ---------------------------- Compatibility ------------------------------- */
// No contents

View File

@ -1,16 +1,9 @@
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdbool.h>
@ -115,6 +108,9 @@ extern "C" {
#define RTC_CNTL_CK8M_DFREQ_DEFAULT 100
#define RTC_CNTL_SCK_DCAP_DEFAULT 255
#define RTC_CNTL_ULPCP_TOUCH_START_WAIT_IN_SLEEP (0xFF)
#define RTC_CNTL_ULPCP_TOUCH_START_WAIT_DEFAULT (0x10)
/*
set sleep_init default param
*/

View File

@ -1,16 +1,9 @@
// Copyright 2017-2021 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _SOC_RTC_CNTL_REG_H_
#define _SOC_RTC_CNTL_REG_H_
@ -3033,30 +3026,30 @@ ork.*/
#define RTC_CNTL_TOUCH_DEBOUNCE_M ((RTC_CNTL_TOUCH_DEBOUNCE_V)<<(RTC_CNTL_TOUCH_DEBOUNCE_S))
#define RTC_CNTL_TOUCH_DEBOUNCE_V 0x7
#define RTC_CNTL_TOUCH_DEBOUNCE_S 25
/* RTC_CNTL_TOUCH_HYSTERESIS : R/W ;bitpos:[24:23] ;default: 2'd1 ; */
/*description: .*/
#define RTC_CNTL_TOUCH_HYSTERESIS 0x00000003
#define RTC_CNTL_TOUCH_HYSTERESIS_M ((RTC_CNTL_TOUCH_HYSTERESIS_V)<<(RTC_CNTL_TOUCH_HYSTERESIS_S))
#define RTC_CNTL_TOUCH_HYSTERESIS_V 0x3
#define RTC_CNTL_TOUCH_HYSTERESIS_S 23
/* RTC_CNTL_TOUCH_CONFIG3 : R/W ;bitpos:[24:23] ;default: 2'd1 ; */
/*description: */
#define RTC_CNTL_TOUCH_CONFIG3 0x00000003
#define RTC_CNTL_TOUCH_CONFIG3_M ((RTC_CNTL_TOUCH_CONFIG3_V) << (RTC_CNTL_TOUCH_CONFIG3_S))
#define RTC_CNTL_TOUCH_CONFIG3_V 0x3
#define RTC_CNTL_TOUCH_CONFIG3_S 23
/* RTC_CNTL_TOUCH_NOISE_THRES : R/W ;bitpos:[22:21] ;default: 2'd1 ; */
/*description: .*/
#define RTC_CNTL_TOUCH_NOISE_THRES 0x00000003
#define RTC_CNTL_TOUCH_NOISE_THRES_M ((RTC_CNTL_TOUCH_NOISE_THRES_V)<<(RTC_CNTL_TOUCH_NOISE_THRES_S))
#define RTC_CNTL_TOUCH_NOISE_THRES_V 0x3
#define RTC_CNTL_TOUCH_NOISE_THRES_S 21
/* RTC_CNTL_TOUCH_NEG_NOISE_THRES : R/W ;bitpos:[20:19] ;default: 2'd1 ; */
/*description: .*/
#define RTC_CNTL_TOUCH_NEG_NOISE_THRES 0x00000003
#define RTC_CNTL_TOUCH_NEG_NOISE_THRES_M ((RTC_CNTL_TOUCH_NEG_NOISE_THRES_V)<<(RTC_CNTL_TOUCH_NEG_NOISE_THRES_S))
#define RTC_CNTL_TOUCH_NEG_NOISE_THRES_V 0x3
#define RTC_CNTL_TOUCH_NEG_NOISE_THRES_S 19
/* RTC_CNTL_TOUCH_NEG_NOISE_LIMIT : R/W ;bitpos:[18:15] ;default: 4'd5 ; */
/*description: negative threshold counter limit.*/
#define RTC_CNTL_TOUCH_NEG_NOISE_LIMIT 0x0000000F
#define RTC_CNTL_TOUCH_NEG_NOISE_LIMIT_M ((RTC_CNTL_TOUCH_NEG_NOISE_LIMIT_V)<<(RTC_CNTL_TOUCH_NEG_NOISE_LIMIT_S))
#define RTC_CNTL_TOUCH_NEG_NOISE_LIMIT_V 0xF
#define RTC_CNTL_TOUCH_NEG_NOISE_LIMIT_S 15
/* RTC_CNTL_TOUCH_CONFIG2 : R/W ;bitpos:[20:19] ;default: 2'd1 ; */
/*description: */
#define RTC_CNTL_TOUCH_CONFIG2 0x00000003
#define RTC_CNTL_TOUCH_CONFIG2_M ((RTC_CNTL_TOUCH_CONFIG2_V) << (RTC_CNTL_TOUCH_CONFIG2_S))
#define RTC_CNTL_TOUCH_CONFIG2_V 0x3
#define RTC_CNTL_TOUCH_CONFIG2_S 19
/* RTC_CNTL_TOUCH_CONFIG1 : R/W ;bitpos:[18:15] ;default: 4'd5 ; */
/*description: */
#define RTC_CNTL_TOUCH_CONFIG1 0x0000000F
#define RTC_CNTL_TOUCH_CONFIG1_M ((RTC_CNTL_TOUCH_CONFIG1_V) << (RTC_CNTL_TOUCH_CONFIG1_S))
#define RTC_CNTL_TOUCH_CONFIG1_V 0xF
#define RTC_CNTL_TOUCH_CONFIG1_S 15
/* RTC_CNTL_TOUCH_JITTER_STEP : R/W ;bitpos:[14:11] ;default: 4'd1 ; */
/*description: touch jitter step.*/
#define RTC_CNTL_TOUCH_JITTER_STEP 0x0000000F
@ -3075,12 +3068,12 @@ ork.*/
#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_S 8
/* RTC_CNTL_TOUCH_BYPASS_NEG_NOISE_THRES : R/W ;bitpos:[7] ;default: 1'b0 ; */
/*description: .*/
#define RTC_CNTL_TOUCH_BYPASS_NEG_NOISE_THRES (BIT(7))
#define RTC_CNTL_TOUCH_BYPASS_NEG_NOISE_THRES_M (BIT(7))
#define RTC_CNTL_TOUCH_BYPASS_NEG_NOISE_THRES_V 0x1
#define RTC_CNTL_TOUCH_BYPASS_NEG_NOISE_THRES_S 7
/* RTC_CNTL_TOUCH_BYPASS_NEG_THRES : R/W ;bitpos:[7] ;default: 1'b0 ; */
/*description: */
#define RTC_CNTL_TOUCH_BYPASS_NEG_THRES (BIT(7))
#define RTC_CNTL_TOUCH_BYPASS_NEG_THRES_M (BIT(7))
#define RTC_CNTL_TOUCH_BYPASS_NEG_THRES_V 0x1
#define RTC_CNTL_TOUCH_BYPASS_NEG_THRES_S 7
#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 ; */

View File

@ -1,16 +1,9 @@
// Copyright 2017-2021 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _SOC_RTC_CNTL_STRUCT_H_
#define _SOC_RTC_CNTL_STRUCT_H_
@ -809,10 +802,10 @@ typedef volatile struct rtc_cntl_dev_s {
uint32_t touch_bypass_noise_thres : 1;
uint32_t touch_smooth_lvl : 2;
uint32_t touch_jitter_step : 4; /*touch jitter step*/
uint32_t touch_neg_noise_limit : 4; /*negative threshold counter limit*/
uint32_t touch_neg_noise_thres : 2;
uint32_t config1: 4;
uint32_t config2: 2;
uint32_t touch_noise_thres : 2;
uint32_t touch_hysteresis : 2;
uint32_t config3: 2;
uint32_t touch_debounce : 3; /*debounce counter*/
uint32_t touch_filter_mode : 3; /*0: IIR ? 1: IIR ? 2: IIR 1/8 3: Jitter*/
uint32_t touch_filter_en : 1; /*touch filter enable*/

View File

@ -1,16 +1,9 @@
// Copyright 2017-2021 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _SOC_SENS_STRUCT_H_
#define _SOC_SENS_STRUCT_H_
@ -266,7 +259,7 @@ typedef volatile struct sens_dev_s {
} sar_touch_status0;
union {
struct {
uint32_t touch_pad1_data : 22;
uint32_t touch_pad_data : 22;
uint32_t reserved22 : 7;
uint32_t touch_pad_debounce : 3;
};

View File

@ -197,6 +197,7 @@
#define SOC_SPIRAM_SUPPORTED 1
/*-------------------------- SYS TIMER CAPS ----------------------------------*/
#define SOC_TOUCH_VERSION_2 (1) // Hardware version of touch sensor
#define SOC_SYSTIMER_COUNTER_NUM (2) // Number of counter units
#define SOC_SYSTIMER_ALARM_NUM (3) // Number of alarm units
#define SOC_SYSTIMER_BIT_WIDTH_LO (32) // Bit width of systimer low part
@ -213,7 +214,12 @@
#define SOC_TIMER_GROUP_TOTAL_TIMERS (SOC_TIMER_GROUPS * SOC_TIMER_GROUP_TIMERS_PER_GROUP)
/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/
#include "touch_sensor_caps.h"
#define SOC_TOUCH_SENSOR_NUM (15) /*! 15 Touch channels */
#define SOC_TOUCH_PROXIMITY_CHANNEL_NUM (3) /* Sopport touch proximity channel number. */
#define SOC_TOUCH_PROXIMITY_MEAS_DONE_SUPPORTED (1) /*Sopport touch proximity channel measure done interrupt type. */
#define SOC_TOUCH_PAD_THRESHOLD_MAX (0x1FFFFF) /*!<If set touch threshold max value, The touch sensor can't be in touched status */
#define SOC_TOUCH_PAD_MEASURE_WAIT_MAX (0xFF) /*!<The timer frequency is 8Mhz, the max value is 0xff */
/*-------------------------- TWAI CAPS ---------------------------------------*/
#include "twai_caps.h"
@ -279,6 +285,7 @@
#define SOC_PM_SUPPORT_TAGMEM_PD (1)
#define SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP (1) /*!<Supports waking up from touch pad trigger */
/*-------------------------- Flash Encryption CAPS----------------------------*/
#define SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX (64)

View File

@ -1,16 +1,8 @@
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* Pin definition header file. The long term plan is to have a single soc_pins.h for all
@ -25,3 +17,4 @@
#include "soc/spi_pins.h"
#include "soc/sdio_slave_pins.h"
#include "soc/sdmmc_pins.h"
#include "soc/touch_sensor_pins.h"

View File

@ -1,33 +0,0 @@
// Copyright 2019-2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#define SOC_TOUCH_SENSOR_NUM (15)
#define SOC_TOUCH_PAD_MEASURE_WAIT_MAX (0xFF)
#define SOC_TOUCH_PAD_THRESHOLD_MAX (0x1FFFFF)
#define SOC_TOUCH_SHIELD_CHANNEL (14)
#define SOC_TOUCH_DENOISE_CHANNEL (0)
#define SOC_TOUCH_PROXIMITY_CHANNEL_NUM (3)
#define SOC_TOUCH_PAD_WAKE_SUPPORTED (1) /*!<Supports waking up from touch pad trigger */
#ifdef __cplusplus
}
#endif

View File

@ -1,19 +1,13 @@
// Copyright 2010-2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
//Touch channels
/* Note: T0 is an internal channel that does not have a corresponding external GPIO. */
#define TOUCH_PAD_GPIO1_CHANNEL TOUCH_PAD_NUM1
@ -22,23 +16,38 @@
#define TOUCH_PAD_GPIO2_CHANNEL TOUCH_PAD_NUM2
#define TOUCH_PAD_NUM2_GPIO_NUM 2
#define TOUCH_PAD_GPIO15_CHANNEL TOUCH_PAD_NUM3
#define TOUCH_PAD_NUM3_GPIO_NUM 15
#define TOUCH_PAD_GPIO3_CHANNEL TOUCH_PAD_NUM3
#define TOUCH_PAD_NUM3_GPIO_NUM 3
#define TOUCH_PAD_GPIO13_CHANNEL TOUCH_PAD_NUM4
#define TOUCH_PAD_NUM4_GPIO_NUM 13
#define TOUCH_PAD_GPIO4_CHANNEL TOUCH_PAD_NUM4
#define TOUCH_PAD_NUM4_GPIO_NUM 4
#define TOUCH_PAD_GPIO12_CHANNEL TOUCH_PAD_NUM5
#define TOUCH_PAD_NUM5_GPIO_NUM 12
#define TOUCH_PAD_GPIO5_CHANNEL TOUCH_PAD_NUM5
#define TOUCH_PAD_NUM5_GPIO_NUM 5
#define TOUCH_PAD_GPIO14_CHANNEL TOUCH_PAD_NUM6
#define TOUCH_PAD_NUM6_GPIO_NUM 14
#define TOUCH_PAD_GPIO6_CHANNEL TOUCH_PAD_NUM6
#define TOUCH_PAD_NUM6_GPIO_NUM 6
#define TOUCH_PAD_GPIO27_CHANNEL TOUCH_PAD_NUM7
#define TOUCH_PAD_NUM7_GPIO_NUM 27
#define TOUCH_PAD_GPIO7_CHANNEL TOUCH_PAD_NUM7
#define TOUCH_PAD_NUM7_GPIO_NUM 7
#define TOUCH_PAD_GPIO33_CHANNEL TOUCH_PAD_NUM8
#define TOUCH_PAD_NUM8_GPIO_NUM 33
#define TOUCH_PAD_GPIO8_CHANNEL TOUCH_PAD_NUM8
#define TOUCH_PAD_NUM8_GPIO_NUM 8
#define TOUCH_PAD_GPIO32_CHANNEL TOUCH_PAD_NUM9
#define TOUCH_PAD_NUM9_GPIO_NUM 32
#define TOUCH_PAD_GPIO9_CHANNEL TOUCH_PAD_NUM9
#define TOUCH_PAD_NUM9_GPIO_NUM 9
#define TOUCH_PAD_GPIO10_CHANNEL TOUCH_PAD_NUM10
#define TOUCH_PAD_NUM10_GPIO_NUM 10
#define TOUCH_PAD_GPIO11_CHANNEL TOUCH_PAD_NUM11
#define TOUCH_PAD_NUM11_GPIO_NUM 11
#define TOUCH_PAD_GPIO12_CHANNEL TOUCH_PAD_NUM12
#define TOUCH_PAD_NUM12_GPIO_NUM 12
#define TOUCH_PAD_GPIO13_CHANNEL TOUCH_PAD_NUM13
#define TOUCH_PAD_NUM13_GPIO_NUM 13
#define TOUCH_PAD_GPIO14_CHANNEL TOUCH_PAD_NUM14
#define TOUCH_PAD_NUM14_GPIO_NUM 14

View File

@ -0,0 +1,20 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#define SOC_TOUCH_SHIELD_CHANNEL (14) /*!< The waterproof function includes a shielded channel (TOUCH_PAD_NUM14) */
#define SOC_TOUCH_DENOISE_CHANNEL (0) /*!< 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. */
#ifdef __cplusplus
}
#endif

View File

@ -1,20 +1,13 @@
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "soc/touch_sensor_periph.h"
/* Store IO number corresponding to the Touch Sensor channel number. */
/* Note: T0 is an internal channel that does not have a corresponding external GPIO. */
const int touch_sensor_channel_io_map[SOC_TOUCH_SENSOR_NUM] = {
-1,
TOUCH_PAD_NUM1_GPIO_NUM,
@ -26,4 +19,9 @@ const int touch_sensor_channel_io_map[SOC_TOUCH_SENSOR_NUM] = {
TOUCH_PAD_NUM7_GPIO_NUM,
TOUCH_PAD_NUM8_GPIO_NUM,
TOUCH_PAD_NUM9_GPIO_NUM,
TOUCH_PAD_NUM10_GPIO_NUM,
TOUCH_PAD_NUM11_GPIO_NUM,
TOUCH_PAD_NUM12_GPIO_NUM,
TOUCH_PAD_NUM13_GPIO_NUM,
TOUCH_PAD_NUM14_GPIO_NUM
};

View File

@ -2,26 +2,28 @@ Touch Sensor
============
:link_to_translation:`zh_CN:[中文]`
{IDF_TARGET_TOUCH_SENSOR_VERSION:default="v2", esp32="v1"}
Introduction
------------
A touch sensor system is built on a substrate which carries electrodes and relevant connections under a protective flat surface. When a user touches the surface, the capacitance variation is used to evaluate if the touch was valid.
.. only:: esp32
.. only:: SOC_TOUCH_VERSION_1
ESP32 can handle up to 10 capacitive touch pads / GPIOs.
Touch sensor on {IDF_TARGET_NAME} can support up to 10 capacitive touch pads / GPIOs.
.. only:: esp32s2
.. only:: SOC_TOUCH_VERSION_2
{IDF_TARGET_NAME} can handle up to 14 capacitive touch pads / GPIOs.
Touch sensor on {IDF_TARGET_NAME} can support up to 14 capacitive touch pads / GPIOs.
The sensing pads can be arranged in different combinations (e.g., matrix, slider), so that a larger area or more points can be detected. The touch pad sensing process is under the control of a hardware-implemented finite-state machine (FSM) which is initiated by software or a dedicated hardware timer.
The sensing pads can be arranged in different combinations (e.g., matrix, slider), so that a larger area or more points can be detected. The touch pad sensing process is under the control of a hardware-implemented finite-state machine (FSM) which is initiated by software or a dedicated hardware timer.
For design, operation, and control registers of a touch sensor, see *{IDF_TARGET_NAME} Technical Reference Manual* > *On-Chip Sensors and Analog Signal Processing* [`PDF <{IDF_TARGET_TRM_EN_URL}#sensor>`__].
In-depth design details of touch sensors and firmware development guidelines for {IDF_TARGET_NAME} are available in `Touch Sensor Application Note <https://github.com/espressif/esp-iot-solution/blob/release/v1.0/documents/touch_pad_solution/touch_sensor_design_en.md>`_.
.. only:: esp32
.. only:: SOC_TOUCH_VERSION_1
For more information about testing touch sensors in various configurations, please check the `Guide for ESP32-Sense-Kit <https://github.com/espressif/esp-dev-kits/blob/master/esp32-sense-kit/docs/esp32_sense_kit_guide_en.md>`_.
@ -59,7 +61,7 @@ Use the function :cpp:func:`touch_pad_set_fsm_mode` to select if touch pad measu
Touch State Measurements
^^^^^^^^^^^^^^^^^^^^^^^^
.. only:: esp32
.. only:: SOC_TOUCH_VERSION_1
The following two functions come in handy to read raw or filtered measurements from the sensor:
@ -72,7 +74,7 @@ Touch State Measurements
Before using :cpp:func:`touch_pad_read_filtered`, you need to initialize and configure the filter by calling specific filter functions described in Section `Filtering of Measurements`_.
.. only:: esp32s2
.. only:: SOC_TOUCH_VERSION_2
The following function come in handy to read raw measurements from the sensor:
@ -80,7 +82,7 @@ Touch State Measurements
It can also be used, for example, to evaluate a particular touch pad design by checking the range of sensor readings when a pad is touched or released. This information can be then used to establish a touch threshold.
For the demonstration of how to read the touch pad data, check the application example :example:`peripherals/touch_pad_read`.
For the demonstration of how to read the touch pad data, check the application example :example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_read`.
Optimization of Measurements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -115,7 +117,7 @@ All functions are provided in pairs to *set* a specific parameter and to *get* t
Filtering of Measurements
^^^^^^^^^^^^^^^^^^^^^^^^^
.. only:: esp32
.. only:: SOC_TOUCH_VERSION_1
If measurements are noisy, you can filter them with provided API functions. Before using the filter, please start it by calling :cpp:func:`touch_pad_filter_start`.
@ -123,7 +125,7 @@ Filtering of Measurements
You can stop the filter with :cpp:func:`touch_pad_filter_stop`. If not required anymore, the filter can be deleted by invoking :cpp:func:`touch_pad_filter_delete`.
.. only:: esp32s2
.. only:: SOC_TOUCH_VERSION_2
If measurements are noisy, you can filter them with provided API functions. The {IDF_TARGET_NAME}'s touch functionality provide two sets of APIs for doing this.
@ -139,7 +141,7 @@ Touch detection is implemented in ESP32's hardware based on the user-configured
Hardware touch detection can also be wired to interrupts. This is described in the next section.
If measurements are noisy and capacity changes are small, hardware touch detection might be unreliable. To resolve this issue, instead of using hardware detection / provided interrupts, implement measurement filtering and perform touch detection in your own application. For sample implementation of both methods of touch detection, see :example:`peripherals/touch_pad_interrupt`.
If measurements are noisy and capacity changes are small, hardware touch detection might be unreliable. To resolve this issue, instead of using hardware detection / provided interrupts, implement measurement filtering and perform touch detection in your own application. For sample implementation of both methods of touch detection, see :example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_interrupt`.
Touch Triggered Interrupts
^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -148,7 +150,7 @@ Before enabling an interrupt on a touch detection, you should establish a touch
Once a detection threshold is established, it can be set during initialization with :cpp:func:`touch_pad_config` or at the runtime with :cpp:func:`touch_pad_set_thresh`.
.. only:: esp32
.. only:: SOC_TOUCH_VERSION_1
In the next step, configure how interrupts are triggered. They can be triggered below or above the threshold, which is set with the function :cpp:func:`touch_pad_set_trigger_mode`.
@ -159,13 +161,13 @@ Finally, configure and manage interrupt calls using the following functions:
When interrupts are operational, you can obtain the information from which particular pad an interrupt came by invoking :cpp:func:`touch_pad_get_status` and clear the pad status with :cpp:func:`touch_pad_clear_status`.
.. only:: esp32
.. only:: SOC_TOUCH_VERSION_1
.. note::
Interrupts on touch detection operate on raw / unfiltered measurements checked against user established threshold and are implemented in hardware. Enabling the software filtering API (see :ref:`touch_pad-api-filtering-of-measurements`) does not affect this process.
.. only:: esp32
.. only:: SOC_TOUCH_VERSION_1
Wakeup from Sleep Mode
^^^^^^^^^^^^^^^^^^^^^^
@ -182,8 +184,8 @@ When interrupts are operational, you can obtain the information from which parti
Application Examples
--------------------
- Touch sensor read example: :example:`peripherals/touch_pad_read`.
- Touch sensor interrupt example: :example:`peripherals/touch_pad_interrupt`.
- Touch sensor read example: :example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_read`.
- Touch sensor interrupt example: :example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_interrupt`.
.. _touch_pad-api-reference:

View File

@ -58,7 +58,7 @@ This wakeup mode doesn't require RTC peripherals or RTC memories to be powered o
:cpp:func:`esp_sleep_enable_timer_wakeup` function can be used to enable deep sleep wakeup using a timer.
.. only:: SOC_TOUCH_PAD_WAKE_SUPPORTED
.. only:: SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP
Touch pad
^^^^^^^^^

View File

@ -2,18 +2,20 @@
============
:link_to_translation:`en:[English]`
{IDF_TARGET_TOUCH_SENSOR_VERSION:default="v2", esp32="v1"}
概述
------------
触摸传感器系统由保护覆盖层、触摸电极、绝缘基板和走线组成,保护覆盖层位于最上层,绝缘基板上设有电极及走线。用户触摸覆盖层将产生电容变化,根据电容变化判断此次触摸是否为有效触摸行为。
.. only:: esp32
.. only:: SOC_TOUCH_VERSION_1
ESP32 最多支持 10 个电容式触摸传感器通道/GPIO。
ESP32 最多支持 10 个电容式触摸传感器通道/GPIO。
.. only:: esp32s2
.. only:: SOC_TOUCH_VERSION_2
{IDF_TARGET_NAME} 最多支持 14 个电容式触摸传感器通道/GPIO。
{IDF_TARGET_NAME} 最多支持 14 个电容式触摸传感器通道/GPIO。
触摸传感器可以以矩阵或滑条等方式组合使用,从而覆盖更大触感区域及更多触感点。触摸传感由软件或专用硬件计时器发起,由有限状态机 (FSM) 硬件控制。
@ -21,7 +23,7 @@
请参考 `触摸传感器应用方案简介 <https://github.com/espressif/esp-iot-solution/blob/release/v1.0/documents/touch_pad_solution/touch_sensor_design_en.md>`_,查看触摸传感器设计详情和固件开发指南。
.. only:: esp32
.. only:: SOC_TOUCH_VERSION_1
如果想评估触摸传感器的多种应用场景,请查看 `ESP32 触摸功能开发套件 <https://github.com/espressif/esp-dev-kits/blob/master/esp32-sense-kit/docs/esp32_sense_kit_guide_en.md>`_
@ -59,7 +61,7 @@
触摸状态测量
^^^^^^^^^^^^^^^^^^^^^^^^
.. only:: esp32
.. only:: SOC_TOUCH_VERSION_1
借助以下两个函数从传感器读取原始数据和滤波后的数据:
@ -72,7 +74,7 @@
使用 :cpp:func:`touch_pad_read_filtered` 之前,需要先调用 `滤波采样`_ 中特定的滤波器函数来初始化并配置该滤波器。
.. only:: esp32s2
.. only:: SOC_TOUCH_VERSION_2
借助以下函数从传感器读取原始数据:
@ -80,7 +82,7 @@
该函数也可以用于检查触碰和释放触摸传感器时传感器读数变化范围,然后根据这些信息设定触摸传感器的触摸阈值。
请参考应用示例 :example:`peripherals/touch_pad_read`,查看如何使用读取触摸传感器数据。
请参考应用示例 :example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_read`,查看如何使用读取触摸传感器数据。
优化测量
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -115,7 +117,7 @@
滤波采样
^^^^^^^^^^^^^^^^^^^^^^^^^
.. only:: esp32
.. only:: SOC_TOUCH_VERSION_1
如果测量中存在噪声,可以使用提供的 API 函数对采样进行滤波。使用滤波器之前,请先调用 :cpp:func:`touch_pad_filter_start` 启动该滤波器。
@ -123,7 +125,7 @@
如需停止滤波器,请调用 :cpp:func:`touch_pad_filter_stop` 函数。如果不再使用该滤波器,请调用 :cpp:func:`touch_pad_filter_delete` 删除此滤波器。
.. only:: esp32s2
.. only:: SOC_TOUCH_VERSION_2
如果测量中存在噪声,可以使用提供的 API 函数对采样进行滤波。{IDF_TARGET_NAME} 的触摸功能提供了两套 API 可实现此功能。
@ -139,7 +141,7 @@
用户也可以将硬件触摸监测连接至中断,详细介绍见下一章节。
如果测量中存在噪声,且电容变化幅度较小,硬件触摸监测结果可能就不太理想。如需解决这一问题,不建议使用硬件监测或中断信号,建议用户在自己的应用程序中进行采样滤波,并执行触摸监测。请参考 :example:`peripherals/touch_pad_interrupt`,查看以上两种触摸监测的实现方式。
如果测量中存在噪声,且电容变化幅度较小,硬件触摸监测结果可能就不太理想。如需解决这一问题,不建议使用硬件监测或中断信号,建议用户在自己的应用程序中进行采样滤波,并执行触摸监测。请参考 :example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_interrupt`,查看以上两种触摸监测的实现方式。
中断触发
^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -148,7 +150,7 @@
确定监测阈值后就可以在初始化时调用 :cpp:func:`touch_pad_config` 设置此阈值,或在运行时调用 :cpp:func:`touch_pad_set_thresh` 设置此阈值。
.. only:: esp32
.. only:: SOC_TOUCH_VERSION_1
下一步就是设置如何触发中断。用户可以设置在阈值以下或以上触发中断,具体触发模式由函数 :cpp:func:`touch_pad_set_trigger_mode` 设置。
@ -159,13 +161,13 @@
中断配置完成后,用户可以调用 :cpp:func:`touch_pad_get_status` 查看中断信号来自哪个触摸传感器,也可以调用 :cpp:func:`touch_pad_clear_status` 清除触摸传感器状态信息。
.. only:: esp32
.. only:: SOC_TOUCH_VERSION_1
.. note::
触摸监测中的中断信号基于原始/未经滤波的采样(对比用户设置的阈值),并在硬件中实现。启用软件滤波 API (请参考 :ref:`touch_pad-api-filtering-of-measurements`)并不会影响这一过程。
.. only:: esp32
.. only:: SOC_TOUCH_VERSION_1
从睡眠模式唤醒
^^^^^^^^^^^^^^^^^^^^^^
@ -182,8 +184,8 @@
应用示例
--------------------
- 触摸传感器读值示例::example:`peripherals/touch_pad_read`
- 触摸传感器中断示例::example:`peripherals/touch_pad_interrupt`
- 触摸传感器读值示例::example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_read`
- 触摸传感器中断示例::example:`peripherals/touch_sensor/touch_sensor_{IDF_TARGET_TOUCH_SENSOR_VERSION}/touch_pad_interrupt`
.. _touch_pad-api-reference:

View File

@ -1,2 +0,0 @@
idf_component_register(SRCS "${CONFIG_IDF_TARGET}/tp_interrupt_main.c"
INCLUDE_DIRS ".")

View File

@ -1,2 +0,0 @@
idf_component_register(SRCS "${CONFIG_IDF_TARGET}/tp_read_main.c"
INCLUDE_DIRS ".")

View File

@ -1,16 +1,8 @@
/* Touch Sensor - Example
For other examples please check:
https://github.com/espressif/esp-idf/tree/master/examples
See README.md file to get detailed usage of this example.
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

View File

@ -1,16 +1,8 @@
/* Touch Sensor waterproof - Example
For other examples please check:
https://github.com/espressif/esp-idf/tree/master/examples
See README.md file to get detailed usage of this example.
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

View File

@ -1,16 +1,8 @@
/* Touch Sensor - Example
For other examples please check:
https://github.com/espressif/esp-idf/tree/master/examples
See README.md file to get detailed usage of this example.
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

View File

@ -1,16 +1,8 @@
/* Touch Sensor - Example
For other examples please check:
https://github.com/espressif/esp-idf/tree/master/examples
See README.md file to get detailed usage of this example.
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

View File

@ -1,16 +1,8 @@
/* Touch Sensor - Example
For other examples please check:
https://github.com/espressif/esp-idf/tree/master/examples
See README.md file to get detailed usage of this example.
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

View File

@ -0,0 +1,4 @@
| Version | Supported Targets |
| ------- | ----------------- |
| V1 | ESP32 |
| V2 | ESP32S2, ESP32S3 |

View File

@ -1,5 +1,5 @@
| Supported Targets | ESP32 | ESP32-S2 |
| ----------------- | ----- | -------- |
| Supported Targets | ESP32 |
| ----------------- | ----- |
# Touch Pad Interrupt Example
@ -35,30 +35,6 @@ I (22903) Touch pad: Waiting for any pad being touched...
Note: Sensing threshold is set up automatically at start up by performing simple calibration. Application is reading current value for each pad and assuming two thirds of this value as the sensing threshold. Do not touch pads on application start up, otherwise sensing may not work correctly.
## ESP32-S2 platform
Demonstrates how to set up ESP32-S2's capacitive touch pad peripheral to trigger interrupt when a pad is touched. It also shows how to detect the touch event by the software for sensor designs when greater touch detection sensitivity is required.
ESP32-S2 supports touch detection by configuring hardware registers. The hardware periodically detects the pulse counts. If the number of pulse counts exceeds the set threshold, a hardware interrupt will be generated to notify the application layer that a certain touch sensor channel may be triggered.
The application is cycling between the interrupt mode and the pooling mode with a filter, to compare performance of the touch sensor system in both scenarios:
```
I (304) Touch pad: Initializing touch pad
I (304) Touch pad: Denoise function init
I (304) Touch pad: touch pad waterproof init
I (304) Touch pad: touch pad filter init 2
I (414) Touch pad: test init: touch pad [7] base 7382, thresh 1476
I (414) Touch pad: test init: touch pad [9] base 7349, thresh 1469
I (414) Touch pad: test init: touch pad [11] base 8047, thresh 1609
I (414) Touch pad: test init: touch pad [13] base 8104, thresh 810
I (5954) Touch pad: TouchSensor [9] be actived, status mask 0x200
W (6034) Touch pad: TouchSensor [13] be actived, enter guard mode
W (6034) Touch pad: In guard mode. No response
W (6174) Touch pad: TouchSensor [13] be actived, exit guard mode
I (6194) Touch pad: TouchSensor [9] be inactived, status mask 0x0
```
## Reference Information
For a simpler example how to configure and read capacitive touch pads, please refer to [touch_pad_read](../touch_pad_read).

View File

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

View File

@ -2,5 +2,3 @@
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
COMPONENT_SRCDIRS := $(IDF_TARGET)

View File

@ -1,11 +1,9 @@
/* Touch Pad Interrupt Example
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

View File

@ -0,0 +1,31 @@
| Supported Targets | ESP32 |
| ----------------- | ----- |
# Touch Pad Read Example
## ESP32 plaform
Read and display raw values or IIR filtered values from capacitive touch pad sensors.
Once configured, ESP32 is continuously measuring capacitance of touch pad sensors. Measurement is reflected as numeric value inversely related to sensor's capacitance. The capacitance is bigger when sensor is touched with a finger and the measured value smaller. In opposite situation, when finger is released, capacitance is smaller and the measured value bigger.
To detect when a sensor is touched and when not, each particular design should be calibrated by obtaining both measurements for each individual sensor. Then a threshold between both values should be established. Using specific threshold, API is then able to distinguish whether specific sensor is touched or released.
ESP32 supports reading up to ten capacitive touch pad sensors T0 - T9, connected to specific GPIO pins. For information on available pins please refer to [Technical Reference Manual](https://espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf). Application initializes all ten sensor pads. Then in a loop reads sensors T0 - T9 and displays obtained values (after a colon) on a serial terminal:
```
Touch Sensor filter mode read, the output format is:
Touchpad num:[raw data, filtered data]
T0:[1072,1071] T1:[ 475, 475] T2:[1004,1003] T3:[1232,1231] T4:[1675,1676] T5:[1146,1146] T6:[1607,1607] T7:[1118,1118] T8:[1695,1695] T9:[1223,1222]
T0:[1072,1071] T1:[ 475, 475] T2:[1003,1003] T3:[1231,1231] T4:[1676,1676] T5:[1146,1146] T6:[1607,1607] T7:[1118,1118] T8:[1694,1694] T9:[1222,1221]
T0:[1071,1071] T1:[ 475, 475] T2:[1004,1004] T3:[1231,1231] T4:[1678,1677] T5:[1147,1146] T6:[1607,1607] T7:[1118,1118] T8:[1694,1694] T9:[1222,1221]
```
## Reference Information
For hardware and firmware design guidelines on ESP32 touch sensor system, please refer to [Touch Sensor Application Note](https://github.com/espressif/esp-iot-solution/blob/release/v1.0/documents/touch_pad_solution/touch_sensor_design_en.md), where you may find comprehensive information on how to design and implement touch sensing applications, such as linear slider, wheel slider, matrix buttons and spring buttons.
There is another similar example that demonstrates how to perform simple calibration and trigger an interrupt when a pat is touched - see [touch_pad_interrupt](../touch_pad_interrupt).
See the README.md file in the upper level 'examples' directory for more information about examples.

View File

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

View File

@ -2,5 +2,3 @@
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
COMPONENT_SRCDIRS := $(IDF_TARGET)

View File

@ -1,11 +1,9 @@
/* Touch Pad Read Example
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

View File

@ -0,0 +1,6 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(touch_pad_interrupt)

View File

@ -0,0 +1,8 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#
PROJECT_NAME := touch_pad_interrupt
include $(IDF_PATH)/make/project.mk

View File

@ -0,0 +1,36 @@
| Supported Targets | ESP32-S2 | ESP32-S3 |
| ----------------- | -------- | -------- |
# Touch Pad Interrupt Example
## ESP32-S2, ESP32-S3 platform
Demonstrates how to set up ESP32-S2's capacitive touch pad peripheral to trigger interrupt when a pad is touched. It also shows how to detect the touch event by the software for sensor designs when greater touch detection sensitivity is required.
ESP32-S2 supports touch detection by configuring hardware registers. The hardware periodically detects the pulse counts. If the number of pulse counts exceeds the set threshold, a hardware interrupt will be generated to notify the application layer that a certain touch sensor channel may be triggered.
The application is cycling between the interrupt mode and the pooling mode with a filter, to compare performance of the touch sensor system in both scenarios:
```
I (304) Touch pad: Initializing touch pad
I (304) Touch pad: Denoise function init
I (304) Touch pad: touch pad waterproof init
I (304) Touch pad: touch pad filter init 2
I (414) Touch pad: test init: touch pad [7] base 7382, thresh 1476
I (414) Touch pad: test init: touch pad [9] base 7349, thresh 1469
I (414) Touch pad: test init: touch pad [11] base 8047, thresh 1609
I (414) Touch pad: test init: touch pad [13] base 8104, thresh 810
I (5954) Touch pad: TouchSensor [9] be actived, status mask 0x200
W (6034) Touch pad: TouchSensor [13] be actived, enter guard mode
W (6034) Touch pad: In guard mode. No response
W (6174) Touch pad: TouchSensor [13] be actived, exit guard mode
I (6194) Touch pad: TouchSensor [9] be inactived, status mask 0x0
```
## Reference Information
For a simpler example how to configure and read capacitive touch pads, please refer to [touch_pad_read](../touch_pad_read).
Design and implementation of the touch sensor system is a complex process. The [Touch Sensor Application Note](https://github.com/espressif/esp-iot-solution/blob/release/v1.0/documents/touch_pad_solution/touch_sensor_design_en.md) contains several ESP32 specific notes and comments to optimize the design and get the best out of the application with sensors controlled with the ESP32.
See the README.md file in the upper level 'examples' directory for more information about examples.

View File

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

View File

@ -0,0 +1,4 @@
#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

View File

@ -1,11 +1,9 @@
/* Touch Pad Interrupt Example
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
@ -118,7 +116,7 @@ static void tp_example_read_task(void *pvParameter)
ESP_LOGW(TAG, "TouchSensor [%d] be activated, enter guard mode", evt.pad_num);
} else {
if (guard_mode_flag == 0) {
ESP_LOGI(TAG, "TouchSensor [%d] be inactivated, status mask 0x%x", evt.pad_num, evt.pad_status);
ESP_LOGI(TAG, "TouchSensor [%d] be activated, status mask 0x%x", evt.pad_num, evt.pad_status);
} else {
ESP_LOGW(TAG, "In guard mode. No response");
}
@ -128,7 +126,7 @@ static void tp_example_read_task(void *pvParameter)
/* if guard pad be touched, other pads no response. */
if (evt.pad_num == button[3]) {
guard_mode_flag = 0;
ESP_LOGW(TAG, "TouchSensor [%d] be activated, exit guard mode", evt.pad_num);
ESP_LOGW(TAG, "TouchSensor [%d] be inactivated, exit guard mode", evt.pad_num);
} else {
if (guard_mode_flag == 0) {
ESP_LOGI(TAG, "TouchSensor [%d] be inactivated, status mask 0x%x", evt.pad_num, evt.pad_status);
@ -161,11 +159,11 @@ void app_main(void)
#if TOUCH_CHANGE_CONFIG
/* If you want change the touch sensor default setting, please write here(after initialize). There are examples: */
touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT);
touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_MEASURE_CYCLE_DEFAULT);
touch_pad_set_voltage(TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD);
touch_pad_set_idle_channel_connect(TOUCH_PAD_IDLE_CH_CONNECT_DEFAULT);
for (int i = 0; i < TOUCH_BUTTON_NUM; i++) {
touch_pad_set_cnt_mode(i, TOUCH_PAD_SLOPE_DEFAULT, TOUCH_PAD_TIE_OPT_DEFAULT);
touch_pad_set_cnt_mode(button[i], TOUCH_PAD_SLOPE_DEFAULT, TOUCH_PAD_TIE_OPT_DEFAULT);
}
#endif

View File

@ -0,0 +1,6 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(touch_pad_read)

View File

@ -0,0 +1,8 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#
PROJECT_NAME := touch_pad_read
include $(IDF_PATH)/make/project.mk

View File

@ -1,28 +1,9 @@
| Supported Targets | ESP32 | ESP32-S2 |
| ----------------- | ----- | -------- |
| Supported Targets | ESP32-S2 | ESP32-S3 |
| ----------------- | -------- | -------- |
# Touch Pad Read Example
## ESP32 plaform
Read and display raw values or IIR filtered values from capacitive touch pad sensors.
Once configured, ESP32 is continuously measuring capacitance of touch pad sensors. Measurement is reflected as numeric value inversely related to sensor's capacitance. The capacitance is bigger when sensor is touched with a finger and the measured value smaller. In opposite situation, when finger is released, capacitance is smaller and the measured value bigger.
To detect when a sensor is touched and when not, each particular design should be calibrated by obtaining both measurements for each individual sensor. Then a threshold between both values should be established. Using specific threshold, API is then able to distinguish whether specific sensor is touched or released.
ESP32 supports reading up to ten capacitive touch pad sensors T0 - T9, connected to specific GPIO pins. For information on available pins please refer to [Technical Reference Manual](https://espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf). Application initializes all ten sensor pads. Then in a loop reads sensors T0 - T9 and displays obtained values (after a colon) on a serial terminal:
```
Touch Sensor filter mode read, the output format is:
Touchpad num:[raw data, filtered data]
T0:[1072,1071] T1:[ 475, 475] T2:[1004,1003] T3:[1232,1231] T4:[1675,1676] T5:[1146,1146] T6:[1607,1607] T7:[1118,1118] T8:[1695,1695] T9:[1223,1222]
T0:[1072,1071] T1:[ 475, 475] T2:[1003,1003] T3:[1231,1231] T4:[1676,1676] T5:[1146,1146] T6:[1607,1607] T7:[1118,1118] T8:[1694,1694] T9:[1222,1221]
T0:[1071,1071] T1:[ 475, 475] T2:[1004,1004] T3:[1231,1231] T4:[1678,1677] T5:[1147,1146] T6:[1607,1607] T7:[1118,1118] T8:[1694,1694] T9:[1222,1221]
```
## ESP32-S2 platform
## ESP32-S2, ESP32-S3 platform
Read and display raw values from capacitive touch pad sensors.

View File

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

View File

@ -0,0 +1,4 @@
#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

View File

@ -1,11 +1,9 @@
/* Touch Pad Read Example
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
@ -64,11 +62,11 @@ void app_main(void)
}
#if TOUCH_CHANGE_CONFIG
/* If you want change the touch sensor default setting, please write here(after initialize). There are examples: */
touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_SLEEP_CYCLE_DEFAULT);
touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_MEASURE_CYCLE_DEFAULT);
touch_pad_set_voltage(TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD);
touch_pad_set_idle_channel_connect(TOUCH_PAD_IDLE_CH_CONNECT_DEFAULT);
for (int i = 0; i < TOUCH_BUTTON_NUM; i++) {
touch_pad_set_cnt_mode(i, TOUCH_PAD_SLOPE_DEFAULT, TOUCH_PAD_TIE_OPT_DEFAULT);
touch_pad_set_cnt_mode(button[i], TOUCH_PAD_SLOPE_DEFAULT, TOUCH_PAD_TIE_OPT_DEFAULT);
}
#endif
/* Denoise setting at TouchSensor 0. */

View File

@ -211,7 +211,7 @@ void app_main(void)
touch_pad_config(TOUCH_PAD_NUM9, TOUCH_THRESH_NO_USE);
calibrate_touch_pad(TOUCH_PAD_NUM8);
calibrate_touch_pad(TOUCH_PAD_NUM9);
#elif CONFIG_IDF_TARGET_ESP32S2
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
/* Initialize touch pad peripheral. */
touch_pad_init();
/* Only support one touch channel in sleep mode. */

View File

@ -1635,7 +1635,6 @@ components/hal/esp32s3/include/hal/mpu_ll.h
components/hal/esp32s3/include/hal/mwdt_ll.h
components/hal/esp32s3/include/hal/pcnt_ll.h
components/hal/esp32s3/include/hal/rtc_cntl_ll.h
components/hal/esp32s3/include/hal/rtc_io_ll.h
components/hal/esp32s3/include/hal/rwdt_ll.h
components/hal/esp32s3/include/hal/sha_ll.h
components/hal/esp32s3/include/hal/sigmadelta_ll.h
@ -1646,8 +1645,6 @@ components/hal/esp32s3/include/hal/spi_ll.h
components/hal/esp32s3/include/hal/spimem_flash_ll.h
components/hal/esp32s3/include/hal/systimer_ll.h
components/hal/esp32s3/include/hal/timer_ll.h
components/hal/esp32s3/include/hal/touch_sensor_hal.h
components/hal/esp32s3/include/hal/touch_sensor_ll.h
components/hal/esp32s3/include/hal/trace_ll.h
components/hal/esp32s3/include/hal/twai_ll.h
components/hal/esp32s3/include/hal/uart_ll.h
@ -1655,7 +1652,6 @@ components/hal/esp32s3/include/hal/uhci_ll.h
components/hal/esp32s3/include/hal/usb_ll.h
components/hal/esp32s3/include/hal/usb_serial_jtag_ll.h
components/hal/esp32s3/interrupt_descriptor_table.c
components/hal/esp32s3/touch_sensor_hal.c
components/hal/gdma_hal.c
components/hal/gpio_hal.c
components/hal/i2c_hal.c
@ -1716,7 +1712,6 @@ components/hal/include/hal/systimer_types.h
components/hal/include/hal/timer_hal.h
components/hal/include/hal/timer_types.h
components/hal/include/hal/touch_sensor_hal.h
components/hal/include/hal/touch_sensor_types.h
components/hal/include/hal/twai_hal.h
components/hal/include/hal/twai_types.h
components/hal/include/hal/uart_hal.h
@ -2261,7 +2256,6 @@ components/soc/esp32/include/soc/sens_struct.h
components/soc/esp32/include/soc/slc_reg.h
components/soc/esp32/include/soc/slc_struct.h
components/soc/esp32/include/soc/soc.h
components/soc/esp32/include/soc/soc_caps.h
components/soc/esp32/include/soc/soc_pins.h
components/soc/esp32/include/soc/soc_ulp.h
components/soc/esp32/include/soc/spi_pins.h
@ -2642,9 +2636,6 @@ components/soc/esp32s3/include/soc/periph_defs.h
components/soc/esp32s3/include/soc/reset_reasons.h
components/soc/esp32s3/include/soc/rmt_reg.h
components/soc/esp32s3/include/soc/rmt_struct.h
components/soc/esp32s3/include/soc/rtc.h
components/soc/esp32s3/include/soc/rtc_cntl_reg.h
components/soc/esp32s3/include/soc/rtc_cntl_struct.h
components/soc/esp32s3/include/soc/rtc_gpio_channel.h
components/soc/esp32s3/include/soc/rtc_i2c_reg.h
components/soc/esp32s3/include/soc/rtc_i2c_struct.h
@ -2657,13 +2648,11 @@ components/soc/esp32s3/include/soc/sdmmc_pins.h
components/soc/esp32s3/include/soc/sdmmc_reg.h
components/soc/esp32s3/include/soc/sdmmc_struct.h
components/soc/esp32s3/include/soc/sens_reg.h
components/soc/esp32s3/include/soc/sens_struct.h
components/soc/esp32s3/include/soc/sensitive_reg.h
components/soc/esp32s3/include/soc/sensitive_struct.h
components/soc/esp32s3/include/soc/sigmadelta_caps.h
components/soc/esp32s3/include/soc/soc.h
components/soc/esp32s3/include/soc/soc_caps.h
components/soc/esp32s3/include/soc/soc_pins.h
components/soc/esp32s3/include/soc/soc_ulp.h
components/soc/esp32s3/include/soc/spi_mem_reg.h
components/soc/esp32s3/include/soc/spi_mem_struct.h
@ -2680,7 +2669,6 @@ components/soc/esp32s3/include/soc/timer_group_reg.h
components/soc/esp32s3/include/soc/timer_group_struct.h
components/soc/esp32s3/include/soc/touch_channel.h
components/soc/esp32s3/include/soc/touch_sensor_caps.h
components/soc/esp32s3/include/soc/touch_sensor_channel.h
components/soc/esp32s3/include/soc/twai_caps.h
components/soc/esp32s3/include/soc/twai_struct.h
components/soc/esp32s3/include/soc/uart_caps.h
@ -2715,7 +2703,6 @@ components/soc/esp32s3/sdmmc_periph.c
components/soc/esp32s3/sigmadelta_periph.c
components/soc/esp32s3/spi_periph.c
components/soc/esp32s3/timer_periph.c
components/soc/esp32s3/touch_sensor_periph.c
components/soc/esp32s3/uart_periph.c
components/soc/esp32s3/usb_periph.c
components/soc/esp32s3/usb_periph.h