Skip to content

Commit afda4c1

Browse files
committed
Merge branch 'feature/support_p4_ulp_touch_driver' into 'master'
feat(ulp_touch): support ulp touch driver on p4 Closes IDF-12546 See merge request espressif/esp-idf!37362
2 parents 71e4d9e + c9cc7bb commit afda4c1

File tree

28 files changed

+725
-24
lines changed

28 files changed

+725
-24
lines changed

components/esp_driver_touch_sens/common/touch_sens_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "esp_check.h"
3333
#include "touch_sens_private.h"
3434

35-
#define TOUCH_CHANNEL_CHECK(num) ESP_RETURN_ON_FALSE(num >= TOUCH_MIN_CHAN_ID && num <= TOUCH_MAX_CHAN_ID, \
35+
#define TOUCH_CHANNEL_CHECK(num) ESP_RETURN_ON_FALSE((int)(num) >= (int)TOUCH_MIN_CHAN_ID && num <= TOUCH_MAX_CHAN_ID, \
3636
ESP_ERR_INVALID_ARG, TAG, "The channel number is out of supported range");
3737

3838
static const char *TAG = "touch";

components/esp_driver_touch_sens/hw_ver1/include/driver/touch_version_types.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
extern "C" {
2020
#endif
2121

22-
#define TOUCH_MIN_CHAN_ID 0 /*!< The minimum available channel id of the touch pad */
23-
#define TOUCH_MAX_CHAN_ID 9 /*!< The maximum available channel id of the touch pad */
24-
2522
/**
2623
* @brief Helper macro to the default configurations of the touch sensor controller
2724
*

components/esp_driver_touch_sens/hw_ver2/include/driver/touch_version_types.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
extern "C" {
2020
#endif
2121

22-
#define TOUCH_MIN_CHAN_ID 1 /*!< The minimum available channel id of the touch pad */
23-
#define TOUCH_MAX_CHAN_ID 14 /*!< The maximum available channel id of the touch pad */
24-
2522
#define TOUCH_SHIELD_CHAN_ID 14 /*!< The touch channel that can be used as the shield channel */
2623

2724
/**

components/esp_driver_touch_sens/hw_ver3/include/driver/touch_version_types.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
extern "C" {
2020
#endif
2121

22-
#define TOUCH_MIN_CHAN_ID 0 /*!< The minimum available channel id of the touch pad */
23-
#define TOUCH_MAX_CHAN_ID 13 /*!< The maximum available channel id of the touch pad */
24-
2522
/**
2623
* @brief Helper macro to the default configurations of the touch sensor controller
2724
*

components/esp_driver_touch_sens/include/driver/touch_sens_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ extern "C" {
2222
#define TOUCH_PROXIMITY_CHAN_NUM SOC_TOUCH_PROXIMITY_CHANNEL_NUM /*!< The supported proximity channel number in proximity sensing mode */
2323
#endif
2424

25+
#define TOUCH_MIN_CHAN_ID SOC_TOUCH_MIN_CHAN_ID /*!< The minimum available channel id of the touch pad */
26+
#define TOUCH_MAX_CHAN_ID SOC_TOUCH_MAX_CHAN_ID /*!< The maximum available channel id of the touch pad */
27+
2528
/**
2629
* @brief The chip sleep level that allows the touch sensor to wake-up
2730
*

components/hal/esp32p4/include/hal/touch_sensor_ll.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,18 @@ static inline void touch_ll_sample_cfg_set_engaged_num(uint8_t sample_cfg_num)
584584
LP_ANA_PERI.touch_scan_ctrl2.freq_scan_cnt_limit = sample_cfg_num ? sample_cfg_num : 1;
585585
}
586586

587+
/**
588+
* Get the engaged sample configuration number
589+
*
590+
* @return The engaged sample configuration number, range 0~3.
591+
*/
592+
static inline uint32_t touch_ll_sample_cfg_get_engaged_num(void)
593+
{
594+
uint32_t sample_cfg_num = LP_ANA_PERI.touch_scan_ctrl2.freq_scan_cnt_limit;
595+
return sample_cfg_num ? sample_cfg_num : 1;
596+
}
597+
598+
587599
/**
588600
* Set capacitance and resistance of the RC filter of the sampling frequency.
589601
*

components/hal/esp32s2/include/hal/touch_sensor_ll.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,29 @@ static inline void touch_ll_sleep_read_data(uint32_t *raw_data)
16821682
*raw_data = SENS.sar_touch_status[touch_num - 1].touch_pad_data;
16831683
}
16841684

1685+
/**
1686+
* Get the data of the touch channel according to the types
1687+
*
1688+
* @param sample_cfg_id The sample configuration index
1689+
* @param type data type
1690+
* 0/1: TOUCH_LL_READ_RAW, the raw data of the touch channel
1691+
* 2: TOUCH_LL_READ_BENCHMARK, benchmark value of touch channel,
1692+
* the benchmark value is the maximum during the first measurement period
1693+
* 3: TOUCH_LL_READ_SMOOTH, the smoothed data that obtained by filtering the raw data.
1694+
* @param smooth_data pointer to smoothed data
1695+
*/
1696+
__attribute__((always_inline))
1697+
static inline void touch_ll_sleep_read_chan_data(uint8_t type, uint32_t *data)
1698+
{
1699+
SENS.sar_touch_conf.touch_data_sel = type;
1700+
if (type == TOUCH_LL_READ_RAW) {
1701+
uint32_t touch_num = RTCCNTL.touch_slp_thres.touch_slp_pad;
1702+
*data = SENS.sar_touch_status[touch_num - 1].touch_pad_data;
1703+
} else {
1704+
*data = SENS.sar_touch_slp_status.touch_slp_data;
1705+
}
1706+
}
1707+
16851708
/**
16861709
* Select touch sensor dbias to save power in sleep mode.
16871710
*

components/hal/esp32s3/include/hal/touch_sensor_ll.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,29 @@ static inline void touch_ll_sleep_read_data(uint32_t *raw_data)
17181718
*raw_data = SENS.sar_touch_status[touch_num - 1].touch_pad_data;
17191719
}
17201720

1721+
/**
1722+
* Get the data of the touch channel according to the types
1723+
*
1724+
* @param sample_cfg_id The sample configuration index
1725+
* @param type data type
1726+
* 0/1: TOUCH_LL_READ_RAW, the raw data of the touch channel
1727+
* 2: TOUCH_LL_READ_BENCHMARK, benchmark value of touch channel,
1728+
* the benchmark value is the maximum during the first measurement period
1729+
* 3: TOUCH_LL_READ_SMOOTH, the smoothed data that obtained by filtering the raw data.
1730+
* @param smooth_data pointer to smoothed data
1731+
*/
1732+
__attribute__((always_inline))
1733+
static inline void touch_ll_sleep_read_chan_data(uint8_t type, uint32_t *data)
1734+
{
1735+
SENS.sar_touch_conf.touch_data_sel = type;
1736+
if (type == TOUCH_LL_READ_RAW) {
1737+
uint32_t touch_num = RTCCNTL.touch_slp_thres.touch_slp_pad;
1738+
*data = SENS.sar_touch_status[touch_num - 1].touch_pad_data;
1739+
} else {
1740+
*data = SENS.sar_touch_slp_status.touch_slp_data;
1741+
}
1742+
}
1743+
17211744

17221745
/**
17231746
* Select touch sensor dbias to save power in sleep mode.

components/soc/esp32/include/soc/Kconfig.soc_caps.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,14 @@ config SOC_TOUCH_SENSOR_NUM
735735
int
736736
default 10
737737

738+
config SOC_TOUCH_MIN_CHAN_ID
739+
int
740+
default 0
741+
742+
config SOC_TOUCH_MAX_CHAN_ID
743+
int
744+
default 9
745+
738746
config SOC_TOUCH_SUPPORT_SLEEP_WAKEUP
739747
bool
740748
default y

components/soc/esp32/include/soc/soc_caps.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@
336336
/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/
337337
#define SOC_TOUCH_SENSOR_VERSION (1U) /*!<Hardware version of touch sensor */
338338
#define SOC_TOUCH_SENSOR_NUM (10)
339+
#define SOC_TOUCH_MIN_CHAN_ID (0U) /*!< Touch minimum channel number */
340+
#define SOC_TOUCH_MAX_CHAN_ID (9) /*!< Touch maximum channel number */
339341
#define SOC_TOUCH_SUPPORT_SLEEP_WAKEUP (1)
340342
#define SOC_TOUCH_SAMPLE_CFG_NUM (1U) /*!< The sample configuration number in total, each sampler can be used to sample on one frequency */
341343

components/soc/esp32p4/include/soc/Kconfig.soc_caps.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,14 @@ config SOC_TOUCH_SENSOR_NUM
17231723
int
17241724
default 14
17251725

1726+
config SOC_TOUCH_MIN_CHAN_ID
1727+
int
1728+
default 0
1729+
1730+
config SOC_TOUCH_MAX_CHAN_ID
1731+
int
1732+
default 13
1733+
17261734
config SOC_TOUCH_SUPPORT_SLEEP_WAKEUP
17271735
bool
17281736
default y

components/soc/esp32p4/include/soc/soc_caps.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,8 @@
635635
/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/
636636
#define SOC_TOUCH_SENSOR_VERSION (3) /*!< Hardware version of touch sensor */
637637
#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 */
638+
#define SOC_TOUCH_MIN_CHAN_ID (0U) /*!< Touch minimum channel number */
639+
#define SOC_TOUCH_MAX_CHAN_ID (13) /*!< Touch maximum channel number */
638640

639641
/* Touch Sensor Features */
640642
#define SOC_TOUCH_SUPPORT_SLEEP_WAKEUP (1) /*!< Touch sensor supports sleep awake */

components/soc/esp32s2/include/soc/Kconfig.soc_caps.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,14 @@ config SOC_TOUCH_SENSOR_NUM
831831
int
832832
default 15
833833

834+
config SOC_TOUCH_MIN_CHAN_ID
835+
bool
836+
default y
837+
838+
config SOC_TOUCH_MAX_CHAN_ID
839+
int
840+
default 14
841+
834842
config SOC_TOUCH_SUPPORT_BENCHMARK
835843
bool
836844
default y

components/soc/esp32s2/include/soc/soc_caps.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@
349349
/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/
350350
#define SOC_TOUCH_SENSOR_VERSION (2) /*!< Hardware version of touch sensor */
351351
#define SOC_TOUCH_SENSOR_NUM (15) /*!< 15 Touch channels */
352+
#define SOC_TOUCH_MIN_CHAN_ID (1) /*!< Touch minimum channel number, (0 is internal denoise channel) */
353+
#define SOC_TOUCH_MAX_CHAN_ID (14) /*!< Touch maximum channel number */
352354
#define SOC_TOUCH_SUPPORT_BENCHMARK (1) /*!< Touch sensor supports benchmark configuration */
353355
#define SOC_TOUCH_SUPPORT_SLEEP_WAKEUP (1) /*!< Touch sensor supports sleep awake */
354356
#define SOC_TOUCH_SUPPORT_WATERPROOF (1) /*!< Touch sensor supports waterproof */

components/soc/esp32s3/include/soc/Kconfig.soc_caps.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,14 @@ config SOC_TOUCH_SENSOR_NUM
10271027
int
10281028
default 15
10291029

1030+
config SOC_TOUCH_MIN_CHAN_ID
1031+
bool
1032+
default y
1033+
1034+
config SOC_TOUCH_MAX_CHAN_ID
1035+
int
1036+
default 14
1037+
10301038
config SOC_TOUCH_SUPPORT_BENCHMARK
10311039
bool
10321040
default y

components/soc/esp32s3/include/soc/soc_caps.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@
399399
/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/
400400
#define SOC_TOUCH_SENSOR_VERSION (2) /*!< Hardware version of touch sensor */
401401
#define SOC_TOUCH_SENSOR_NUM (15) /*!< 15 Touch channels */
402+
#define SOC_TOUCH_MIN_CHAN_ID (1) /*!< Touch minimum channel number, (0 is internal denoise channel) */
403+
#define SOC_TOUCH_MAX_CHAN_ID (14) /*!< Touch maximum channel number */
402404
#define SOC_TOUCH_SUPPORT_BENCHMARK (1) /*!< Touch sensor supports benchmark configuration */
403405
#define SOC_TOUCH_SUPPORT_SLEEP_WAKEUP (1) /*!< Touch sensor supports sleep awake */
404406
#define SOC_TOUCH_SUPPORT_WATERPROOF (1) /*!< Touch sensor supports waterproof */

components/ulp/cmake/IDFULPProject.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ function(ulp_apply_default_sources ulp_app_name)
132132
"${IDF_PATH}/components/ulp/lp_core/shared/ulp_lp_core_lp_vad_shared.c"
133133
"${IDF_PATH}/components/ulp/lp_core/shared/ulp_lp_core_critical_section_shared.c")
134134

135+
if(CONFIG_SOC_TOUCH_SENSOR_SUPPORTED)
136+
list(APPEND ULP_S_SOURCES
137+
"${IDF_PATH}/components/ulp/lp_core/lp_core/lp_core_touch.c")
138+
endif()
139+
135140
set(target_folder ${IDF_TARGET})
136141

137142
target_link_options(${ulp_app_name}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include "esp_err.h"
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
/**
16+
* @brief Read raw data of touch sensor on the LP core
17+
*
18+
* @param[in] touch_num Touch pad index
19+
* @param[out] raw_data Raw data buffer pointer to accept touch sensor raw value,
20+
* buffer size should be equal to the number of enabled sampling frequencies
21+
* @return esp_err_t ESP_OK when successful
22+
*/
23+
esp_err_t lp_core_touch_pad_read_raw_data(int touch_num, uint32_t *raw_data);
24+
25+
/**
26+
* @brief Read benchmark of touch sensor on the LP core
27+
*
28+
* @param[in] touch_num Touch pad index
29+
* @param[out] benchmark Benchmark data buffer pointer to accept touch sensor benchmark value,
30+
* buffer size should be equal to the number of enabled sampling frequencies
31+
* @return esp_err_t ESP_OK when successful
32+
*/
33+
esp_err_t lp_core_touch_pad_read_benchmark(int touch_num, uint32_t *benchmark);
34+
35+
/**
36+
* @brief Read the filtered (smoothened) touch sensor data on the LP core
37+
*
38+
* @param[in] touch_num Touch pad index
39+
* @param[out] smooth_data Smooth data buffer pointer to accept touch sensor smooth value,
40+
* buffer size should be equal to the number of enabled sampling frequencies
41+
* @return esp_err_t ESP_OK when successful
42+
*/
43+
esp_err_t lp_core_touch_pad_filter_read_smooth(int touch_num, uint32_t *smooth_data);
44+
45+
/**
46+
* @brief Force reset benchmark to raw data of touch sensor.
47+
*
48+
* @param[in] touch_num Touch pad index
49+
* @param[in] mask Mask of the sample freuqencies that need to be reset
50+
* @return esp_err_t ESP_OK when successful
51+
*/
52+
esp_err_t lp_core_touch_pad_reset_benchmark(int touch_num, uint32_t mask);
53+
54+
/**
55+
* @brief Read raw data of touch sensor sleep channel on the LP core
56+
*
57+
* @param[in] touch_num Touch pad index that has been registered as sleep channel
58+
* @param[out] raw_data Raw data buffer pointer to accept touch sensor raw value,
59+
* buffer size should be equal to the number of enabled sampling frequencies
60+
* @return esp_err_t ESP_OK when successful
61+
*/
62+
esp_err_t lp_core_touch_pad_sleep_channel_read_data(int touch_num, uint32_t *raw_data);
63+
64+
/**
65+
* @brief Read benchmark of touch sensor sleep channel on the LP core
66+
*
67+
* @param[in] touch_num Touch pad index that has been registered as sleep channel
68+
* @param[out] benchmark Benchmark data buffer pointer to accept touch sensor benchmark value,
69+
* buffer size should be equal to the number of enabled sampling frequencies
70+
* @return esp_err_t ESP_OK when successful
71+
*/
72+
esp_err_t lp_core_touch_pad_sleep_channel_read_benchmark(int touch_num, uint32_t *benchmark);
73+
74+
/**
75+
* @brief Read the filtered (smoothened) touch sensor sleep channel data on the LP core
76+
*
77+
* @param[in] touch_num Touch pad index that has been registered as sleep channel
78+
* @param[out] smooth_dat Smooth data buffer pointer to accept touch sensor smooth value,
79+
* buffer size should be equal to the number of enabled sampling frequencies
80+
* @return esp_err_t ESP_OK when successful
81+
*/
82+
esp_err_t lp_core_touch_pad_sleep_channel_read_smooth(int touch_num, uint32_t *smooth_data);
83+
84+
/**
85+
* @brief Reset benchmark of touch sensor sleep channel.
86+
* @param[in] mask Mask of the sample freuqencies that need to be reset
87+
* @return esp_err_t ESP_OK when successful
88+
*/
89+
esp_err_t lp_core_touch_pad_sleep_channel_reset_benchmark(uint32_t mask);
90+
91+
#ifdef __cplusplus
92+
}
93+
#endif

0 commit comments

Comments
 (0)