refactor(touch): remove legacy touch driver dependency in ulp

This commit is contained in:
laokaiyao
2025-10-09 13:17:54 +08:00
committed by Kevin (Lao Kaiyao)
parent f4e999fd3e
commit 14cf724f64
15 changed files with 97 additions and 85 deletions
@@ -16,15 +16,6 @@
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 The chip sleep level that allows the touch sensor to wake-up
*
@@ -1,8 +1,5 @@
components/esp_driver_touch_sens/test_apps/touch_sens:
disable:
- if: SOC_TOUCH_SENSOR_SUPPORTED != 1
- if: SOC_TOUCH_SENSOR_VERSION == 1
temporary: true
reason: currently driver ng does not support version 1
depends_components:
- esp_driver_touch_sens
@@ -1,3 +1,3 @@
| Supported Targets | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | -------- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- |
@@ -3,6 +3,7 @@
import pytest
from pytest_embedded import Dut
from pytest_embedded_idf.utils import idf_parametrize
from pytest_embedded_idf.utils import soc_filtered_targets
@pytest.mark.generic
@@ -14,6 +15,6 @@ from pytest_embedded_idf.utils import idf_parametrize
],
indirect=True,
)
@idf_parametrize('target', ['esp32s2', 'esp32s3', 'esp32p4'], indirect=['target'])
@idf_parametrize('target', soc_filtered_targets('SOC_TOUCH_SENSOR_SUPPORTED == 1'), indirect=['target'])
def test_touch_sens(dut: Dut) -> None:
dut.run_all_single_board_cases()
@@ -336,6 +336,7 @@ static inline void touch_ll_enable_channel_mask(uint16_t enable_mask)
*
* @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;
@@ -12,6 +12,15 @@
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
*
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -8,7 +8,7 @@
#include "esp_err.h"
#include "ulp_riscv_register_ops.h"
#include "hal/touch_sensor_legacy_types.h"
#include "hal/touch_sens_types.h"
#ifdef __cplusplus
extern "C" {
@@ -22,7 +22,7 @@ extern "C" {
* @param raw_data Pointer to accept touch sensor value
* @return esp_err_t ESP_OK when successful
*/
esp_err_t ulp_riscv_touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data);
esp_err_t ulp_riscv_touch_pad_read_raw_data(int touch_num, uint32_t *raw_data);
/**
* @brief Read benchmark of touch sensor on the ULP RISC-V core
@@ -32,7 +32,7 @@ esp_err_t ulp_riscv_touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw
* @param benchmark Pointer to accept touch sensor benchmark value
* @return esp_err_t ESP_OK when successful
*/
esp_err_t ulp_riscv_touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark);
esp_err_t ulp_riscv_touch_pad_read_benchmark(int touch_num, uint32_t *benchmark);
/**
* @brief Read the filtered (smoothened) touch sensor data on the ULP RISC-V core
@@ -42,7 +42,7 @@ esp_err_t ulp_riscv_touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *be
* @param smooth_data Pointer to accept smoothened touch sensor value
* @return esp_err_t ESP_OK when successful
*/
esp_err_t ulp_riscv_touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth_data);
esp_err_t ulp_riscv_touch_pad_filter_read_smooth(int touch_num, uint32_t *smooth_data);
/**
* @brief Force reset benchmark to raw data of touch sensor.
@@ -51,7 +51,7 @@ esp_err_t ulp_riscv_touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t
* @param touch_num Touch pad index (TOUCH_PAD_MAX resets baseline of all channels)
* @return esp_err_t ESP_OK when successful
*/
esp_err_t ulp_riscv_touch_pad_reset_benchmark(touch_pad_t touch_num);
esp_err_t ulp_riscv_touch_pad_reset_benchmark(int touch_num);
/**
* @brief Read raw data of touch sensor sleep channel on the ULP RISC-V core
@@ -61,7 +61,7 @@ esp_err_t ulp_riscv_touch_pad_reset_benchmark(touch_pad_t touch_num);
* @param raw_data Pointer to accept touch sensor value
* @return esp_err_t ESP_OK when successful
*/
esp_err_t ulp_riscv_touch_pad_sleep_channel_read_data(touch_pad_t touch_num, uint32_t *raw_data);
esp_err_t ulp_riscv_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
@@ -71,7 +71,7 @@ esp_err_t ulp_riscv_touch_pad_sleep_channel_read_data(touch_pad_t touch_num, uin
* @param benchmark Pointer to accept touch sensor benchmark value
* @return esp_err_t ESP_OK when successful
*/
esp_err_t ulp_riscv_touch_pad_sleep_channel_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark);
esp_err_t ulp_riscv_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
@@ -81,7 +81,7 @@ esp_err_t ulp_riscv_touch_pad_sleep_channel_read_benchmark(touch_pad_t touch_num
* @param smooth_data Pointer to accept smoothened touch sensor value
* @return esp_err_t ESP_OK when successful
*/
esp_err_t ulp_riscv_touch_pad_sleep_channel_read_smooth(touch_pad_t touch_num, uint32_t *smooth_data);
esp_err_t ulp_riscv_touch_pad_sleep_channel_read_smooth(int touch_num, uint32_t *smooth_data);
/**
* @brief Reset benchmark of touch sensor sleep channel.
@@ -17,7 +17,7 @@
} \
} \
esp_err_t ulp_riscv_touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data)
esp_err_t ulp_riscv_touch_pad_read_raw_data(int touch_num, uint32_t *raw_data)
{
/* Check Arguments */
if (!raw_data) {
@@ -31,7 +31,7 @@ esp_err_t ulp_riscv_touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw
return ESP_OK;
}
esp_err_t ulp_riscv_touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark)
esp_err_t ulp_riscv_touch_pad_read_benchmark(int touch_num, uint32_t *benchmark)
{
/* Check Arguments */
if (!benchmark) {
@@ -45,7 +45,7 @@ esp_err_t ulp_riscv_touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *be
return ESP_OK;
}
esp_err_t ulp_riscv_touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth_data)
esp_err_t ulp_riscv_touch_pad_filter_read_smooth(int touch_num, uint32_t *smooth_data)
{
/* Check Arguments */
if (!smooth_data) {
@@ -59,10 +59,10 @@ esp_err_t ulp_riscv_touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t
return ESP_OK;
}
esp_err_t ulp_riscv_touch_pad_reset_benchmark(touch_pad_t touch_num)
esp_err_t ulp_riscv_touch_pad_reset_benchmark(int touch_num)
{
/* Check Arguments */
if (touch_num > TOUCH_PAD_MAX || touch_num < 0) {
if (touch_num > SOC_TOUCH_MAX_CHAN_ID || touch_num < 0) {
return ESP_ERR_INVALID_ARG;
}
@@ -72,7 +72,7 @@ esp_err_t ulp_riscv_touch_pad_reset_benchmark(touch_pad_t 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)
esp_err_t ulp_riscv_touch_pad_sleep_channel_read_data(int touch_num, uint32_t *raw_data)
{
/* Check Arguments */
if (!raw_data) {
@@ -86,7 +86,7 @@ esp_err_t ulp_riscv_touch_pad_sleep_channel_read_data(touch_pad_t touch_num, uin
return ESP_OK;
}
esp_err_t ulp_riscv_touch_pad_sleep_channel_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark)
esp_err_t ulp_riscv_touch_pad_sleep_channel_read_benchmark(int touch_num, uint32_t *benchmark)
{
/* Check Arguments */
if (!benchmark) {
@@ -100,7 +100,7 @@ esp_err_t ulp_riscv_touch_pad_sleep_channel_read_benchmark(touch_pad_t touch_num
return ESP_OK;
}
esp_err_t ulp_riscv_touch_pad_sleep_channel_read_smooth(touch_pad_t touch_num, uint32_t *smooth_data)
esp_err_t ulp_riscv_touch_pad_sleep_channel_read_smooth(int touch_num, uint32_t *smooth_data)
{
/* Check Arguments */
if (!smooth_data) {
@@ -287,6 +287,8 @@ Touch Sensor
The ``touch_sensor_sample_config_t::bypass_shield_output`` member for version 3 touch sensor has been removed because it is not supported in the version 3 hardware.
The dependencies of legacy touch sensor driver are removed from ULP touch driver, now you need to use ``int`` instead of ``touch_pad_t`` to indicate the touch channel ID.
I2S
---
@@ -287,6 +287,8 @@ Touch Sensor
第三版触摸传感器的驱动配置项 ``touch_sensor_sample_config_t::bypass_shield_output`` 已被移除,因为第三版触摸传感器硬件已不支持该功能。
旧版触摸传感器驱动依赖已被移除,现在你需要使用 ``int`` 类型代替 ``touch_pad_t`` 类型来指示触摸通道 ID。
I2S
---
@@ -1,7 +1,7 @@
# Register the component
idf_component_register(SRCS "ulp_riscv_touch_example_main.c"
INCLUDE_DIRS ""
PRIV_REQUIRES driver
PRIV_REQUIRES esp_driver_touch_sens
REQUIRES ulp)
#
@@ -0,0 +1,3 @@
dependencies:
touch_sens_examples_common:
path: ${IDF_PATH}/examples/peripherals/touch_sensor/touch_sens_examples_common
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -21,21 +21,21 @@ uint32_t touch_data = 0;
#define TOUCH_PAD_THRESHOLD 1000U
#define TOUCH_BUTTON_NUM 14U
static const touch_pad_t button[TOUCH_BUTTON_NUM] = {
TOUCH_PAD_NUM1,
TOUCH_PAD_NUM2,
TOUCH_PAD_NUM3,
TOUCH_PAD_NUM4,
TOUCH_PAD_NUM5,
TOUCH_PAD_NUM6,
TOUCH_PAD_NUM7,
TOUCH_PAD_NUM8,
TOUCH_PAD_NUM9,
TOUCH_PAD_NUM10,
TOUCH_PAD_NUM11,
TOUCH_PAD_NUM12,
TOUCH_PAD_NUM13,
TOUCH_PAD_NUM14
static const int button[TOUCH_BUTTON_NUM] = {
TOUCH_MIN_CHAN_ID,
TOUCH_MIN_CHAN_ID + 1,
TOUCH_MIN_CHAN_ID + 2,
TOUCH_MIN_CHAN_ID + 3,
TOUCH_MIN_CHAN_ID + 4,
TOUCH_MIN_CHAN_ID + 5,
TOUCH_MIN_CHAN_ID + 6,
TOUCH_MIN_CHAN_ID + 7,
TOUCH_MIN_CHAN_ID + 8,
TOUCH_MIN_CHAN_ID + 9,
TOUCH_MIN_CHAN_ID + 10,
TOUCH_MIN_CHAN_ID + 11,
TOUCH_MIN_CHAN_ID + 12,
TOUCH_MIN_CHAN_ID + 13,
};
int main (void)
@@ -10,53 +10,60 @@
#include "esp_sleep.h"
#include "ulp_riscv.h"
#include "ulp_main.h"
#include "driver/touch_sensor.h"
#include "driver/touch_sens.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "touch_sens_example_config.h"
extern const uint8_t _binary_ulp_main_bin_start[];
extern const uint8_t _binary_ulp_main_bin_end[];
#define TOUCH_BUTTON_NUM 14U
static const touch_pad_t button[TOUCH_BUTTON_NUM] = {
TOUCH_PAD_NUM1,
TOUCH_PAD_NUM2,
TOUCH_PAD_NUM3,
TOUCH_PAD_NUM4,
TOUCH_PAD_NUM5,
TOUCH_PAD_NUM6,
TOUCH_PAD_NUM7,
TOUCH_PAD_NUM8,
TOUCH_PAD_NUM9,
TOUCH_PAD_NUM10,
TOUCH_PAD_NUM11,
TOUCH_PAD_NUM12,
TOUCH_PAD_NUM13,
TOUCH_PAD_NUM14
static const int s_channel_id[TOUCH_BUTTON_NUM] = {
TOUCH_MIN_CHAN_ID,
TOUCH_MIN_CHAN_ID + 1,
TOUCH_MIN_CHAN_ID + 2,
TOUCH_MIN_CHAN_ID + 3,
TOUCH_MIN_CHAN_ID + 4,
TOUCH_MIN_CHAN_ID + 5,
TOUCH_MIN_CHAN_ID + 6,
TOUCH_MIN_CHAN_ID + 7,
TOUCH_MIN_CHAN_ID + 8,
TOUCH_MIN_CHAN_ID + 9,
TOUCH_MIN_CHAN_ID + 10,
TOUCH_MIN_CHAN_ID + 11,
TOUCH_MIN_CHAN_ID + 12,
TOUCH_MIN_CHAN_ID + 13,
};
static void init_touch_pad(void)
{
/* Initialize touch pad peripheral. */
touch_pad_init();
/* Handles of touch sensor and its channels*/
static touch_sensor_handle_t s_sens_handle = NULL;
static touch_channel_handle_t s_chan_handle[TOUCH_BUTTON_NUM];
static void init_touch_sensor(void)
{
/* Create a new touch sensor controller handle with default sample configuration */
touch_sensor_sample_config_t sample_cfg[TOUCH_SAMPLE_CFG_NUM] = EXAMPLE_TOUCH_SAMPLE_CFG_DEFAULT();
touch_sensor_config_t sens_cfg = TOUCH_SENSOR_DEFAULT_BASIC_CONFIG(1, sample_cfg);
ESP_ERROR_CHECK(touch_sensor_new_controller(&sens_cfg, &s_sens_handle));
/* Create and enable the new touch channel handles with default configurations */
touch_channel_config_t chan_cfg = EXAMPLE_TOUCH_CHAN_CFG_DEFAULT();
/* Allocate new touch channel on the touch controller */
for (int i = 0; i < TOUCH_BUTTON_NUM; i++) {
touch_pad_config(button[i]);
ESP_ERROR_CHECK(touch_sensor_new_channel(s_sens_handle, s_channel_id[i], &chan_cfg, &s_chan_handle[i]));
}
/* Denoise setting at TouchSensor 0. */
touch_pad_denoise_t denoise = {
/* The bits to be cancelled are determined according to the noise level. */
.grade = TOUCH_PAD_DENOISE_BIT4,
.cap_level = TOUCH_PAD_DENOISE_CAP_L4,
};
touch_pad_denoise_set_config(&denoise);
touch_pad_denoise_enable();
/* Confiture the default filter for the touch sensor (Note: Touch V1 uses software filter) */
touch_sensor_filter_config_t filter_cfg = TOUCH_SENSOR_DEFAULT_FILTER_CONFIG();
ESP_ERROR_CHECK(touch_sensor_config_filter(s_sens_handle, &filter_cfg));
/* Enable touch sensor clock. Work mode is "timer trigger". */
touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
touch_pad_fsm_start();
/* Enable the touch sensor */
ESP_ERROR_CHECK(touch_sensor_enable(s_sens_handle));
/* Start continuous scanning, you can also trigger oneshot scanning manually */
ESP_ERROR_CHECK(touch_sensor_start_continuous_scanning(s_sens_handle));
}
static void init_ulp_program(void)
@@ -88,8 +95,8 @@ void app_main(void)
printf("ULP-RISC-V woke up the main CPU! \n");
uint32_t touch_data = ulp_touch_data;
for (int i = 0; i < TOUCH_BUTTON_NUM; i++) {
if ((touch_data >> button[i]) & 0x1) {
printf("T%d touched\n", button[i]);
if ((touch_data >> s_channel_id[i]) & 0x1) {
printf("T%d touched\n", s_channel_id[i]);
}
}
printf("\n");
@@ -97,7 +104,7 @@ void app_main(void)
/* not a wakeup from ULP, load the firmware */
printf("Not a ULP-RISC-V wakeup, initializing ...\n");
/* Initialize Touch peripheral */
init_touch_pad();
init_touch_sensor();
/* Initialize ULP core */
init_ulp_program();
@@ -7,4 +7,3 @@ CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
CONFIG_BOOTLOADER_LOG_LEVEL=2
CONFIG_LOG_DEFAULT_LEVEL_WARN=y
CONFIG_LOG_DEFAULT_LEVEL=2
CONFIG_TOUCH_SUPPRESS_DEPRECATE_WARN=y