mirror of
https://github.com/espressif/esp-idf.git
synced 2026-04-27 19:13:21 +00:00
feat(ulp_touch): add example for lp_touch
This commit is contained in:
@@ -46,11 +46,7 @@ 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)
|
||||
@@ -81,10 +77,6 @@ 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()
|
||||
|
||||
@@ -132,6 +132,11 @@ function(ulp_apply_default_sources ulp_app_name)
|
||||
"${IDF_PATH}/components/ulp/lp_core/shared/ulp_lp_core_lp_vad_shared.c"
|
||||
"${IDF_PATH}/components/ulp/lp_core/shared/ulp_lp_core_critical_section_shared.c")
|
||||
|
||||
if(CONFIG_SOC_TOUCH_SENSOR_SUPPORTED)
|
||||
list(APPEND ULP_S_SOURCES
|
||||
"${IDF_PATH}/components/ulp/lp_core/lp_core/lp_core_touch.c")
|
||||
endif()
|
||||
|
||||
set(target_folder ${IDF_TARGET})
|
||||
|
||||
target_link_options(${ulp_app_name}
|
||||
|
||||
@@ -13,81 +13,80 @@ 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
|
||||
* @brief Read raw data of touch sensor on the LP core
|
||||
*
|
||||
* @param touch_num Touch pad index
|
||||
* @param raw_data Pointer to accept touch sensor value
|
||||
* @return esp_err_t ESP_OK when successful
|
||||
* @param[in] touch_num Touch pad index
|
||||
* @param[out] raw_data Raw data buffer pointer to accept touch sensor raw value,
|
||||
* buffer size should be equal to the number of enabled sampling frequencies
|
||||
* @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
|
||||
* @brief Read benchmark of touch sensor on the LP core
|
||||
*
|
||||
* @param touch_num Touch pad index
|
||||
* @param benchmark Pointer to accept touch sensor benchmark value
|
||||
* @return esp_err_t ESP_OK when successful
|
||||
* @param[in] touch_num Touch pad index
|
||||
* @param[out] benchmark Benchmark data buffer pointer to accept touch sensor benchmark value,
|
||||
* buffer size should be equal to the number of enabled sampling frequencies
|
||||
* @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
|
||||
* @brief Read the filtered (smoothened) touch sensor data on the LP core
|
||||
*
|
||||
* @param touch_num Touch pad index
|
||||
* @param smooth_data Pointer to accept smoothened touch sensor value
|
||||
* @return esp_err_t ESP_OK when successful
|
||||
* @param[in] touch_num Touch pad index
|
||||
* @param[out] smooth_data Smooth data buffer pointer to accept touch sensor smooth value,
|
||||
* buffer size should be equal to the number of enabled sampling frequencies
|
||||
* @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)
|
||||
* @param[in] touch_num Touch pad index
|
||||
* @param[in] mask Mask of the sample freuqencies that need to be reset
|
||||
* @return esp_err_t ESP_OK when successful
|
||||
*/
|
||||
esp_err_t lp_core_touch_pad_reset_benchmark(int touch_num);
|
||||
esp_err_t lp_core_touch_pad_reset_benchmark(int touch_num, uint32_t mask);
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @brief Read raw data of touch sensor sleep channel on the LP core
|
||||
*
|
||||
* @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
|
||||
* @param[in] touch_num Touch pad index that has been registered as sleep channel
|
||||
* @param[out] raw_data Raw data buffer pointer to accept touch sensor raw value,
|
||||
* buffer size should be equal to the number of enabled sampling frequencies
|
||||
* @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
|
||||
* @brief Read benchmark of touch sensor sleep channel on the LP core
|
||||
*
|
||||
* @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
|
||||
* @param[in] touch_num Touch pad index that has been registered as sleep channel
|
||||
* @param[out] benchmark Benchmark data buffer pointer to accept touch sensor benchmark value,
|
||||
* buffer size should be equal to the number of enabled sampling frequencies
|
||||
* @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
|
||||
* @brief Read the filtered (smoothened) touch sensor sleep channel data on the LP core
|
||||
*
|
||||
* @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
|
||||
* @param[in] touch_num Touch pad index that has been registered as sleep channel
|
||||
* @param[out] smooth_dat Smooth data buffer pointer to accept touch sensor smooth value,
|
||||
* buffer size should be equal to the number of enabled sampling frequencies
|
||||
* @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
|
||||
*
|
||||
* @param[in] mask Mask of the sample freuqencies that need to be reset
|
||||
* @return esp_err_t ESP_OK when successful
|
||||
*/
|
||||
esp_err_t lp_core_touch_pad_sleep_channel_reset_benchmark(void);
|
||||
esp_err_t lp_core_touch_pad_sleep_channel_reset_benchmark(uint32_t mask);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "ulp_riscv_touch_ulp_core.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "hal/touch_sensor_ll.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
/* Check Touch Channel correctness */
|
||||
#define ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(channel) \
|
||||
#define LP_CORE_TOUCH_CHANNEL_CHECK_AND_RETURN(channel) \
|
||||
{ \
|
||||
if (channel >= SOC_TOUCH_MAX_CHAN_ID || \
|
||||
channel < SOC_TOUCH_MIN_CHAN_ID) { \
|
||||
@@ -17,13 +17,13 @@
|
||||
} \
|
||||
} \
|
||||
|
||||
esp_err_t ulp_riscv_touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data)
|
||||
esp_err_t lp_core_touch_pad_read_raw_data(int 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);
|
||||
LP_CORE_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read raw touch data */
|
||||
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
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t ulp_riscv_touch_pad_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark)
|
||||
esp_err_t lp_core_touch_pad_read_benchmark(int touch_num, uint32_t *benchmark)
|
||||
{
|
||||
/* Check Arguments */
|
||||
if (!benchmark) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
LP_CORE_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read benchmark data */
|
||||
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
|
||||
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 lp_core_touch_pad_filter_read_smooth(int 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);
|
||||
LP_CORE_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read smoothened touch sensor data */
|
||||
uint32_t engaged_sampler_cnt = touch_ll_sample_cfg_get_engaged_num();
|
||||
@@ -69,12 +69,11 @@ 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 lp_core_touch_pad_reset_benchmark(int touch_num, uint32_t mask)
|
||||
{
|
||||
(void) mask; // Currently not support, reserved for future use
|
||||
/* Check Arguments */
|
||||
if (touch_num > TOUCH_PAD_MAX || touch_num < 0) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
LP_CORE_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Reset benchmark */
|
||||
touch_ll_reset_chan_benchmark(BIT(touch_num));
|
||||
@@ -82,13 +81,13 @@ 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 lp_core_touch_pad_sleep_channel_read_data(int 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);
|
||||
LP_CORE_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read raw touch data */
|
||||
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
|
||||
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 lp_core_touch_pad_sleep_channel_read_benchmark(int touch_num, uint32_t *benchmark)
|
||||
{
|
||||
/* Check Arguments */
|
||||
if (!benchmark) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ULP_RISCV_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
LP_CORE_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read benchmark data */
|
||||
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
|
||||
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 lp_core_touch_pad_sleep_channel_read_smooth(int 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);
|
||||
LP_CORE_TOUCH_CHANNEL_CHECK_AND_RETURN(touch_num);
|
||||
|
||||
/* Read smoothened touch sensor data */
|
||||
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
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t ulp_riscv_touch_pad_sleep_channel_reset_benchmark(void)
|
||||
esp_err_t lp_core_touch_pad_sleep_channel_reset_benchmark(uint32_t mask)
|
||||
{
|
||||
(void) mask; // Currently not support, reserved for future use
|
||||
/* Reset benchmark */
|
||||
touch_ll_sleep_reset_benchmark();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user