forked from espressif/esp-idf
feat(ulp_touch): support ulp touch driver on p4
This commit is contained in:
@@ -19,9 +19,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TOUCH_MIN_CHAN_ID 0 /*!< The minimum available channel id of the touch pad */
|
||||
#define TOUCH_MAX_CHAN_ID 9 /*!< The maximum available channel id of the touch pad */
|
||||
|
||||
/**
|
||||
* @brief Helper macro to the default configurations of the touch sensor controller
|
||||
*
|
||||
|
@@ -19,9 +19,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TOUCH_MIN_CHAN_ID 1 /*!< The minimum available channel id of the touch pad */
|
||||
#define TOUCH_MAX_CHAN_ID 14 /*!< The maximum available channel id of the touch pad */
|
||||
|
||||
#define TOUCH_SHIELD_CHAN_ID 14 /*!< The touch channel that can be used as the shield channel */
|
||||
|
||||
/**
|
||||
|
@@ -19,9 +19,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TOUCH_MIN_CHAN_ID 0 /*!< The minimum available channel id of the touch pad */
|
||||
#define TOUCH_MAX_CHAN_ID 13 /*!< The maximum available channel id of the touch pad */
|
||||
|
||||
/**
|
||||
* @brief Helper macro to the default configurations of the touch sensor controller
|
||||
*
|
||||
|
@@ -22,6 +22,9 @@ extern "C" {
|
||||
#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 */
|
||||
|
||||
/**
|
||||
* @brief The chip sleep level that allows the touch sensor to wake-up
|
||||
*
|
||||
|
@@ -584,6 +584,18 @@ static inline void touch_ll_sample_cfg_set_engaged_num(uint8_t sample_cfg_num)
|
||||
LP_ANA_PERI.touch_scan_ctrl2.freq_scan_cnt_limit = sample_cfg_num ? sample_cfg_num : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the engaged sample configuration number
|
||||
*
|
||||
* @return The engaged sample configuration number, range 0~3.
|
||||
*/
|
||||
static inline uint32_t touch_ll_sample_cfg_get_engaged_num(void)
|
||||
{
|
||||
uint32_t sample_cfg_num = LP_ANA_PERI.touch_scan_ctrl2.freq_scan_cnt_limit;
|
||||
return sample_cfg_num ? sample_cfg_num : 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set capacitance and resistance of the RC filter of the sampling frequency.
|
||||
*
|
||||
|
@@ -1682,6 +1682,29 @@ static inline void touch_ll_sleep_read_data(uint32_t *raw_data)
|
||||
*raw_data = SENS.sar_touch_status[touch_num - 1].touch_pad_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data of the touch channel according to the types
|
||||
*
|
||||
* @param sample_cfg_id The sample configuration index
|
||||
* @param type data type
|
||||
* 0/1: TOUCH_LL_READ_RAW, the raw data of the 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 smooth_data pointer to smoothed data
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline void touch_ll_sleep_read_chan_data(uint8_t type, uint32_t *data)
|
||||
{
|
||||
SENS.sar_touch_conf.touch_data_sel = type;
|
||||
if (type == TOUCH_LL_READ_RAW) {
|
||||
uint32_t touch_num = RTCCNTL.touch_slp_thres.touch_slp_pad;
|
||||
*data = SENS.sar_touch_status[touch_num - 1].touch_pad_data;
|
||||
} else {
|
||||
*data = SENS.sar_touch_slp_status.touch_slp_data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Select touch sensor dbias to save power in sleep mode.
|
||||
*
|
||||
|
@@ -1718,6 +1718,29 @@ static inline void touch_ll_sleep_read_data(uint32_t *raw_data)
|
||||
*raw_data = SENS.sar_touch_status[touch_num - 1].touch_pad_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data of the touch channel according to the types
|
||||
*
|
||||
* @param sample_cfg_id The sample configuration index
|
||||
* @param type data type
|
||||
* 0/1: TOUCH_LL_READ_RAW, the raw data of the 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 smooth_data pointer to smoothed data
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline void touch_ll_sleep_read_chan_data(uint8_t type, uint32_t *data)
|
||||
{
|
||||
SENS.sar_touch_conf.touch_data_sel = type;
|
||||
if (type == TOUCH_LL_READ_RAW) {
|
||||
uint32_t touch_num = RTCCNTL.touch_slp_thres.touch_slp_pad;
|
||||
*data = SENS.sar_touch_status[touch_num - 1].touch_pad_data;
|
||||
} else {
|
||||
*data = SENS.sar_touch_slp_status.touch_slp_data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Select touch sensor dbias to save power in sleep mode.
|
||||
|
@@ -735,6 +735,14 @@ config SOC_TOUCH_SENSOR_NUM
|
||||
int
|
||||
default 10
|
||||
|
||||
config SOC_TOUCH_MIN_CHAN_ID
|
||||
bool
|
||||
default n
|
||||
|
||||
config SOC_TOUCH_MAX_CHAN_ID
|
||||
int
|
||||
default 9
|
||||
|
||||
config SOC_TOUCH_SUPPORT_SLEEP_WAKEUP
|
||||
bool
|
||||
default y
|
||||
|
@@ -336,6 +336,8 @@
|
||||
/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/
|
||||
#define SOC_TOUCH_SENSOR_VERSION (1U) /*!<Hardware version of touch sensor */
|
||||
#define SOC_TOUCH_SENSOR_NUM (10)
|
||||
#define SOC_TOUCH_MIN_CHAN_ID (0) /*!< Touch minimum channel number */
|
||||
#define SOC_TOUCH_MAX_CHAN_ID (9) /*!< Touch maximum channel number */
|
||||
#define SOC_TOUCH_SUPPORT_SLEEP_WAKEUP (1)
|
||||
#define SOC_TOUCH_SAMPLE_CFG_NUM (1U) /*!< The sample configuration number in total, each sampler can be used to sample on one frequency */
|
||||
|
||||
|
@@ -1723,6 +1723,14 @@ config SOC_TOUCH_SENSOR_NUM
|
||||
int
|
||||
default 14
|
||||
|
||||
config SOC_TOUCH_MIN_CHAN_ID
|
||||
bool
|
||||
default n
|
||||
|
||||
config SOC_TOUCH_MAX_CHAN_ID
|
||||
int
|
||||
default 13
|
||||
|
||||
config SOC_TOUCH_SUPPORT_SLEEP_WAKEUP
|
||||
bool
|
||||
default y
|
||||
|
@@ -635,6 +635,8 @@
|
||||
/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/
|
||||
#define SOC_TOUCH_SENSOR_VERSION (3) /*!< Hardware version of touch sensor */
|
||||
#define SOC_TOUCH_SENSOR_NUM (14) /*!< Touch available channel number. Actually there are 15 Touch channels, but channel 14 is not pinned out, limit to 14 channels */
|
||||
#define SOC_TOUCH_MIN_CHAN_ID (0) /*!< Touch minimum channel number */
|
||||
#define SOC_TOUCH_MAX_CHAN_ID (13) /*!< Touch maximum channel number */
|
||||
|
||||
/* Touch Sensor Features */
|
||||
#define SOC_TOUCH_SUPPORT_SLEEP_WAKEUP (1) /*!< Touch sensor supports sleep awake */
|
||||
|
@@ -831,6 +831,14 @@ config SOC_TOUCH_SENSOR_NUM
|
||||
int
|
||||
default 15
|
||||
|
||||
config SOC_TOUCH_MIN_CHAN_ID
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TOUCH_MAX_CHAN_ID
|
||||
int
|
||||
default 14
|
||||
|
||||
config SOC_TOUCH_SUPPORT_BENCHMARK
|
||||
bool
|
||||
default y
|
||||
|
@@ -349,6 +349,8 @@
|
||||
/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/
|
||||
#define SOC_TOUCH_SENSOR_VERSION (2) /*!< Hardware version of touch sensor */
|
||||
#define SOC_TOUCH_SENSOR_NUM (15) /*!< 15 Touch channels */
|
||||
#define SOC_TOUCH_MIN_CHAN_ID (1) /*!< Touch minimum channel number, (0 is internal denoise channel) */
|
||||
#define SOC_TOUCH_MAX_CHAN_ID (14) /*!< Touch maximum channel number */
|
||||
#define SOC_TOUCH_SUPPORT_BENCHMARK (1) /*!< Touch sensor supports benchmark configuration */
|
||||
#define SOC_TOUCH_SUPPORT_SLEEP_WAKEUP (1) /*!< Touch sensor supports sleep awake */
|
||||
#define SOC_TOUCH_SUPPORT_WATERPROOF (1) /*!< Touch sensor supports waterproof */
|
||||
|
@@ -1027,6 +1027,14 @@ config SOC_TOUCH_SENSOR_NUM
|
||||
int
|
||||
default 15
|
||||
|
||||
config SOC_TOUCH_MIN_CHAN_ID
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TOUCH_MAX_CHAN_ID
|
||||
int
|
||||
default 14
|
||||
|
||||
config SOC_TOUCH_SUPPORT_BENCHMARK
|
||||
bool
|
||||
default y
|
||||
|
@@ -399,6 +399,8 @@
|
||||
/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/
|
||||
#define SOC_TOUCH_SENSOR_VERSION (2) /*!< Hardware version of touch sensor */
|
||||
#define SOC_TOUCH_SENSOR_NUM (15) /*!< 15 Touch channels */
|
||||
#define SOC_TOUCH_MIN_CHAN_ID (1) /*!< Touch minimum channel number, (0 is internal denoise channel) */
|
||||
#define SOC_TOUCH_MAX_CHAN_ID (14) /*!< Touch maximum channel number */
|
||||
#define SOC_TOUCH_SUPPORT_BENCHMARK (1) /*!< Touch sensor supports benchmark configuration */
|
||||
#define SOC_TOUCH_SUPPORT_SLEEP_WAKEUP (1) /*!< Touch sensor supports sleep awake */
|
||||
#define SOC_TOUCH_SUPPORT_WATERPROOF (1) /*!< Touch sensor supports waterproof */
|
||||
|
@@ -46,7 +46,11 @@ if(CONFIG_ULP_COPROC_TYPE_FSM OR CONFIG_ULP_COPROC_TYPE_RISCV)
|
||||
"ulp_riscv/ulp_riscv.c"
|
||||
"ulp_riscv/ulp_riscv_lock.c"
|
||||
"ulp_riscv/ulp_riscv_i2c.c")
|
||||
if(CONFIG_SOC_TOUCH_SENSOR_SUPPORTED)
|
||||
list(APPEND srcs "ulp_riscv/ulp_riscv_touch.c")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
if(CONFIG_ULP_COPROC_TYPE_LP_CORE)
|
||||
@@ -77,6 +81,10 @@ if(CONFIG_ULP_COPROC_TYPE_LP_CORE)
|
||||
list(APPEND srcs "lp_core/lp_core_etm.c")
|
||||
endif()
|
||||
|
||||
if(CONFIG_SOC_TOUCH_SENSOR_SUPPORTED)
|
||||
list(APPEND srcs "lp_core/lp_core_touch.c")
|
||||
endif()
|
||||
|
||||
if(CONFIG_SOC_LP_ADC_SUPPORTED)
|
||||
list(APPEND srcs "lp_core/shared/ulp_lp_core_lp_adc_shared.c")
|
||||
endif()
|
||||
|
94
components/ulp/lp_core/lp_core/include/ulp_lp_core_touch.h
Normal file
94
components/ulp/lp_core/lp_core/include/ulp_lp_core_touch.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Read raw data of touch sensor on the ULP RISC-V core
|
||||
* @note Refer `touch_pad_read_raw_data()` for more details
|
||||
*
|
||||
* @param touch_num Touch pad index
|
||||
* @param raw_data Pointer to accept touch sensor value
|
||||
* @return esp_err_t ESP_OK when successful
|
||||
*/
|
||||
esp_err_t lp_core_touch_pad_read_raw_data(int touch_num, uint32_t *raw_data);
|
||||
|
||||
/**
|
||||
* @brief Read benchmark of touch sensor on the ULP RISC-V core
|
||||
* @note Refer `touch_pad_read_benchmark()` for more details
|
||||
*
|
||||
* @param touch_num Touch pad index
|
||||
* @param benchmark Pointer to accept touch sensor benchmark value
|
||||
* @return esp_err_t ESP_OK when successful
|
||||
*/
|
||||
esp_err_t lp_core_touch_pad_read_benchmark(int touch_num, uint32_t *benchmark);
|
||||
|
||||
/**
|
||||
* @brief Read the filtered (smoothened) touch sensor data on the ULP RISC-V core
|
||||
* @note Refer `touch_pad_filter_read_smooth()` for more details
|
||||
*
|
||||
* @param touch_num Touch pad index
|
||||
* @param smooth_data Pointer to accept smoothened touch sensor value
|
||||
* @return esp_err_t ESP_OK when successful
|
||||
*/
|
||||
esp_err_t lp_core_touch_pad_filter_read_smooth(int touch_num, uint32_t *smooth_data);
|
||||
|
||||
/**
|
||||
* @brief Force reset benchmark to raw data of touch sensor.
|
||||
* @note Refer `touch_pad_reset_benchmark()` for more details
|
||||
*
|
||||
* @param touch_num Touch pad index (TOUCH_PAD_MAX resets basaline of all channels)
|
||||
* @return esp_err_t ESP_OK when successful
|
||||
*/
|
||||
esp_err_t lp_core_touch_pad_reset_benchmark(int touch_num);
|
||||
|
||||
/**
|
||||
* @brief Read raw data of touch sensor sleep channel on the ULP RISC-V core
|
||||
* @note Refer `touch_pad_sleep_channel_read_data()` for more details
|
||||
*
|
||||
* @param touch_num Touch pad index (Only one touch sensor channel is supported in deep sleep)
|
||||
* @param raw_data Pointer to accept touch sensor value
|
||||
* @return esp_err_t ESP_OK when successful
|
||||
*/
|
||||
esp_err_t lp_core_touch_pad_sleep_channel_read_data(int touch_num, uint32_t *raw_data);
|
||||
|
||||
/**
|
||||
* @brief Read benchmark of touch sensor sleep channel on the ULP RISC-V core
|
||||
* @note Refer `touch_pad_sleep_channel_read_benchmark()` for more details
|
||||
*
|
||||
* @param touch_num Touch pad index (Only one touch sensor channel is supported in deep sleep)
|
||||
* @param benchmark Pointer to accept touch sensor benchmark value
|
||||
* @return esp_err_t ESP_OK when successful
|
||||
*/
|
||||
esp_err_t lp_core_touch_pad_sleep_channel_read_benchmark(int touch_num, uint32_t *benchmark);
|
||||
|
||||
/**
|
||||
* @brief Read the filtered (smoothened) touch sensor sleep channel data on the ULP RISC-V core
|
||||
* @note Refer `touch_pad_sleep_channel_read_smooth()` for more details
|
||||
*
|
||||
* @param touch_num Touch pad index (Only one touch sensor channel is supported in deep sleep)
|
||||
* @param smooth_data Pointer to accept smoothened touch sensor value
|
||||
* @return esp_err_t ESP_OK when successful
|
||||
*/
|
||||
esp_err_t lp_core_touch_pad_sleep_channel_read_smooth(int touch_num, uint32_t *smooth_data);
|
||||
|
||||
/**
|
||||
* @brief Reset benchmark of touch sensor sleep channel.
|
||||
* @note Refer `touch_pad_sleep_channel_reset_benchmark()` for more details
|
||||
*
|
||||
* @return esp_err_t ESP_OK when successful
|
||||
*/
|
||||
esp_err_t lp_core_touch_pad_sleep_channel_reset_benchmark(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
143
components/ulp/lp_core/lp_core/lp_core_touch.c
Normal file
143
components/ulp/lp_core/lp_core/lp_core_touch.c
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "ulp_riscv_touch_ulp_core.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "hal/touch_sensor_ll.h"
|
||||
|
||||
/* Check Touch Channel correctness */
|
||||
#define ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(channel) \
|
||||
{ \
|
||||
if (channel >= SOC_TOUCH_MAX_CHAN_ID || \
|
||||
channel < SOC_TOUCH_MIN_CHAN_ID) { \
|
||||
return ESP_ERR_INVALID_ARG; \
|
||||
} \
|
||||
} \
|
||||
|
||||
esp_err_t ulp_riscv_touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data)
|
||||
{
|
||||
/* Check Arguments */
|
||||
if (!raw_data) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read raw touch data */
|
||||
uint32_t engaged_sampler_cnt = touch_ll_sample_cfg_get_engaged_num();
|
||||
for (int i = 0; i < engaged_sampler_cnt; i++) {
|
||||
// Only have smooth data on V3, no raw data
|
||||
touch_ll_read_chan_data((int)touch_num, i + 1, TOUCH_LL_READ_SMOOTH, &raw_data[i]);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t ulp_riscv_touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark)
|
||||
{
|
||||
/* Check Arguments */
|
||||
if (!benchmark) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read benchmark data */
|
||||
uint32_t engaged_sampler_cnt = touch_ll_sample_cfg_get_engaged_num();
|
||||
for (int i = 0; i < engaged_sampler_cnt; i++) {
|
||||
touch_ll_read_chan_data((int)touch_num, i + 1, TOUCH_LL_READ_BENCHMARK, &benchmark[i]);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t ulp_riscv_touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth_data)
|
||||
{
|
||||
/* Check Arguments */
|
||||
if (!smooth_data) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read smoothened touch sensor data */
|
||||
uint32_t engaged_sampler_cnt = touch_ll_sample_cfg_get_engaged_num();
|
||||
for (int i = 0; i < engaged_sampler_cnt; i++) {
|
||||
touch_ll_read_chan_data((int)touch_num, i + 1, TOUCH_LL_READ_SMOOTH, &smooth_data[i]);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t ulp_riscv_touch_pad_reset_benchmark(touch_pad_t touch_num)
|
||||
{
|
||||
/* Check Arguments */
|
||||
if (touch_num > TOUCH_PAD_MAX || touch_num < 0) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* Reset benchmark */
|
||||
touch_ll_reset_chan_benchmark(BIT(touch_num));
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t ulp_riscv_touch_pad_sleep_channel_read_data(touch_pad_t touch_num, uint32_t *raw_data)
|
||||
{
|
||||
/* Check Arguments */
|
||||
if (!raw_data) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read raw touch data */
|
||||
uint32_t engaged_sampler_cnt = touch_ll_sample_cfg_get_engaged_num();
|
||||
for (int i = 0; i < engaged_sampler_cnt; i++) {
|
||||
// Only have smooth data on V3, no raw data
|
||||
touch_ll_sleep_read_chan_data(TOUCH_LL_READ_SMOOTH, i + 1, &raw_data[i]);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t ulp_riscv_touch_pad_sleep_channel_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark)
|
||||
{
|
||||
/* Check Arguments */
|
||||
if (!benchmark) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read benchmark data */
|
||||
uint32_t engaged_sampler_cnt = touch_ll_sample_cfg_get_engaged_num();
|
||||
for (int i = 0; i < engaged_sampler_cnt; i++) {
|
||||
touch_ll_sleep_read_chan_data(TOUCH_LL_READ_BENCHMARK, i + 1, &benchmark[i]);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t ulp_riscv_touch_pad_sleep_channel_read_smooth(touch_pad_t touch_num, uint32_t *smooth_data)
|
||||
{
|
||||
/* Check Arguments */
|
||||
if (!smooth_data) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read smoothened touch sensor data */
|
||||
uint32_t engaged_sampler_cnt = touch_ll_sample_cfg_get_engaged_num();
|
||||
for (int i = 0; i < engaged_sampler_cnt; i++) {
|
||||
touch_ll_sleep_read_chan_data(TOUCH_LL_READ_SMOOTH, i + 1, &smooth_data[i]);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t ulp_riscv_touch_pad_sleep_channel_reset_benchmark(void)
|
||||
{
|
||||
/* Reset benchmark */
|
||||
touch_ll_sleep_reset_benchmark();
|
||||
|
||||
return ESP_OK;
|
||||
}
|
@@ -1,20 +1,18 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "ulp_riscv_touch_ulp_core.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/touch_sensor_pins.h"
|
||||
#include "hal/touch_sensor_hal.h"
|
||||
#include "hal/touch_sensor_ll.h"
|
||||
|
||||
/* Check Touch Channel correctness */
|
||||
#define ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(channel) \
|
||||
{ \
|
||||
if (channel >= SOC_TOUCH_SENSOR_NUM || \
|
||||
channel < 0 || \
|
||||
channel == SOC_TOUCH_DENOISE_CHANNEL) { \
|
||||
if (channel >= SOC_TOUCH_MAX_CHAN_ID || \
|
||||
channel < SOC_TOUCH_MIN_CHAN_ID) { \
|
||||
return ESP_ERR_INVALID_ARG; \
|
||||
} \
|
||||
} \
|
||||
@@ -28,7 +26,7 @@ esp_err_t ulp_riscv_touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw
|
||||
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read raw touch data */
|
||||
*raw_data = touch_hal_read_raw_data(touch_num);
|
||||
touch_ll_read_chan_data((int)touch_num, TOUCH_LL_READ_RAW, raw_data);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -42,7 +40,7 @@ esp_err_t ulp_riscv_touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *be
|
||||
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read benchmark data */
|
||||
touch_hal_read_benchmark(touch_num, benchmark);
|
||||
touch_ll_read_chan_data((int)touch_num, TOUCH_LL_READ_BENCHMARK, benchmark);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -56,7 +54,7 @@ esp_err_t ulp_riscv_touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t
|
||||
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read smoothened touch sensor data */
|
||||
touch_hal_filter_read_smooth(touch_num, smooth_data);
|
||||
touch_ll_read_chan_data((int)touch_num, TOUCH_LL_READ_SMOOTH, smooth_data);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -69,7 +67,7 @@ esp_err_t ulp_riscv_touch_pad_reset_benchmark(touch_pad_t touch_num)
|
||||
}
|
||||
|
||||
/* Reset benchmark */
|
||||
touch_hal_reset_benchmark(touch_num);
|
||||
touch_ll_reset_chan_benchmark(BIT(touch_num));
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -83,7 +81,7 @@ esp_err_t ulp_riscv_touch_pad_sleep_channel_read_data(touch_pad_t touch_num, uin
|
||||
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read raw touch data */
|
||||
touch_hal_sleep_read_data(raw_data);
|
||||
touch_ll_sleep_read_chan_data(TOUCH_LL_READ_RAW, raw_data);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -97,7 +95,7 @@ esp_err_t ulp_riscv_touch_pad_sleep_channel_read_benchmark(touch_pad_t touch_num
|
||||
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read benchmark data */
|
||||
touch_hal_sleep_read_benchmark(benchmark);
|
||||
touch_ll_sleep_read_chan_data(TOUCH_LL_READ_BENCHMARK, benchmark);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -111,7 +109,7 @@ esp_err_t ulp_riscv_touch_pad_sleep_channel_read_smooth(touch_pad_t touch_num, u
|
||||
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read smoothened touch sensor data */
|
||||
touch_hal_sleep_read_smooth(smooth_data);
|
||||
touch_ll_sleep_read_chan_data(TOUCH_LL_READ_SMOOTH, smooth_data);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -119,7 +117,7 @@ esp_err_t ulp_riscv_touch_pad_sleep_channel_read_smooth(touch_pad_t touch_num, u
|
||||
esp_err_t ulp_riscv_touch_pad_sleep_channel_reset_benchmark(void)
|
||||
{
|
||||
/* Reset benchmark */
|
||||
touch_hal_sleep_reset_benchmark();
|
||||
touch_ll_sleep_reset_benchmark();
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
Reference in New Issue
Block a user