Skip to content

Commit c9cc7bb

Browse files
committed
feat(ulp_touch): add example for lp_touch
1 parent ffb8adc commit c9cc7bb

File tree

17 files changed

+436
-70
lines changed

17 files changed

+436
-70
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/soc/esp32/include/soc/Kconfig.soc_caps.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,8 @@ config SOC_TOUCH_SENSOR_NUM
736736
default 10
737737

738738
config SOC_TOUCH_MIN_CHAN_ID
739-
bool
740-
default n
739+
int
740+
default 0
741741

742742
config SOC_TOUCH_MAX_CHAN_ID
743743
int

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@
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 (0) /*!< Touch minimum channel number */
339+
#define SOC_TOUCH_MIN_CHAN_ID (0U) /*!< Touch minimum channel number */
340340
#define SOC_TOUCH_MAX_CHAN_ID (9) /*!< Touch maximum channel number */
341341
#define SOC_TOUCH_SUPPORT_SLEEP_WAKEUP (1)
342342
#define SOC_TOUCH_SAMPLE_CFG_NUM (1U) /*!< The sample configuration number in total, each sampler can be used to sample on one frequency */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,8 +1724,8 @@ config SOC_TOUCH_SENSOR_NUM
17241724
default 14
17251725

17261726
config SOC_TOUCH_MIN_CHAN_ID
1727-
bool
1728-
default n
1727+
int
1728+
default 0
17291729

17301730
config SOC_TOUCH_MAX_CHAN_ID
17311731
int

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@
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 (0) /*!< Touch minimum channel number */
638+
#define SOC_TOUCH_MIN_CHAN_ID (0U) /*!< Touch minimum channel number */
639639
#define SOC_TOUCH_MAX_CHAN_ID (13) /*!< Touch maximum channel number */
640640

641641
/* Touch Sensor Features */

components/ulp/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ if(CONFIG_ULP_COPROC_TYPE_FSM OR CONFIG_ULP_COPROC_TYPE_RISCV)
4646
"ulp_riscv/ulp_riscv.c"
4747
"ulp_riscv/ulp_riscv_lock.c"
4848
"ulp_riscv/ulp_riscv_i2c.c")
49-
if(CONFIG_SOC_TOUCH_SENSOR_SUPPORTED)
50-
list(APPEND srcs "ulp_riscv/ulp_riscv_touch.c")
51-
endif()
5249
endif()
53-
5450
endif()
5551

5652
if(CONFIG_ULP_COPROC_TYPE_LP_CORE)
@@ -81,10 +77,6 @@ if(CONFIG_ULP_COPROC_TYPE_LP_CORE)
8177
list(APPEND srcs "lp_core/lp_core_etm.c")
8278
endif()
8379

84-
if(CONFIG_SOC_TOUCH_SENSOR_SUPPORTED)
85-
list(APPEND srcs "lp_core/lp_core_touch.c")
86-
endif()
87-
8880
if(CONFIG_SOC_LP_ADC_SUPPORTED)
8981
list(APPEND srcs "lp_core/shared/ulp_lp_core_lp_adc_shared.c")
9082
endif()

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}

components/ulp/lp_core/lp_core/include/ulp_lp_core_touch.h

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,81 +13,80 @@ extern "C" {
1313
#endif
1414

1515
/**
16-
* @brief Read raw data of touch sensor on the ULP RISC-V core
17-
* @note Refer `touch_pad_read_raw_data()` for more details
16+
* @brief Read raw data of touch sensor on the LP core
1817
*
19-
* @param touch_num Touch pad index
20-
* @param raw_data Pointer to accept touch sensor value
21-
* @return esp_err_t ESP_OK when successful
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
2222
*/
2323
esp_err_t lp_core_touch_pad_read_raw_data(int touch_num, uint32_t *raw_data);
2424

2525
/**
26-
* @brief Read benchmark of touch sensor on the ULP RISC-V core
27-
* @note Refer `touch_pad_read_benchmark()` for more details
26+
* @brief Read benchmark of touch sensor on the LP core
2827
*
29-
* @param touch_num Touch pad index
30-
* @param benchmark Pointer to accept touch sensor benchmark value
31-
* @return esp_err_t ESP_OK when successful
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
3232
*/
3333
esp_err_t lp_core_touch_pad_read_benchmark(int touch_num, uint32_t *benchmark);
3434

3535
/**
36-
* @brief Read the filtered (smoothened) touch sensor data on the ULP RISC-V core
37-
* @note Refer `touch_pad_filter_read_smooth()` for more details
36+
* @brief Read the filtered (smoothened) touch sensor data on the LP core
3837
*
39-
* @param touch_num Touch pad index
40-
* @param smooth_data Pointer to accept smoothened touch sensor value
41-
* @return esp_err_t ESP_OK when successful
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
4242
*/
4343
esp_err_t lp_core_touch_pad_filter_read_smooth(int touch_num, uint32_t *smooth_data);
4444

4545
/**
4646
* @brief Force reset benchmark to raw data of touch sensor.
47-
* @note Refer `touch_pad_reset_benchmark()` for more details
4847
*
49-
* @param touch_num Touch pad index (TOUCH_PAD_MAX resets basaline of all channels)
48+
* @param[in] touch_num Touch pad index
49+
* @param[in] mask Mask of the sample freuqencies that need to be reset
5050
* @return esp_err_t ESP_OK when successful
5151
*/
52-
esp_err_t lp_core_touch_pad_reset_benchmark(int touch_num);
52+
esp_err_t lp_core_touch_pad_reset_benchmark(int touch_num, uint32_t mask);
5353

5454
/**
55-
* @brief Read raw data of touch sensor sleep channel on the ULP RISC-V core
56-
* @note Refer `touch_pad_sleep_channel_read_data()` for more details
55+
* @brief Read raw data of touch sensor sleep channel on the LP core
5756
*
58-
* @param touch_num Touch pad index (Only one touch sensor channel is supported in deep sleep)
59-
* @param raw_data Pointer to accept touch sensor value
60-
* @return esp_err_t ESP_OK when successful
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
6161
*/
6262
esp_err_t lp_core_touch_pad_sleep_channel_read_data(int touch_num, uint32_t *raw_data);
6363

6464
/**
65-
* @brief Read benchmark of touch sensor sleep channel on the ULP RISC-V core
66-
* @note Refer `touch_pad_sleep_channel_read_benchmark()` for more details
65+
* @brief Read benchmark of touch sensor sleep channel on the LP core
6766
*
68-
* @param touch_num Touch pad index (Only one touch sensor channel is supported in deep sleep)
69-
* @param benchmark Pointer to accept touch sensor benchmark value
70-
* @return esp_err_t ESP_OK when successful
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
7171
*/
7272
esp_err_t lp_core_touch_pad_sleep_channel_read_benchmark(int touch_num, uint32_t *benchmark);
7373

7474
/**
75-
* @brief Read the filtered (smoothened) touch sensor sleep channel data on the ULP RISC-V core
76-
* @note Refer `touch_pad_sleep_channel_read_smooth()` for more details
75+
* @brief Read the filtered (smoothened) touch sensor sleep channel data on the LP core
7776
*
78-
* @param touch_num Touch pad index (Only one touch sensor channel is supported in deep sleep)
79-
* @param smooth_data Pointer to accept smoothened touch sensor value
80-
* @return esp_err_t ESP_OK when successful
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
8181
*/
8282
esp_err_t lp_core_touch_pad_sleep_channel_read_smooth(int touch_num, uint32_t *smooth_data);
8383

8484
/**
8585
* @brief Reset benchmark of touch sensor sleep channel.
86-
* @note Refer `touch_pad_sleep_channel_reset_benchmark()` for more details
87-
*
86+
* @param[in] mask Mask of the sample freuqencies that need to be reset
8887
* @return esp_err_t ESP_OK when successful
8988
*/
90-
esp_err_t lp_core_touch_pad_sleep_channel_reset_benchmark(void);
89+
esp_err_t lp_core_touch_pad_sleep_channel_reset_benchmark(uint32_t mask);
9190

9291
#ifdef __cplusplus
9392
}

components/ulp/lp_core/lp_core/lp_core_touch.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#include "ulp_riscv_touch_ulp_core.h"
87
#include "soc/soc_caps.h"
98
#include "hal/touch_sensor_ll.h"
9+
#include "esp_err.h"
1010

1111
/* Check Touch Channel correctness */
12-
#define ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(channel) \
12+
#define LP_CORE_TOUCH_CHANNEL_CHECK_AND_RETURN(channel) \
1313
{ \
1414
if (channel >= SOC_TOUCH_MAX_CHAN_ID || \
1515
channel < SOC_TOUCH_MIN_CHAN_ID) { \
1616
return ESP_ERR_INVALID_ARG; \
1717
} \
1818
} \
1919

20-
esp_err_t ulp_riscv_touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data)
20+
esp_err_t lp_core_touch_pad_read_raw_data(int touch_num, uint32_t *raw_data)
2121
{
2222
/* Check Arguments */
2323
if (!raw_data) {
2424
return ESP_ERR_INVALID_ARG;
2525
}
26-
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
26+
LP_CORE_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
2727

2828
/* Read raw touch data */
2929
uint32_t engaged_sampler_cnt = touch_ll_sample_cfg_get_engaged_num();
@@ -35,13 +35,13 @@ esp_err_t ulp_riscv_touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw
3535
return ESP_OK;
3636
}
3737

38-
esp_err_t ulp_riscv_touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark)
38+
esp_err_t lp_core_touch_pad_read_benchmark(int touch_num, uint32_t *benchmark)
3939
{
4040
/* Check Arguments */
4141
if (!benchmark) {
4242
return ESP_ERR_INVALID_ARG;
4343
}
44-
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
44+
LP_CORE_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
4545

4646
/* Read benchmark data */
4747
uint32_t engaged_sampler_cnt = touch_ll_sample_cfg_get_engaged_num();
@@ -52,13 +52,13 @@ esp_err_t ulp_riscv_touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *be
5252
return ESP_OK;
5353
}
5454

55-
esp_err_t ulp_riscv_touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth_data)
55+
esp_err_t lp_core_touch_pad_filter_read_smooth(int touch_num, uint32_t *smooth_data)
5656
{
5757
/* Check Arguments */
5858
if (!smooth_data) {
5959
return ESP_ERR_INVALID_ARG;
6060
}
61-
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
61+
LP_CORE_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
6262

6363
/* Read smoothened touch sensor data */
6464
uint32_t engaged_sampler_cnt = touch_ll_sample_cfg_get_engaged_num();
@@ -69,26 +69,25 @@ esp_err_t ulp_riscv_touch_pad_filter_read_smooth(touch_pad_t touch_num, uint32_t
6969
return ESP_OK;
7070
}
7171

72-
esp_err_t ulp_riscv_touch_pad_reset_benchmark(touch_pad_t touch_num)
72+
esp_err_t lp_core_touch_pad_reset_benchmark(int touch_num, uint32_t mask)
7373
{
74+
(void) mask; // Currently not support, reserved for future use
7475
/* Check Arguments */
75-
if (touch_num > TOUCH_PAD_MAX || touch_num < 0) {
76-
return ESP_ERR_INVALID_ARG;
77-
}
76+
LP_CORE_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
7877

7978
/* Reset benchmark */
8079
touch_ll_reset_chan_benchmark(BIT(touch_num));
8180

8281
return ESP_OK;
8382
}
8483

85-
esp_err_t ulp_riscv_touch_pad_sleep_channel_read_data(touch_pad_t touch_num, uint32_t *raw_data)
84+
esp_err_t lp_core_touch_pad_sleep_channel_read_data(int touch_num, uint32_t *raw_data)
8685
{
8786
/* Check Arguments */
8887
if (!raw_data) {
8988
return ESP_ERR_INVALID_ARG;
9089
}
91-
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
90+
LP_CORE_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
9291

9392
/* Read raw touch data */
9493
uint32_t engaged_sampler_cnt = touch_ll_sample_cfg_get_engaged_num();
@@ -100,13 +99,13 @@ esp_err_t ulp_riscv_touch_pad_sleep_channel_read_data(touch_pad_t touch_num, uin
10099
return ESP_OK;
101100
}
102101

103-
esp_err_t ulp_riscv_touch_pad_sleep_channel_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark)
102+
esp_err_t lp_core_touch_pad_sleep_channel_read_benchmark(int touch_num, uint32_t *benchmark)
104103
{
105104
/* Check Arguments */
106105
if (!benchmark) {
107106
return ESP_ERR_INVALID_ARG;
108107
}
109-
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
108+
LP_CORE_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
110109

111110
/* Read benchmark data */
112111
uint32_t engaged_sampler_cnt = touch_ll_sample_cfg_get_engaged_num();
@@ -117,13 +116,13 @@ esp_err_t ulp_riscv_touch_pad_sleep_channel_read_benchmark(touch_pad_t touch_num
117116
return ESP_OK;
118117
}
119118

120-
esp_err_t ulp_riscv_touch_pad_sleep_channel_read_smooth(touch_pad_t touch_num, uint32_t *smooth_data)
119+
esp_err_t lp_core_touch_pad_sleep_channel_read_smooth(int touch_num, uint32_t *smooth_data)
121120
{
122121
/* Check Arguments */
123122
if (!smooth_data) {
124123
return ESP_ERR_INVALID_ARG;
125124
}
126-
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
125+
LP_CORE_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
127126

128127
/* Read smoothened touch sensor data */
129128
uint32_t engaged_sampler_cnt = touch_ll_sample_cfg_get_engaged_num();
@@ -134,8 +133,9 @@ esp_err_t ulp_riscv_touch_pad_sleep_channel_read_smooth(touch_pad_t touch_num, u
134133
return ESP_OK;
135134
}
136135

137-
esp_err_t ulp_riscv_touch_pad_sleep_channel_reset_benchmark(void)
136+
esp_err_t lp_core_touch_pad_sleep_channel_reset_benchmark(uint32_t mask)
138137
{
138+
(void) mask; // Currently not support, reserved for future use
139139
/* Reset benchmark */
140140
touch_ll_sleep_reset_benchmark();
141141

examples/system/.build-test-rules.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ examples/system/ulp/lp_core/lp_spi:
334334
depends_components:
335335
- ulp
336336

337+
examples/system/ulp/lp_core/lp_touch:
338+
enable:
339+
- if: SOC_TOUCH_SENSOR_SUPPORTED == 1 and (SOC_DEEP_SLEEP_SUPPORTED == 1 and SOC_LP_CORE_SUPPORTED == 1)
340+
depends_components:
341+
- ulp
342+
337343
examples/system/ulp/lp_core/lp_uart/lp_uart_char_seq_wakeup:
338344
disable:
339345
- if: (SOC_ULP_LP_UART_SUPPORTED != 1)

0 commit comments

Comments
 (0)