refactor(touch): refactor touch low-level for s2 & s3

This commit is contained in:
laokaiyao
2024-10-17 18:17:36 +08:00
committed by Kevin (Lao Kaiyao)
parent e4c92855ee
commit 1cd9dd5001
18 changed files with 1658 additions and 538 deletions

View File

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

View File

@@ -25,6 +25,7 @@
#include "soc/pmu_struct.h"
#include "soc/soc_caps.h"
#include "hal/touch_sensor_types.h"
#include "hal/touch_sens_types.h"
#ifdef __cplusplus
extern "C" {
@@ -222,10 +223,9 @@ static inline void touch_ll_force_done_curr_measurement(void)
* The measurement action can be triggered by the hardware timer, as well as by the software instruction.
* @note
* The timer should be triggered
* @param is_sleep Whether in sleep state
*/
__attribute__((always_inline))
static inline void touch_ll_start_fsm_repeated_timer(bool is_sleep)
static inline void touch_ll_start_fsm_repeated_timer(void)
{
/**
* Touch timer trigger measurement and always wait measurement done.
@@ -238,10 +238,9 @@ static inline void touch_ll_start_fsm_repeated_timer(bool is_sleep)
/**
* Stop touch sensor FSM timer.
* The measurement action can be triggered by the hardware timer, as well as by the software instruction.
* @param is_sleep Whether in sleep state
*/
__attribute__((always_inline))
static inline void touch_ll_stop_fsm_repeated_timer(bool is_sleep)
static inline void touch_ll_stop_fsm_repeated_timer(void)
{
PMU.touch_pwr_cntl.sleep_timer_en = 0;
touch_ll_force_done_curr_measurement();
@@ -326,7 +325,7 @@ static inline void touch_ll_enable_scan_mask(uint16_t chan_mask, bool enable)
* @return
* - ESP_OK on success
*/
static inline void touch_ll_set_channel_mask(uint16_t enable_mask)
static inline void touch_ll_enable_channel_mask(uint16_t enable_mask)
{
// Channel shift workaround: the lowest bit takes no effect
uint16_t mask = (enable_mask << 1) & TOUCH_PAD_BIT_MASK_ALL;
@@ -502,7 +501,7 @@ static inline uint32_t touch_ll_get_current_meas_channel(void)
*
* @param int_mask interrupt mask
*/
static inline void touch_ll_intr_enable(uint32_t int_mask)
static inline void touch_ll_interrupt_enable(uint32_t int_mask)
{
uint32_t mask = LP_TOUCH.int_ena.val;
mask |= (int_mask & TOUCH_LL_INTR_MASK_ALL);
@@ -514,7 +513,7 @@ static inline void touch_ll_intr_enable(uint32_t int_mask)
*
* @param int_mask interrupt mask
*/
static inline void touch_ll_intr_disable(uint32_t int_mask)
static inline void touch_ll_interrupt_disable(uint32_t int_mask)
{
uint32_t mask = LP_TOUCH.int_ena.val;
mask &= ~(int_mask & TOUCH_LL_INTR_MASK_ALL);
@@ -527,7 +526,7 @@ static inline void touch_ll_intr_disable(uint32_t int_mask)
* @param int_mask Pad mask to clear interrupts
*/
__attribute__((always_inline))
static inline void touch_ll_intr_clear(touch_pad_intr_mask_t int_mask)
static inline void touch_ll_interrupt_clear(touch_pad_intr_mask_t int_mask)
{
LP_TOUCH.int_clr.val = int_mask;
}
@@ -545,28 +544,23 @@ static inline uint32_t touch_ll_get_intr_status_mask(void)
}
/**
* Enable the timeout check for all touch sensor channels measurements.
* Set the timeout to enable or disable the check for all touch sensor channels measurements.
* When the touch reading of a touch channel exceeds the measurement threshold,
* If enable: a timeout interrupt will be generated and it will go to the next channel measurement.
* If disable: the FSM is always on the channel, until the measurement of this channel is over.
*
* @param timeout_cycles The maximum time cycles of the measurement on one channel.
* Set to 0 to disable the timeout.
* Set to non-zero to enable the timeout and set the timeout cycles.
*/
static inline void touch_ll_timeout_enable(uint32_t timeout_cycles)
static inline void touch_ll_set_timeout(uint32_t timeout_cycles)
{
LP_ANA_PERI.touch_scan_ctrl2.touch_timeout_num = timeout_cycles;
LP_ANA_PERI.touch_scan_ctrl2.touch_timeout_en = 1;
}
/**
* Disable the timeout check for all touch sensor channels measurements.
* When the touch reading of a touch channel exceeds the measurement threshold,
* If enable: a timeout interrupt will be generated and it will go to the next channel measurement.
* If disable: the FSM is always on the channel, until the measurement of this channel is over.
*/
static inline void touch_ll_timeout_disable(void)
{
LP_ANA_PERI.touch_scan_ctrl2.touch_timeout_en = 0;
if (timeout_cycles) {
LP_ANA_PERI.touch_scan_ctrl2.touch_timeout_num = timeout_cycles;
LP_ANA_PERI.touch_scan_ctrl2.touch_timeout_en = 1;
} else {
LP_ANA_PERI.touch_scan_ctrl2.touch_timeout_en = 0;
}
}
/**

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@@ -0,0 +1,131 @@
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_bit_defs.h"
#include "soc/soc_caps.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Touch sensor upper charging voltage limit
*/
typedef enum {
TOUCH_VOLT_LIM_H_0V9, /*!< Touch sensor upper voltage limit is 0.9V while charging a touch pad */
TOUCH_VOLT_LIM_H_1V0, /*!< Touch sensor upper voltage limit is 1.0V while charging a touch pad */
TOUCH_VOLT_LIM_H_1V1, /*!< Touch sensor upper voltage limit is 1.1V while charging a touch pad */
TOUCH_VOLT_LIM_H_1V2, /*!< Touch sensor upper voltage limit is 1.2V while charging a touch pad */
// No 1V3
TOUCH_VOLT_LIM_H_1V4, /*!< Touch sensor upper voltage limit is 1.4V while charging a touch pad */
TOUCH_VOLT_LIM_H_1V5, /*!< Touch sensor upper voltage limit is 1.5V while charging a touch pad */
TOUCH_VOLT_LIM_H_1V6, /*!< Touch sensor upper voltage limit is 1.6V while charging a touch pad */
TOUCH_VOLT_LIM_H_1V7, /*!< Touch sensor upper voltage limit is 1.7V while charging a touch pad */
// No 1V8
TOUCH_VOLT_LIM_H_1V9, /*!< Touch sensor upper voltage limit is 1.9V while charging a touch pad */
TOUCH_VOLT_LIM_H_2V0, /*!< Touch sensor upper voltage limit is 2.0V while charging a touch pad */
TOUCH_VOLT_LIM_H_2V1, /*!< Touch sensor upper voltage limit is 2.1V while charging a touch pad */
TOUCH_VOLT_LIM_H_2V2, /*!< Touch sensor upper voltage limit is 2.2V while charging a touch pad */
// No 2V3
TOUCH_VOLT_LIM_H_2V4, /*!< Touch sensor upper voltage limit is 2.4V while charging a touch pad */
TOUCH_VOLT_LIM_H_2V5, /*!< Touch sensor upper voltage limit is 2.5V while charging a touch pad */
TOUCH_VOLT_LIM_H_2V6, /*!< Touch sensor upper voltage limit is 2.6V while charging a touch pad */
TOUCH_VOLT_LIM_H_2V7, /*!< Touch sensor upper voltage limit is 2.7V while charging a touch pad */
} touch_volt_lim_h_t;
/**
* @brief Touch sensor lower discharging voltage limit
*/
typedef enum {
TOUCH_VOLT_LIM_L_0V5, /*!< Touch sensor lower voltage limit is 0.5V while charging a touch pad */
TOUCH_VOLT_LIM_L_0V6, /*!< Touch sensor lower voltage limit is 0.5V while charging a touch pad */
TOUCH_VOLT_LIM_L_0V7, /*!< Touch sensor lower voltage limit is 0.5V while charging a touch pad */
TOUCH_VOLT_LIM_L_0V8, /*!< Touch sensor lower voltage limit is 0.5V while charging a touch pad */
} touch_volt_lim_l_t;
/**
* @brief Touch sensor charge and discharge speed
*/
typedef enum {
TOUCH_CHARGE_SPEED_0 = 0, /*!< Touch sensor charge and discharge speed, no charge, always zero */
TOUCH_CHARGE_SPEED_1 = 1, /*!< Touch sensor charge and discharge speed, slowest */
TOUCH_CHARGE_SPEED_2 = 2, /*!< Touch sensor charge and discharge speed */
TOUCH_CHARGE_SPEED_3 = 3, /*!< Touch sensor charge and discharge speed */
TOUCH_CHARGE_SPEED_4 = 4, /*!< Touch sensor charge and discharge speed */
TOUCH_CHARGE_SPEED_5 = 5, /*!< Touch sensor charge and discharge speed */
TOUCH_CHARGE_SPEED_6 = 6, /*!< Touch sensor charge and discharge speed */
TOUCH_CHARGE_SPEED_7 = 7, /*!< Touch sensor charge and discharge speed, fastest */
} touch_charge_speed_t;
/**
* @brief Touch sensor initial voltage before charging
*/
typedef enum {
TOUCH_INIT_CHARGE_VOLT_LOW = 0, /*!< Tie the initial charge voltage to low */
TOUCH_INIT_CHARGE_VOLT_HIGH = 1,/*!< Tie the initial charge voltage to high */
} touch_init_charge_volt_t;
/** Touch channel idle state configuration */
typedef enum {
TOUCH_IDLE_CONN_HIGHZ = 0, /*!< The idle (enabled but not measuring) touch channel is in high resistance state */
TOUCH_IDLE_CONN_GND = 1, /*!< The idle (enabled but not measuring) touch channel is connected to the ground */
} touch_idle_conn_t;
/**
* @brief Touch sensor denoise channel internal reference capacitance
*
*/
typedef enum {
TOUCH_DENOISE_CHAN_CAP_L0 = 0, /*!< Denoise channel internal reference capacitance is 5pf */
TOUCH_DENOISE_CHAN_CAP_L1 = 1, /*!< Denoise channel internal reference capacitance is 6.4pf */
TOUCH_DENOISE_CHAN_CAP_L2 = 2, /*!< Denoise channel internal reference capacitance is 7.8pf */
TOUCH_DENOISE_CHAN_CAP_L3 = 3, /*!< Denoise channel internal reference capacitance is 9.2pf */
TOUCH_DENOISE_CHAN_CAP_L4 = 4, /*!< Denoise channel internal reference capacitance is 10.6pf */
TOUCH_DENOISE_CHAN_CAP_L5 = 5, /*!< Denoise channel internal reference capacitance is 12.0pf */
TOUCH_DENOISE_CHAN_CAP_L6 = 6, /*!< Denoise channel internal reference capacitance is 13.4pf */
TOUCH_DENOISE_CHAN_CAP_L7 = 7, /*!< Denoise channel internal reference capacitance is 14.8pf */
} touch_denoise_chan_cap_t;
/**
* @brief Touch sensor denoise channel noise suppression resolution
*
*/
typedef enum {
TOUCH_DENOISE_CHAN_RES_BIT12 = 0, /*!< Denoise channel noise suppression resolution is 12bit */
TOUCH_DENOISE_CHAN_RES_BIT10 = 1, /*!< Denoise channel noise suppression resolution is 10bit */
TOUCH_DENOISE_CHAN_RES_BIT8 = 2, /*!< Denoise channel noise suppression resolution is 8bit */
TOUCH_DENOISE_CHAN_RES_BIT4 = 3, /*!< Denoise channel noise suppression resolution is 4bit */
} touch_denoise_chan_res_t;
/**
* @brief Touch sensor bias type
*
*/
typedef enum {
TOUCH_BIAS_TYPE_BANDGAP, /*!< Use bandgap-bias to charge/discharge the touch channel, which is more stable but power-consuming */
TOUCH_BIAS_TYPE_SELF, /*!< Use self-bias to charge/discharge the touch channel, which is less stable but power-saving */
} touch_bias_type_t;
/**
* @brief Touch channel counting mode of the binarized touch output
*
*/
typedef enum {
TOUCH_PAD_OUT_AS_DATA, /*!< Counting the output of touch channel as data.
* The value will be smaller than actual value but more sensitive when the frequency of touch_out is close to the source clock
* Normally we treat the output as data when it is lower than the sample clock
*/
TOUCH_PAD_OUT_AS_CLOCK, /*!< Counting the output of touch channel as clock.
* The value is accurate but less sensitive when the frequency of touch_out is close to the source clock
* Normally we treat the output as clock when it is higher than the sample clock
*/
} touch_out_mode_t;
#ifdef __cplusplus
}
#endif

View File

@@ -14,6 +14,7 @@
#pragma once
#include "soc/soc_caps.h"
#if SOC_TOUCH_SENSOR_SUPPORTED
#include "hal/touch_sensor_ll.h"
#include "hal/touch_sensor_types.h"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -798,14 +798,14 @@ typedef volatile struct rtc_cntl_dev_s {
union {
struct {
uint32_t reserved0 : 7;
uint32_t touch_bypass_neg_noise_thres : 1;
uint32_t touch_bypass_nn_thres : 1;
uint32_t touch_bypass_noise_thres : 1;
uint32_t touch_smooth_lvl : 2;
uint32_t touch_jitter_step : 4; /*touch jitter step*/
uint32_t config1: 4;
uint32_t config2: 2;
uint32_t config1 : 4;
uint32_t config2 : 2;
uint32_t touch_noise_thres : 2;
uint32_t config3: 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*/