mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
feat(hal): graudate the touch sensor hal driver into a new component
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
idf_build_get_property(target IDF_TARGET)
|
||||
|
||||
if(${target} STREQUAL "linux")
|
||||
return() # This component is not supported by the POSIX/Linux simulator
|
||||
endif()
|
||||
|
||||
set(srcs)
|
||||
set(includes)
|
||||
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${target}/include")
|
||||
list(APPEND includes "${target}/include")
|
||||
endif()
|
||||
# "include" should be behind "${target}/include", because `include_next` has sequence requirement
|
||||
list(APPEND includes "include")
|
||||
|
||||
# Touch Sensor related source files
|
||||
if(CONFIG_SOC_TOUCH_SENSOR_SUPPORTED)
|
||||
# Source files for the legacy touch hal driver
|
||||
if(CONFIG_SOC_TOUCH_SENSOR_VERSION LESS 3)
|
||||
list(APPEND srcs "${target}/touch_sensor_legacy_hal.c"
|
||||
"touch_sensor_legacy_hal.c"
|
||||
)
|
||||
endif()
|
||||
list(APPEND srcs "touch_sens_hal.c" "${target}/touch_sensor_periph.c")
|
||||
endif()
|
||||
|
||||
idf_component_register(SRCS ${srcs}
|
||||
INCLUDE_DIRS ${includes}
|
||||
REQUIRES soc hal)
|
||||
@@ -0,0 +1,52 @@
|
||||
# ESP Hardware Abstraction Layer for Touch Sensor Peripheral
|
||||
|
||||
> [!NOTE]
|
||||
> This component is currently in beta. Its API, behavior, and compatibility may change at any time and without notice; backward compatibility is not guaranteed. Use caution when integrating into production systems.
|
||||
|
||||
## Overview
|
||||
|
||||
The `esp_hal_touch_sens` component provides a **Hardware Abstraction Layer** for Touch Sensor controller supported targets. Touch sensors detect touch events by measuring changes in capacitance when a finger or object approaches the touch pad, enabling capacitive touch interfaces for user interaction.
|
||||
|
||||
## Architecture
|
||||
|
||||
The Touch Sensor HAL is structured in two main sub-layers:
|
||||
|
||||
1. **HAL Layer (Upper)**: Defines the operational steps and data structures required to control touch sensor peripherals (e.g., initialization, channel configuration, filter setup, measurement control).
|
||||
|
||||
2. **Low-Level Layer (Bottom)**: Serves as a translation layer between the HAL and the register files defined in the `soc` component, handling target-specific register configurations.
|
||||
|
||||
## Supported Touch Sensor Controllers
|
||||
|
||||
This HAL supports various touch sensor controller versions depending on the ESP chip:
|
||||
|
||||
- **Touch Sensor Version 1**: Basic touch sensor functionality (ESP32)
|
||||
- **Touch Sensor Version 2**: Enhanced features including improved filtering and denoise capabilities (ESP32-S2, ESP32-S3)
|
||||
- **Touch Sensor Version 3**: Advanced features with frequency hopping, multiple sample configurations, and enhanced waterproof support (ESP32-P4 and newer chips)
|
||||
|
||||
## Features
|
||||
|
||||
- **Channel Management**: Multi-channel touch pad support with independent configuration
|
||||
- **Measurement Control**: Configurable charge/discharge cycles, voltage thresholds, and measurement intervals
|
||||
- **Filtering and Signal Processing**:
|
||||
- Benchmark filter (IIR filter, jitter filter)
|
||||
- Smooth data filter for noise reduction
|
||||
- Debounce and noise threshold configuration
|
||||
- Active threshold hysteresis
|
||||
- **Denoise Function**: Internal denoise channel (T0) to filter out power supply noise and external EMI
|
||||
- **Waterproof Support**: Guard pad and shield channel configuration for water-resistant applications
|
||||
- **Proximity Sensing**: Up to three touch channels can be configured as proximity sensors
|
||||
- **Sleep Channel**: Deep sleep wake-up support with configurable sleep channel
|
||||
- **FSM Operation**: Hardware timer or software-triggered measurement modes
|
||||
- **Interrupt Handling**: Multiple interrupt types (active, inactive, done, scan done, timeout, proximity done)
|
||||
- **Sample Configuration**: Multiple sample configurations with frequency hopping support (Version 3)
|
||||
|
||||
## Usage
|
||||
|
||||
The HAL functions primarily serve ESP-IDF peripheral drivers such as `esp_driver_touch_sens`.
|
||||
|
||||
Advanced developers can use these interfaces directly when implementing custom drivers, with the understanding that API stability is not guaranteed.
|
||||
|
||||
## Dependencies
|
||||
|
||||
- `soc`: Provides chip-specific register definitions
|
||||
- `hal`: Core hardware abstraction utilities and macros
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* NOTICE
|
||||
* The hal is not public api, don't use in application code.
|
||||
* See readme.md in hal/include/hal/readme.md
|
||||
******************************************************************************/
|
||||
|
||||
// The HAL layer for touch sensor (esp32 specific part)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hal/touch_sensor_ll.h"
|
||||
#include "hal/touch_sensor_legacy_types.h"
|
||||
|
||||
#include_next "hal/touch_sensor_legacy_hal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Set touch sensor measurement time.
|
||||
*
|
||||
* @param meas_time The duration of the touch sensor measurement.
|
||||
* t_meas = meas_time / (8MHz), the maximum measure time is 0xffff / 8M = 8.19 ms.
|
||||
*/
|
||||
#define touch_hal_set_meas_time(meas_time) touch_ll_set_meas_time(meas_time)
|
||||
|
||||
/**
|
||||
* Get touch sensor measurement time.
|
||||
*
|
||||
* @param meas_time Pointer to accept measurement cycle count.
|
||||
*/
|
||||
#define touch_hal_get_meas_time(meas_time) touch_ll_get_meas_time(meas_time)
|
||||
|
||||
/**
|
||||
* Set touch sensor interrupt trigger mode.
|
||||
* Interrupt can be triggered either when touch value is less than
|
||||
* threshold or when touch value is more than threshold.
|
||||
*
|
||||
* @param mode Touch sensor interrupt trigger mode.
|
||||
*/
|
||||
#define touch_hal_set_trigger_mode(mode) touch_ll_set_trigger_mode(mode)
|
||||
|
||||
/**
|
||||
* Get touch sensor interrupt trigger mode.
|
||||
* Interrupt can be triggered either when touch value is less than
|
||||
* threshold or when touch value is more than threshold.
|
||||
*
|
||||
* @param mode Touch sensor interrupt trigger mode.
|
||||
*/
|
||||
#define touch_hal_get_trigger_mode(mode) touch_ll_get_trigger_mode(mode)
|
||||
|
||||
/**
|
||||
* Set touch sensor interrupt trigger source. There are two sets of touch signals.
|
||||
* Set1 and set2 can be mapped to several touch signals. Either set will be triggered
|
||||
* if at least one of its touch signal is 'touched'. The interrupt can be configured to be generated
|
||||
* if set1 is triggered, or only if both sets are triggered.
|
||||
*
|
||||
* @param src Touch sensor interrupt trigger source.
|
||||
*/
|
||||
#define touch_hal_set_trigger_source(src) touch_ll_set_trigger_source(src)
|
||||
|
||||
/**
|
||||
* Get touch sensor interrupt trigger source.
|
||||
*
|
||||
* @param src Pointer to accept touch sensor interrupt trigger source.
|
||||
*/
|
||||
#define touch_hal_get_trigger_source(src) touch_ll_get_trigger_source(src)
|
||||
|
||||
/**
|
||||
* Set touch sensor group mask.
|
||||
* Touch pad module has two sets of signals, 'Touched' signal is triggered only if
|
||||
* at least one of touch pad in this group is "touched".
|
||||
* This function will set the register bits according to the given bitmask.
|
||||
*
|
||||
* @param set1_mask bitmask of touch sensor signal group1, it's a 10-bit value
|
||||
* @param set2_mask bitmask of touch sensor signal group2, it's a 10-bit value
|
||||
*/
|
||||
#define touch_hal_set_group_mask(group1_mask, group2_mask) touch_ll_set_group_mask(group1_mask, group2_mask)
|
||||
|
||||
/**
|
||||
* Get touch sensor group mask.
|
||||
*
|
||||
* @param set1_mask pointer to accept bitmask of touch sensor signal group1, it's a 10-bit value
|
||||
* @param set2_mask pointer to accept bitmask of touch sensor signal group2, it's a 10-bit value
|
||||
*/
|
||||
#define touch_hal_get_group_mask(group1_mask, group2_mask) touch_ll_get_group_mask(group1_mask, group2_mask)
|
||||
|
||||
/**
|
||||
* Clear touch sensor group mask.
|
||||
*
|
||||
* @param set1_mask pointer to accept bitmask of touch sensor signal group1, it's a 10-bit value
|
||||
* @param set2_mask pointer to accept bitmask of touch sensor signal group2, it's a 10-bit value
|
||||
*/
|
||||
#define touch_hal_clear_group_mask(group1_mask, group2_mask) touch_ll_clear_group_mask(group1_mask, group2_mask)
|
||||
|
||||
/**
|
||||
* To enable touch pad interrupt.
|
||||
*/
|
||||
#define touch_hal_intr_enable() touch_ll_intr_enable()
|
||||
|
||||
/**
|
||||
* To disable touch pad interrupt.
|
||||
*/
|
||||
#define touch_hal_intr_disable() touch_ll_intr_disable()
|
||||
|
||||
/**
|
||||
* To clear touch pad interrupt.
|
||||
*/
|
||||
#define touch_hal_intr_clear() touch_ll_intr_clear()
|
||||
|
||||
/**
|
||||
* Get the touch pad which caused wakeup from deep sleep.
|
||||
*
|
||||
* @param pad_num pointer to touch pad which caused wakeup.
|
||||
*/
|
||||
void touch_hal_get_wakeup_status(touch_pad_t *pad_num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,921 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* NOTICE
|
||||
* The ll is not public api, don't use in application code.
|
||||
* See readme.md in hal/include/hal/readme.md
|
||||
******************************************************************************/
|
||||
|
||||
// The Lowlevel layer for Touch Sensor
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include "hal/misc.h"
|
||||
#include "hal/assert.h"
|
||||
#include "hal/touch_sensor_periph.h"
|
||||
#include "soc/sens_struct.h"
|
||||
#include "soc/rtc_io_struct.h"
|
||||
#include "soc/rtc_cntl_struct.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/soc_caps_full.h"
|
||||
#include "hal/touch_sens_types.h"
|
||||
|
||||
#define TOUCH_LL_GET(_attr) TOUCH_LL_ ## _attr
|
||||
#define TOUCH_LL_CHAN_NUM 10
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//Some register bits of touch sensor 8 and 9 are mismatched, we need to swap the bits.
|
||||
#define TOUCH_LL_BIT_SWAP(data, n, m) (((data >> n) & 0x1) == ((data >> m) & 0x1) ? (data) : ((data) ^ ((0x1 <<n) | (0x1 << m))))
|
||||
#define TOUCH_LL_BITS_SWAP(v) TOUCH_LL_BIT_SWAP(v, 8, 9)
|
||||
#define TOUCH_LL_CHAN_SWAP(chan) ((chan) == 8 ? 9 : ((chan) == 9 ? 8 : (chan)))
|
||||
#define TOUCH_LL_FULL_CHANNEL_MASK ((uint16_t)((1U << TOUCH_LL_GET(CHAN_NUM)) - 1))
|
||||
#define TOUCH_LL_READ_RAW 0x0
|
||||
|
||||
#define TOUCH_LL_CHARGE_DURATION_MAX (0xFFFF)
|
||||
#define TOUCH_LL_PAD_MEASURE_WAIT_MAX (0xFF) // The timer frequency is 8Mhz, the max value is 0xff
|
||||
#define TOUCH_LL_ACTIVE_THRESH_MAX (0xFFFF) // Max channel active threshold
|
||||
|
||||
#define TOUCH_LL_INTR_MASK_TRIGGER (1UL << 6) // Interrupt when the touch interrupt is triggered (depends on intr trigger mode)
|
||||
#define TOUCH_LL_INTR_MASK_ALL (TOUCH_LL_INTR_MASK_TRIGGER)
|
||||
|
||||
/*********************************** Interrupts *******************************/
|
||||
/**
|
||||
* Enable touch sensor interrupt by bitmask.
|
||||
*
|
||||
* @param int_mask interrupt mask
|
||||
*/
|
||||
static inline void touch_ll_interrupt_enable(uint32_t int_mask)
|
||||
{
|
||||
(void) int_mask;
|
||||
// Only one interrupt, set directly
|
||||
RTCCNTL.int_ena.rtc_touch = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable touch sensor interrupt by bitmask.
|
||||
*
|
||||
* @param int_mask interrupt mask
|
||||
*/
|
||||
static inline void touch_ll_interrupt_disable(uint32_t int_mask)
|
||||
{
|
||||
(void) int_mask;
|
||||
// Only one interrupt, clear directly
|
||||
RTCCNTL.int_ena.rtc_touch = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear touch sensor interrupt by bitmask.
|
||||
*
|
||||
* @param int_mask Pad mask to clear interrupts
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline void touch_ll_interrupt_clear(uint32_t int_mask)
|
||||
{
|
||||
(void) int_mask;
|
||||
RTCCNTL.int_clr.rtc_touch = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bitmask of touch sensor interrupt status.
|
||||
*
|
||||
* @return type interrupt type
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline uint32_t touch_ll_get_intr_status_mask(void)
|
||||
{
|
||||
// intr status bit of touch (bit7) is not same as the enable bit (bit6)
|
||||
return RTCCNTL.int_st.rtc_touch ? TOUCH_LL_INTR_MASK_TRIGGER : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set touch sensor interrupt trigger mode.
|
||||
* Interrupt can be triggered either when touch value is below the threshold (touched) or
|
||||
* or when touch value exceed the threshold (release).
|
||||
*
|
||||
* @param mode Touch sensor interrupt trigger mode.
|
||||
* - TOUCH_INTR_TRIG_ON_BELOW_THRESH: interrupt triggers when touched (touch value is below the threshold)
|
||||
* - TOUCH_INTR_TRIG_ON_ABOVE_THRESH: interrupt triggers when released (touch value is exceed the threshold)
|
||||
*/
|
||||
static inline void touch_ll_set_intr_trigger_mode(touch_intr_trig_mode_t mode)
|
||||
{
|
||||
SENS.sar_touch_ctrl1.touch_out_sel = mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set touch sensor interrupt trigger source. There are two sets of touch signals.
|
||||
* Set1 and set2 can be mapped to several touch signals. Either set will be triggered
|
||||
* if at least one of its touch signal is 'touched'. The interrupt can be configured to be generated
|
||||
* if set1 is triggered, or only if both sets are triggered.
|
||||
*
|
||||
* @param group Touch sensor interrupt trigger group.
|
||||
*/
|
||||
static inline void touch_ll_set_intr_trigger_group(touch_intr_trig_group_t group)
|
||||
{
|
||||
SENS.sar_touch_ctrl1.touch_out_1en = group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set touch sensor group mask.
|
||||
* Touch pad module has two sets of signals, 'Touched' signal is triggered only if
|
||||
* at least one of touch pad in this group is "touched".
|
||||
* This function will set the register bits according to the given bitmask.
|
||||
*
|
||||
* @param group1_mask bitmask of touch sensor signal group1, it's a 10-bit value
|
||||
* @param group2_mask bitmask of touch sensor signal group2, it's a 10-bit value
|
||||
*/
|
||||
static inline void touch_ll_config_trigger_group1(uint32_t touch_num, bool enable)
|
||||
{
|
||||
touch_num = TOUCH_LL_CHAN_SWAP(touch_num);
|
||||
uint32_t mask = SENS.sar_touch_enable.touch_pad_outen1;
|
||||
if (enable) {
|
||||
mask |= (1 << touch_num);
|
||||
} else {
|
||||
mask &= ~(1 << touch_num);
|
||||
}
|
||||
SENS.sar_touch_enable.touch_pad_outen1 = mask;
|
||||
}
|
||||
|
||||
static inline void touch_ll_config_trigger_group2(uint32_t touch_num, bool enable)
|
||||
{
|
||||
touch_num = TOUCH_LL_CHAN_SWAP(touch_num);
|
||||
uint32_t mask = SENS.sar_touch_enable.touch_pad_outen2;
|
||||
if (enable) {
|
||||
mask |= (1 << touch_num);
|
||||
} else {
|
||||
mask &= ~(1 << touch_num);
|
||||
}
|
||||
SENS.sar_touch_enable.touch_pad_outen2 = mask;
|
||||
}
|
||||
|
||||
static inline void touch_ll_reset_trigger_groups(void)
|
||||
{
|
||||
SENS.sar_touch_enable.touch_pad_outen1 = 0;
|
||||
SENS.sar_touch_enable.touch_pad_outen2 = 0;
|
||||
}
|
||||
|
||||
/********************************* Status Info ********************************/
|
||||
/**
|
||||
* Get touch sensor measure status. No block.
|
||||
*
|
||||
* @return
|
||||
* - If touch sensors measure done.
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline bool touch_ll_is_measure_done(void)
|
||||
{
|
||||
return (bool)SENS.sar_touch_ctrl2.touch_meas_done;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the touch sensor active channel mask, usually used in ISR to decide which channels are 'touched'.
|
||||
*
|
||||
* @param active_mask The touch channel status. e.g. Touch1 trigger status is `status_mask & (BIT1)`.
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline void touch_ll_get_active_channel_mask(uint32_t *active_mask)
|
||||
{
|
||||
*active_mask = TOUCH_LL_BITS_SWAP(SENS.sar_touch_ctrl2.touch_meas_en);
|
||||
}
|
||||
|
||||
/**************************** Measurement Configuration ***********************/
|
||||
|
||||
/**
|
||||
* Set touch sensor threshold of charge cycles that triggers pad active state.
|
||||
* The threshold determines the sensitivity of the touch sensor.
|
||||
* The threshold is the original value of the trigger state minus the benchmark value.
|
||||
*
|
||||
* @note If set "TOUCH_PAD_THRESHOLD_MAX", the touch is never be triggered.
|
||||
* @param touch_num The touch pad id
|
||||
* @param thresh The threshold of charge cycles
|
||||
*/
|
||||
static inline void touch_ll_set_chan_active_threshold(uint32_t touch_num, uint32_t thresh)
|
||||
{
|
||||
// Workaround: swap chan 8 and chan 9
|
||||
touch_num = TOUCH_LL_CHAN_SWAP(touch_num);
|
||||
if (touch_num & 0x1) {
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(SENS.touch_thresh[touch_num >> 1], l_thresh, thresh);
|
||||
} else {
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(SENS.touch_thresh[touch_num >> 1], h_thresh, thresh);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get touch sensor threshold of charge cycles that triggers pad active state.
|
||||
* The threshold determines the sensitivity of the touch sensor.
|
||||
* The threshold is the original value of the trigger state minus the benchmark value.
|
||||
*
|
||||
* @note If set "TOUCH_PAD_THRESHOLD_MAX", the touch is never be triggered.
|
||||
* @param touch_num The touch pad id
|
||||
* @return
|
||||
* - The threshold of charge cycles
|
||||
*/
|
||||
static inline uint32_t touch_ll_get_chan_active_threshold(uint32_t touch_num)
|
||||
{
|
||||
// Workaround: swap chan 8 and chan 9
|
||||
touch_num = TOUCH_LL_CHAN_SWAP(touch_num);
|
||||
if (touch_num & 0x1) {
|
||||
return HAL_FORCE_READ_U32_REG_FIELD(SENS.touch_thresh[touch_num >> 1], l_thresh);
|
||||
} else {
|
||||
return HAL_FORCE_READ_U32_REG_FIELD(SENS.touch_thresh[touch_num >> 1], h_thresh);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the power on wait cycle
|
||||
*
|
||||
* @param wait_cycles
|
||||
*/
|
||||
static inline void touch_ll_set_power_on_wait_cycle(uint32_t wait_cycles)
|
||||
{
|
||||
//the waiting cycles (in 8MHz) between TOUCH_START and TOUCH_XPD
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(SENS.sar_touch_ctrl1, touch_xpd_wait, wait_cycles); //wait volt stable
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the duration of the charge window
|
||||
*
|
||||
* @param duration The duration of the touch channel charge / discharge window.
|
||||
* duration = meas_ticks / (8MHz), the maximum duration is 0xffff / 8M = 8.19 ms.
|
||||
*/
|
||||
static inline void touch_ll_set_charge_window_duration(uint32_t duration)
|
||||
{
|
||||
//touch sensor charge/discharge window duration= meas_cycle / 8Mhz
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(SENS.sar_touch_ctrl1, touch_meas_delay, duration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set touch sensor sleep time.
|
||||
*
|
||||
* @param interval_ticks The touch sensor will sleep for some cycles after each measurement.
|
||||
* interval_ticks decide the interval between each measurement.
|
||||
* t_sleep = interval_ticks / (RTC_SLOW_CLK frequency).
|
||||
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
|
||||
*/
|
||||
static inline void touch_ll_set_measure_interval_ticks(uint16_t interval_ticks)
|
||||
{
|
||||
//touch sensor sleep cycle Time = sleep_cycle / RTC_SLOW_CLK
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(SENS.sar_touch_ctrl2, touch_sleep_cycles, interval_ticks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Touch pad charge speed.
|
||||
*
|
||||
* @param touch_num Touch channel number
|
||||
* @param charge_speed Charge speed of this touch channel
|
||||
*/
|
||||
static inline void touch_ll_set_charge_speed(uint32_t touch_num, touch_charge_speed_t charge_speed)
|
||||
{
|
||||
RTCIO.touch_pad[touch_num].slope = charge_speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the upper limitation of the touch channel voltage while charging
|
||||
*
|
||||
* @param high_lim The high(upper) limitation of charge
|
||||
*/
|
||||
static inline void touch_ll_set_charge_voltage_high_limit(touch_volt_lim_h_t high_lim)
|
||||
{
|
||||
RTCIO.touch_cfg.drefh = (uint32_t)high_lim & 0x3;
|
||||
RTCIO.touch_cfg.drange = (uint32_t)high_lim >> 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the lower limitation of the touch channel voltage while discharging
|
||||
*
|
||||
* @param low_lim The lower limitation of discharge
|
||||
*/
|
||||
static inline void touch_ll_set_charge_voltage_low_limit(touch_volt_lim_l_t low_lim)
|
||||
{
|
||||
RTCIO.touch_cfg.drefl = low_lim;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the initial charge voltage of touch channel
|
||||
* i.e., the touch pad measurement start from a low voltage or a high voltage
|
||||
*
|
||||
* @param touch_num Touch channel number
|
||||
* @param init_charge_volt The initial charge voltage
|
||||
*/
|
||||
static inline void touch_ll_set_init_charge_voltage(uint32_t touch_num, touch_init_charge_volt_t init_charge_volt)
|
||||
{
|
||||
// Workaround: swap chan 8 and chan 9
|
||||
touch_num = TOUCH_LL_CHAN_SWAP(touch_num);
|
||||
if (init_charge_volt == TOUCH_INIT_CHARGE_VOLT_FLOAT) {
|
||||
RTCIO.touch_pad[touch_num].xpd = 0;
|
||||
} else {
|
||||
RTCIO.touch_pad[touch_num].xpd = 1;
|
||||
RTCIO.touch_pad[touch_num].tie_opt = init_charge_volt;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable touch sensor channel. Register touch channel into touch sensor measurement group.
|
||||
* The working mode of the touch sensor is simultaneous measurement.
|
||||
* This function will set the measure bits according to the given bitmask.
|
||||
*
|
||||
* @note If set this mask, the FSM timer should be stop firstly.
|
||||
* @note The touch sensor that in scan map, should be deinit GPIO function firstly.
|
||||
* @param enable_mask bitmask of touch sensor scan group.
|
||||
* e.g. TOUCH_PAD_NUM1 -> BIT(1)
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
static inline void touch_ll_enable_channel_mask(uint16_t enable_mask)
|
||||
{
|
||||
SENS.sar_touch_enable.touch_pad_worken = TOUCH_LL_BITS_SWAP(enable_mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all touch sensor channels active status.
|
||||
*
|
||||
* @note Generally no manual removal is required.
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline void touch_ll_clear_active_channel_status(void)
|
||||
{
|
||||
SENS.sar_touch_ctrl2.touch_meas_en_clr = 1;
|
||||
}
|
||||
|
||||
/********************************* FSM Operation ******************************/
|
||||
/**
|
||||
* Enable touch sensor FSM timer trigger (continuous) mode or software trigger (oneshot) mode.
|
||||
*
|
||||
* @param enable Enable FSM timer mode.
|
||||
* True: the FSM will trigger scanning repeatedly under the control of the hardware timer (continuous mode)
|
||||
* False: the FSM will trigger scanning once under the control of the software (continuous mode)
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline void touch_ll_enable_fsm_timer(bool enable)
|
||||
{
|
||||
SENS.sar_touch_ctrl2.touch_start_force = !enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start touch sensor FSM timer to run FSM repeatedly
|
||||
* The measurement action can be triggered by the hardware timer, as well as by the software instruction.
|
||||
* @note
|
||||
* The timer should be triggered
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline void touch_ll_start_fsm_repeated_timer(void)
|
||||
{
|
||||
RTCCNTL.state0.touch_slp_timer_en = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop touch sensor FSM timer.
|
||||
* The measurement action can be triggered by the hardware timer, as well as by the software instruction.
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline void touch_ll_stop_fsm_repeated_timer(void)
|
||||
{
|
||||
RTCCNTL.state0.touch_slp_timer_en = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the FSM repeated timer enabled.
|
||||
* @note when the timer is enabled, RTC clock should not be power down
|
||||
*
|
||||
* @return
|
||||
* - true: enabled
|
||||
* - false: disabled
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline bool touch_ll_is_fsm_repeated_timer_enabled(void)
|
||||
{
|
||||
return (bool)RTCCNTL.state0.touch_slp_timer_en;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the touch sensor FSM start signal from software
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline void touch_ll_trigger_oneshot_measurement(void)
|
||||
{
|
||||
SENS.sar_touch_ctrl2.touch_start_en = 1;
|
||||
SENS.sar_touch_ctrl2.touch_start_en = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Power on the channel by mask
|
||||
*
|
||||
* @param chan_mask The channel mask that needs to power on
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline void touch_ll_channel_sw_measure_mask(uint16_t chan_mask)
|
||||
{
|
||||
(void) chan_mask;
|
||||
// Only for compatibility
|
||||
}
|
||||
|
||||
/************************************** Data **********************************/
|
||||
/**
|
||||
* Get the data of the touch channel according to the types
|
||||
*
|
||||
* @param touch_num touch pad index
|
||||
* @param type data type
|
||||
* 0/1: TOUCH_LL_READ_RAW, raw data of touch channel
|
||||
* 2: TOUCH_LL_READ_BENCHMARK, benchmark value of touch channel,
|
||||
* the benchmark value is the maximum during the first measurement period
|
||||
* 3: TOUCH_LL_READ_SMOOTH, the smoothed data that obtained by filtering the raw data.
|
||||
* @param data pointer to the data
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline void touch_ll_read_chan_data(uint32_t touch_num, uint8_t type, uint32_t *data)
|
||||
{
|
||||
HAL_ASSERT(type == TOUCH_LL_READ_RAW);
|
||||
HAL_ASSERT(touch_num < TOUCH_LL_GET(CHAN_NUM));
|
||||
touch_num = TOUCH_LL_CHAN_SWAP(touch_num);
|
||||
if (touch_num & 0x1) {
|
||||
*data = HAL_FORCE_READ_U32_REG_FIELD(SENS.touch_meas[touch_num >> 1], l_val);
|
||||
} else {
|
||||
*data = HAL_FORCE_READ_U32_REG_FIELD(SENS.touch_meas[touch_num >> 1], h_val);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* Legacy APIs (to be removed in esp-idf v6.0) */
|
||||
/******************************************************************************/
|
||||
|
||||
#include "hal/touch_sensor_legacy_types.h"
|
||||
|
||||
/**
|
||||
* Swap the number of touch8 and touch9.
|
||||
*
|
||||
* @touch_num Touch channel num.
|
||||
*/
|
||||
static inline touch_pad_t touch_ll_num_wrap(touch_pad_t touch_num)
|
||||
{
|
||||
if (touch_num == TOUCH_PAD_NUM8) {
|
||||
return TOUCH_PAD_NUM9;
|
||||
} else if (touch_num == TOUCH_PAD_NUM9) {
|
||||
return TOUCH_PAD_NUM8;
|
||||
}
|
||||
return touch_num;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set touch sensor measurement time.
|
||||
*
|
||||
* @param meas_time The duration of the touch sensor measurement.
|
||||
* t_meas = meas_time / (8MHz), the maximum measure time is 0xffff / 8M = 8.19 ms.
|
||||
*/
|
||||
static inline void touch_ll_set_meas_time(uint16_t meas_time)
|
||||
{
|
||||
//touch sensor measure time= meas_cycle / 8Mhz
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(SENS.sar_touch_ctrl1, touch_meas_delay, meas_time);
|
||||
//the waiting cycles (in 8MHz) between TOUCH_START and TOUCH_XPD
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(SENS.sar_touch_ctrl1, touch_xpd_wait, TOUCH_LL_PAD_MEASURE_WAIT_MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get touch sensor measurement time.
|
||||
*
|
||||
* @param meas_time Pointer to accept measurement cycle count.
|
||||
*/
|
||||
static inline void touch_ll_get_meas_time(uint16_t *meas_time)
|
||||
{
|
||||
*meas_time = HAL_FORCE_READ_U32_REG_FIELD(SENS.sar_touch_ctrl1, touch_meas_delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set touch sensor sleep time (interval of measurement).
|
||||
*
|
||||
* @param sleep_time The touch sensor will sleep after each measurement.
|
||||
* sleep_cycle decide the interval between each measurement.
|
||||
* t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
|
||||
* The approximate frequency value of RTC_SLOW_CLK can be obtained using `rtc_clk_slow_freq_get_hz` function.
|
||||
*/
|
||||
static inline void touch_ll_set_sleep_time(uint16_t sleep_time)
|
||||
{
|
||||
//touch sensor sleep cycle Time = sleep_cycle / RTC_SLOW_CLK( can be 150k or 32k depending on the options)
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(SENS.sar_touch_ctrl2, touch_sleep_cycles, sleep_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get touch sensor sleep time.
|
||||
*
|
||||
* @param sleep_time Pointer to accept sleep cycle count.
|
||||
*/
|
||||
static inline void touch_ll_get_sleep_time(uint16_t *sleep_time)
|
||||
{
|
||||
*sleep_time = HAL_FORCE_READ_U32_REG_FIELD(SENS.sar_touch_ctrl2, touch_sleep_cycles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set touch sensor high voltage threshold of charge.
|
||||
* The touch sensor measures the channel capacitance value by charging and discharging the channel.
|
||||
* So the high threshold should be less than the supply voltage.
|
||||
*
|
||||
* @param refh The high voltage threshold of charge.
|
||||
*/
|
||||
static inline void touch_ll_set_voltage_high(touch_high_volt_t refh)
|
||||
{
|
||||
RTCIO.touch_cfg.drefh = refh;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get touch sensor high voltage threshold of charge.
|
||||
* The touch sensor measures the channel capacitance value by charging and discharging the channel.
|
||||
* So the high threshold should be less than the supply voltage.
|
||||
*
|
||||
* @param refh The high voltage threshold of charge.
|
||||
*/
|
||||
static inline void touch_ll_get_voltage_high(touch_high_volt_t *refh)
|
||||
{
|
||||
*refh = (touch_high_volt_t)RTCIO.touch_cfg.drefh;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set touch sensor low voltage threshold of discharge.
|
||||
* The touch sensor measures the channel capacitance value by charging and discharging the channel.
|
||||
*
|
||||
* @param refl The low voltage threshold of discharge.
|
||||
*/
|
||||
static inline void touch_ll_set_voltage_low(touch_low_volt_t refl)
|
||||
{
|
||||
RTCIO.touch_cfg.drefl = refl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get touch sensor low voltage threshold of discharge.
|
||||
* The touch sensor measures the channel capacitance value by charging and discharging the channel.
|
||||
*
|
||||
* @param refl The low voltage threshold of discharge.
|
||||
*/
|
||||
static inline void touch_ll_get_voltage_low(touch_low_volt_t *refl)
|
||||
{
|
||||
*refl = (touch_low_volt_t)RTCIO.touch_cfg.drefl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set touch sensor high voltage attenuation of charge. The actual charge threshold is high voltage threshold minus attenuation value.
|
||||
* The touch sensor measures the channel capacitance value by charging and discharging the channel.
|
||||
* So the high threshold should be less than the supply voltage.
|
||||
*
|
||||
* @param refh The high voltage threshold of charge.
|
||||
*/
|
||||
static inline void touch_ll_set_voltage_attenuation(touch_volt_atten_t atten)
|
||||
{
|
||||
RTCIO.touch_cfg.drange = atten;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get touch sensor high voltage attenuation of charge. The actual charge threshold is high voltage threshold minus attenuation value.
|
||||
* The touch sensor measures the channel capacitance value by charging and discharging the channel.
|
||||
* So the high threshold should be less than the supply voltage.
|
||||
*
|
||||
* @param refh The high voltage threshold of charge.
|
||||
*/
|
||||
static inline void touch_ll_get_voltage_attenuation(touch_volt_atten_t *atten)
|
||||
{
|
||||
*atten = (touch_volt_atten_t)RTCIO.touch_cfg.drange;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set touch sensor charge/discharge speed(currents) for each pad.
|
||||
* If the slope is 0, the counter would always be zero.
|
||||
* If the slope is 1, the charging and discharging would be slow. The measurement time becomes longer.
|
||||
* If the slope is set 7, which is the maximum value, the charging and discharging would be fast.
|
||||
* The measurement time becomes shorter.
|
||||
*
|
||||
* @note The higher the charge and discharge current, the greater the immunity of the touch channel,
|
||||
* but it will increase the system power consumption.
|
||||
* @param touch_num Touch pad index.
|
||||
* @param slope touch pad charge/discharge speed(currents).
|
||||
*/
|
||||
static inline void touch_ll_set_slope(touch_pad_t touch_num, touch_cnt_slope_t slope)
|
||||
{
|
||||
RTCIO.touch_pad[touch_num].slope = slope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get touch sensor charge/discharge speed(currents) for each pad.
|
||||
* If the slope is 0, the counter would always be zero.
|
||||
* If the slope is 1, the charging and discharging would be slow. The measurement time becomes longer.
|
||||
* If the slope is set 7, which is the maximum value, the charging and discharging would be fast.
|
||||
* The measurement time becomes shorter.
|
||||
*
|
||||
* @param touch_num Touch pad index.
|
||||
* @param slope touch pad charge/discharge speed(currents).
|
||||
*/
|
||||
static inline void touch_ll_get_slope(touch_pad_t touch_num, touch_cnt_slope_t *slope)
|
||||
{
|
||||
*slope = (touch_cnt_slope_t)RTCIO.touch_pad[touch_num].slope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set initial voltage state of touch channel for each measurement.
|
||||
*
|
||||
* @param touch_num Touch pad index.
|
||||
* @param opt Initial voltage state.
|
||||
*/
|
||||
static inline void touch_ll_set_tie_option(touch_pad_t touch_num, touch_tie_opt_t opt)
|
||||
{
|
||||
touch_pad_t touch_pad_wrap = touch_ll_num_wrap(touch_num);
|
||||
if (opt == TOUCH_PAD_TIE_OPT_FLOAT) {
|
||||
RTCIO.touch_pad[touch_pad_wrap].xpd = 0;
|
||||
} else {
|
||||
RTCIO.touch_pad[touch_pad_wrap].xpd = 1;
|
||||
RTCIO.touch_pad[touch_pad_wrap].tie_opt = opt;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get initial voltage state of touch channel for each measurement.
|
||||
*
|
||||
* @param touch_num Touch pad index.
|
||||
* @param opt Initial voltage state.
|
||||
*/
|
||||
static inline void touch_ll_get_tie_option(touch_pad_t touch_num, touch_tie_opt_t *opt)
|
||||
{
|
||||
touch_pad_t touch_pad_wrap = touch_ll_num_wrap(touch_num);
|
||||
if (RTCIO.touch_pad[touch_pad_wrap].xpd) {
|
||||
*opt = (touch_tie_opt_t)RTCIO.touch_pad[touch_pad_wrap].tie_opt;
|
||||
} else {
|
||||
*opt = TOUCH_PAD_TIE_OPT_FLOAT;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set touch sensor FSM mode.
|
||||
* The measurement action can be triggered by the hardware timer, as well as by the software instruction.
|
||||
*
|
||||
* @param mode FSM mode.
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline void touch_ll_set_fsm_mode(touch_fsm_mode_t mode)
|
||||
{
|
||||
SENS.sar_touch_ctrl2.touch_start_fsm_en = 1;
|
||||
SENS.sar_touch_ctrl2.touch_start_en = 0;
|
||||
SENS.sar_touch_ctrl2.touch_start_force = mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get touch sensor FSM mode.
|
||||
* The measurement action can be triggered by the hardware timer, as well as by the software instruction.
|
||||
*
|
||||
* @param mode FSM mode.
|
||||
*/
|
||||
static inline void touch_ll_get_fsm_mode(touch_fsm_mode_t *mode)
|
||||
{
|
||||
*mode = (touch_fsm_mode_t)SENS.sar_touch_ctrl2.touch_start_force;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start touch sensor FSM timer.
|
||||
* The measurement action can be triggered by the hardware timer, as well as by the software instruction.
|
||||
*
|
||||
* @param mode FSM mode.
|
||||
*/
|
||||
static inline void touch_ll_start_fsm(void)
|
||||
{
|
||||
RTCCNTL.state0.touch_slp_timer_en = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop touch sensor FSM timer.
|
||||
* The measurement action can be triggered by the hardware timer, as well as by the software instruction.
|
||||
*
|
||||
* @param mode FSM mode.
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline void touch_ll_stop_fsm(void)
|
||||
{
|
||||
RTCCNTL.state0.touch_slp_timer_en = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger a touch sensor measurement, only support in SW mode of FSM.
|
||||
*/
|
||||
static inline void touch_ll_start_sw_meas(void)
|
||||
{
|
||||
SENS.sar_touch_ctrl2.touch_start_en = 1;
|
||||
SENS.sar_touch_ctrl2.touch_start_en = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set touch sensor interrupt threshold.
|
||||
*
|
||||
* @note Refer to `touch_pad_set_trigger_mode` to see how to set trigger mode.
|
||||
* @param touch_num touch pad index.
|
||||
* @param threshold threshold of touchpad count.
|
||||
*/
|
||||
static inline void touch_ll_set_threshold(touch_pad_t touch_num, uint16_t threshold)
|
||||
{
|
||||
touch_pad_t tp_wrap = touch_ll_num_wrap(touch_num);
|
||||
if (tp_wrap & 0x1) {
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(SENS.touch_thresh[tp_wrap / 2], l_thresh, threshold);
|
||||
} else {
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(SENS.touch_thresh[tp_wrap / 2], h_thresh, threshold);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get touch sensor interrupt threshold.
|
||||
*
|
||||
* @param touch_num touch pad index.
|
||||
* @param threshold pointer to accept threshold.
|
||||
*/
|
||||
static inline void touch_ll_get_threshold(touch_pad_t touch_num, uint16_t *threshold)
|
||||
{
|
||||
touch_pad_t tp_wrap = touch_ll_num_wrap(touch_num);
|
||||
if (threshold) {
|
||||
*threshold = (tp_wrap & 0x1) ?
|
||||
HAL_FORCE_READ_U32_REG_FIELD(SENS.touch_thresh[tp_wrap / 2], l_thresh) :
|
||||
HAL_FORCE_READ_U32_REG_FIELD(SENS.touch_thresh[tp_wrap / 2], h_thresh);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set touch sensor interrupt trigger mode.
|
||||
* Interrupt can be triggered either when touch value is less than
|
||||
* threshold or when touch value is more than threshold.
|
||||
*
|
||||
* @param mode Touch sensor interrupt trigger mode.
|
||||
*/
|
||||
static inline void touch_ll_set_trigger_mode(touch_trigger_mode_t mode)
|
||||
{
|
||||
SENS.sar_touch_ctrl1.touch_out_sel = mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get touch sensor interrupt trigger mode.
|
||||
* Interrupt can be triggered either when touch value is less than
|
||||
* threshold or when touch value is more than threshold.
|
||||
*
|
||||
* @param mode Touch sensor interrupt trigger mode.
|
||||
*/
|
||||
static inline void touch_ll_get_trigger_mode(touch_trigger_mode_t *mode)
|
||||
{
|
||||
*mode = (touch_trigger_mode_t)SENS.sar_touch_ctrl1.touch_out_sel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set touch sensor interrupt trigger source. There are two sets of touch signals.
|
||||
* Set1 and set2 can be mapped to several touch signals. Either set will be triggered
|
||||
* if at least one of its touch signal is 'touched'. The interrupt can be configured to be generated
|
||||
* if set1 is triggered, or only if both sets are triggered.
|
||||
*
|
||||
* @param src Touch sensor interrupt trigger source.
|
||||
*/
|
||||
static inline void touch_ll_set_trigger_source(touch_trigger_src_t src)
|
||||
{
|
||||
SENS.sar_touch_ctrl1.touch_out_1en = src;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get touch sensor interrupt trigger source.
|
||||
*
|
||||
* @param src Pointer to accept touch sensor interrupt trigger source.
|
||||
*/
|
||||
static inline void touch_ll_get_trigger_source(touch_trigger_src_t *src)
|
||||
{
|
||||
*src = (touch_trigger_src_t)SENS.sar_touch_ctrl1.touch_out_1en;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable touch sensor channel. Register touch channel into touch sensor measurement group.
|
||||
* The working mode of the touch sensor is simultaneous measurement.
|
||||
* This function will set the measure bits according to the given bitmask.
|
||||
*
|
||||
* @note If set this mask, the FSM timer should be stop firsty.
|
||||
* @note The touch sensor that in scan map, should be deinit GPIO function firstly.
|
||||
* @param enable_mask bitmask of touch sensor scan group.
|
||||
* e.g. TOUCH_PAD_NUM1 -> BIT(1)
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
static inline void touch_ll_set_channel_mask(uint16_t enable_mask)
|
||||
{
|
||||
SENS.sar_touch_enable.touch_pad_worken |= TOUCH_LL_BITS_SWAP(enable_mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get touch sensor channel mask.
|
||||
*
|
||||
* @param enable_mask bitmask of touch sensor scan group.
|
||||
* e.g. TOUCH_PAD_NUM1 -> BIT(1)
|
||||
*/
|
||||
static inline void touch_ll_get_channel_mask(uint16_t *enable_mask)
|
||||
{
|
||||
*enable_mask = TOUCH_LL_BITS_SWAP(SENS.sar_touch_enable.touch_pad_worken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable touch sensor channel by bitmask.
|
||||
*
|
||||
* @param enable_mask bitmask of touch sensor scan group.
|
||||
* e.g. TOUCH_PAD_NUM1 -> BIT(1)
|
||||
*/
|
||||
static inline void touch_ll_clear_channel_mask(uint16_t disable_mask)
|
||||
{
|
||||
SENS.sar_touch_enable.touch_pad_worken &= TOUCH_LL_BITS_SWAP(~disable_mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set touch sensor group mask.
|
||||
* Touch pad module has two sets of signals, 'Touched' signal is triggered only if
|
||||
* at least one of touch pad in this group is "touched".
|
||||
* This function will set the register bits according to the given bitmask.
|
||||
*
|
||||
* @param set1_mask bitmask of touch sensor signal group1, it's a 10-bit value
|
||||
* @param set2_mask bitmask of touch sensor signal group2, it's a 10-bit value
|
||||
*/
|
||||
static inline void touch_ll_set_group_mask(uint16_t group1_mask, uint16_t group2_mask)
|
||||
{
|
||||
SENS.sar_touch_enable.touch_pad_outen1 |= TOUCH_LL_BITS_SWAP(group1_mask);
|
||||
SENS.sar_touch_enable.touch_pad_outen2 |= TOUCH_LL_BITS_SWAP(group2_mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get touch sensor group mask.
|
||||
*
|
||||
* @param set1_mask pointer to accept bitmask of touch sensor signal group1, it's a 10-bit value
|
||||
* @param set2_mask pointer to accept bitmask of touch sensor signal group2, it's a 10-bit value
|
||||
*/
|
||||
static inline void touch_ll_get_group_mask(uint16_t *group1_mask, uint16_t *group2_mask)
|
||||
{
|
||||
*group1_mask = TOUCH_LL_BITS_SWAP(SENS.sar_touch_enable.touch_pad_outen1);
|
||||
*group2_mask = TOUCH_LL_BITS_SWAP(SENS.sar_touch_enable.touch_pad_outen2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear touch sensor group mask.
|
||||
*
|
||||
* @param set1_mask pointer to accept bitmask of touch sensor signal group1, it's a 10-bit value
|
||||
* @param set2_mask pointer to accept bitmask of touch sensor signal group2, it's a 10-bit value
|
||||
*/
|
||||
static inline void touch_ll_clear_group_mask(uint16_t group1_mask, uint16_t group2_mask)
|
||||
{
|
||||
SENS.sar_touch_enable.touch_pad_outen1 &= TOUCH_LL_BITS_SWAP(~group1_mask);
|
||||
SENS.sar_touch_enable.touch_pad_outen2 &= TOUCH_LL_BITS_SWAP(~group2_mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the touch sensor status, usually used in ISR to decide which pads are 'touched'.
|
||||
*
|
||||
* @param status_mask The touch sensor status. e.g. Touch1 trigger status is `status_mask & (BIT1)`.
|
||||
*/
|
||||
static inline void touch_ll_read_trigger_status_mask(uint32_t *status_mask)
|
||||
{
|
||||
*status_mask = TOUCH_LL_BITS_SWAP(SENS.sar_touch_ctrl2.touch_meas_en);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all touch sensor status.
|
||||
*/
|
||||
static inline void touch_ll_clear_trigger_status_mask(void)
|
||||
{
|
||||
SENS.sar_touch_ctrl2.touch_meas_en_clr = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* To enable touch pad interrupt.
|
||||
*/
|
||||
static inline void touch_ll_intr_enable(void)
|
||||
{
|
||||
RTCCNTL.int_ena.rtc_touch = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* To disable touch pad interrupt.
|
||||
*/
|
||||
static inline void touch_ll_intr_disable(void)
|
||||
{
|
||||
RTCCNTL.int_ena.rtc_touch = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* To clear touch pad interrupt.
|
||||
*/
|
||||
static inline void touch_ll_intr_clear(void)
|
||||
{
|
||||
RTCCNTL.int_clr.rtc_touch = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get touch sensor raw data (touch sensor counter value) from register. No block.
|
||||
*
|
||||
* @param touch_num touch pad index.
|
||||
* @return touch_value pointer to accept touch sensor value.
|
||||
*/
|
||||
static inline uint32_t touch_ll_read_raw_data(touch_pad_t touch_num)
|
||||
{
|
||||
touch_pad_t tp_wrap = touch_ll_num_wrap(touch_num);
|
||||
return ((tp_wrap & 0x1) ? HAL_FORCE_READ_U32_REG_FIELD(SENS.touch_meas[tp_wrap / 2], l_val) :
|
||||
HAL_FORCE_READ_U32_REG_FIELD(SENS.touch_meas[tp_wrap / 2], h_val));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
// The HAL layer for Touch sensor (common part)
|
||||
|
||||
#include "hal/touch_sensor_legacy_hal.h"
|
||||
#include "hal/touch_sensor_legacy_types.h"
|
||||
|
||||
void touch_hal_init(void)
|
||||
{
|
||||
touch_ll_stop_fsm();
|
||||
touch_ll_intr_disable();
|
||||
touch_ll_intr_clear();
|
||||
touch_ll_clear_channel_mask(TOUCH_PAD_BIT_MASK_ALL);
|
||||
touch_ll_clear_group_mask(TOUCH_PAD_BIT_MASK_ALL, TOUCH_PAD_BIT_MASK_ALL);
|
||||
touch_ll_set_trigger_mode(TOUCH_TRIGGER_MODE_DEFAULT);
|
||||
touch_ll_set_trigger_source(TOUCH_TRIGGER_SOURCE_DEFAULT);
|
||||
touch_ll_clear_trigger_status_mask();
|
||||
touch_ll_set_meas_time(TOUCH_PAD_MEASURE_CYCLE_DEFAULT);
|
||||
touch_ll_set_sleep_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT);
|
||||
touch_ll_set_fsm_mode(TOUCH_FSM_MODE_DEFAULT);
|
||||
touch_ll_start_fsm();
|
||||
}
|
||||
|
||||
void touch_hal_deinit(void)
|
||||
{
|
||||
touch_ll_stop_fsm();
|
||||
touch_ll_clear_trigger_status_mask();
|
||||
touch_ll_intr_disable();
|
||||
}
|
||||
|
||||
void touch_hal_get_wakeup_status(touch_pad_t *pad_num)
|
||||
{
|
||||
uint32_t touch_mask = 0;
|
||||
touch_ll_read_trigger_status_mask(&touch_mask);
|
||||
if (touch_mask == 0) {
|
||||
*pad_num = -1;
|
||||
} else {
|
||||
*pad_num = (touch_pad_t)(__builtin_ffs(touch_mask) - 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "soc/touch_sensor_channel.h"
|
||||
|
||||
/* Store IO number corresponding to the Touch Sensor channel number. */
|
||||
const int touch_sensor_channel_io_map[] = {
|
||||
TOUCH_PAD_NUM0_GPIO_NUM,
|
||||
TOUCH_PAD_NUM1_GPIO_NUM,
|
||||
TOUCH_PAD_NUM2_GPIO_NUM,
|
||||
TOUCH_PAD_NUM3_GPIO_NUM,
|
||||
TOUCH_PAD_NUM4_GPIO_NUM,
|
||||
TOUCH_PAD_NUM5_GPIO_NUM,
|
||||
TOUCH_PAD_NUM6_GPIO_NUM,
|
||||
TOUCH_PAD_NUM7_GPIO_NUM,
|
||||
TOUCH_PAD_NUM8_GPIO_NUM,
|
||||
TOUCH_PAD_NUM9_GPIO_NUM
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "soc/touch_sensor_channel.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[] = {
|
||||
-1,
|
||||
TOUCH_PAD_NUM1_GPIO_NUM,
|
||||
TOUCH_PAD_NUM2_GPIO_NUM,
|
||||
TOUCH_PAD_NUM3_GPIO_NUM,
|
||||
TOUCH_PAD_NUM4_GPIO_NUM,
|
||||
TOUCH_PAD_NUM5_GPIO_NUM,
|
||||
TOUCH_PAD_NUM6_GPIO_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,
|
||||
};
|
||||
@@ -0,0 +1,624 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* NOTICE
|
||||
* The hal is not public api, don't use in application code.
|
||||
* See readme.md in hal/include/hal/readme.md
|
||||
******************************************************************************/
|
||||
|
||||
// The HAL layer for touch sensor (ESP32-S2 specific part)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hal/touch_sensor_ll.h"
|
||||
#include "hal/touch_sensor_legacy_types.h"
|
||||
|
||||
#include_next "hal/touch_sensor_legacy_hal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Reset the whole of touch module.
|
||||
*
|
||||
* @note Call this function after `touch_pad_fsm_stop`,
|
||||
*/
|
||||
#define touch_hal_reset() touch_ll_reset()
|
||||
|
||||
/**
|
||||
* Set touch sensor measurement time.
|
||||
*
|
||||
* @param meas_time The duration of the touch sensor measurement.
|
||||
* t_meas = meas_time / (8MHz), the maximum measure time is 0xffff / 8M = 8.19 ms.
|
||||
*/
|
||||
#define touch_hal_set_meas_times(meas_time) touch_ll_set_meas_times(meas_time)
|
||||
|
||||
/**
|
||||
* Get touch sensor times of charge and discharge.
|
||||
*
|
||||
* @param meas_times Pointer to accept times count of charge and discharge.
|
||||
*/
|
||||
#define touch_hal_get_measure_times(meas_time) touch_ll_get_measure_times(meas_time)
|
||||
|
||||
/**
|
||||
* Set connection type of touch channel in idle status.
|
||||
* When a channel is in measurement mode, other initialized channels are in idle mode.
|
||||
* The touch channel is generally adjacent to the trace, so the connection state of the idle channel
|
||||
* affects the stability and sensitivity of the test channel.
|
||||
* The `CONN_HIGHZ`(high resistance) setting increases the sensitivity of touch channels.
|
||||
* The `CONN_GND`(grounding) setting increases the stability of touch channels.
|
||||
*
|
||||
* @param type Select idle channel connect to high resistance state or ground.
|
||||
*/
|
||||
#define touch_hal_set_idle_channel_connect(type) touch_ll_set_idle_channel_connect(type)
|
||||
|
||||
/**
|
||||
* Set connection type of touch channel in idle status.
|
||||
* When a channel is in measurement mode, other initialized channels are in idle mode.
|
||||
* The touch channel is generally adjacent to the trace, so the connection state of the idle channel
|
||||
* affects the stability and sensitivity of the test channel.
|
||||
* The `CONN_HIGHZ`(high resistance) setting increases the sensitivity of touch channels.
|
||||
* The `CONN_GND`(grounding) setting increases the stability of touch channels.
|
||||
*
|
||||
* @param type Select idle channel connect to high resistance state or ground.
|
||||
*/
|
||||
#define touch_hal_get_idle_channel_connect(type) touch_ll_get_idle_channel_connect(type)
|
||||
|
||||
/**
|
||||
* Get the current measure channel. Touch sensor measurement is cyclic scan mode.
|
||||
*
|
||||
* @return
|
||||
* - touch channel number
|
||||
*/
|
||||
#define touch_hal_get_current_meas_channel() touch_ll_get_current_meas_channel()
|
||||
|
||||
/**
|
||||
* Enable touch sensor interrupt by bitmask.
|
||||
*
|
||||
* @param type interrupt type
|
||||
*/
|
||||
#define touch_hal_intr_enable(int_mask) touch_ll_intr_enable(int_mask)
|
||||
|
||||
/**
|
||||
* Disable touch sensor interrupt by bitmask.
|
||||
*
|
||||
* @param type interrupt type
|
||||
*/
|
||||
#define touch_hal_intr_disable(int_mask) touch_ll_intr_disable(int_mask)
|
||||
|
||||
/**
|
||||
* Clear touch sensor interrupt by bitmask.
|
||||
*
|
||||
* @param int_mask Pad mask to clear interrupts
|
||||
*/
|
||||
#define touch_hal_intr_clear(int_mask) touch_ll_intr_clear(int_mask)
|
||||
|
||||
/**
|
||||
* Get the bitmask of touch sensor interrupt status.
|
||||
*
|
||||
* @return type interrupt type
|
||||
*/
|
||||
#define touch_hal_read_intr_status_mask() touch_ll_read_intr_status_mask()
|
||||
|
||||
/**
|
||||
* Enable 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.
|
||||
*
|
||||
* @note Set the timeout threshold correctly before enabling it.
|
||||
*/
|
||||
#define touch_hal_timeout_enable() touch_ll_timeout_enable()
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @note Set the timeout threshold correctly before enabling it.
|
||||
*/
|
||||
#define touch_hal_timeout_disable() touch_ll_timeout_disable()
|
||||
|
||||
/**
|
||||
* Set timeout threshold for all touch sensor channels measurements.
|
||||
* Compared with touch readings.
|
||||
*
|
||||
* @param threshold Set to the maximum time measured on one channel.
|
||||
*/
|
||||
#define touch_hal_timeout_set_threshold(threshold) touch_ll_timeout_set_threshold(threshold)
|
||||
|
||||
/**
|
||||
* Get timeout threshold for all touch sensor channels measurements.
|
||||
* Compared with touch readings.
|
||||
*
|
||||
* @param threshold Point to timeout threshold.
|
||||
*/
|
||||
#define touch_hal_timeout_get_threshold(threshold) touch_ll_timeout_get_threshold(threshold)
|
||||
|
||||
/**
|
||||
* Touch timer trigger measurement and always wait measurement done.
|
||||
* Force done for touch timer ensures that the timer always can get the measurement done signal.
|
||||
*/
|
||||
#define touch_hal_timer_force_done() touch_ll_timer_force_done()
|
||||
|
||||
/************************ Filter register setting ************************/
|
||||
|
||||
/**
|
||||
* Set parameter of touch sensor filter and detection algorithm.
|
||||
* For more details on the detection algorithm, please refer to the application documentation.
|
||||
*
|
||||
* @param filter_info select filter type and threshold of detection algorithm
|
||||
*/
|
||||
void touch_hal_filter_set_config(const touch_filter_config_t *filter_info);
|
||||
|
||||
/**
|
||||
* Get parameter of touch sensor filter and detection algorithm.
|
||||
* For more details on the detection algorithm, please refer to the application documentation.
|
||||
*
|
||||
* @param filter_info select filter type and threshold of detection algorithm
|
||||
*/
|
||||
void touch_hal_filter_get_config(touch_filter_config_t *filter_info);
|
||||
|
||||
/**
|
||||
* Get smoothed data that obtained by filtering the raw data.
|
||||
*
|
||||
* @param touch_num touch pad index
|
||||
* @param smooth_data pointer to smoothed data
|
||||
*/
|
||||
#define touch_hal_filter_read_smooth(touch_num, smooth_data) touch_ll_filter_read_smooth(touch_num, smooth_data)
|
||||
|
||||
/**
|
||||
* Get benchmark value of touch sensor.
|
||||
*
|
||||
* @note After initialization, the benchmark value is the maximum during the first measurement period.
|
||||
* @param touch_num touch pad index
|
||||
* @param touch_value pointer to accept touch sensor value
|
||||
*/
|
||||
#define touch_hal_read_benchmark(touch_num, benchmark) touch_ll_read_benchmark(touch_num, benchmark)
|
||||
|
||||
/**
|
||||
* Force reset benchmark to raw data of touch sensor.
|
||||
*
|
||||
* @param touch_num touch pad index
|
||||
* - TOUCH_PAD_MAX Reset baseline of all channels.
|
||||
*/
|
||||
#define touch_hal_reset_benchmark(touch_num) touch_ll_reset_benchmark(touch_num)
|
||||
|
||||
/**
|
||||
* Set filter mode. The input of the filter is the raw value of touch reading,
|
||||
* and the output of the filter is involved in the judgment of the touch state.
|
||||
*
|
||||
* @param mode Filter mode type. Refer to `touch_filter_mode_t`.
|
||||
*/
|
||||
#define touch_hal_filter_set_filter_mode(mode) touch_ll_filter_set_filter_mode(mode)
|
||||
|
||||
/**
|
||||
* Get filter mode. The input of the filter is the raw value of touch reading,
|
||||
* and the output of the filter is involved in the judgment of the touch state.
|
||||
*
|
||||
* @param mode Filter mode type. Refer to `touch_filter_mode_t`.
|
||||
*/
|
||||
#define touch_hal_filter_get_filter_mode(mode) touch_ll_filter_get_filter_mode(mode)
|
||||
|
||||
/**
|
||||
* Set debounce count, such as `n`. If the measured values continue to exceed
|
||||
* the threshold for `n` times, it is determined that the touch sensor state changes.
|
||||
*
|
||||
* @param dbc_cnt Debounce count value.
|
||||
*/
|
||||
#define touch_hal_filter_set_debounce(dbc_cnt) touch_ll_filter_set_debounce(dbc_cnt)
|
||||
|
||||
/**
|
||||
* Get debounce count.
|
||||
*
|
||||
* @param dbc_cnt Debounce count value.
|
||||
*/
|
||||
#define touch_hal_filter_get_debounce(dbc_cnt) touch_ll_filter_get_debounce(dbc_cnt)
|
||||
|
||||
/**
|
||||
* Set noise threshold coefficient. Higher = More noise resistance.
|
||||
* The actual noise should be less than (noise coefficient * touch threshold).
|
||||
* Range: 0 ~ 3. The coefficient is 0: 4/8; 1: 3/8; 2: 2/8; 3: 1;
|
||||
*
|
||||
* @param hys_thr Noise threshold coefficient.
|
||||
*/
|
||||
#define touch_hal_filter_set_noise_thres(noise_thr) touch_ll_filter_set_noise_thres(noise_thr)
|
||||
|
||||
/**
|
||||
* Get noise threshold coefficient. Higher = More noise resistance.
|
||||
* The actual noise should be less than (noise coefficient * touch threshold).
|
||||
* Range: 0 ~ 3. The coefficient is 0: 4/8; 1: 3/8; 2: 2/8; 3: 1;
|
||||
*
|
||||
* @param noise_thr Noise threshold coefficient.
|
||||
*/
|
||||
#define touch_hal_filter_get_noise_thres(noise_thr) touch_ll_filter_get_noise_thres(noise_thr)
|
||||
|
||||
/**
|
||||
* Set the cumulative number of benchmark reset processes. such as `n`. If the measured values continue to exceed
|
||||
* the negative noise threshold for `n` times, the benchmark reset to raw data.
|
||||
* Range: 0 ~ 15
|
||||
*
|
||||
* @param reset_cnt The cumulative number of benchmark reset processes.
|
||||
*/
|
||||
#define touch_hal_filter_set_benchmark_reset(reset_cnt) touch_ll_filter_set_benchmark_reset(reset_cnt)
|
||||
|
||||
/**
|
||||
* Get the cumulative number of benchmark reset processes. such as `n`. If the measured values continue to exceed
|
||||
* the negative noise threshold for `n` times, the benchmark reset to raw data.
|
||||
* Range: 0 ~ 15
|
||||
*
|
||||
* @param reset_cnt The cumulative number of benchmark reset processes.
|
||||
*/
|
||||
#define touch_hal_filter_get_benchmark_reset(reset_cnt) touch_ll_filter_get_benchmark_reset(reset_cnt)
|
||||
|
||||
/**
|
||||
* Set jitter filter step size.
|
||||
* If filter mode is jitter, should set filter step for jitter.
|
||||
* Range: 0 ~ 15
|
||||
*
|
||||
* @param step The step size of the data change.
|
||||
*/
|
||||
#define touch_hal_filter_set_jitter_step(step) touch_ll_filter_set_jitter_step(step)
|
||||
|
||||
/**
|
||||
* Get jitter filter step size.
|
||||
* If filter mode is jitter, should set filter step for jitter.
|
||||
* Range: 0 ~ 15
|
||||
*
|
||||
* @param step The step size of the data change.
|
||||
*/
|
||||
#define touch_hal_filter_get_jitter_step(step) touch_ll_filter_get_jitter_step(step)
|
||||
|
||||
/**
|
||||
* 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(enable) touch_ll_filter_enable(enable)
|
||||
|
||||
/************************ Denoise register setting ************************/
|
||||
|
||||
/**
|
||||
* set parameter of denoise pad (TOUCH_PAD_NUM0).
|
||||
* T0 is an internal channel that does not have a corresponding external GPIO.
|
||||
* T0 will work simultaneously with the measured channel Tn. Finally, the actual
|
||||
* measured value of Tn is the value after subtracting lower bits of T0.
|
||||
* This denoise function filters out interference introduced on all channels,
|
||||
* such as noise introduced by the power supply and external EMI.
|
||||
*
|
||||
* @param denoise parameter of denoise
|
||||
*/
|
||||
void touch_hal_denoise_set_config(const touch_pad_denoise_t *denoise);
|
||||
|
||||
/**
|
||||
* @brief get parameter of denoise pad (TOUCH_PAD_NUM0).
|
||||
*
|
||||
* @param denoise Pointer to parameter of denoise
|
||||
*/
|
||||
void touch_hal_denoise_get_config(touch_pad_denoise_t *denoise);
|
||||
|
||||
/**
|
||||
* Enable denoise function.
|
||||
* T0 is an internal channel that does not have a corresponding external GPIO.
|
||||
* T0 will work simultaneously with the measured channel Tn. Finally, the actual
|
||||
* measured value of Tn is the value after subtracting lower bits of T0.
|
||||
* This denoise function filters out interference introduced on all channels,
|
||||
* such as noise introduced by the power supply and external EMI.
|
||||
*/
|
||||
void touch_hal_denoise_enable(void);
|
||||
|
||||
/**
|
||||
* Enable denoise function.
|
||||
* T0 is an internal channel that does not have a corresponding external GPIO.
|
||||
* T0 will work simultaneously with the measured channel Tn. Finally, the actual
|
||||
* measured value of Tn is the value after subtracting lower bits of T0.
|
||||
* 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_enable(false)
|
||||
|
||||
/**
|
||||
* Set internal reference capacitance of denoise channel.
|
||||
* Select the appropriate internal reference capacitance value so that
|
||||
* the reading of denoise channel is closest to the reading of the channel being measured.
|
||||
*
|
||||
* @param cap_level Capacitance level.
|
||||
*/
|
||||
#define touch_hal_denoise_set_cap_level(cap_level) touch_ll_denoise_set_cap_level(cap_level)
|
||||
|
||||
/**
|
||||
* Get internal reference capacitance of denoise channel.
|
||||
* Select the appropriate internal reference capacitance value so that
|
||||
* the reading of denoise channel is closest to the reading of the channel being measured.
|
||||
*
|
||||
* @param cap_level Capacitance level.
|
||||
*/
|
||||
#define touch_hal_denoise_get_cap_level(cap_level) touch_ll_denoise_get_cap_level(cap_level)
|
||||
|
||||
/**
|
||||
* Set denoise range of denoise channel.
|
||||
* Determined by measuring the noise amplitude of the denoise channel.
|
||||
*
|
||||
* @param grade Denoise range of denoise channel.
|
||||
*/
|
||||
#define touch_hal_denoise_set_grade(grade) touch_ll_denoise_set_grade(grade)
|
||||
|
||||
/**
|
||||
* Set denoise range of denoise channel.
|
||||
* Determined by measuring the noise amplitude of the denoise channel.
|
||||
*
|
||||
* @param grade Denoise range of denoise channel.
|
||||
*/
|
||||
#define touch_hal_denoise_get_grade(grade) touch_ll_denoise_get_grade(grade)
|
||||
|
||||
/**
|
||||
* Read denoise measure value (TOUCH_PAD_NUM0).
|
||||
*
|
||||
* @param denoise value of denoise.
|
||||
*/
|
||||
#define touch_hal_denoise_read_data(data) touch_ll_denoise_read_data(data)
|
||||
|
||||
/************************ Waterproof register setting ************************/
|
||||
/**
|
||||
* Set touch channel use for guard pad.
|
||||
*
|
||||
* @param pad_num Touch sensor channel number.
|
||||
*/
|
||||
#define touch_hal_waterproof_set_guard_pad(pad_num) touch_ll_waterproof_set_guard_pad(pad_num)
|
||||
|
||||
/**
|
||||
* Get touch channel use for guard pad.
|
||||
*
|
||||
* @param pad_num Touch sensor channel number.
|
||||
*/
|
||||
#define touch_hal_waterproof_get_guard_pad(pad_num) touch_ll_waterproof_get_guard_pad(pad_num)
|
||||
|
||||
/**
|
||||
* Set max equivalent capacitance for shield channel.
|
||||
* The equivalent capacitance of the shielded channel can be calculated
|
||||
* from the reading of denoise channel.
|
||||
*
|
||||
* @param pad_num Touch sensor channel number.
|
||||
*/
|
||||
#define touch_hal_waterproof_set_sheild_driver(driver_level) touch_ll_waterproof_set_shield_driver(driver_level)
|
||||
|
||||
/**
|
||||
* Get max equivalent capacitance for shield channel.
|
||||
* The equivalent capacitance of the shielded channel can be calculated
|
||||
* from the reading of denoise channel.
|
||||
*
|
||||
* @param pad_num Touch sensor channel number.
|
||||
*/
|
||||
#define touch_hal_waterproof_get_sheild_driver(driver_level) touch_ll_waterproof_get_shield_driver(driver_level)
|
||||
|
||||
/**
|
||||
* Set parameter of waterproof function.
|
||||
*
|
||||
* The waterproof function includes a shielded channel (TOUCH_PAD_NUM14) and a guard channel.
|
||||
* Guard pad is used to detect the large area of water covering the touch panel.
|
||||
* Shield pad is used to shield the influence of water droplets covering the touch panel.
|
||||
* It is generally designed as a grid and is placed around the touch buttons.
|
||||
*
|
||||
* @param waterproof parameter of waterproof
|
||||
*/
|
||||
void touch_hal_waterproof_set_config(const touch_pad_waterproof_t *waterproof);
|
||||
|
||||
/**
|
||||
* Get parameter of waterproof function.
|
||||
*
|
||||
* @param waterproof parameter of waterproof.
|
||||
*/
|
||||
void touch_hal_waterproof_get_config(touch_pad_waterproof_t *waterproof);
|
||||
|
||||
/**
|
||||
* Enable parameter of waterproof function.
|
||||
* Should be called after function ``touch_hal_waterproof_set_config``.
|
||||
*/
|
||||
void touch_hal_waterproof_enable(void);
|
||||
|
||||
/**
|
||||
* Disable parameter of waterproof function.
|
||||
*/
|
||||
#define touch_hal_waterproof_disable() touch_ll_waterproof_enable(false)
|
||||
|
||||
/************************ Proximity register setting ************************/
|
||||
|
||||
/**
|
||||
* Enable/disable proximity function of touch channels.
|
||||
* The proximity sensor measurement is the accumulation of touch channel measurements.
|
||||
*
|
||||
* @note Supports up to three touch channels configured as proximity sensors.
|
||||
* @param touch_num touch pad index
|
||||
* @param enabled true: enable the proximity function; false: disable the proximity function
|
||||
* @return
|
||||
* - true: Configured correctly.
|
||||
* - false: Configured error.
|
||||
*/
|
||||
bool touch_hal_enable_proximity(touch_pad_t touch_num, bool enabled);
|
||||
|
||||
/**
|
||||
* Set touch channel number for proximity pad.
|
||||
* If disable the proximity pad, point this pad to `TOUCH_PAD_NUM0`
|
||||
*
|
||||
* @param prox_pad The array of three proximity pads.
|
||||
*/
|
||||
#define touch_hal_proximity_set_channel_num(prox_pad) touch_ll_proximity_set_channel_num(prox_pad)
|
||||
|
||||
/**
|
||||
* Get touch channel number for proximity pad.
|
||||
* If disable the proximity pad, point this pad to `TOUCH_PAD_NUM0`
|
||||
*
|
||||
* @param prox_pad The array of three proximity pads.
|
||||
*/
|
||||
#define touch_hal_proximity_get_channel_num(prox_pad) touch_ll_proximity_get_channel_num(prox_pad)
|
||||
|
||||
/**
|
||||
* Set cumulative measurement times for proximity pad.
|
||||
*
|
||||
* @param times The cumulative number of measurement cycles.
|
||||
*/
|
||||
#define touch_hal_proximity_set_meas_times(times) touch_ll_proximity_set_meas_times(times)
|
||||
|
||||
/**
|
||||
* Get cumulative measurement times for proximity pad.
|
||||
*
|
||||
* @param times The cumulative number of measurement cycles.
|
||||
*/
|
||||
#define touch_hal_proximity_get_meas_times(times) touch_ll_proximity_get_meas_times(times)
|
||||
|
||||
/**
|
||||
* Read current cumulative measurement times for proximity pad.
|
||||
*
|
||||
* @param times The cumulative number of measurement cycles.
|
||||
*/
|
||||
#define touch_hal_proximity_read_meas_cnt(touch_num, cnt) touch_ll_proximity_read_meas_cnt(touch_num, cnt)
|
||||
|
||||
/**
|
||||
* Check if the touch sensor channel is the proximity pad.
|
||||
*
|
||||
* @param touch_num The touch sensor channel number.
|
||||
*/
|
||||
#define touch_hal_proximity_pad_check(touch_num) touch_ll_proximity_pad_check(touch_num)
|
||||
|
||||
/************** sleep pad setting ***********************/
|
||||
|
||||
/**
|
||||
* Get parameter of touch sensor sleep channel.
|
||||
* The touch sensor can works in sleep mode to wake up sleep.
|
||||
* After the sleep channel is configured, users should query the channel reading using a specific function.
|
||||
*
|
||||
* @param slp_config Point to touch sleep pad config.
|
||||
*/
|
||||
void touch_hal_sleep_channel_get_config(touch_pad_sleep_channel_t *slp_config);
|
||||
|
||||
/**
|
||||
* Set parameter of touch sensor sleep channel.
|
||||
* The touch sensor can works in sleep mode to wake up sleep.
|
||||
* After the sleep channel is configured, users should query the channel reading using a specific function.
|
||||
*
|
||||
* @note ESP32S2 only support one channel to be set sleep channel.
|
||||
*
|
||||
* @param pad_num touch sleep pad number.
|
||||
* @param enable Enable/disable sleep pad function.
|
||||
*/
|
||||
void touch_hal_sleep_channel_enable(touch_pad_t pad_num, bool enable);
|
||||
|
||||
/**
|
||||
* Set touch channel number for sleep pad.
|
||||
*
|
||||
* @note Only one touch sensor channel is supported in deep sleep mode.
|
||||
* @param touch_num Touch sensor channel number.
|
||||
*/
|
||||
#define touch_hal_sleep_set_channel_num(touch_num) touch_ll_sleep_set_channel_num(touch_num)
|
||||
|
||||
/**
|
||||
* Get touch channel number for sleep pad.
|
||||
*
|
||||
* @note Only one touch sensor channel is supported in deep sleep mode.
|
||||
* @param touch_num Touch sensor channel number.
|
||||
*/
|
||||
#define touch_hal_sleep_get_channel_num(touch_num) touch_ll_sleep_get_channel_num(touch_num)
|
||||
|
||||
/**
|
||||
* Set the trigger threshold of touch sensor in deep sleep.
|
||||
* The threshold determines the sensitivity of the touch sensor.
|
||||
* The threshold is the original value of the trigger state minus the benchmark value.
|
||||
*
|
||||
* @note The threshold at sleep is the same as the threshold before sleep.
|
||||
*/
|
||||
#define touch_hal_sleep_set_threshold(touch_thres) touch_ll_sleep_set_threshold(touch_thres)
|
||||
|
||||
/**
|
||||
* Get the trigger threshold of touch sensor in deep sleep.
|
||||
* The threshold determines the sensitivity of the touch sensor.
|
||||
* The threshold is the original value of the trigger state minus the benchmark value.
|
||||
*
|
||||
* @note The threshold at sleep is the same as the threshold before sleep.
|
||||
*/
|
||||
#define touch_hal_sleep_get_threshold(touch_thres) touch_ll_sleep_get_threshold(touch_thres)
|
||||
|
||||
/**
|
||||
* Enable proximity function for sleep pad.
|
||||
* @param enable the proximity sensing
|
||||
*/
|
||||
#define touch_hal_sleep_enable_approach(enable) touch_ll_sleep_enable_proximity_sensing(enable)
|
||||
|
||||
/**
|
||||
* Read benchmark of touch sensor for sleep pad.
|
||||
*
|
||||
* @param benchmark Pointer to accept touch sensor benchmark value.
|
||||
*/
|
||||
#define touch_hal_sleep_read_benchmark(benchmark) touch_ll_sleep_read_benchmark(benchmark)
|
||||
|
||||
/**
|
||||
* Read smooth data of touch sensor for sleep pad.
|
||||
*/
|
||||
#define touch_hal_sleep_read_smooth(smooth_data) touch_ll_sleep_read_smooth(smooth_data)
|
||||
|
||||
/**
|
||||
* Read raw data of touch sensor for sleep pad.
|
||||
*/
|
||||
#define touch_hal_sleep_read_data(raw_data) touch_ll_sleep_read_data(raw_data)
|
||||
|
||||
/**
|
||||
* Reset benchmark of touch sensor for sleep pad.
|
||||
*/
|
||||
#define touch_hal_sleep_reset_benchmark() touch_ll_sleep_reset_benchmark()
|
||||
|
||||
/**
|
||||
* Read debounce of touch sensor for sleep pad.
|
||||
*
|
||||
* @param debounce Pointer to accept touch sensor debounce value.
|
||||
*/
|
||||
#define touch_hal_sleep_read_debounce(debounce) touch_ll_sleep_read_debounce(debounce)
|
||||
|
||||
/**
|
||||
* Read proximity count of touch sensor for sleep pad.
|
||||
* @param proximity_cnt Pointer to accept touch sensor proximity count value.
|
||||
*/
|
||||
#define touch_hal_sleep_read_proximity_cnt(approach_cnt) touch_ll_sleep_read_proximity_cnt(approach_cnt)
|
||||
|
||||
/**
|
||||
* Get the touch pad which caused wakeup from deep sleep.
|
||||
*
|
||||
* @param pad_num pointer to touch pad which caused wakeup.
|
||||
*/
|
||||
#define touch_hal_get_wakeup_status(pad_num) touch_ll_get_wakeup_status(pad_num)
|
||||
|
||||
/**
|
||||
* Change the operating frequency of touch pad in deep sleep state. Reducing the operating frequency can effectively reduce power consumption.
|
||||
* If this function is not called, the working frequency of touch in the deep sleep state is the same as that in the wake-up state.
|
||||
*
|
||||
* @param sleep_cycle The touch sensor will sleep after each measurement.
|
||||
* sleep_cycle decide the interval between each measurement.
|
||||
* t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
|
||||
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
|
||||
* @param meas_times The times of charge and discharge in each measure process of touch channels.
|
||||
* The timer frequency is 8Mhz. Range: 0 ~ 0xffff.
|
||||
* Recommended typical value: Modify this value to make the measurement time around 1ms.
|
||||
*/
|
||||
void touch_hal_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times);
|
||||
|
||||
/**
|
||||
* Get the operating frequency of touch pad in deep sleep state. Reducing the operating frequency can effectively reduce power consumption.
|
||||
*
|
||||
* @param sleep_cycle The touch sensor will sleep after each measurement.
|
||||
* sleep_cycle decide the interval between each measurement.
|
||||
* t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
|
||||
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
|
||||
* @param meas_times The times of charge and discharge in each measure process of touch channels.
|
||||
* The timer frequency is 8Mhz. Range: 0 ~ 0xffff.
|
||||
* Recommended typical value: Modify this value to make the measurement time around 1ms.
|
||||
*/
|
||||
void touch_hal_sleep_channel_get_work_time(uint16_t *sleep_cycle, uint16_t *meas_times);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2024 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_legacy_hal.h"
|
||||
#include "hal/touch_sensor_legacy_types.h"
|
||||
|
||||
static int s_sleep_cycle = -1;
|
||||
static int s_meas_times = -1;
|
||||
|
||||
void touch_hal_init(void)
|
||||
{
|
||||
touch_ll_stop_fsm();
|
||||
touch_ll_intr_disable(TOUCH_PAD_INTR_MASK_ALL);
|
||||
touch_ll_intr_clear(TOUCH_PAD_INTR_MASK_ALL);
|
||||
touch_ll_clear_channel_mask(TOUCH_PAD_BIT_MASK_ALL);
|
||||
touch_ll_clear_trigger_status_mask();
|
||||
touch_ll_set_meas_times(TOUCH_PAD_MEASURE_CYCLE_DEFAULT);
|
||||
touch_ll_set_sleep_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT);
|
||||
/* Configure the touch-sensor power domain into self-bias since bandgap-bias
|
||||
* level is different under sleep-mode compared to running-mode. self-bias is
|
||||
* always on after chip startup. */
|
||||
touch_ll_sleep_low_power(true);
|
||||
touch_ll_set_voltage_high(TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD);
|
||||
touch_ll_set_voltage_low(TOUCH_PAD_LOW_VOLTAGE_THRESHOLD);
|
||||
touch_ll_set_voltage_attenuation(TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD);
|
||||
touch_ll_set_idle_channel_connect(TOUCH_PAD_IDLE_CH_CONNECT_DEFAULT);
|
||||
/* Clear touch channels to initialize the channel value (benchmark, raw_data).
|
||||
* Note: Should call it after enable clock gate. */
|
||||
touch_ll_clkgate(true); // Enable clock gate for touch sensor.
|
||||
touch_ll_reset_benchmark(TOUCH_PAD_MAX);
|
||||
touch_ll_sleep_reset_benchmark();
|
||||
}
|
||||
|
||||
void touch_hal_deinit(void)
|
||||
{
|
||||
touch_ll_reset_benchmark(TOUCH_PAD_MAX);
|
||||
touch_ll_sleep_reset_benchmark();
|
||||
touch_ll_stop_fsm();
|
||||
touch_ll_clkgate(false);
|
||||
touch_ll_clear_channel_mask(TOUCH_PAD_BIT_MASK_ALL);
|
||||
touch_ll_clear_trigger_status_mask();
|
||||
touch_ll_intr_disable(TOUCH_PAD_INTR_MASK_ALL);
|
||||
touch_ll_timeout_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_enable_proximity_sensing(false);
|
||||
touch_ll_reset(); // Reset the touch sensor FSM.
|
||||
}
|
||||
|
||||
void touch_hal_filter_set_config(const touch_filter_config_t *filter_info)
|
||||
{
|
||||
touch_ll_filter_set_filter_mode(filter_info->mode);
|
||||
touch_ll_filter_set_debounce(filter_info->debounce_cnt);
|
||||
touch_ll_filter_set_noise_thres(filter_info->noise_thr);
|
||||
touch_ll_filter_set_jitter_step(filter_info->jitter_step);
|
||||
touch_ll_filter_set_smooth_mode(filter_info->smh_lvl);
|
||||
}
|
||||
|
||||
void touch_hal_filter_get_config(touch_filter_config_t *filter_info)
|
||||
{
|
||||
touch_ll_filter_get_filter_mode(&filter_info->mode);
|
||||
touch_ll_filter_get_debounce(&filter_info->debounce_cnt);
|
||||
touch_ll_filter_get_noise_thres(&filter_info->noise_thr);
|
||||
touch_ll_filter_get_jitter_step(&filter_info->jitter_step);
|
||||
touch_ll_filter_get_smooth_mode(&filter_info->smh_lvl);
|
||||
}
|
||||
|
||||
void touch_hal_denoise_set_config(const touch_pad_denoise_t *denoise)
|
||||
{
|
||||
touch_ll_denoise_set_cap_level(denoise->cap_level);
|
||||
touch_ll_denoise_set_grade(denoise->grade);
|
||||
}
|
||||
|
||||
void touch_hal_denoise_get_config(touch_pad_denoise_t *denoise)
|
||||
{
|
||||
touch_ll_denoise_get_cap_level(&denoise->cap_level);
|
||||
touch_ll_denoise_get_grade(&denoise->grade);
|
||||
}
|
||||
|
||||
void touch_hal_denoise_enable(void)
|
||||
{
|
||||
touch_ll_clear_channel_mask(1U << TOUCH_LL_GET(DENOISE_CHAN_ID));
|
||||
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_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_shield_driver(&waterproof->shield_driver);
|
||||
}
|
||||
|
||||
void touch_hal_waterproof_enable(void)
|
||||
{
|
||||
touch_ll_clear_channel_mask(1U << TOUCH_LL_GET(SHIELD_CHAN_ID));
|
||||
touch_ll_waterproof_enable(true);
|
||||
}
|
||||
|
||||
bool touch_hal_enable_proximity(touch_pad_t touch_num, bool enabled)
|
||||
{
|
||||
int i = 0;
|
||||
touch_pad_t ch_num[SOC_TOUCH_PROXIMITY_CHANNEL_NUM] = {0};
|
||||
touch_ll_proximity_get_channel_num(ch_num);
|
||||
if (enabled) {
|
||||
for (i = 0; i < SOC_TOUCH_PROXIMITY_CHANNEL_NUM; i++) {
|
||||
if (ch_num[i] == TOUCH_PAD_NUM0 || ch_num[i] >= TOUCH_PAD_MAX || ch_num[i] == touch_num) {
|
||||
ch_num[i] = touch_num;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == SOC_TOUCH_PROXIMITY_CHANNEL_NUM) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < SOC_TOUCH_PROXIMITY_CHANNEL_NUM; i++) {
|
||||
if (ch_num[i] == touch_num) {
|
||||
ch_num[i] = TOUCH_PAD_NUM0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
touch_ll_proximity_set_channel_num(ch_num);
|
||||
return true;
|
||||
}
|
||||
|
||||
void touch_hal_sleep_channel_enable(touch_pad_t pad_num, bool enable)
|
||||
{
|
||||
if (enable) {
|
||||
touch_ll_sleep_set_channel_num(pad_num);
|
||||
touch_ll_sleep_set_threshold(TOUCH_PAD_THRESHOLD_MAX);
|
||||
touch_ll_sleep_reset_benchmark();
|
||||
} else {
|
||||
touch_ll_sleep_set_channel_num(TOUCH_PAD_NUM0);
|
||||
}
|
||||
}
|
||||
|
||||
void touch_hal_sleep_channel_get_config(touch_pad_sleep_channel_t *slp_config)
|
||||
{
|
||||
touch_ll_sleep_get_channel_num((uint32_t *)&slp_config->touch_num);
|
||||
slp_config->en_proximity = touch_ll_sleep_is_proximity_enabled();
|
||||
}
|
||||
|
||||
void touch_hal_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times)
|
||||
{
|
||||
s_sleep_cycle = (int)sleep_cycle;
|
||||
s_meas_times = (int)meas_times;
|
||||
}
|
||||
|
||||
void touch_hal_sleep_channel_get_work_time(uint16_t *sleep_cycle, uint16_t *meas_times)
|
||||
{
|
||||
if (s_meas_times < 0) {
|
||||
touch_ll_get_measure_times(meas_times);
|
||||
} else {
|
||||
*meas_times = (uint16_t)s_meas_times;
|
||||
}
|
||||
if (s_sleep_cycle < 0) {
|
||||
touch_ll_get_sleep_time(sleep_cycle);
|
||||
} else {
|
||||
*sleep_cycle = (uint16_t)s_sleep_cycle;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "soc/touch_sensor_channel.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[] = {
|
||||
-1,
|
||||
TOUCH_PAD_NUM1_GPIO_NUM,
|
||||
TOUCH_PAD_NUM2_GPIO_NUM,
|
||||
TOUCH_PAD_NUM3_GPIO_NUM,
|
||||
TOUCH_PAD_NUM4_GPIO_NUM,
|
||||
TOUCH_PAD_NUM5_GPIO_NUM,
|
||||
TOUCH_PAD_NUM6_GPIO_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
|
||||
};
|
||||
@@ -0,0 +1,624 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* NOTICE
|
||||
* The hal is not public api, don't use in application code.
|
||||
* See readme.md in hal/include/hal/readme.md
|
||||
******************************************************************************/
|
||||
|
||||
// The HAL layer for touch sensor (ESP32-S3 specific part)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hal/touch_sensor_ll.h"
|
||||
#include "hal/touch_sensor_legacy_types.h"
|
||||
|
||||
#include_next "hal/touch_sensor_legacy_hal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Reset the whole of touch module.
|
||||
*
|
||||
* @note Call this function after `touch_pad_fsm_stop`,
|
||||
*/
|
||||
#define touch_hal_reset() touch_ll_reset()
|
||||
|
||||
/**
|
||||
* Set touch sensor measurement time.
|
||||
*
|
||||
* @param meas_time The duration of the touch sensor measurement.
|
||||
* t_meas = meas_time / (8MHz), the maximum measure time is 0xffff / 8M = 8.19 ms.
|
||||
*/
|
||||
#define touch_hal_set_meas_times(meas_time) touch_ll_set_meas_times(meas_time)
|
||||
|
||||
/**
|
||||
* Get touch sensor times of charge and discharge.
|
||||
*
|
||||
* @param meas_times Pointer to accept times count of charge and discharge.
|
||||
*/
|
||||
#define touch_hal_get_measure_times(meas_time) touch_ll_get_measure_times(meas_time)
|
||||
|
||||
/**
|
||||
* Set connection type of touch channel in idle status.
|
||||
* When a channel is in measurement mode, other initialized channels are in idle mode.
|
||||
* The touch channel is generally adjacent to the trace, so the connection state of the idle channel
|
||||
* affects the stability and sensitivity of the test channel.
|
||||
* The `CONN_HIGHZ`(high resistance) setting increases the sensitivity of touch channels.
|
||||
* The `CONN_GND`(grounding) setting increases the stability of touch channels.
|
||||
*
|
||||
* @param type Select idle channel connect to high resistance state or ground.
|
||||
*/
|
||||
#define touch_hal_set_idle_channel_connect(type) touch_ll_set_idle_channel_connect(type)
|
||||
|
||||
/**
|
||||
* Set connection type of touch channel in idle status.
|
||||
* When a channel is in measurement mode, other initialized channels are in idle mode.
|
||||
* The touch channel is generally adjacent to the trace, so the connection state of the idle channel
|
||||
* affects the stability and sensitivity of the test channel.
|
||||
* The `CONN_HIGHZ`(high resistance) setting increases the sensitivity of touch channels.
|
||||
* The `CONN_GND`(grounding) setting increases the stability of touch channels.
|
||||
*
|
||||
* @param type Select idle channel connect to high resistance state or ground.
|
||||
*/
|
||||
#define touch_hal_get_idle_channel_connect(type) touch_ll_get_idle_channel_connect(type)
|
||||
|
||||
/**
|
||||
* Get the current measure channel. Touch sensor measurement is cyclic scan mode.
|
||||
*
|
||||
* @return
|
||||
* - touch channel number
|
||||
*/
|
||||
#define touch_hal_get_current_meas_channel() touch_ll_get_current_meas_channel()
|
||||
|
||||
/**
|
||||
* Enable touch sensor interrupt by bitmask.
|
||||
*
|
||||
* @param type interrupt type
|
||||
*/
|
||||
#define touch_hal_intr_enable(int_mask) touch_ll_intr_enable(int_mask)
|
||||
|
||||
/**
|
||||
* Disable touch sensor interrupt by bitmask.
|
||||
*
|
||||
* @param type interrupt type
|
||||
*/
|
||||
#define touch_hal_intr_disable(int_mask) touch_ll_intr_disable(int_mask)
|
||||
|
||||
/**
|
||||
* Clear touch sensor interrupt by bitmask.
|
||||
*
|
||||
* @param int_mask Pad mask to clear interrupts
|
||||
*/
|
||||
#define touch_hal_intr_clear(int_mask) touch_ll_intr_clear(int_mask)
|
||||
|
||||
/**
|
||||
* Get the bitmask of touch sensor interrupt status.
|
||||
*
|
||||
* @return type interrupt type
|
||||
*/
|
||||
#define touch_hal_read_intr_status_mask() touch_ll_read_intr_status_mask()
|
||||
|
||||
/**
|
||||
* Enable 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.
|
||||
*
|
||||
* @note Set the timeout threshold correctly before enabling it.
|
||||
*/
|
||||
#define touch_hal_timeout_enable() touch_ll_timeout_enable()
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @note Set the timeout threshold correctly before enabling it.
|
||||
*/
|
||||
#define touch_hal_timeout_disable() touch_ll_timeout_disable()
|
||||
|
||||
/**
|
||||
* Set timeout threshold for all touch sensor channels measurements.
|
||||
* Compared with touch readings.
|
||||
*
|
||||
* @param threshold Set to the maximum time measured on one channel.
|
||||
*/
|
||||
#define touch_hal_timeout_set_threshold(threshold) touch_ll_timeout_set_threshold(threshold)
|
||||
|
||||
/**
|
||||
* Get timeout threshold for all touch sensor channels measurements.
|
||||
* Compared with touch readings.
|
||||
*
|
||||
* @param threshold Point to timeout threshold.
|
||||
*/
|
||||
#define touch_hal_timeout_get_threshold(threshold) touch_ll_timeout_get_threshold(threshold)
|
||||
|
||||
/**
|
||||
* Touch timer trigger measurement and always wait measurement done.
|
||||
* Force done for touch timer ensures that the timer always can get the measurement done signal.
|
||||
*/
|
||||
#define touch_hal_timer_force_done() touch_ll_timer_force_done()
|
||||
|
||||
/************************ Filter register setting ************************/
|
||||
|
||||
/**
|
||||
* Set parameter of touch sensor filter and detection algorithm.
|
||||
* For more details on the detection algorithm, please refer to the application documentation.
|
||||
*
|
||||
* @param filter_info select filter type and threshold of detection algorithm
|
||||
*/
|
||||
void touch_hal_filter_set_config(const touch_filter_config_t *filter_info);
|
||||
|
||||
/**
|
||||
* Get parameter of touch sensor filter and detection algorithm.
|
||||
* For more details on the detection algorithm, please refer to the application documentation.
|
||||
*
|
||||
* @param filter_info select filter type and threshold of detection algorithm
|
||||
*/
|
||||
void touch_hal_filter_get_config(touch_filter_config_t *filter_info);
|
||||
|
||||
/**
|
||||
* Get smoothed data that obtained by filtering the raw data.
|
||||
*
|
||||
* @param touch_num touch pad index
|
||||
* @param smooth_data pointer to smoothed data
|
||||
*/
|
||||
#define touch_hal_filter_read_smooth(touch_num, smooth_data) touch_ll_filter_read_smooth(touch_num, smooth_data)
|
||||
|
||||
/**
|
||||
* Get benchmark value of touch sensor.
|
||||
*
|
||||
* @note After initialization, the benchmark value is the maximum during the first measurement period.
|
||||
* @param touch_num touch pad index
|
||||
* @param touch_value pointer to accept touch sensor value
|
||||
*/
|
||||
#define touch_hal_read_benchmark(touch_num, benchmark) touch_ll_read_benchmark(touch_num, benchmark)
|
||||
|
||||
/**
|
||||
* Force reset benchmark to raw data of touch sensor.
|
||||
*
|
||||
* @param touch_num touch pad index
|
||||
* - TOUCH_PAD_MAX Reset baseline of all channels.
|
||||
*/
|
||||
#define touch_hal_reset_benchmark(touch_num) touch_ll_reset_benchmark(touch_num)
|
||||
|
||||
/**
|
||||
* Set filter mode. The input of the filter is the raw value of touch reading,
|
||||
* and the output of the filter is involved in the judgment of the touch state.
|
||||
*
|
||||
* @param mode Filter mode type. Refer to ``touch_filter_mode_t``.
|
||||
*/
|
||||
#define touch_hal_filter_set_filter_mode(mode) touch_ll_filter_set_filter_mode(mode)
|
||||
|
||||
/**
|
||||
* Get filter mode. The input of the filter is the raw value of touch reading,
|
||||
* and the output of the filter is involved in the judgment of the touch state.
|
||||
*
|
||||
* @param mode Filter mode type. Refer to ``touch_filter_mode_t``.
|
||||
*/
|
||||
#define touch_hal_filter_get_filter_mode(mode) touch_ll_filter_get_filter_mode(mode)
|
||||
|
||||
/**
|
||||
* Set debounce count, such as `n`. If the measured values continue to exceed
|
||||
* the threshold for `n` times, it is determined that the touch sensor state changes.
|
||||
*
|
||||
* @param dbc_cnt Debounce count value.
|
||||
*/
|
||||
#define touch_hal_filter_set_debounce(dbc_cnt) touch_ll_filter_set_debounce(dbc_cnt)
|
||||
|
||||
/**
|
||||
* Get debounce count.
|
||||
*
|
||||
* @param dbc_cnt Debounce count value.
|
||||
*/
|
||||
#define touch_hal_filter_get_debounce(dbc_cnt) touch_ll_filter_get_debounce(dbc_cnt)
|
||||
|
||||
/**
|
||||
* Set noise threshold coefficient. Higher = More noise resistance.
|
||||
* The actual noise should be less than (noise coefficient * touch threshold).
|
||||
* Range: 0 ~ 3. The coefficient is 0: 4/8; 1: 3/8; 2: 2/8; 3: 1;
|
||||
*
|
||||
* @param hys_thr Noise threshold coefficient.
|
||||
*/
|
||||
#define touch_hal_filter_set_noise_thres(noise_thr) touch_ll_filter_set_noise_thres(noise_thr)
|
||||
|
||||
/**
|
||||
* Get noise threshold coefficient. Higher = More noise resistance.
|
||||
* The actual noise should be less than (noise coefficient * touch threshold).
|
||||
* Range: 0 ~ 3. The coefficient is 0: 4/8; 1: 3/8; 2: 2/8; 3: 1;
|
||||
*
|
||||
* @param noise_thr Noise threshold coefficient.
|
||||
*/
|
||||
#define touch_hal_filter_get_noise_thres(noise_thr) touch_ll_filter_get_noise_thres(noise_thr)
|
||||
|
||||
/**
|
||||
* Set the cumulative number of benchmark reset processes. such as `n`. If the measured values continue to exceed
|
||||
* the negative noise threshold for `n` times, the benchmark reset to raw data.
|
||||
* Range: 0 ~ 15
|
||||
*
|
||||
* @param reset_cnt The cumulative number of benchmark reset processes.
|
||||
*/
|
||||
#define touch_hal_filter_set_benchmark_reset(reset_cnt) touch_ll_filter_set_benchmark_reset(reset_cnt)
|
||||
|
||||
/**
|
||||
* Get the cumulative number of benchmark reset processes. such as `n`. If the measured values continue to exceed
|
||||
* the negative noise threshold for `n` times, the benchmark reset to raw data.
|
||||
* Range: 0 ~ 15
|
||||
*
|
||||
* @param reset_cnt The cumulative number of benchmark reset processes.
|
||||
*/
|
||||
#define touch_hal_filter_get_benchmark_reset(reset_cnt) touch_ll_filter_get_benchmark_reset(reset_cnt)
|
||||
|
||||
/**
|
||||
* Set jitter filter step size.
|
||||
* If filter mode is jitter, should set filter step for jitter.
|
||||
* Range: 0 ~ 15
|
||||
*
|
||||
* @param step The step size of the data change.
|
||||
*/
|
||||
#define touch_hal_filter_set_jitter_step(step) touch_ll_filter_set_jitter_step(step)
|
||||
|
||||
/**
|
||||
* Get jitter filter step size.
|
||||
* If filter mode is jitter, should set filter step for jitter.
|
||||
* Range: 0 ~ 15
|
||||
*
|
||||
* @param step The step size of the data change.
|
||||
*/
|
||||
#define touch_hal_filter_get_jitter_step(step) touch_ll_filter_get_jitter_step(step)
|
||||
|
||||
/**
|
||||
* 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(enable) touch_ll_filter_enable(enable)
|
||||
|
||||
/************************ Denoise register setting ************************/
|
||||
|
||||
/**
|
||||
* set parameter of denoise pad (TOUCH_PAD_NUM0).
|
||||
* T0 is an internal channel that does not have a corresponding external GPIO.
|
||||
* T0 will work simultaneously with the measured channel Tn. Finally, the actual
|
||||
* measured value of Tn is the value after subtracting lower bits of T0.
|
||||
* This denoise function filters out interference introduced on all channels,
|
||||
* such as noise introduced by the power supply and external EMI.
|
||||
*
|
||||
* @param denoise parameter of denoise
|
||||
*/
|
||||
void touch_hal_denoise_set_config(const touch_pad_denoise_t *denoise);
|
||||
|
||||
/**
|
||||
* @brief get parameter of denoise pad (TOUCH_PAD_NUM0).
|
||||
*
|
||||
* @param denoise Pointer to parameter of denoise
|
||||
*/
|
||||
void touch_hal_denoise_get_config(touch_pad_denoise_t *denoise);
|
||||
|
||||
/**
|
||||
* Enable denoise function.
|
||||
* T0 is an internal channel that does not have a corresponding external GPIO.
|
||||
* T0 will work simultaneously with the measured channel Tn. Finally, the actual
|
||||
* measured value of Tn is the value after subtracting lower bits of T0.
|
||||
* This denoise function filters out interference introduced on all channels,
|
||||
* such as noise introduced by the power supply and external EMI.
|
||||
*/
|
||||
void touch_hal_denoise_enable(void);
|
||||
|
||||
/**
|
||||
* Enable denoise function.
|
||||
* T0 is an internal channel that does not have a corresponding external GPIO.
|
||||
* T0 will work simultaneously with the measured channel Tn. Finally, the actual
|
||||
* measured value of Tn is the value after subtracting lower bits of T0.
|
||||
* 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_enable(false)
|
||||
|
||||
/**
|
||||
* Set internal reference capacitance of denoise channel.
|
||||
* Select the appropriate internal reference capacitance value so that
|
||||
* the reading of denoise channel is closest to the reading of the channel being measured.
|
||||
*
|
||||
* @param cap_level Capacitance level.
|
||||
*/
|
||||
#define touch_hal_denoise_set_cap_level(cap_level) touch_ll_denoise_set_cap_level(cap_level)
|
||||
|
||||
/**
|
||||
* Get internal reference capacitance of denoise channel.
|
||||
* Select the appropriate internal reference capacitance value so that
|
||||
* the reading of denoise channel is closest to the reading of the channel being measured.
|
||||
*
|
||||
* @param cap_level Capacitance level.
|
||||
*/
|
||||
#define touch_hal_denoise_get_cap_level(cap_level) touch_ll_denoise_get_cap_level(cap_level)
|
||||
|
||||
/**
|
||||
* Set denoise range of denoise channel.
|
||||
* Determined by measuring the noise amplitude of the denoise channel.
|
||||
*
|
||||
* @param grade Denoise range of denoise channel.
|
||||
*/
|
||||
#define touch_hal_denoise_set_grade(grade) touch_ll_denoise_set_grade(grade)
|
||||
|
||||
/**
|
||||
* Set denoise range of denoise channel.
|
||||
* Determined by measuring the noise amplitude of the denoise channel.
|
||||
*
|
||||
* @param grade Denoise range of denoise channel.
|
||||
*/
|
||||
#define touch_hal_denoise_get_grade(grade) touch_ll_denoise_get_grade(grade)
|
||||
|
||||
/**
|
||||
* Read denoise measure value (TOUCH_PAD_NUM0).
|
||||
*
|
||||
* @param denoise value of denoise.
|
||||
*/
|
||||
#define touch_hal_denoise_read_data(data) touch_ll_denoise_read_data(data)
|
||||
|
||||
/************************ Waterproof register setting ************************/
|
||||
/**
|
||||
* Set touch channel use for guard pad.
|
||||
*
|
||||
* @param pad_num Touch sensor channel number.
|
||||
*/
|
||||
#define touch_hal_waterproof_set_guard_pad(pad_num) touch_ll_waterproof_set_guard_pad(pad_num)
|
||||
|
||||
/**
|
||||
* Get touch channel use for guard pad.
|
||||
*
|
||||
* @param pad_num Touch sensor channel number.
|
||||
*/
|
||||
#define touch_hal_waterproof_get_guard_pad(pad_num) touch_ll_waterproof_get_guard_pad(pad_num)
|
||||
|
||||
/**
|
||||
* Set max equivalent capacitance for shield channel.
|
||||
* The equivalent capacitance of the shielded channel can be calculated
|
||||
* from the reading of denoise channel.
|
||||
*
|
||||
* @param pad_num Touch sensor channel number.
|
||||
*/
|
||||
#define touch_hal_waterproof_set_sheild_driver(driver_level) touch_ll_waterproof_set_shield_driver(driver_level)
|
||||
|
||||
/**
|
||||
* Get max equivalent capacitance for shield channel.
|
||||
* The equivalent capacitance of the shielded channel can be calculated
|
||||
* from the reading of denoise channel.
|
||||
*
|
||||
* @param pad_num Touch sensor channel number.
|
||||
*/
|
||||
#define touch_hal_waterproof_get_sheild_driver(driver_level) touch_ll_waterproof_get_shield_driver(driver_level)
|
||||
|
||||
/**
|
||||
* Set parameter of waterproof function.
|
||||
*
|
||||
* The waterproof function includes a shielded channel (TOUCH_PAD_NUM14) and a guard channel.
|
||||
* Guard pad is used to detect the large area of water covering the touch panel.
|
||||
* Shield pad is used to shield the influence of water droplets covering the touch panel.
|
||||
* It is generally designed as a grid and is placed around the touch buttons.
|
||||
*
|
||||
* @param waterproof parameter of waterproof
|
||||
*/
|
||||
void touch_hal_waterproof_set_config(const touch_pad_waterproof_t *waterproof);
|
||||
|
||||
/**
|
||||
* Get parameter of waterproof function.
|
||||
*
|
||||
* @param waterproof parameter of waterproof.
|
||||
*/
|
||||
void touch_hal_waterproof_get_config(touch_pad_waterproof_t *waterproof);
|
||||
|
||||
/**
|
||||
* Enable parameter of waterproof function.
|
||||
* Should be called after function ``touch_hal_waterproof_set_config``.
|
||||
*/
|
||||
void touch_hal_waterproof_enable(void);
|
||||
|
||||
/**
|
||||
* Disable parameter of waterproof function.
|
||||
*/
|
||||
#define touch_hal_waterproof_disable() touch_ll_waterproof_enable(false)
|
||||
|
||||
/************************ Proximity register setting ************************/
|
||||
|
||||
/**
|
||||
* Enable/disable proximity function of touch channels.
|
||||
* The proximity sensor measurement is the accumulation of touch channel measurements.
|
||||
*
|
||||
* @note Supports up to three touch channels configured as proximity sensors.
|
||||
* @param touch_num touch pad index
|
||||
* @param enabled true: enable the proximity function; false: disable the proximity function
|
||||
* @return
|
||||
* - true: Configured correctly.
|
||||
* - false: Configured error.
|
||||
*/
|
||||
bool touch_hal_enable_proximity(touch_pad_t touch_num, bool enabled);
|
||||
|
||||
/**
|
||||
* Set touch channel number for proximity pad.
|
||||
* If disable the proximity pad, point this pad to `TOUCH_PAD_NUM0`
|
||||
*
|
||||
* @param prox_pad The array of three proximity pads.
|
||||
*/
|
||||
#define touch_hal_proximity_set_channel_num(prox_pad) touch_ll_proximity_set_channel_num(prox_pad)
|
||||
|
||||
/**
|
||||
* Get touch channel number for proximity pad.
|
||||
* If disable the proximity pad, point this pad to `TOUCH_PAD_NUM0`
|
||||
*
|
||||
* @param prox_pad The array of three proximity pads.
|
||||
*/
|
||||
#define touch_hal_proximity_get_channel_num(prox_pad) touch_ll_proximity_get_channel_num(prox_pad)
|
||||
|
||||
/**
|
||||
* Set cumulative measurement times for proximity pad.
|
||||
*
|
||||
* @param times The cumulative number of measurement cycles.
|
||||
*/
|
||||
#define touch_hal_proximity_set_meas_times(times) touch_ll_proximity_set_meas_times(times)
|
||||
|
||||
/**
|
||||
* Get cumulative measurement times for proximity pad.
|
||||
*
|
||||
* @param times The cumulative number of measurement cycles.
|
||||
*/
|
||||
#define touch_hal_proximity_get_meas_times(times) touch_ll_proximity_get_meas_times(times)
|
||||
|
||||
/**
|
||||
* Read current cumulative measurement times for proximity pad.
|
||||
*
|
||||
* @param times The cumulative number of measurement cycles.
|
||||
*/
|
||||
#define touch_hal_proximity_read_meas_cnt(touch_num, cnt) touch_ll_proximity_read_meas_cnt(touch_num, cnt)
|
||||
|
||||
/**
|
||||
* Check if the touch sensor channel is the proximity pad.
|
||||
*
|
||||
* @param touch_num The touch sensor channel number.
|
||||
*/
|
||||
#define touch_hal_proximity_pad_check(touch_num) touch_ll_proximity_pad_check(touch_num)
|
||||
|
||||
/************** sleep pad setting ***********************/
|
||||
|
||||
/**
|
||||
* Get parameter of touch sensor sleep channel.
|
||||
* The touch sensor can works in sleep mode to wake up sleep.
|
||||
* After the sleep channel is configured, users should query the channel reading using a specific function.
|
||||
*
|
||||
* @param slp_config Point to touch sleep pad config.
|
||||
*/
|
||||
void touch_hal_sleep_channel_get_config(touch_pad_sleep_channel_t *slp_config);
|
||||
|
||||
/**
|
||||
* Set parameter of touch sensor sleep channel.
|
||||
* The touch sensor can works in sleep mode to wake up sleep.
|
||||
* After the sleep channel is configured, users should query the channel reading using a specific function.
|
||||
*
|
||||
* @note ESP32S2 only support one channel to be set sleep channel.
|
||||
*
|
||||
* @param pad_num touch sleep pad number.
|
||||
* @param enable Enable/disable sleep pad function.
|
||||
*/
|
||||
void touch_hal_sleep_channel_enable(touch_pad_t pad_num, bool enable);
|
||||
|
||||
/**
|
||||
* Set touch channel number for sleep pad.
|
||||
*
|
||||
* @note Only one touch sensor channel is supported in deep sleep mode.
|
||||
* @param touch_num Touch sensor channel number.
|
||||
*/
|
||||
#define touch_hal_sleep_set_channel_num(touch_num) touch_ll_sleep_set_channel_num(touch_num)
|
||||
|
||||
/**
|
||||
* Get touch channel number for sleep pad.
|
||||
*
|
||||
* @note Only one touch sensor channel is supported in deep sleep mode.
|
||||
* @param touch_num Touch sensor channel number.
|
||||
*/
|
||||
#define touch_hal_sleep_get_channel_num(touch_num) touch_ll_sleep_get_channel_num(touch_num)
|
||||
|
||||
/**
|
||||
* Set the trigger threshold of touch sensor in deep sleep.
|
||||
* The threshold determines the sensitivity of the touch sensor.
|
||||
* The threshold is the original value of the trigger state minus the benchmark value.
|
||||
*
|
||||
* @note The threshold at sleep is the same as the threshold before sleep.
|
||||
*/
|
||||
#define touch_hal_sleep_set_threshold(touch_thres) touch_ll_sleep_set_threshold(touch_thres)
|
||||
|
||||
/**
|
||||
* Get the trigger threshold of touch sensor in deep sleep.
|
||||
* The threshold determines the sensitivity of the touch sensor.
|
||||
* The threshold is the original value of the trigger state minus the benchmark value.
|
||||
*
|
||||
* @note The threshold at sleep is the same as the threshold before sleep.
|
||||
*/
|
||||
#define touch_hal_sleep_get_threshold(touch_thres) touch_ll_sleep_get_threshold(touch_thres)
|
||||
|
||||
/**
|
||||
* Enable proximity function for sleep pad.
|
||||
* @param enable the proximity sensing
|
||||
*/
|
||||
#define touch_hal_sleep_enable_approach(enable) touch_ll_sleep_enable_proximity_sensing(enable)
|
||||
|
||||
/**
|
||||
* Read benchmark of touch sensor for sleep pad.
|
||||
*
|
||||
* @param benchmark Pointer to accept touch sensor benchmark value.
|
||||
*/
|
||||
#define touch_hal_sleep_read_benchmark(benchmark) touch_ll_sleep_read_benchmark(benchmark)
|
||||
|
||||
/**
|
||||
* Read smooth data of touch sensor for sleep pad.
|
||||
*/
|
||||
#define touch_hal_sleep_read_smooth(smooth_data) touch_ll_sleep_read_smooth(smooth_data)
|
||||
|
||||
/**
|
||||
* Read raw data of touch sensor for sleep pad.
|
||||
*/
|
||||
#define touch_hal_sleep_read_data(raw_data) touch_ll_sleep_read_data(raw_data)
|
||||
|
||||
/**
|
||||
* Reset benchmark of touch sensor for sleep pad.
|
||||
*/
|
||||
#define touch_hal_sleep_reset_benchmark() touch_ll_sleep_reset_benchmark()
|
||||
|
||||
/**
|
||||
* Read debounce of touch sensor for sleep pad.
|
||||
*
|
||||
* @param debounce Pointer to accept touch sensor debounce value.
|
||||
*/
|
||||
#define touch_hal_sleep_read_debounce(debounce) touch_ll_sleep_read_debounce(debounce)
|
||||
|
||||
/**
|
||||
* Read proximity count of touch sensor for sleep pad.
|
||||
* @param proximity_cnt Pointer to accept touch sensor proximity count value.
|
||||
*/
|
||||
#define touch_hal_sleep_read_proximity_cnt(approach_cnt) touch_ll_sleep_read_proximity_cnt(approach_cnt)
|
||||
|
||||
/**
|
||||
* Get the touch pad which caused wakeup from deep sleep.
|
||||
*
|
||||
* @param pad_num pointer to touch pad which caused wakeup.
|
||||
*/
|
||||
#define touch_hal_get_wakeup_status(pad_num) touch_ll_get_wakeup_status(pad_num)
|
||||
|
||||
/**
|
||||
* Change the operating frequency of touch pad in deep sleep state. Reducing the operating frequency can effectively reduce power consumption.
|
||||
* If this function is not called, the working frequency of touch in the deep sleep state is the same as that in the wake-up state.
|
||||
*
|
||||
* @param sleep_cycle The touch sensor will sleep after each measurement.
|
||||
* sleep_cycle decide the interval between each measurement.
|
||||
* t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
|
||||
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
|
||||
* @param meas_times The times of charge and discharge in each measure process of touch channels.
|
||||
* The timer frequency is 8Mhz. Range: 0 ~ 0xffff.
|
||||
* Recommended typical value: Modify this value to make the measurement time around 1ms.
|
||||
*/
|
||||
void touch_hal_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times);
|
||||
|
||||
/**
|
||||
* Get the operating frequency of touch pad in deep sleep state. Reducing the operating frequency can effectively reduce power consumption.
|
||||
*
|
||||
* @param sleep_cycle The touch sensor will sleep after each measurement.
|
||||
* sleep_cycle decide the interval between each measurement.
|
||||
* t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
|
||||
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
|
||||
* @param meas_times The times of charge and discharge in each measure process of touch channels.
|
||||
* The timer frequency is 8Mhz. Range: 0 ~ 0xffff.
|
||||
* Recommended typical value: Modify this value to make the measurement time around 1ms.
|
||||
*/
|
||||
void touch_hal_sleep_channel_get_work_time(uint16_t *sleep_cycle, uint16_t *meas_times);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2024 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_legacy_hal.h"
|
||||
#include "hal/touch_sensor_ll.h"
|
||||
#include "hal/touch_sensor_legacy_types.h"
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
static int s_sleep_cycle = -1;
|
||||
static int s_meas_times = -1;
|
||||
|
||||
void touch_hal_init(void)
|
||||
{
|
||||
touch_ll_stop_fsm();
|
||||
touch_ll_intr_disable(TOUCH_PAD_INTR_MASK_ALL);
|
||||
touch_ll_intr_clear(TOUCH_PAD_INTR_MASK_ALL);
|
||||
touch_ll_clear_channel_mask(TOUCH_PAD_BIT_MASK_ALL);
|
||||
touch_ll_clear_trigger_status_mask();
|
||||
touch_ll_set_meas_times(TOUCH_PAD_MEASURE_CYCLE_DEFAULT);
|
||||
touch_ll_set_sleep_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT);
|
||||
/* Configure the touch-sensor power domain into self-bias since bandgap-bias
|
||||
* level is different under sleep-mode compared to running-mode. self-bias is
|
||||
* always on after chip startup. */
|
||||
touch_ll_sleep_low_power(true);
|
||||
touch_ll_set_voltage_high(TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD);
|
||||
touch_ll_set_voltage_low(TOUCH_PAD_LOW_VOLTAGE_THRESHOLD);
|
||||
touch_ll_set_voltage_attenuation(TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD);
|
||||
touch_ll_set_idle_channel_connect(TOUCH_PAD_IDLE_CH_CONNECT_DEFAULT);
|
||||
/* Clear touch channels to initialize the channel value (benchmark, raw_data).
|
||||
* Note: Should call it after enable clock gate. */
|
||||
touch_ll_clkgate(true); // Enable clock gate for touch sensor.
|
||||
touch_ll_reset_benchmark(TOUCH_PAD_MAX);
|
||||
touch_ll_sleep_reset_benchmark();
|
||||
}
|
||||
|
||||
void touch_hal_deinit(void)
|
||||
{
|
||||
touch_ll_reset_benchmark(TOUCH_PAD_MAX);
|
||||
touch_ll_sleep_reset_benchmark();
|
||||
touch_ll_stop_fsm();
|
||||
touch_ll_clkgate(false);
|
||||
touch_ll_clear_channel_mask(TOUCH_PAD_BIT_MASK_ALL);
|
||||
touch_ll_clear_trigger_status_mask();
|
||||
touch_ll_intr_disable(TOUCH_PAD_INTR_MASK_ALL);
|
||||
touch_ll_timeout_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_enable_proximity_sensing(false);
|
||||
touch_ll_reset(); // Reset the touch sensor FSM.
|
||||
}
|
||||
|
||||
void touch_hal_filter_set_config(const touch_filter_config_t *filter_info)
|
||||
{
|
||||
touch_ll_filter_set_filter_mode(filter_info->mode);
|
||||
touch_ll_filter_set_debounce(filter_info->debounce_cnt);
|
||||
touch_ll_filter_set_noise_thres(filter_info->noise_thr);
|
||||
touch_ll_filter_set_jitter_step(filter_info->jitter_step);
|
||||
touch_ll_filter_set_smooth_mode(filter_info->smh_lvl);
|
||||
}
|
||||
|
||||
void touch_hal_filter_get_config(touch_filter_config_t *filter_info)
|
||||
{
|
||||
touch_ll_filter_get_filter_mode(&filter_info->mode);
|
||||
touch_ll_filter_get_debounce(&filter_info->debounce_cnt);
|
||||
touch_ll_filter_get_noise_thres(&filter_info->noise_thr);
|
||||
touch_ll_filter_get_jitter_step(&filter_info->jitter_step);
|
||||
touch_ll_filter_get_smooth_mode(&filter_info->smh_lvl);
|
||||
}
|
||||
|
||||
void touch_hal_denoise_set_config(const touch_pad_denoise_t *denoise)
|
||||
{
|
||||
touch_ll_denoise_set_cap_level(denoise->cap_level);
|
||||
touch_ll_denoise_set_grade(denoise->grade);
|
||||
}
|
||||
|
||||
void touch_hal_denoise_get_config(touch_pad_denoise_t *denoise)
|
||||
{
|
||||
touch_ll_denoise_get_cap_level(&denoise->cap_level);
|
||||
touch_ll_denoise_get_grade(&denoise->grade);
|
||||
}
|
||||
|
||||
void touch_hal_denoise_enable(void)
|
||||
{
|
||||
touch_ll_clear_channel_mask(1U << TOUCH_LL_GET(DENOISE_CHAN_ID));
|
||||
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_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_shield_driver(&waterproof->shield_driver);
|
||||
}
|
||||
|
||||
void touch_hal_waterproof_enable(void)
|
||||
{
|
||||
touch_ll_clear_channel_mask(1U << TOUCH_LL_GET(SHIELD_CHAN_ID));
|
||||
touch_ll_waterproof_enable(true);
|
||||
}
|
||||
|
||||
bool touch_hal_enable_proximity(touch_pad_t touch_num, bool enabled)
|
||||
{
|
||||
int i = 0;
|
||||
touch_pad_t ch_num[SOC_TOUCH_PROXIMITY_CHANNEL_NUM] = {0};
|
||||
touch_ll_proximity_get_channel_num(ch_num);
|
||||
if (enabled) {
|
||||
for (i = 0; i < SOC_TOUCH_PROXIMITY_CHANNEL_NUM; i++) {
|
||||
if (ch_num[i] == TOUCH_PAD_NUM0 || ch_num[i] >= TOUCH_PAD_MAX || ch_num[i] == touch_num) {
|
||||
ch_num[i] = touch_num;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == SOC_TOUCH_PROXIMITY_CHANNEL_NUM) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < SOC_TOUCH_PROXIMITY_CHANNEL_NUM; i++) {
|
||||
if (ch_num[i] == touch_num) {
|
||||
ch_num[i] = TOUCH_PAD_NUM0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
touch_ll_proximity_set_channel_num(ch_num);
|
||||
return true;
|
||||
}
|
||||
|
||||
void touch_hal_sleep_channel_enable(touch_pad_t pad_num, bool enable)
|
||||
{
|
||||
if (enable) {
|
||||
touch_ll_sleep_set_channel_num(pad_num);
|
||||
touch_ll_sleep_set_threshold(TOUCH_PAD_THRESHOLD_MAX);
|
||||
touch_ll_sleep_reset_benchmark();
|
||||
} else {
|
||||
touch_ll_sleep_set_channel_num(TOUCH_PAD_NUM0);
|
||||
}
|
||||
}
|
||||
|
||||
void touch_hal_sleep_channel_get_config(touch_pad_sleep_channel_t *slp_config)
|
||||
{
|
||||
touch_ll_sleep_get_channel_num((uint32_t *)&slp_config->touch_num);
|
||||
slp_config->en_proximity = touch_ll_sleep_is_proximity_enabled();
|
||||
}
|
||||
|
||||
void touch_hal_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times)
|
||||
{
|
||||
s_sleep_cycle = (int)sleep_cycle;
|
||||
s_meas_times = (int)meas_times;
|
||||
}
|
||||
|
||||
void touch_hal_sleep_channel_get_work_time(uint16_t *sleep_cycle, uint16_t *meas_times)
|
||||
{
|
||||
if (s_meas_times < 0) {
|
||||
touch_ll_get_measure_times(meas_times);
|
||||
} else {
|
||||
*meas_times = (uint16_t)s_meas_times;
|
||||
}
|
||||
if (s_sleep_cycle < 0) {
|
||||
touch_ll_get_sleep_time(sleep_cycle);
|
||||
} else {
|
||||
*sleep_cycle = (uint16_t)s_sleep_cycle;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "soc/touch_sensor_channel.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[] = {
|
||||
-1,
|
||||
TOUCH_PAD_NUM1_GPIO_NUM,
|
||||
TOUCH_PAD_NUM2_GPIO_NUM,
|
||||
TOUCH_PAD_NUM3_GPIO_NUM,
|
||||
TOUCH_PAD_NUM4_GPIO_NUM,
|
||||
TOUCH_PAD_NUM5_GPIO_NUM,
|
||||
TOUCH_PAD_NUM6_GPIO_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
|
||||
};
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* NOTICE
|
||||
* The hal is not public api, don't use in application code.
|
||||
* See readme.md in hal/include/hal/readme.md
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
#if SOC_TOUCH_SENSOR_SUPPORTED
|
||||
#include "hal/touch_sensor_ll.h"
|
||||
#include "hal/touch_sens_types.h"
|
||||
#endif // SOC_TOUCH_SENSOR_SUPPORTED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#if SOC_TOUCH_SENSOR_SUPPORTED
|
||||
#if SOC_TOUCH_SENSOR_VERSION == 1
|
||||
/**
|
||||
* @brief Sample configurations of the touch sensor V1
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t charge_duration_ticks;
|
||||
touch_volt_lim_h_t charge_volt_lim_h; /*!< The upper voltage limit while charging a touch pad. i.e., the touch controller won't charge the touch pad higher than this high voltage limitation. */
|
||||
touch_volt_lim_l_t charge_volt_lim_l; /*!< The lower voltage limit while discharging a touch pad. i.e., the touch controller won't discharge the touch pad lower than this low voltage limitation. */
|
||||
} touch_hal_sample_config_v1_t;
|
||||
|
||||
/**
|
||||
* @brief Alias of touch_hal_sample_config_v1_t for compatibility
|
||||
*/
|
||||
typedef touch_hal_sample_config_v1_t touch_hal_sample_config_t;
|
||||
|
||||
#elif SOC_TOUCH_SENSOR_VERSION == 2
|
||||
|
||||
/**
|
||||
* @brief Sample configurations of the touch sensor V2
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t charge_times; /*!< The charge and discharge times of this sample configuration, the read data are positive correlation to the charge_times */
|
||||
touch_volt_lim_h_t charge_volt_lim_h; /*!< The upper voltage limit while charging a touch pad. i.e., the touch controller won't charge the touch pad higher than this high voltage limitation. */
|
||||
touch_volt_lim_l_t charge_volt_lim_l; /*!< The lower voltage limit while discharging a touch pad. i.e., the touch controller won't discharge the touch pad lower than this low voltage limitation. */
|
||||
touch_idle_conn_t idle_conn; /*!< The connection of the idle touch channels.
|
||||
* The idle touch channel is a channel which is enabled and power-on but not under measuring.
|
||||
*/
|
||||
touch_bias_type_t bias_type; /*!< The type of the touch sensor bias. Which affects the charge/discharge stability and power consumption */
|
||||
} touch_hal_sample_config_v2_t;
|
||||
|
||||
/**
|
||||
* @brief Alias of touch_hal_sample_config_v2_t for compatibility
|
||||
*/
|
||||
typedef touch_hal_sample_config_v2_t touch_hal_sample_config_t;
|
||||
|
||||
#elif SOC_TOUCH_SENSOR_VERSION == 3
|
||||
|
||||
/**
|
||||
* @brief Sample configurations of the touch sensor V3
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t div_num; /*!< The division of the touch output signal. It is proportional to the gain of the read data */
|
||||
uint32_t charge_times; /*!< The charge and discharge times of the sample configuration, the read data are positive correlation to the charge_times */
|
||||
uint8_t rc_filter_res; /*!< The resistance of the RC filter of the sample configuration, range [0, 3], while 0 = 0K, 1 = 1.5K, 2 = 3K, 3 = 4.5K */
|
||||
uint8_t rc_filter_cap; /*!< The capacitance of the RC filter of the sample configuration, range [0, 127], while 0 = 0pF, 1 = 20fF, ..., 127 = 2.54pF */
|
||||
uint8_t low_drv; /*!< Low speed touch driver, only effective when high speed driver is disabled */
|
||||
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 */
|
||||
} touch_hal_sample_config_v3_t;
|
||||
|
||||
/**
|
||||
* @brief Alias of touch_hal_sample_config_v3_t for compatibility
|
||||
*/
|
||||
typedef touch_hal_sample_config_v3_t touch_hal_sample_config_t;
|
||||
|
||||
#else
|
||||
#error "Unsupported touch sensor version"
|
||||
typedef int touch_hal_sample_config_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Configurations of the touch sensor controller
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t power_on_wait_ticks; /*!< The waiting time between the channels power on and able to measure, to ensure the data stability */
|
||||
uint32_t meas_interval_ticks; /*!< Measurement interval of each channels */ // TODO: Test the supported range
|
||||
#if SOC_TOUCH_SENSOR_VERSION == 1
|
||||
touch_intr_trig_mode_t intr_trig_mode;
|
||||
touch_intr_trig_group_t intr_trig_group;
|
||||
#elif SOC_TOUCH_SENSOR_VERSION == 2
|
||||
uint32_t timeout_ticks; /*!< The maximum time of measuring one channel, if the time exceeds this value, the timeout interrupt will be triggered.
|
||||
* Set to '0' to ignore the measurement time limitation, otherwise please set a proper time considering the configurations
|
||||
* of the sample configurations below.
|
||||
*/
|
||||
#elif SOC_TOUCH_SENSOR_VERSION == 3
|
||||
uint32_t timeout_ticks; /*!< The maximum time of measuring one channel, if the time exceeds this value, the timeout interrupt will be triggered.
|
||||
* Set to '0' to ignore the measurement time limitation, otherwise please set a proper time considering the configurations
|
||||
* of the sample configurations below.
|
||||
*/
|
||||
touch_out_mode_t output_mode; /*!< Touch channel counting mode of the binarized touch output */
|
||||
#endif // SOC_TOUCH_SENSOR_VERSION == 3
|
||||
uint32_t sample_cfg_num; /*!< The sample configuration number that used for sampling */
|
||||
uint32_t trigger_rise_cnt; /*!< The counter of triggered frequency points to judge whether a channel active.
|
||||
* For example, there are 3 sample configurations activated, and the trigger_rise_cnt is 2,
|
||||
* then the channel will only be active when at least 2 of 3 sample configurations triggered.
|
||||
* Range: [0 ~ sample_cfg_num], '0' means select the recommended value automatically.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* @brief Configure the touch sensor hardware with the configuration
|
||||
*
|
||||
* @param[in] cfg Touch sensor hardware configuration
|
||||
*/
|
||||
void touch_hal_config_controller(const touch_hal_config_t *cfg);
|
||||
|
||||
/**
|
||||
* @brief Save the touch sensor hardware configuration
|
||||
* @note The saved configurations will be applied before entering deep sleep
|
||||
*
|
||||
* @param[in] deep_slp_chan The touch sensor channel that can wake-up the chip from deep sleep, -1 means all enabled channel can wakeup
|
||||
* @param[in] deep_slp_cfg The hardware configuration that takes effect during the deep sleep
|
||||
* @param[in] dslp_allow_pd Whether allow RTC_PERIPH domain power down during the deep sleep
|
||||
*/
|
||||
void touch_hal_save_sleep_config(int deep_slp_chan, const touch_hal_config_t *deep_slp_cfg, bool dslp_allow_pd);
|
||||
|
||||
/**
|
||||
* @brief Prepare for the deep sleep
|
||||
* @note Including apply the deep sleep configuration, clear interrupts, resetting benchmark
|
||||
*/
|
||||
void touch_hal_prepare_deep_sleep(void);
|
||||
|
||||
#endif // SOC_TOUCH_SENSOR_SUPPORTED
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TOUCH_SAMPLE_CFG_NUM SOC_TOUCH_SAMPLE_CFG_NUM /*!< The supported max sample configuration number */
|
||||
#if SOC_TOUCH_SUPPORT_PROX_SENSING
|
||||
#define TOUCH_PROXIMITY_CHAN_NUM SOC_TOUCH_PROXIMITY_CHANNEL_NUM /*!< The supported proximity channel number in proximity sensing mode */
|
||||
#endif
|
||||
|
||||
#define TOUCH_MIN_CHAN_ID SOC_TOUCH_MIN_CHAN_ID /*!< The minimum available channel id of the touch pad */
|
||||
#define TOUCH_MAX_CHAN_ID SOC_TOUCH_MAX_CHAN_ID /*!< The maximum available channel id of the touch pad */
|
||||
#define TOUCH_TOTAL_CHAN_NUM (TOUCH_MAX_CHAN_ID - TOUCH_MIN_CHAN_ID + 1) /*!< The total channel number of the touch sensor */
|
||||
|
||||
/**
|
||||
* @brief Touch sensor shield channel drive capability level
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_SHIELD_CAP_40PF, /*!< The max equivalent capacitance in shield channel is 40pf */
|
||||
TOUCH_SHIELD_CAP_80PF, /*!< The max equivalent capacitance in shield channel is 80pf */
|
||||
TOUCH_SHIELD_CAP_120PF, /*!< The max equivalent capacitance in shield channel is 120pf */
|
||||
TOUCH_SHIELD_CAP_160PF, /*!< The max equivalent capacitance in shield channel is 160pf */
|
||||
TOUCH_SHIELD_CAP_200PF, /*!< The max equivalent capacitance in shield channel is 200pf */
|
||||
TOUCH_SHIELD_CAP_240PF, /*!< The max equivalent capacitance in shield channel is 240pf */
|
||||
TOUCH_SHIELD_CAP_280PF, /*!< The max equivalent capacitance in shield channel is 280pf */
|
||||
TOUCH_SHIELD_CAP_320PF, /*!< The max equivalent capacitance in shield channel is 320pf */
|
||||
} touch_chan_shield_cap_t;
|
||||
|
||||
/**
|
||||
* @brief Touch channel Infinite Impulse Response (IIR) filter or Jitter filter for benchmark
|
||||
* @note Recommended filter coefficient selection is `IIR_16`.
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_BM_IIR_FILTER_4, /*!< IIR Filter for benchmark, 1/4 raw_value + 3/4 benchmark */
|
||||
TOUCH_BM_IIR_FILTER_8, /*!< IIR Filter for benchmark, 1/8 raw_value + 7/8 benchmark */
|
||||
TOUCH_BM_IIR_FILTER_16, /*!< IIR Filter for benchmark, 1/16 raw_value + 15/16 benchmark (typical) */
|
||||
TOUCH_BM_IIR_FILTER_32, /*!< IIR Filter for benchmark, 1/32 raw_value + 31/32 benchmark */
|
||||
TOUCH_BM_IIR_FILTER_64, /*!< IIR Filter for benchmark, 1/64 raw_value + 63/64 benchmark */
|
||||
TOUCH_BM_IIR_FILTER_128, /*!< IIR Filter for benchmark, 1/128 raw_value + 127/128 benchmark */
|
||||
#if SOC_TOUCH_SENSOR_VERSION == 2
|
||||
TOUCH_BM_IIR_FILTER_256, /*!< IIR Filter for benchmark, 1/256 raw_value + 255/256 benchmark */
|
||||
#endif
|
||||
TOUCH_BM_JITTER_FILTER, /*!< Jitter Filter for benchmark, raw value +/- jitter_step */
|
||||
} touch_benchmark_filter_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Touch channel Infinite Impulse Response (IIR) filter for smooth data
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_SMOOTH_NO_FILTER, /*!< No filter adopted for smooth data, smooth data equals raw data */
|
||||
TOUCH_SMOOTH_IIR_FILTER_2, /*!< IIR filter adopted for smooth data, smooth data equals 1/2 raw data + 1/2 last smooth data (typical) */
|
||||
TOUCH_SMOOTH_IIR_FILTER_4, /*!< IIR filter adopted for smooth data, smooth data equals 1/4 raw data + 3/4 last smooth data */
|
||||
TOUCH_SMOOTH_IIR_FILTER_8, /*!< IIR filter adopted for smooth data, smooth data equals 1/8 raw data + 7/8 last smooth data */
|
||||
} touch_smooth_filter_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Touch sensor upper charging voltage limit
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_VOLT_LIM_H_0V9, /*!< Touch sensor upper voltage limit is 0.9V while charging a touch pad */
|
||||
TOUCH_VOLT_LIM_H_1V0, /*!< Touch sensor upper voltage limit is 1.0V while charging a touch pad */
|
||||
TOUCH_VOLT_LIM_H_1V1, /*!< Touch sensor upper voltage limit is 1.1V while charging a touch pad */
|
||||
TOUCH_VOLT_LIM_H_1V2, /*!< Touch sensor upper voltage limit is 1.2V while charging a touch pad */
|
||||
// No 1V3
|
||||
TOUCH_VOLT_LIM_H_1V4, /*!< Touch sensor upper voltage limit is 1.4V while charging a touch pad */
|
||||
TOUCH_VOLT_LIM_H_1V5, /*!< Touch sensor upper voltage limit is 1.5V while charging a touch pad */
|
||||
TOUCH_VOLT_LIM_H_1V6, /*!< Touch sensor upper voltage limit is 1.6V while charging a touch pad */
|
||||
TOUCH_VOLT_LIM_H_1V7, /*!< Touch sensor upper voltage limit is 1.7V while charging a touch pad */
|
||||
// No 1V8
|
||||
TOUCH_VOLT_LIM_H_1V9, /*!< Touch sensor upper voltage limit is 1.9V while charging a touch pad */
|
||||
TOUCH_VOLT_LIM_H_2V0, /*!< Touch sensor upper voltage limit is 2.0V while charging a touch pad */
|
||||
TOUCH_VOLT_LIM_H_2V1, /*!< Touch sensor upper voltage limit is 2.1V while charging a touch pad */
|
||||
TOUCH_VOLT_LIM_H_2V2, /*!< Touch sensor upper voltage limit is 2.2V while charging a touch pad */
|
||||
// No 2V3
|
||||
TOUCH_VOLT_LIM_H_2V4, /*!< Touch sensor upper voltage limit is 2.4V while charging a touch pad */
|
||||
TOUCH_VOLT_LIM_H_2V5, /*!< Touch sensor upper voltage limit is 2.5V while charging a touch pad */
|
||||
TOUCH_VOLT_LIM_H_2V6, /*!< Touch sensor upper voltage limit is 2.6V while charging a touch pad */
|
||||
TOUCH_VOLT_LIM_H_2V7, /*!< Touch sensor upper voltage limit is 2.7V while charging a touch pad */
|
||||
} touch_volt_lim_h_t;
|
||||
|
||||
/**
|
||||
* @brief Touch sensor lower discharging voltage limit
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_VOLT_LIM_L_0V5, /*!< Touch sensor lower voltage limit is 0.5V while discharging a touch pad */
|
||||
TOUCH_VOLT_LIM_L_0V6, /*!< Touch sensor lower voltage limit is 0.6V while discharging a touch pad */
|
||||
TOUCH_VOLT_LIM_L_0V7, /*!< Touch sensor lower voltage limit is 0.7V while discharging a touch pad */
|
||||
TOUCH_VOLT_LIM_L_0V8, /*!< Touch sensor lower voltage limit is 0.8V while discharging a touch pad */
|
||||
} touch_volt_lim_l_t;
|
||||
|
||||
/**
|
||||
* @brief Touch sensor charge and discharge speed
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_CHARGE_SPEED_0 = 0, /*!< Touch sensor charge and discharge speed, no charge, always zero */
|
||||
TOUCH_CHARGE_SPEED_1 = 1, /*!< Touch sensor charge and discharge speed, slowest */
|
||||
TOUCH_CHARGE_SPEED_2 = 2, /*!< Touch sensor charge and discharge speed */
|
||||
TOUCH_CHARGE_SPEED_3 = 3, /*!< Touch sensor charge and discharge speed */
|
||||
TOUCH_CHARGE_SPEED_4 = 4, /*!< Touch sensor charge and discharge speed */
|
||||
TOUCH_CHARGE_SPEED_5 = 5, /*!< Touch sensor charge and discharge speed */
|
||||
TOUCH_CHARGE_SPEED_6 = 6, /*!< Touch sensor charge and discharge speed */
|
||||
TOUCH_CHARGE_SPEED_7 = 7, /*!< Touch sensor charge and discharge speed, fastest */
|
||||
} touch_charge_speed_t;
|
||||
|
||||
/**
|
||||
* @brief Touch sensor initial voltage before charging
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_INIT_CHARGE_VOLT_LOW = 0, /*!< Tie the initial charge voltage to low. */
|
||||
TOUCH_INIT_CHARGE_VOLT_HIGH = 1, /*!< Tie the initial charge voltage to high. */
|
||||
TOUCH_INIT_CHARGE_VOLT_FLOAT = 2, /*!< The initial charge voltage will be float. The touch pad will be powered off between two measurements */
|
||||
TOUCH_INIT_CHARGE_VOLT_DEFAULT = TOUCH_INIT_CHARGE_VOLT_FLOAT, /*!< The initial charge voltage is default to be float. */
|
||||
} touch_init_charge_volt_t;
|
||||
|
||||
/**
|
||||
* @brief Touch channel idle state configuration
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_IDLE_CONN_HIGHZ = 0, /*!< The idle (enabled but not measuring) touch channel is at high resistance state */
|
||||
TOUCH_IDLE_CONN_GND = 1, /*!< The idle (enabled but not measuring) touch channel is connected to the ground */
|
||||
} touch_idle_conn_t;
|
||||
|
||||
/**
|
||||
* @brief Touch sensor denoise channel internal reference capacitance
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_DENOISE_CHAN_CAP_5PF = 0, /*!< Denoise channel internal reference capacitance is 5.0pf */
|
||||
TOUCH_DENOISE_CHAN_CAP_6PF = 1, /*!< Denoise channel internal reference capacitance is 6.4pf */
|
||||
TOUCH_DENOISE_CHAN_CAP_7PF = 2, /*!< Denoise channel internal reference capacitance is 7.8pf */
|
||||
TOUCH_DENOISE_CHAN_CAP_9PF = 3, /*!< Denoise channel internal reference capacitance is 9.2pf */
|
||||
TOUCH_DENOISE_CHAN_CAP_10PF = 4, /*!< Denoise channel internal reference capacitance is 10.6pf */
|
||||
TOUCH_DENOISE_CHAN_CAP_12PF = 5, /*!< Denoise channel internal reference capacitance is 12.0pf */
|
||||
TOUCH_DENOISE_CHAN_CAP_13PF = 6, /*!< Denoise channel internal reference capacitance is 13.4pf */
|
||||
TOUCH_DENOISE_CHAN_CAP_14PF = 7, /*!< Denoise channel internal reference capacitance is 14.8pf */
|
||||
} touch_denoise_chan_cap_t;
|
||||
|
||||
/**
|
||||
* @brief Touch sensor denoise channel noise suppression resolution
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_DENOISE_CHAN_RESOLUTION_BIT12 = 0, /*!< Denoise channel noise suppression resolution is 12bit */
|
||||
TOUCH_DENOISE_CHAN_RESOLUTION_BIT10 = 1, /*!< Denoise channel noise suppression resolution is 10bit */
|
||||
TOUCH_DENOISE_CHAN_RESOLUTION_BIT8 = 2, /*!< Denoise channel noise suppression resolution is 8bit */
|
||||
TOUCH_DENOISE_CHAN_RESOLUTION_BIT4 = 3, /*!< Denoise channel noise suppression resolution is 4bit */
|
||||
} touch_denoise_chan_resolution_t;
|
||||
|
||||
/**
|
||||
* @brief Touch sensor bias type
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_BIAS_TYPE_BANDGAP, /*!< Use bandgap-bias to charge/discharge the touch channel, which is more stable but power-consuming */
|
||||
TOUCH_BIAS_TYPE_SELF, /*!< Use self-bias to charge/discharge the touch channel, which is less stable but power-saving */
|
||||
} touch_bias_type_t;
|
||||
|
||||
/**
|
||||
* @brief Touch channel binarized output counting mode
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_PAD_OUT_AS_DATA, /*!< Counting the output of touch channel as data.
|
||||
* The value will be smaller than actual value but more sensitive when the frequency of touch_out is close to the source clock
|
||||
* Normally we treat the output as data when it is lower than the sample clock
|
||||
*/
|
||||
TOUCH_PAD_OUT_AS_CLOCK, /*!< Counting the output of touch channel as clock.
|
||||
* The value is accurate but less sensitive when the frequency of touch_out is close to the source clock
|
||||
* Normally we treat the output as clock when it is higher than the sample clock
|
||||
*/
|
||||
} touch_out_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Touch interrupt trigger mode
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_INTR_TRIG_ON_BELOW_THRESH, /*!< The touch active interrupt will trigger when the measured data below the absolute threshold */
|
||||
TOUCH_INTR_TRIG_ON_ABOVE_THRESH, /*!< The touch active interrupt will trigger when the measured data above the absolute threshold */
|
||||
} touch_intr_trig_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Touch interrupt trigger group
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_INTR_TRIG_GROUP_BOTH, /*!< Both channel groups can trigger the interrupt */
|
||||
TOUCH_INTR_TRIG_GROUP_1, /*!< Only the channels in group 1 can trigger the interrupt */
|
||||
} touch_intr_trig_group_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* NOTICE
|
||||
* The hal is not public api, don't use in application code.
|
||||
* See readme.md in hal/include/hal/readme.md
|
||||
******************************************************************************/
|
||||
|
||||
// The legacy HAL layer for touch sensor (common part)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
#if SOC_TOUCH_SENSOR_SUPPORTED
|
||||
#include "hal/touch_sensor_ll.h"
|
||||
#include "hal/touch_sensor_legacy_types.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if SOC_TOUCH_SENSOR_SUPPORTED
|
||||
typedef struct {
|
||||
touch_high_volt_t refh;
|
||||
touch_low_volt_t refl;
|
||||
touch_volt_atten_t atten;
|
||||
} touch_hal_volt_t;
|
||||
|
||||
typedef struct {
|
||||
touch_cnt_slope_t slope; /*!<Set touch sensor charge/discharge speed(currents) for each pad.*/
|
||||
touch_tie_opt_t tie_opt; /*!<Set initial voltage state of touch channel for each measurement.*/
|
||||
} touch_hal_meas_mode_t;
|
||||
|
||||
/**
|
||||
* Set touch sensor sleep time (interval of measurement).
|
||||
*
|
||||
* @param sleep_time The touch sensor will sleep after each measurement.
|
||||
* sleep_cycle decide the interval between each measurement.
|
||||
* t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
|
||||
* The approximate frequency value of RTC_SLOW_CLK can be obtained using `rtc_clk_slow_freq_get_hz` function.
|
||||
*/
|
||||
#define touch_hal_set_sleep_time(sleep_time) touch_ll_set_sleep_time(sleep_time)
|
||||
|
||||
/**
|
||||
* Get touch sensor sleep time.
|
||||
*
|
||||
* @param sleep_time Pointer to accept sleep cycle count.
|
||||
*/
|
||||
#define touch_hal_get_sleep_time(sleep_time) touch_ll_get_sleep_time(sleep_time)
|
||||
|
||||
/**
|
||||
* Set touch sensor high / low voltage threshold of charge.
|
||||
* The touch sensor measures the channel capacitance value by charging and discharging the channel.
|
||||
* So charge threshold should be less than the supply voltage.
|
||||
* The actual charge threshold is high voltage threshold minus attenuation value.
|
||||
*
|
||||
* @param refh The high voltage threshold of charge.
|
||||
*/
|
||||
void touch_hal_set_voltage(const touch_hal_volt_t *volt);
|
||||
|
||||
/**
|
||||
* Get touch sensor high / low voltage threshold of charge.
|
||||
* The touch sensor measures the channel capacitance value by charging and discharging the channel.
|
||||
* So charge threshold should be less than the supply voltage.
|
||||
* The actual charge threshold is high voltage threshold minus attenuation value.
|
||||
*
|
||||
* @param refh The voltage threshold of charge / discharge.
|
||||
*/
|
||||
void touch_hal_get_voltage(touch_hal_volt_t *volt);
|
||||
|
||||
/**
|
||||
* Set touch sensor charge/discharge speed(currents) and initial voltage state for each pad measurement.
|
||||
*
|
||||
* @param touch_num Touch pad index.
|
||||
* @param meas Touch pad measurement config.
|
||||
*/
|
||||
void touch_hal_set_meas_mode(touch_pad_t touch_num, const touch_hal_meas_mode_t *meas);
|
||||
|
||||
/**
|
||||
* Get touch sensor charge/discharge speed(currents) and initial voltage state for each pad measurement.
|
||||
*
|
||||
* @param touch_num Touch pad index.
|
||||
* @param meas Touch pad measurement config.
|
||||
*/
|
||||
void touch_hal_get_meas_mode(touch_pad_t touch_num, touch_hal_meas_mode_t *meas);
|
||||
|
||||
/**
|
||||
* Set touch sensor FSM mode.
|
||||
* The measurement action can be triggered by the hardware timer, as well as by the software instruction.
|
||||
*
|
||||
* @param mode FSM mode.
|
||||
*/
|
||||
#define touch_hal_set_fsm_mode(mode) touch_ll_set_fsm_mode(mode)
|
||||
|
||||
/**
|
||||
* Get touch sensor FSM mode.
|
||||
* The measurement action can be triggered by the hardware timer, as well as by the software instruction.
|
||||
*
|
||||
* @param mode FSM mode.
|
||||
*/
|
||||
#define touch_hal_get_fsm_mode(mode) touch_ll_get_fsm_mode(mode)
|
||||
|
||||
/**
|
||||
* Start touch sensor FSM timer.
|
||||
* The measurement action can be triggered by the hardware timer, as well as by the software instruction.
|
||||
*/
|
||||
#define touch_hal_start_fsm() touch_ll_start_fsm()
|
||||
|
||||
/**
|
||||
* Stop touch sensor FSM timer.
|
||||
* The measurement action can be triggered by the hardware timer, as well as by the software instruction.
|
||||
*/
|
||||
#define touch_hal_stop_fsm() touch_ll_stop_fsm()
|
||||
|
||||
/**
|
||||
* Trigger a touch sensor measurement, only support in SW mode of FSM.
|
||||
*/
|
||||
#define touch_hal_start_sw_meas() touch_ll_start_sw_meas()
|
||||
|
||||
/**
|
||||
* Set touch sensor interrupt threshold.
|
||||
*
|
||||
* @note Refer to `touch_pad_set_trigger_mode` to see how to set trigger mode.
|
||||
* @param touch_num touch pad index.
|
||||
* @param threshold threshold of touchpad count.
|
||||
*/
|
||||
#define touch_hal_set_threshold(touch_num, threshold) touch_ll_set_threshold(touch_num, threshold)
|
||||
|
||||
/**
|
||||
* Get touch sensor interrupt threshold.
|
||||
*
|
||||
* @param touch_num touch pad index.
|
||||
* @param threshold pointer to accept threshold.
|
||||
*/
|
||||
#define touch_hal_get_threshold(touch_num, threshold) touch_ll_get_threshold(touch_num, threshold)
|
||||
|
||||
/**
|
||||
* Enable touch sensor channel. Register touch channel into touch sensor measurement group.
|
||||
* The working mode of the touch sensor is simultaneous measurement.
|
||||
* This function will set the measure bits according to the given bitmask.
|
||||
*
|
||||
* @note If set this mask, the FSM timer should be stop firsty.
|
||||
* @note The touch sensor that in scan map, should be deinit GPIO function firstly.
|
||||
* @param enable_mask bitmask of touch sensor scan group.
|
||||
* e.g. TOUCH_PAD_NUM1 -> BIT(1)
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
#define touch_hal_set_channel_mask(enable_mask) touch_ll_set_channel_mask(enable_mask)
|
||||
|
||||
/**
|
||||
* Get touch sensor channel mask.
|
||||
*
|
||||
* @param enable_mask bitmask of touch sensor scan group.
|
||||
* e.g. TOUCH_PAD_NUM1 -> BIT(1)
|
||||
*/
|
||||
#define touch_hal_get_channel_mask(enable_mask) touch_ll_get_channel_mask(enable_mask)
|
||||
|
||||
/**
|
||||
* Disable touch sensor channel by bitmask.
|
||||
*
|
||||
* @param enable_mask bitmask of touch sensor scan group.
|
||||
* e.g. TOUCH_PAD_NUM1 -> BIT(1)
|
||||
*/
|
||||
#define touch_hal_clear_channel_mask(disable_mask) touch_ll_clear_channel_mask(disable_mask)
|
||||
|
||||
/**
|
||||
* Get the touch sensor status, usually used in ISR to decide which pads are 'touched'.
|
||||
*
|
||||
* @param status_mask The touch sensor status. e.g. Touch1 trigger status is `status_mask & (BIT1)`.
|
||||
*/
|
||||
#define touch_hal_read_trigger_status_mask(status_mask) touch_ll_read_trigger_status_mask(status_mask)
|
||||
|
||||
/**
|
||||
* Clear all touch sensor status.
|
||||
*/
|
||||
#define touch_hal_clear_trigger_status_mask() touch_ll_clear_trigger_status_mask()
|
||||
|
||||
/**
|
||||
* Get touch sensor raw data (touch sensor counter value) from register. No block.
|
||||
*
|
||||
* @param touch_num touch pad index.
|
||||
* @return touch_value pointer to accept touch sensor value.
|
||||
*/
|
||||
#define touch_hal_read_raw_data(touch_num) touch_ll_read_raw_data(touch_num)
|
||||
|
||||
/**
|
||||
* Get touch sensor measure status. No block.
|
||||
*
|
||||
* @return
|
||||
* - If touch sensors measure done.
|
||||
*/
|
||||
#define touch_hal_meas_is_done() touch_ll_is_measure_done()
|
||||
|
||||
/**
|
||||
* Initialize touch module.
|
||||
*
|
||||
* @note If default parameter don't match the usage scenario, it can be changed after this function.
|
||||
*/
|
||||
void touch_hal_init(void);
|
||||
|
||||
/**
|
||||
* Un-install touch pad driver.
|
||||
*
|
||||
* @note After this function is called, other touch functions are prohibited from being called.
|
||||
*/
|
||||
void touch_hal_deinit(void);
|
||||
|
||||
/**
|
||||
* Configure touch sensor for each channel.
|
||||
*/
|
||||
void touch_hal_config(touch_pad_t touch_num);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,309 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "esp_attr.h"
|
||||
#include "esp_bit_defs.h"
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Touch pad channel */
|
||||
typedef enum {
|
||||
TOUCH_PAD_NUM0 = 0, /*!< Touch pad channel 0 is GPIO4(ESP32) */
|
||||
TOUCH_PAD_NUM1, /*!< Touch pad channel 1 is GPIO0(ESP32) / GPIO1(ESP32-S2) */
|
||||
TOUCH_PAD_NUM2, /*!< Touch pad channel 2 is GPIO2(ESP32) / GPIO2(ESP32-S2) */
|
||||
TOUCH_PAD_NUM3, /*!< Touch pad channel 3 is GPIO15(ESP32) / GPIO3(ESP32-S2) */
|
||||
TOUCH_PAD_NUM4, /*!< Touch pad channel 4 is GPIO13(ESP32) / GPIO4(ESP32-S2) */
|
||||
TOUCH_PAD_NUM5, /*!< Touch pad channel 5 is GPIO12(ESP32) / GPIO5(ESP32-S2) */
|
||||
TOUCH_PAD_NUM6, /*!< Touch pad channel 6 is GPIO14(ESP32) / GPIO6(ESP32-S2) */
|
||||
TOUCH_PAD_NUM7, /*!< Touch pad channel 7 is GPIO27(ESP32) / GPIO7(ESP32-S2) */
|
||||
TOUCH_PAD_NUM8, /*!< Touch pad channel 8 is GPIO33(ESP32) / GPIO8(ESP32-S2) */
|
||||
TOUCH_PAD_NUM9, /*!< Touch pad channel 9 is GPIO32(ESP32) / GPIO9(ESP32-S2) */
|
||||
#if !SOC_IS(ESP32)
|
||||
TOUCH_PAD_NUM10, /*!< Touch channel 10 is GPIO10(ESP32-S2) */
|
||||
TOUCH_PAD_NUM11, /*!< Touch channel 11 is GPIO11(ESP32-S2) */
|
||||
TOUCH_PAD_NUM12, /*!< Touch channel 12 is GPIO12(ESP32-S2) */
|
||||
TOUCH_PAD_NUM13, /*!< Touch channel 13 is GPIO13(ESP32-S2) */
|
||||
TOUCH_PAD_NUM14, /*!< Touch channel 14 is GPIO14(ESP32-S2) */
|
||||
#endif
|
||||
TOUCH_PAD_MAX,
|
||||
} touch_pad_t;
|
||||
|
||||
/** Touch sensor high reference voltage */
|
||||
typedef enum {
|
||||
TOUCH_HVOLT_KEEP = -1, /*!<Touch sensor high reference voltage, no change */
|
||||
TOUCH_HVOLT_2V4 = 0, /*!<Touch sensor high reference voltage, 2.4V */
|
||||
TOUCH_HVOLT_2V5, /*!<Touch sensor high reference voltage, 2.5V */
|
||||
TOUCH_HVOLT_2V6, /*!<Touch sensor high reference voltage, 2.6V */
|
||||
TOUCH_HVOLT_2V7, /*!<Touch sensor high reference voltage, 2.7V */
|
||||
TOUCH_HVOLT_MAX,
|
||||
} touch_high_volt_t;
|
||||
|
||||
/** Touch sensor low reference voltage */
|
||||
typedef enum {
|
||||
TOUCH_LVOLT_KEEP = -1, /*!<Touch sensor low reference voltage, no change */
|
||||
TOUCH_LVOLT_0V5 = 0, /*!<Touch sensor low reference voltage, 0.5V */
|
||||
TOUCH_LVOLT_0V6, /*!<Touch sensor low reference voltage, 0.6V */
|
||||
TOUCH_LVOLT_0V7, /*!<Touch sensor low reference voltage, 0.7V */
|
||||
TOUCH_LVOLT_0V8, /*!<Touch sensor low reference voltage, 0.8V */
|
||||
TOUCH_LVOLT_MAX,
|
||||
} touch_low_volt_t;
|
||||
|
||||
/** Touch sensor high reference voltage attenuation */
|
||||
typedef enum {
|
||||
TOUCH_HVOLT_ATTEN_KEEP = -1, /*!<Touch sensor high reference voltage attenuation, no change */
|
||||
TOUCH_HVOLT_ATTEN_1V5 = 0, /*!<Touch sensor high reference voltage attenuation, 1.5V attenuation */
|
||||
TOUCH_HVOLT_ATTEN_1V, /*!<Touch sensor high reference voltage attenuation, 1.0V attenuation */
|
||||
TOUCH_HVOLT_ATTEN_0V5, /*!<Touch sensor high reference voltage attenuation, 0.5V attenuation */
|
||||
TOUCH_HVOLT_ATTEN_0V, /*!<Touch sensor high reference voltage attenuation, 0V attenuation */
|
||||
TOUCH_HVOLT_ATTEN_MAX,
|
||||
} touch_volt_atten_t;
|
||||
|
||||
/** Touch sensor charge/discharge speed */
|
||||
typedef enum {
|
||||
TOUCH_PAD_SLOPE_0 = 0, /*!<Touch sensor charge / discharge speed, always zero */
|
||||
TOUCH_PAD_SLOPE_1 = 1, /*!<Touch sensor charge / discharge speed, slowest */
|
||||
TOUCH_PAD_SLOPE_2 = 2, /*!<Touch sensor charge / discharge speed */
|
||||
TOUCH_PAD_SLOPE_3 = 3, /*!<Touch sensor charge / discharge speed */
|
||||
TOUCH_PAD_SLOPE_4 = 4, /*!<Touch sensor charge / discharge speed */
|
||||
TOUCH_PAD_SLOPE_5 = 5, /*!<Touch sensor charge / discharge speed */
|
||||
TOUCH_PAD_SLOPE_6 = 6, /*!<Touch sensor charge / discharge speed */
|
||||
TOUCH_PAD_SLOPE_7 = 7, /*!<Touch sensor charge / discharge speed, fast */
|
||||
TOUCH_PAD_SLOPE_MAX,
|
||||
} touch_cnt_slope_t;
|
||||
|
||||
/** Touch sensor initial charge level */
|
||||
typedef enum {
|
||||
TOUCH_PAD_TIE_OPT_LOW = 0, /*!<Initial level of charging voltage, low level */
|
||||
TOUCH_PAD_TIE_OPT_HIGH = 1, /*!<Initial level of charging voltage, high level */
|
||||
TOUCH_PAD_TIE_OPT_FLOAT = 2, /*!<Initial level of charging voltage, float */
|
||||
TOUCH_PAD_TIE_OPT_MAX, /*!<The max tie options */
|
||||
} touch_tie_opt_t;
|
||||
|
||||
/** Touch sensor FSM mode */
|
||||
typedef enum {
|
||||
TOUCH_FSM_MODE_TIMER = 0, /*!<To start touch FSM by timer */
|
||||
TOUCH_FSM_MODE_SW, /*!<To start touch FSM by software trigger */
|
||||
TOUCH_FSM_MODE_MAX,
|
||||
} touch_fsm_mode_t;
|
||||
|
||||
/**** ESP32 Only *****/
|
||||
|
||||
typedef enum {
|
||||
TOUCH_TRIGGER_BELOW = 0, /*!<Touch interrupt will happen if counter value is less than threshold.*/
|
||||
TOUCH_TRIGGER_ABOVE = 1, /*!<Touch interrupt will happen if counter value is larger than threshold.*/
|
||||
TOUCH_TRIGGER_MAX,
|
||||
} touch_trigger_mode_t;
|
||||
|
||||
typedef enum {
|
||||
TOUCH_TRIGGER_SOURCE_BOTH = 0, /*!< wakeup interrupt is generated if both SET1 and SET2 are "touched"*/
|
||||
TOUCH_TRIGGER_SOURCE_SET1 = 1, /*!< wakeup interrupt is generated if SET1 is "touched"*/
|
||||
TOUCH_TRIGGER_SOURCE_MAX,
|
||||
} touch_trigger_src_t;
|
||||
|
||||
/********************************/
|
||||
#if SOC_TOUCH_SENSOR_VERSION == 1
|
||||
#define TOUCH_PAD_THRESHOLD_MAX (0) /*!< If set touch threshold max value, The touch sensor can't be in touched status */
|
||||
#define TOUCH_PAD_BIT_MASK_ALL (0x03FF)
|
||||
#elif SOC_TOUCH_SENSOR_VERSION == 2
|
||||
#define TOUCH_PAD_THRESHOLD_MAX (0x1FFFFF) /*!< If set touch threshold max value, The touch sensor can't be in touched status */
|
||||
#define TOUCH_PAD_BIT_MASK_ALL (0x7FFF)
|
||||
#elif SOC_TOUCH_SENSOR_VERSION == 3
|
||||
#define TOUCH_PAD_THRESHOLD_MAX (0xFFFF) /*!< If set touch threshold max value, The touch sensor can't be in touched status */
|
||||
#define TOUCH_PAD_BIT_MASK_ALL (0x3FFF)
|
||||
#endif
|
||||
#define TOUCH_PAD_SLOPE_DEFAULT (TOUCH_PAD_SLOPE_7)
|
||||
#define TOUCH_PAD_TIE_OPT_DEFAULT (TOUCH_PAD_TIE_OPT_FLOAT)
|
||||
#define TOUCH_PAD_BIT_MASK_MAX (TOUCH_PAD_BIT_MASK_ALL)
|
||||
#define TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD (TOUCH_HVOLT_2V7)
|
||||
#define TOUCH_PAD_LOW_VOLTAGE_THRESHOLD (TOUCH_LVOLT_0V5)
|
||||
#define TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD (TOUCH_HVOLT_ATTEN_0V5)
|
||||
#define TOUCH_PAD_IDLE_CH_CONNECT_DEFAULT (TOUCH_PAD_CONN_GND)
|
||||
|
||||
#if SOC_IS(ESP32)
|
||||
|
||||
#define TOUCH_PAD_SLEEP_CYCLE_DEFAULT (0x1000) /*!<The timer frequency is RTC_SLOW_CLK (can be 150k or 32k depending on the options), max value is 0xffff */
|
||||
#define TOUCH_PAD_MEASURE_CYCLE_DEFAULT (0x7fff) /*!<The timer frequency is 8Mhz, the max value is 0x7fff */
|
||||
#define TOUCH_FSM_MODE_DEFAULT (TOUCH_FSM_MODE_SW) /*!<The touch FSM my be started by the software or timer */
|
||||
#define TOUCH_TRIGGER_MODE_DEFAULT (TOUCH_TRIGGER_BELOW) /*!<Interrupts can be triggered if sensor value gets below or above threshold */
|
||||
#define TOUCH_TRIGGER_SOURCE_DEFAULT (TOUCH_TRIGGER_SOURCE_SET1) /*!<The wakeup trigger source can be SET1 or both SET1 and SET2 */
|
||||
|
||||
#endif // SOC_IS(ESP32)
|
||||
|
||||
#if !SOC_IS(ESP32)
|
||||
/**
|
||||
* Excessive total time will slow down the touch response.
|
||||
* Too small measurement time will not be sampled enough, resulting in inaccurate measurements.
|
||||
*
|
||||
* @note The greater the duty cycle of the measurement time, the more system power is consumed.
|
||||
*/
|
||||
#define TOUCH_PAD_SLEEP_CYCLE_DEFAULT (0xf) /*!<The number of sleep cycle in each measure process of touch channels.
|
||||
The timer frequency is RTC_SLOW_CLK (can be 150k or 32k depending on the options).
|
||||
Range: 0 ~ 0xffff */
|
||||
#define TOUCH_PAD_MEASURE_CYCLE_DEFAULT (500) /*!<The times of charge and discharge in each measure process of touch channels.
|
||||
The timer frequency is 8Mhz.
|
||||
Recommended typical value: Modify this value to make the measurement time around 1ms.
|
||||
Range: 0 ~ 0xffff */
|
||||
|
||||
// TODO: replace by ll macro
|
||||
typedef enum {
|
||||
TOUCH_PAD_INTR_MASK_DONE = BIT(0), /*!<Measurement done for one of the enabled channels. */
|
||||
TOUCH_PAD_INTR_MASK_ACTIVE = BIT(1), /*!<Active for one of the enabled channels. */
|
||||
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_SENSOR_VERSION > 1 && !SOC_IS(ESP32S2)
|
||||
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;
|
||||
|
||||
typedef enum {
|
||||
TOUCH_PAD_DENOISE_BIT12 = 0, /*!<Denoise range is 12bit */
|
||||
TOUCH_PAD_DENOISE_BIT10 = 1, /*!<Denoise range is 10bit */
|
||||
TOUCH_PAD_DENOISE_BIT8 = 2, /*!<Denoise range is 8bit */
|
||||
TOUCH_PAD_DENOISE_BIT4 = 3, /*!<Denoise range is 4bit */
|
||||
TOUCH_PAD_DENOISE_MAX
|
||||
} touch_pad_denoise_grade_t;
|
||||
|
||||
typedef enum {
|
||||
TOUCH_PAD_DENOISE_CAP_L0 = 0, /*!<Denoise channel internal reference capacitance is 5pf */
|
||||
TOUCH_PAD_DENOISE_CAP_L1 = 1, /*!<Denoise channel internal reference capacitance is 6.4pf */
|
||||
TOUCH_PAD_DENOISE_CAP_L2 = 2, /*!<Denoise channel internal reference capacitance is 7.8pf */
|
||||
TOUCH_PAD_DENOISE_CAP_L3 = 3, /*!<Denoise channel internal reference capacitance is 9.2pf */
|
||||
TOUCH_PAD_DENOISE_CAP_L4 = 4, /*!<Denoise channel internal reference capacitance is 10.6pf */
|
||||
TOUCH_PAD_DENOISE_CAP_L5 = 5, /*!<Denoise channel internal reference capacitance is 12.0pf */
|
||||
TOUCH_PAD_DENOISE_CAP_L6 = 6, /*!<Denoise channel internal reference capacitance is 13.4pf */
|
||||
TOUCH_PAD_DENOISE_CAP_L7 = 7, /*!<Denoise channel internal reference capacitance is 14.8pf */
|
||||
TOUCH_PAD_DENOISE_CAP_MAX = 8
|
||||
} touch_pad_denoise_cap_t;
|
||||
|
||||
/** Touch sensor denoise configuration */
|
||||
typedef struct touch_pad_denoise {
|
||||
touch_pad_denoise_grade_t grade; /*!<Select denoise range of denoise channel.
|
||||
Determined by measuring the noise amplitude of the denoise channel. */
|
||||
touch_pad_denoise_cap_t cap_level; /*!<Select internal reference capacitance of denoise channel.
|
||||
Ensure that the denoise readings are closest to the readings of the channel being measured.
|
||||
Use `touch_pad_denoise_read_data` to get the reading of denoise channel.
|
||||
The equivalent capacitance of the shielded channel can be calculated
|
||||
from the reading of denoise channel. */
|
||||
} touch_pad_denoise_t;
|
||||
|
||||
/** Touch sensor shield channel drive capability level */
|
||||
typedef enum {
|
||||
TOUCH_PAD_SHIELD_DRV_L0 = 0,/*!<The max equivalent capacitance in shield channel is 40pf */
|
||||
TOUCH_PAD_SHIELD_DRV_L1, /*!<The max equivalent capacitance in shield channel is 80pf */
|
||||
TOUCH_PAD_SHIELD_DRV_L2, /*!<The max equivalent capacitance in shield channel is 120pf */
|
||||
TOUCH_PAD_SHIELD_DRV_L3, /*!<The max equivalent capacitance in shield channel is 160pf */
|
||||
TOUCH_PAD_SHIELD_DRV_L4, /*!<The max equivalent capacitance in shield channel is 200pf */
|
||||
TOUCH_PAD_SHIELD_DRV_L5, /*!<The max equivalent capacitance in shield channel is 240pf */
|
||||
TOUCH_PAD_SHIELD_DRV_L6, /*!<The max equivalent capacitance in shield channel is 280pf */
|
||||
TOUCH_PAD_SHIELD_DRV_L7, /*!<The max equivalent capacitance in shield channel is 320pf */
|
||||
TOUCH_PAD_SHIELD_DRV_MAX
|
||||
} touch_pad_shield_driver_t;
|
||||
|
||||
/** Touch sensor waterproof configuration */
|
||||
typedef struct touch_pad_waterproof {
|
||||
touch_pad_t guard_ring_pad; /*!<Waterproof. Select touch channel use for guard pad.
|
||||
Guard pad is used to detect the large area of water covering the touch panel. */
|
||||
touch_pad_shield_driver_t shield_driver;/*!<Waterproof. Shield channel drive capability configuration.
|
||||
Shield pad is used to shield the influence of water droplets covering the touch panel.
|
||||
When the waterproof function is enabled, Touch14 is set as shield channel by default.
|
||||
The larger the parasitic capacitance on the shielding channel, the higher the drive capability needs to be set.
|
||||
The equivalent capacitance of the shield channel can be estimated through the reading value of the denoise channel(Touch0).*/
|
||||
} touch_pad_waterproof_t;
|
||||
|
||||
/** Touch sensor proximity detection configuration */
|
||||
#define TOUCH_PROXIMITY_MEAS_NUM_MAX (0xFF)
|
||||
|
||||
/** Touch channel idle state configuration */
|
||||
typedef enum {
|
||||
TOUCH_PAD_CONN_HIGHZ = 0, /*!<Idle status of touch channel is high resistance state */
|
||||
TOUCH_PAD_CONN_GND = 1, /*!<Idle status of touch channel is ground connection */
|
||||
TOUCH_PAD_CONN_MAX
|
||||
} touch_pad_conn_type_t;
|
||||
|
||||
/**
|
||||
* @brief Touch channel IIR filter coefficient configuration.
|
||||
* @note On ESP32S2. There is an error in the IIR calculation. The magnitude of the error is twice the filter coefficient.
|
||||
* So please select a smaller filter coefficient on the basis of meeting the filtering requirements.
|
||||
* Recommended filter coefficient selection `IIR_16`.
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_PAD_FILTER_IIR_4 = 0, /*!<The filter mode is first-order IIR filter. The coefficient is 4. */
|
||||
TOUCH_PAD_FILTER_IIR_8, /*!<The filter mode is first-order IIR filter. The coefficient is 8. */
|
||||
TOUCH_PAD_FILTER_IIR_16, /*!<The filter mode is first-order IIR filter. The coefficient is 16 (Typical value). */
|
||||
TOUCH_PAD_FILTER_IIR_32, /*!<The filter mode is first-order IIR filter. The coefficient is 32. */
|
||||
TOUCH_PAD_FILTER_IIR_64, /*!<The filter mode is first-order IIR filter. The coefficient is 64. */
|
||||
TOUCH_PAD_FILTER_IIR_128, /*!<The filter mode is first-order IIR filter. The coefficient is 128. */
|
||||
TOUCH_PAD_FILTER_IIR_256, /*!<The filter mode is first-order IIR filter. The coefficient is 256. */
|
||||
TOUCH_PAD_FILTER_JITTER, /*!<The filter mode is jitter filter */
|
||||
TOUCH_PAD_FILTER_MAX
|
||||
} touch_filter_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Level of filter applied on the original data against large noise interference.
|
||||
* @note On ESP32S2. There is an error in the IIR calculation. The magnitude of the error is twice the filter coefficient.
|
||||
* So please select a smaller filter coefficient on the basis of meeting the filtering requirements.
|
||||
* Recommended filter coefficient selection `IIR_2`.
|
||||
*/
|
||||
typedef enum {
|
||||
TOUCH_PAD_SMOOTH_OFF = 0, /*!<No filtering of raw data. */
|
||||
TOUCH_PAD_SMOOTH_IIR_2 = 1, /*!<Filter the raw data. The coefficient is 2 (Typical value). */
|
||||
TOUCH_PAD_SMOOTH_IIR_4 = 2, /*!<Filter the raw data. The coefficient is 4. */
|
||||
TOUCH_PAD_SMOOTH_IIR_8 = 3, /*!<Filter the raw data. The coefficient is 8. */
|
||||
TOUCH_PAD_SMOOTH_MAX,
|
||||
} touch_smooth_mode_t;
|
||||
|
||||
/** 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,
|
||||
and the output of the filter is involved in the judgment of the touch state. */
|
||||
uint32_t debounce_cnt; /*!<Set debounce count, such as `n`. If the measured values continue to exceed
|
||||
the threshold for `n+1` times, the touch sensor state changes.
|
||||
Range: 0 ~ 7 */
|
||||
uint32_t noise_thr; /*!<Noise threshold coefficient. Higher = More noise resistance.
|
||||
The actual noise should be less than (noise coefficient * touch threshold).
|
||||
Range: 0 ~ 3. The coefficient is 0: 4/8; 1: 3/8; 2: 2/8; 3: 1; */
|
||||
uint32_t jitter_step; /*!<Set jitter filter step size. Range: 0 ~ 15 */
|
||||
touch_smooth_mode_t smh_lvl;/*!<Level of filter applied on the original data against large noise interference. */
|
||||
#define TOUCH_DEBOUNCE_CNT_MAX (7)
|
||||
#define TOUCH_NOISE_THR_MAX (3)
|
||||
#define TOUCH_JITTER_STEP_MAX (15)
|
||||
} touch_filter_config_t;
|
||||
|
||||
/** Touch sensor channel sleep configuration */
|
||||
typedef struct {
|
||||
touch_pad_t touch_num; /*!<Set touch channel number for sleep pad.
|
||||
Only one touch sensor channel is supported in deep sleep mode.
|
||||
If clear the sleep channel, point this pad to `TOUCH_PAD_NUM0` */
|
||||
bool en_proximity; /*!<enable proximity function for sleep pad */
|
||||
} touch_pad_sleep_channel_t;
|
||||
|
||||
#endif // !SOC_IS(ESP32)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern const int touch_sensor_channel_io_map[];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <string.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 {
|
||||
bool deep_slp_allow_pd;
|
||||
int deep_slp_chan;
|
||||
touch_hal_config_t slp_cfg;
|
||||
bool apply_slp_cfg;
|
||||
} touch_hal_deep_sleep_obj_t;
|
||||
|
||||
static touch_hal_deep_sleep_obj_t s_touch_slp_obj = {
|
||||
.deep_slp_chan = -1,
|
||||
.apply_slp_cfg = false,
|
||||
};
|
||||
|
||||
void touch_hal_config_controller(const touch_hal_config_t *cfg)
|
||||
{
|
||||
HAL_ASSERT(cfg);
|
||||
touch_ll_set_power_on_wait_cycle(cfg->power_on_wait_ticks);
|
||||
touch_ll_set_measure_interval_ticks(cfg->meas_interval_ticks);
|
||||
|
||||
#if SOC_TOUCH_SENSOR_VERSION == 1
|
||||
touch_ll_set_intr_trigger_mode(cfg->intr_trig_mode);
|
||||
touch_ll_set_intr_trigger_group(cfg->intr_trig_group);
|
||||
touch_ll_set_charge_window_duration(cfg->sample_cfg->charge_duration_ticks);
|
||||
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);
|
||||
#elif SOC_TOUCH_SENSOR_VERSION == 2
|
||||
touch_ll_sleep_set_channel_num(TOUCH_LL_NULL_CHANNEL);
|
||||
touch_ll_set_timeout(cfg->timeout_ticks);
|
||||
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_sleep_set_channel_num(TOUCH_LL_NULL_CHANNEL);
|
||||
touch_ll_set_timeout(cfg->timeout_ticks);
|
||||
touch_ll_sample_cfg_set_engaged_num(cfg->sample_cfg_num);
|
||||
touch_ll_sample_cfg_set_trigger_rise_cnt(cfg->trigger_rise_cnt);
|
||||
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);
|
||||
touch_ll_sample_cfg_set_rc_filter(i, cfg->sample_cfg[i].rc_filter_cap, cfg->sample_cfg[i].rc_filter_res);
|
||||
touch_ll_sample_cfg_set_driver(i, cfg->sample_cfg[i].low_drv, cfg->sample_cfg[i].high_drv);
|
||||
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, bool dslp_allow_pd)
|
||||
{
|
||||
s_touch_slp_obj.deep_slp_chan = deep_slp_chan;
|
||||
s_touch_slp_obj.deep_slp_allow_pd = dslp_allow_pd;
|
||||
/* If particular deep sleep configuration is given, save it and apply it before entering the deep sleep */
|
||||
if (deep_slp_cfg) {
|
||||
s_touch_slp_obj.apply_slp_cfg = true;
|
||||
memcpy(&s_touch_slp_obj.slp_cfg, deep_slp_cfg, sizeof(touch_hal_config_t));
|
||||
} else {
|
||||
s_touch_slp_obj.apply_slp_cfg = false;
|
||||
}
|
||||
}
|
||||
|
||||
#if SOC_TOUCH_SENSOR_VERSION == 1
|
||||
//This function will only be called when the chip is going to deep sleep.
|
||||
static void s_touch_hal_apply_sleep_config(void)
|
||||
{
|
||||
/* Apply the particular configuration for deep sleep */
|
||||
if (s_touch_slp_obj.apply_slp_cfg) {
|
||||
/* Save the current channel threshold first, because they will be reset by hardware after the recofniguration */
|
||||
uint32_t chan_thresh[TOUCH_LL_GET(CHAN_NUM)] = {};
|
||||
for (int i = 0; i < TOUCH_LL_GET(CHAN_NUM); i++) {
|
||||
chan_thresh[i] = touch_ll_get_chan_active_threshold(i);
|
||||
}
|
||||
/* Reconfigure the touch sensor to use the sleep configuration */
|
||||
touch_hal_config_controller(&s_touch_slp_obj.slp_cfg);
|
||||
/* Restore the channel threshold */
|
||||
for (int i = 0; i < TOUCH_LL_GET(CHAN_NUM); i++) {
|
||||
touch_ll_set_chan_active_threshold(i, chan_thresh[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
//This function will only be called when the chip is going to deep sleep.
|
||||
static void s_touch_hal_apply_sleep_config(void)
|
||||
{
|
||||
/* Apply the particular configuration for deep sleep */
|
||||
if (s_touch_slp_obj.apply_slp_cfg) {
|
||||
touch_hal_config_controller(&s_touch_slp_obj.slp_cfg);
|
||||
}
|
||||
/* Whether to enable touch sensor wake-up the chip from deep sleep */
|
||||
if (s_touch_slp_obj.deep_slp_chan >= 0) {
|
||||
if (s_touch_slp_obj.deep_slp_allow_pd) {
|
||||
touch_ll_sleep_set_channel_num(s_touch_slp_obj.deep_slp_chan);
|
||||
} else {
|
||||
/* If not allow power down but sleep channel is set, then only enable this channel during the deep sleep */
|
||||
touch_ll_sleep_set_channel_num(TOUCH_LL_NULL_CHANNEL);
|
||||
touch_ll_enable_channel_mask(BIT(s_touch_slp_obj.deep_slp_chan));
|
||||
}
|
||||
} else {
|
||||
touch_ll_sleep_set_channel_num(TOUCH_LL_NULL_CHANNEL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void touch_hal_prepare_deep_sleep(void)
|
||||
{
|
||||
s_touch_hal_apply_sleep_config();
|
||||
#if SOC_TOUCH_SUPPORT_BENCHMARK
|
||||
touch_ll_sleep_reset_benchmark();
|
||||
#endif
|
||||
touch_ll_interrupt_clear(TOUCH_LL_INTR_MASK_ALL);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
// The HAL layer for Touch Sensor (common part)
|
||||
|
||||
#include "hal/touch_sensor_legacy_hal.h"
|
||||
#include "hal/touch_sensor_legacy_types.h"
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
void touch_hal_config(touch_pad_t touch_num)
|
||||
{
|
||||
touch_ll_set_threshold(touch_num, TOUCH_PAD_THRESHOLD_MAX);
|
||||
touch_ll_set_slope(touch_num, TOUCH_PAD_SLOPE_DEFAULT);
|
||||
touch_ll_set_tie_option(touch_num, TOUCH_PAD_TIE_OPT_DEFAULT);
|
||||
}
|
||||
|
||||
void touch_hal_set_voltage(const touch_hal_volt_t *volt)
|
||||
{
|
||||
touch_ll_set_voltage_high(volt->refh);
|
||||
touch_ll_set_voltage_low(volt->refl);
|
||||
touch_ll_set_voltage_attenuation(volt->atten);
|
||||
}
|
||||
|
||||
void touch_hal_get_voltage(touch_hal_volt_t *volt)
|
||||
{
|
||||
touch_ll_get_voltage_high(&volt->refh);
|
||||
touch_ll_get_voltage_low(&volt->refl);
|
||||
touch_ll_get_voltage_attenuation(&volt->atten);
|
||||
}
|
||||
|
||||
void touch_hal_set_meas_mode(touch_pad_t touch_num, const touch_hal_meas_mode_t *meas)
|
||||
{
|
||||
touch_ll_set_slope(touch_num, meas->slope);
|
||||
touch_ll_set_tie_option(touch_num, meas->tie_opt);
|
||||
}
|
||||
|
||||
void touch_hal_get_meas_mode(touch_pad_t touch_num, touch_hal_meas_mode_t *meas)
|
||||
{
|
||||
touch_ll_get_slope(touch_num, &meas->slope);
|
||||
touch_ll_get_tie_option(touch_num, &meas->tie_opt);
|
||||
}
|
||||
Reference in New Issue
Block a user