mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
touch_sleep: complete the support for touch sleep
This commit is contained in:
parent
0f1eb82acd
commit
62ab4456a8
@ -23,6 +23,7 @@
|
|||||||
#include "soc/soc_caps.h"
|
#include "soc/soc_caps.h"
|
||||||
#include "driver/rtc_io.h"
|
#include "driver/rtc_io.h"
|
||||||
#include "hal/rtc_io_hal.h"
|
#include "hal/rtc_io_hal.h"
|
||||||
|
#include "hal/rtc_cntl_ll.h"
|
||||||
|
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
|
||||||
|
@ -47,6 +47,11 @@ static inline void rtc_cntl_ll_ulp_int_clear(void)
|
|||||||
REG_SET_BIT(RTC_CNTL_INT_CLR_REG, RTC_CNTL_SAR_INT_CLR);
|
REG_SET_BIT(RTC_CNTL_INT_CLR_REG, RTC_CNTL_SAR_INT_CLR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void rtc_cntl_ll_timer2_set_touch_wait_cycle(uint32_t wait_cycle)
|
||||||
|
{
|
||||||
|
REG_SET_FIELD(RTC_CNTL_TIMER2_REG, RTC_CNTL_ULPCP_TOUCH_START_WAIT, wait_cycle);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -47,6 +47,11 @@ static inline void rtc_cntl_ll_ulp_int_clear(void)
|
|||||||
REG_SET_BIT(RTC_CNTL_INT_CLR_REG, RTC_CNTL_COCPU_TRAP_INT_CLR);
|
REG_SET_BIT(RTC_CNTL_INT_CLR_REG, RTC_CNTL_COCPU_TRAP_INT_CLR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void rtc_cntl_ll_timer2_set_touch_wait_cycle(uint32_t wait_cycle)
|
||||||
|
{
|
||||||
|
REG_SET_FIELD(RTC_CNTL_TIMER2_REG, RTC_CNTL_ULPCP_TOUCH_START_WAIT, wait_cycle);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -127,6 +127,11 @@ static inline void rtc_cntl_ll_ulp_int_clear(void)
|
|||||||
REG_SET_BIT(RTC_CNTL_INT_CLR_REG, RTC_CNTL_COCPU_TRAP_INT_CLR);
|
REG_SET_BIT(RTC_CNTL_INT_CLR_REG, RTC_CNTL_COCPU_TRAP_INT_CLR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void rtc_cntl_ll_timer2_set_touch_wait_cycle(uint32_t wait_cycle)
|
||||||
|
{
|
||||||
|
REG_SET_FIELD(RTC_CNTL_TIMER2_REG, RTC_CNTL_ULPCP_TOUCH_START_WAIT, wait_cycle);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -292,7 +292,7 @@
|
|||||||
/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/
|
/*-------------------------- TOUCH SENSOR CAPS -------------------------------*/
|
||||||
#define SOC_TOUCH_VERSION_2 (1) /*!<Hardware version of touch sensor */
|
#define SOC_TOUCH_VERSION_2 (1) /*!<Hardware version of touch sensor */
|
||||||
#define SOC_TOUCH_SENSOR_NUM (15) /*!<15 Touch channels */
|
#define SOC_TOUCH_SENSOR_NUM (15) /*!<15 Touch channels */
|
||||||
#define SOC_TOUCH_PROXIMITY_CHANNEL_NUM (3) /* Sopport touch proximity channel number. */
|
#define SOC_TOUCH_PROXIMITY_CHANNEL_NUM (3) /*!<Support touch proximity channel number. */
|
||||||
|
|
||||||
#define SOC_TOUCH_PAD_THRESHOLD_MAX (0x1FFFFF) /*!<If set touch threshold max value, The touch sensor can't be in touched status */
|
#define SOC_TOUCH_PAD_THRESHOLD_MAX (0x1FFFFF) /*!<If set touch threshold max value, The touch sensor can't be in touched status */
|
||||||
#define SOC_TOUCH_PAD_MEASURE_WAIT_MAX (0xFF) /*!<The timer frequency is 8Mhz, the max value is 0xff */
|
#define SOC_TOUCH_PAD_MEASURE_WAIT_MAX (0xFF) /*!<The timer frequency is 8Mhz, the max value is 0xff */
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
menu "Touch Element"
|
|
||||||
|
|
||||||
config TE_SKIP_DSLEEP_WAKEUP_CALIBRATION
|
|
||||||
bool "Enable skip deep sleep wakeup calibration"
|
|
||||||
default n
|
|
||||||
help
|
|
||||||
This option allows to store all Touch Sensor channels' threshold into RTC Fast Memory. So that Touch Sensor
|
|
||||||
threshold will only be configured once after Power-on Reset.
|
|
||||||
|
|
||||||
endmenu
|
|
@ -94,6 +94,14 @@ typedef struct {
|
|||||||
touch_pad_t guard_channel; //!< Waterproof Guard-Sensor channel number (index)
|
touch_pad_t guard_channel; //!< Waterproof Guard-Sensor channel number (index)
|
||||||
float guard_sensitivity; //!< Waterproof Guard-Sensor sensitivity
|
float guard_sensitivity; //!< Waterproof Guard-Sensor sensitivity
|
||||||
} touch_elem_waterproof_config_t;
|
} touch_elem_waterproof_config_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Touch element sleep configuration passed to touch_element_enable_light_sleep or touch_element_enable_deep_sleep
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
uint16_t sample_count; //!< scan times in every measurement, normally equal to the 'sample_count' field in 'touch_elem_hw_config_t'.
|
||||||
|
uint16_t sleep_cycle; //!< sleep_cycle decide the interval between two measurements, t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency), normally equal to the 'sleep_cycle' field in 'touch_elem_hw_config_t'.
|
||||||
|
} touch_elem_sleep_config_t;
|
||||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
typedef void *touch_elem_handle_t; //!< Touch element handle type
|
typedef void *touch_elem_handle_t; //!< Touch element handle type
|
||||||
typedef uint32_t touch_elem_event_t; //!< Touch element event type
|
typedef uint32_t touch_elem_event_t; //!< Touch element event type
|
||||||
@ -256,20 +264,74 @@ esp_err_t touch_element_waterproof_add(touch_elem_handle_t element_handle);
|
|||||||
*/
|
*/
|
||||||
esp_err_t touch_element_waterproof_remove(touch_elem_handle_t element_handle);
|
esp_err_t touch_element_waterproof_remove(touch_elem_handle_t element_handle);
|
||||||
|
|
||||||
typedef struct {
|
/**
|
||||||
uint16_t scan_time;
|
* @brief Touch element light sleep initialization
|
||||||
uint16_t sleep_time;
|
*
|
||||||
} touch_elem_sleep_config_t;
|
* @note It should be called after touch button element installed.
|
||||||
|
* Any of installed touch element can wake up from the light sleep
|
||||||
|
*
|
||||||
|
* @param[in] sleep_config Sleep configurations, set NULL to use default config
|
||||||
|
* @return
|
||||||
|
* - ESP_OK: Successfully initialized touch sleep
|
||||||
|
* - ESP_ERR_INVALID_STATE: Touch element is not installed or touch sleep has been installed
|
||||||
|
* - ESP_ERR_INVALID_ARG: inputed argument is NULL
|
||||||
|
* - ESP_ERR_NO_MEM: no memory for touch sleep struct
|
||||||
|
* - ESP_ERR_NOT_SUPPORTED: inputed wakeup_elem_handle is not touch_button_handle_t type, currently only touch_button_handle_t supported
|
||||||
|
*/
|
||||||
|
esp_err_t touch_element_enable_light_sleep(const touch_elem_sleep_config_t *sleep_config);
|
||||||
|
|
||||||
esp_err_t touch_element_sleep_install(touch_elem_sleep_config_t *sleep_config);
|
/**
|
||||||
void touch_element_sleep_uninstall(void);
|
* @brief Release the resources that allocated by touch_element_enable_deep_sleep()
|
||||||
esp_err_t touch_element_sleep_add_wakeup(touch_elem_handle_t element_handle);
|
*
|
||||||
esp_err_t touch_element_sleep_remove_wakeup(touch_elem_handle_t element_handle);
|
* This function will also disable the touch sensor to wake up the device
|
||||||
esp_err_t touch_element_sleep_add_wakeup_channel(touch_pad_t wakeup_channel);
|
*
|
||||||
esp_err_t touch_element_sleep_remove_wakeup_channel(touch_pad_t wakeup_channel);
|
* @return
|
||||||
#ifdef CONFIG_TE_SKIP_DSLEEP_WAKEUP_CALIBRATION
|
* - ESP_OK: uninstall success
|
||||||
esp_err_t touch_element_sleep_config_wakeup_calibration(touch_elem_handle_t element_handle, bool en);
|
* - ESP_ERR_INVALID_STATE: touch sleep has not been installed
|
||||||
#endif
|
*/
|
||||||
|
esp_err_t touch_element_disable_light_sleep(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Touch element deep sleep initialization
|
||||||
|
*
|
||||||
|
* This function will enable the device wake-up from deep sleep or light sleep by touch sensor
|
||||||
|
*
|
||||||
|
* @note It should be called after touch button element installed.
|
||||||
|
* Only one touch button can be registered as the deep sleep wake-up button
|
||||||
|
*
|
||||||
|
* @param[in] wakeup_elem_handle Touch element instance handle for waking up the device, only support button element
|
||||||
|
* @param[in] sleep_config Sleep configurations, set NULL to use default config
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* - ESP_OK: Successfully initialized touch sleep
|
||||||
|
* - ESP_ERR_INVALID_STATE: Touch element is not installed or touch sleep has been installed
|
||||||
|
* - ESP_ERR_INVALID_ARG: inputed argument is NULL
|
||||||
|
* - ESP_ERR_NO_MEM: no memory for touch sleep struct
|
||||||
|
* - ESP_ERR_NOT_SUPPORTED: inputed wakeup_elem_handle is not touch_button_handle_t type, currently only touch_button_handle_t supported
|
||||||
|
*/
|
||||||
|
esp_err_t touch_element_enable_deep_sleep(touch_elem_handle_t wakeup_elem_handle, const touch_elem_sleep_config_t *sleep_config);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Release the resources that allocated by touch_element_enable_deep_sleep()
|
||||||
|
*
|
||||||
|
* This function will also disable the touch sensor to wake up the device
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* - ESP_OK: uninstall success
|
||||||
|
* - ESP_ERR_INVALID_STATE: touch sleep has not been installed
|
||||||
|
*/
|
||||||
|
esp_err_t touch_element_disable_deep_sleep(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Touch element wake up calibrations
|
||||||
|
*
|
||||||
|
* This function will also disable the touch sensor to wake up the device
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* - ESP_OK: uninstall success
|
||||||
|
* - ESP_ERR_INVALID_STATE: touch sleep has not been installed
|
||||||
|
*/
|
||||||
|
esp_err_t touch_element_sleep_enable_wakeup_calibration(touch_elem_handle_t element_handle, bool en);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -56,9 +56,7 @@ typedef struct {
|
|||||||
touch_pad_t channel; //!< Touch channel number(index)
|
touch_pad_t channel; //!< Touch channel number(index)
|
||||||
te_dev_type_t type; //!< Touch channel type TODO: need to refactor as te_class_type_t
|
te_dev_type_t type; //!< Touch channel type TODO: need to refactor as te_class_type_t
|
||||||
te_dev_state_t state; //!< Touch channel current state
|
te_dev_state_t state; //!< Touch channel current state
|
||||||
#ifdef CONFIG_TE_SKIP_DSLEEP_WAKEUP_CALIBRATION
|
|
||||||
bool is_use_last_threshold;
|
bool is_use_last_threshold;
|
||||||
#endif
|
|
||||||
} te_dev_t;
|
} te_dev_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -74,7 +72,6 @@ typedef struct {
|
|||||||
esp_err_t (*set_threshold) (void);
|
esp_err_t (*set_threshold) (void);
|
||||||
void (*process_state) (void);
|
void (*process_state) (void);
|
||||||
void (*update_state) (touch_pad_t, te_state_t);
|
void (*update_state) (touch_pad_t, te_state_t);
|
||||||
touch_elem_handle_t (*search_channel_handle) (touch_pad_t);
|
|
||||||
} te_object_methods_t;
|
} te_object_methods_t;
|
||||||
|
|
||||||
/* -------------------------------------------- Waterproof basic type --------------------------------------------- */
|
/* -------------------------------------------- Waterproof basic type --------------------------------------------- */
|
||||||
@ -88,10 +85,10 @@ typedef struct te_waterproof_s* te_waterproof_handle_t;
|
|||||||
/* -------------------------------------------- Sleep basic type --------------------------------------------- */
|
/* -------------------------------------------- Sleep basic type --------------------------------------------- */
|
||||||
struct te_sleep_s {
|
struct te_sleep_s {
|
||||||
touch_elem_handle_t wakeup_handle;
|
touch_elem_handle_t wakeup_handle;
|
||||||
|
#ifdef CONFIG_PM_ENABLE
|
||||||
esp_pm_lock_handle_t pm_lock;
|
esp_pm_lock_handle_t pm_lock;
|
||||||
#ifdef CONFIG_TE_SKIP_DSLEEP_WAKEUP_CALIBRATION
|
|
||||||
uint32_t *non_volatile_threshold;
|
|
||||||
#endif
|
#endif
|
||||||
|
uint32_t *non_volatile_threshold;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct te_sleep_s* te_sleep_handle_t;
|
typedef struct te_sleep_s* te_sleep_handle_t;
|
||||||
@ -187,17 +184,15 @@ void te_object_method_unregister(te_class_type_t object_type);
|
|||||||
bool te_object_check_channel(const touch_pad_t *channel_array, uint8_t channel_sum);
|
bool te_object_check_channel(const touch_pad_t *channel_array, uint8_t channel_sum);
|
||||||
bool waterproof_check_mask_handle(touch_elem_handle_t te_handle);
|
bool waterproof_check_mask_handle(touch_elem_handle_t te_handle);
|
||||||
bool te_is_touch_dsleep_wakeup(void);
|
bool te_is_touch_dsleep_wakeup(void);
|
||||||
inline touch_pad_t te_get_sleep_channel(void);
|
touch_pad_t te_get_sleep_channel(void);
|
||||||
|
|
||||||
bool button_object_handle_check(touch_elem_handle_t element_handle);
|
bool is_button_object_handle(touch_elem_handle_t element_handle);
|
||||||
bool slider_object_handle_check(touch_elem_handle_t element_handle);
|
bool is_slider_object_handle(touch_elem_handle_t element_handle);
|
||||||
bool matrix_object_handle_check(touch_elem_handle_t element_handle);
|
bool is_matrix_object_handle(touch_elem_handle_t element_handle);
|
||||||
|
|
||||||
#ifdef CONFIG_TE_SKIP_DSLEEP_WAKEUP_CALIBRATION
|
void button_enable_wakeup_calibration(te_button_handle_t button_handle, bool en);
|
||||||
void button_config_wakeup_calibration(te_button_handle_t button_handle, bool en);
|
void slider_enable_wakeup_calibration(te_slider_handle_t slider_handle, bool en);
|
||||||
void slider_config_wakeup_calibration(te_slider_handle_t slider_handle, bool en);
|
void matrix_enable_wakeup_calibration(te_matrix_handle_t matrix_handle, bool en);
|
||||||
void matrix_config_wakeup_calibration(te_matrix_handle_t matrix_handle, bool en);
|
|
||||||
#endif
|
|
||||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -40,7 +40,6 @@ static bool button_object_check_channel(touch_pad_t channel_num);
|
|||||||
static esp_err_t button_object_set_threshold(void);
|
static esp_err_t button_object_set_threshold(void);
|
||||||
static void button_object_process_state(void);
|
static void button_object_process_state(void);
|
||||||
static void button_object_update_state(touch_pad_t channel_num, te_state_t channel_state);
|
static void button_object_update_state(touch_pad_t channel_num, te_state_t channel_state);
|
||||||
static te_button_handle_t button_object_search_channel_handle(touch_pad_t channel_num);
|
|
||||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
|
|
||||||
esp_err_t touch_button_install(const touch_button_global_config_t *global_config)
|
esp_err_t touch_button_install(const touch_button_global_config_t *global_config)
|
||||||
@ -269,21 +268,6 @@ static void button_object_update_state(touch_pad_t channel_num, te_state_t chann
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static te_button_handle_t button_object_search_channel_handle(touch_pad_t channel_num)
|
|
||||||
{
|
|
||||||
te_button_handle_list_t *item;
|
|
||||||
te_button_handle_t button_handle = NULL;
|
|
||||||
SLIST_FOREACH(item, &s_te_btn_obj->handle_list, next) {
|
|
||||||
touch_pad_t button_channel = item->button_handle->device->channel;
|
|
||||||
if (channel_num == button_channel) {
|
|
||||||
button_handle = item->button_handle;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return button_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static esp_err_t button_object_add_instance(te_button_handle_t button_handle)
|
static esp_err_t button_object_add_instance(te_button_handle_t button_handle)
|
||||||
{
|
{
|
||||||
te_button_handle_list_t *item = (te_button_handle_list_t *)calloc(1, sizeof(te_button_handle_list_t));
|
te_button_handle_list_t *item = (te_button_handle_list_t *)calloc(1, sizeof(te_button_handle_list_t));
|
||||||
@ -312,7 +296,7 @@ static esp_err_t button_object_remove_instance(te_button_handle_t button_handle)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool button_object_handle_check(touch_elem_handle_t element_handle)
|
bool is_button_object_handle(touch_elem_handle_t element_handle)
|
||||||
{
|
{
|
||||||
te_button_handle_list_t *item;
|
te_button_handle_list_t *item;
|
||||||
xSemaphoreTake(s_te_btn_obj->mutex, portMAX_DELAY);
|
xSemaphoreTake(s_te_btn_obj->mutex, portMAX_DELAY);
|
||||||
@ -376,12 +360,10 @@ static inline void button_dispatch(te_button_handle_t button_handle, touch_elem_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_TE_SKIP_DSLEEP_WAKEUP_CALIBRATION
|
void button_enable_wakeup_calibration(te_button_handle_t button_handle, bool en)
|
||||||
void button_config_wakeup_calibration(te_button_handle_t button_handle, bool en)
|
|
||||||
{
|
{
|
||||||
button_handle->device->is_use_last_threshold = en;
|
button_handle->device->is_use_last_threshold = !en;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Button process
|
* @brief Button process
|
||||||
|
@ -11,11 +11,11 @@
|
|||||||
#include "freertos/queue.h"
|
#include "freertos/queue.h"
|
||||||
#include "esp_sleep.h"
|
#include "esp_sleep.h"
|
||||||
#include "esp_timer.h"
|
#include "esp_timer.h"
|
||||||
#include "esp_log.h"
|
#include "esp_check.h"
|
||||||
#include "hal/touch_sensor_hal.h" //TODO: remove hal
|
#include "hal/touch_sensor_hal.h" //TODO: remove hal
|
||||||
#include "touch_element/touch_element_private.h"
|
#include "touch_element/touch_element_private.h"
|
||||||
|
|
||||||
#include "esp32s2/rom/rtc.h"
|
#include "esp_rom_sys.h"
|
||||||
|
|
||||||
|
|
||||||
#define TE_CLASS_ITEM(cls, cls_type, cls_item) ((&((cls)[cls_type]))->cls_item)
|
#define TE_CLASS_ITEM(cls, cls_type, cls_item) ((&((cls)[cls_type]))->cls_item)
|
||||||
@ -98,14 +98,10 @@ typedef struct {
|
|||||||
SemaphoreHandle_t mutex; //Global resource mutex
|
SemaphoreHandle_t mutex; //Global resource mutex
|
||||||
bool is_set_threshold; //Threshold configuration state bit
|
bool is_set_threshold; //Threshold configuration state bit
|
||||||
uint32_t denoise_channel_raw; //De-noise channel(TO) raw signal
|
uint32_t denoise_channel_raw; //De-noise channel(TO) raw signal
|
||||||
// touch_elem_sleep_config_t *sleep_config;
|
|
||||||
// esp_pm_lock_handle_t pm_lock_handle;
|
|
||||||
} te_obj_t;
|
} te_obj_t;
|
||||||
|
|
||||||
static te_obj_t *s_te_obj = NULL;
|
static te_obj_t *s_te_obj = NULL;
|
||||||
#ifdef CONFIG_TE_SKIP_DSLEEP_WAKEUP_CALIBRATION
|
|
||||||
RTC_FAST_ATTR uint32_t threshold_shadow[TOUCH_PAD_MAX - 1] = {0};
|
RTC_FAST_ATTR uint32_t threshold_shadow[TOUCH_PAD_MAX - 1] = {0};
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal de-noise channel(Touch channel 0) equivalent capacitance table, depends on hardware design
|
* Internal de-noise channel(Touch channel 0) equivalent capacitance table, depends on hardware design
|
||||||
@ -338,15 +334,15 @@ uint32_t te_get_threshold(touch_pad_t channel_num)
|
|||||||
|
|
||||||
bool te_is_touch_dsleep_wakeup(void)
|
bool te_is_touch_dsleep_wakeup(void)
|
||||||
{
|
{
|
||||||
RESET_REASON rtc_reset_reason = rtc_get_reset_reason(0);
|
soc_reset_reason_t reset_reason = esp_rom_get_reset_reason(0);
|
||||||
if (rtc_reset_reason != DEEPSLEEP_RESET) {
|
if (reset_reason != RESET_REASON_CORE_DEEP_SLEEP) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause();
|
esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause();
|
||||||
return wakeup_reason == ESP_SLEEP_WAKEUP_TOUCHPAD;
|
return wakeup_reason == ESP_SLEEP_WAKEUP_TOUCHPAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline touch_pad_t te_get_sleep_channel(void)
|
touch_pad_t te_get_sleep_channel(void)
|
||||||
{
|
{
|
||||||
touch_pad_sleep_channel_t sleep_channel_info;
|
touch_pad_sleep_channel_t sleep_channel_info;
|
||||||
touch_pad_sleep_channel_get_info(&sleep_channel_info);
|
touch_pad_sleep_channel_get_info(&sleep_channel_info);
|
||||||
@ -413,8 +409,6 @@ static void te_intr_cb(void *arg)
|
|||||||
}
|
}
|
||||||
/*< De-noise channel signal must be read at the time between SCAN_DONE and next measurement beginning(sleep)!!! */
|
/*< De-noise channel signal must be read at the time between SCAN_DONE and next measurement beginning(sleep)!!! */
|
||||||
touch_pad_denoise_read_data(&s_te_obj->denoise_channel_raw); //Update de-noise signal
|
touch_pad_denoise_read_data(&s_te_obj->denoise_channel_raw); //Update de-noise signal
|
||||||
} else {
|
|
||||||
// te_intr_msg.intr_type = TE_INTR_MAX; // Unknown Exception
|
|
||||||
}
|
}
|
||||||
if (need_send_queue) {
|
if (need_send_queue) {
|
||||||
xQueueSendFromISR(s_te_obj->intr_msg_queue, &te_intr_msg, &task_awoken);
|
xQueueSendFromISR(s_te_obj->intr_msg_queue, &te_intr_msg, &task_awoken);
|
||||||
@ -444,12 +438,10 @@ static void te_proc_timer_cb(void *arg)
|
|||||||
if (ret == pdPASS) {
|
if (ret == pdPASS) {
|
||||||
if (te_intr_msg.intr_type == TE_INTR_PRESS || te_intr_msg.intr_type == TE_INTR_RELEASE) {
|
if (te_intr_msg.intr_type == TE_INTR_PRESS || te_intr_msg.intr_type == TE_INTR_RELEASE) {
|
||||||
te_object_update_state(te_intr_msg);
|
te_object_update_state(te_intr_msg);
|
||||||
if (te_intr_msg.intr_type == TE_INTR_RELEASE) {
|
if ((s_te_obj->sleep_handle != NULL) && (te_intr_msg.intr_type == TE_INTR_RELEASE)) {
|
||||||
if (s_te_obj->sleep_handle != NULL) {
|
|
||||||
#ifdef CONFIG_PM_ENABLE
|
#ifdef CONFIG_PM_ENABLE
|
||||||
esp_pm_lock_release(s_te_obj->sleep_handle->pm_lock);
|
esp_pm_lock_release(s_te_obj->sleep_handle->pm_lock);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (te_intr_msg.intr_type == TE_INTR_SCAN_DONE) {
|
} else if (te_intr_msg.intr_type == TE_INTR_SCAN_DONE) {
|
||||||
if (s_te_obj->is_set_threshold != true) {
|
if (s_te_obj->is_set_threshold != true) {
|
||||||
@ -571,9 +563,7 @@ esp_err_t te_dev_init(te_dev_t **device, uint8_t device_num, te_dev_type_t type,
|
|||||||
device[idx]->sens = sens[idx] * divider;
|
device[idx]->sens = sens[idx] * divider;
|
||||||
device[idx]->type = type;
|
device[idx]->type = type;
|
||||||
device[idx]->state = TE_STATE_IDLE;
|
device[idx]->state = TE_STATE_IDLE;
|
||||||
#ifdef CONFIG_TE_SKIP_DSLEEP_WAKEUP_CALIBRATION
|
|
||||||
device[idx]->is_use_last_threshold = false;
|
device[idx]->is_use_last_threshold = false;
|
||||||
#endif
|
|
||||||
esp_err_t ret = touch_pad_config(device[idx]->channel);
|
esp_err_t ret = touch_pad_config(device[idx]->channel);
|
||||||
TE_CHECK(ret == ESP_OK, ret);
|
TE_CHECK(ret == ESP_OK, ret);
|
||||||
}
|
}
|
||||||
@ -587,7 +577,7 @@ void te_dev_deinit(te_dev_t **device, uint8_t device_num)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t te_config_thresh(touch_pad_t channel_num, uint32_t threshold)
|
static esp_err_t te_config_thresh(touch_pad_t channel_num, uint32_t threshold)
|
||||||
{
|
{
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
touch_pad_sleep_channel_t sleep_channel_info;
|
touch_pad_sleep_channel_t sleep_channel_info;
|
||||||
@ -604,15 +594,9 @@ esp_err_t te_dev_set_threshold(te_dev_t *device)
|
|||||||
{
|
{
|
||||||
esp_err_t ret = ESP_OK;
|
esp_err_t ret = ESP_OK;
|
||||||
uint32_t smo_val = 0;
|
uint32_t smo_val = 0;
|
||||||
#ifdef CONFIG_TE_SKIP_DSLEEP_WAKEUP_CALIBRATION
|
|
||||||
if (s_te_obj->sleep_handle == NULL) {
|
if (s_te_obj->sleep_handle && device->is_use_last_threshold) {
|
||||||
ESP_LOGE(TE_TAG, "Touch Element sleep is not installed");
|
|
||||||
return ESP_ERR_INVALID_STATE;
|
|
||||||
}
|
|
||||||
if (device->is_use_last_threshold) {
|
|
||||||
if (te_is_touch_dsleep_wakeup()) { //Deep sleep wakeup reset
|
if (te_is_touch_dsleep_wakeup()) { //Deep sleep wakeup reset
|
||||||
touch_pad_t sleep_channel = te_get_sleep_channel();
|
|
||||||
ets_printf("----config rtc %ld %ld\n", s_te_obj->sleep_handle->non_volatile_threshold[device->channel - 1], sleep_channel);
|
|
||||||
ret = te_config_thresh(device->channel, s_te_obj->sleep_handle->non_volatile_threshold[device->channel - 1]);
|
ret = te_config_thresh(device->channel, s_te_obj->sleep_handle->non_volatile_threshold[device->channel - 1]);
|
||||||
} else { //Other reset
|
} else { //Other reset
|
||||||
smo_val = te_read_smooth_signal(device->channel);
|
smo_val = te_read_smooth_signal(device->channel);
|
||||||
@ -624,11 +608,6 @@ esp_err_t te_dev_set_threshold(te_dev_t *device)
|
|||||||
smo_val = te_read_smooth_signal(device->channel);
|
smo_val = te_read_smooth_signal(device->channel);
|
||||||
ret = te_config_thresh(device->channel, device->sens * smo_val);
|
ret = te_config_thresh(device->channel, device->sens * smo_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
smo_val = te_read_smooth_signal(device->channel);
|
|
||||||
ret = te_config_thresh(device->channel, device->sens * smo_val);
|
|
||||||
#endif
|
|
||||||
ESP_LOGD(TE_DEBUG_TAG, "channel: %"PRIu8", smo_val: %"PRIu32, device->channel, smo_val);
|
ESP_LOGD(TE_DEBUG_TAG, "channel: %"PRIu8", smo_val: %"PRIu32, device->channel, smo_val);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -993,148 +972,146 @@ static void waterproof_guard_update_state(touch_pad_t current_channel, te_state_
|
|||||||
ESP_LOGD(TE_DEBUG_TAG, "waterproof guard state update %d", guard_device->state);
|
ESP_LOGD(TE_DEBUG_TAG, "waterproof guard state update %d", guard_device->state);
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t touch_element_sleep_install(touch_elem_sleep_config_t *sleep_config)
|
esp_err_t touch_element_enable_light_sleep(const touch_elem_sleep_config_t *sleep_config)
|
||||||
{
|
{
|
||||||
TE_CHECK(s_te_obj != NULL, ESP_ERR_INVALID_STATE);
|
TE_CHECK(s_te_obj != NULL, ESP_ERR_INVALID_STATE);
|
||||||
TE_CHECK(s_te_obj->sleep_handle == NULL, ESP_ERR_INVALID_STATE);
|
TE_CHECK(s_te_obj->sleep_handle == NULL, ESP_ERR_INVALID_STATE);
|
||||||
TE_CHECK(sleep_config != NULL, ESP_ERR_INVALID_ARG);
|
uint16_t sample_count = 500;
|
||||||
|
uint16_t sleep_cycle = 0x0f;
|
||||||
s_te_obj->sleep_handle = calloc(1, sizeof(struct te_sleep_s));
|
if (sleep_config) {
|
||||||
if (s_te_obj->sleep_handle == NULL) {
|
sample_count = sleep_config->sample_count;
|
||||||
return ESP_ERR_NO_MEM;
|
sleep_cycle = sleep_config->sleep_cycle;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t ret;
|
s_te_obj->sleep_handle = calloc(1, sizeof(struct te_sleep_s));
|
||||||
touch_pad_sleep_channel_set_work_time(sleep_config->sleep_time, sleep_config->scan_time);
|
TE_CHECK(s_te_obj->sleep_handle, ESP_ERR_NO_MEM);
|
||||||
ret = esp_sleep_enable_touchpad_wakeup();
|
|
||||||
TE_CHECK_GOTO(ret == ESP_OK, cleanup);
|
|
||||||
|
|
||||||
#ifdef CONFIG_TE_SKIP_DSLEEP_WAKEUP_CALIBRATION
|
esp_err_t ret = ESP_OK;
|
||||||
ret = esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_ON);
|
touch_pad_sleep_channel_set_work_time(sleep_cycle, sample_count);
|
||||||
TE_CHECK_GOTO(ret == ESP_OK, cleanup);
|
TE_CHECK_GOTO(esp_sleep_enable_touchpad_wakeup() == ESP_OK, cleanup);
|
||||||
|
|
||||||
|
TE_CHECK_GOTO(esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON) == ESP_OK, cleanup);
|
||||||
s_te_obj->sleep_handle->non_volatile_threshold = threshold_shadow;
|
s_te_obj->sleep_handle->non_volatile_threshold = threshold_shadow;
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_PM_ENABLE
|
#ifdef CONFIG_PM_ENABLE
|
||||||
ret = esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "touch_element", &s_te_obj->sleep_handle->pm_lock);
|
TE_CHECK_GOTO(esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "touch_element", &s_te_obj->sleep_handle->pm_lock) == ESP_OK, cleanup);
|
||||||
TE_CHECK_GOTO(ret == ESP_OK, cleanup);
|
TE_CHECK_GOTO(esp_pm_lock_acquire(s_te_obj->sleep_handle->pm_lock) == ESP_OK, cleanup);
|
||||||
ret = esp_pm_lock_acquire(s_te_obj->sleep_handle->pm_lock);
|
|
||||||
TE_CHECK_GOTO(ret == ESP_OK, cleanup);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
#ifdef CONFIG_PM_ENABLE
|
||||||
if (s_te_obj->sleep_handle->pm_lock != NULL) {
|
if (s_te_obj->sleep_handle->pm_lock != NULL) {
|
||||||
esp_err_t del_ret = esp_pm_lock_delete(s_te_obj->sleep_handle->pm_lock);
|
if (esp_pm_lock_delete(s_te_obj->sleep_handle->pm_lock) != ESP_OK) {
|
||||||
if (del_ret != ESP_OK) {
|
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
TE_FREE_AND_NULL(s_te_obj->sleep_handle);
|
TE_FREE_AND_NULL(s_te_obj->sleep_handle);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void touch_element_sleep_uninstall(void)
|
esp_err_t touch_element_disable_light_sleep(void)
|
||||||
{
|
{
|
||||||
esp_err_t ret;
|
TE_CHECK(s_te_obj->sleep_handle, ESP_ERR_INVALID_STATE);
|
||||||
if (s_te_obj->sleep_handle->pm_lock != NULL) {
|
|
||||||
#ifdef CONFIG_PM_ENABLE
|
#ifdef CONFIG_PM_ENABLE
|
||||||
ret = esp_pm_lock_delete(s_te_obj->sleep_handle->pm_lock);
|
if (s_te_obj->sleep_handle->pm_lock != NULL) {
|
||||||
if (ret != ESP_OK) {
|
/* Sleep channel is going to uninstall, pm lock is not needed anymore,
|
||||||
abort();
|
but we need to make sure that pm lock has been released before delete it. */
|
||||||
}
|
while(esp_pm_lock_release(s_te_obj->sleep_handle->pm_lock) == ESP_OK);
|
||||||
|
esp_err_t ret = esp_pm_lock_delete(s_te_obj->sleep_handle->pm_lock);
|
||||||
|
TE_CHECK(ret == ESP_OK, ret);
|
||||||
|
s_te_obj->sleep_handle->pm_lock = NULL;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TOUCHPAD);
|
||||||
|
TE_FREE_AND_NULL(s_te_obj->sleep_handle);
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t touch_element_enable_deep_sleep(touch_elem_handle_t wakeup_elem_handle, const touch_elem_sleep_config_t *sleep_config)
|
||||||
|
{
|
||||||
|
TE_CHECK(s_te_obj != NULL, ESP_ERR_INVALID_STATE);
|
||||||
|
TE_CHECK(s_te_obj->sleep_handle == NULL, ESP_ERR_INVALID_STATE);
|
||||||
|
TE_CHECK(wakeup_elem_handle != NULL, ESP_ERR_INVALID_ARG);
|
||||||
|
TE_CHECK(sleep_config != NULL, ESP_ERR_INVALID_ARG);
|
||||||
|
uint16_t sample_count = 500;
|
||||||
|
uint16_t sleep_cycle = 0x0f;
|
||||||
|
if (sleep_config) {
|
||||||
|
sample_count = sleep_config->sample_count;
|
||||||
|
sleep_cycle = sleep_config->sleep_cycle;
|
||||||
}
|
}
|
||||||
if (s_te_obj->sleep_handle->wakeup_handle != NULL) {
|
|
||||||
te_button_handle_t button_handle = s_te_obj->sleep_handle->wakeup_handle;
|
s_te_obj->sleep_handle = calloc(1, sizeof(struct te_sleep_s));
|
||||||
ret = touch_pad_sleep_channel_enable(button_handle->device->channel, false);
|
TE_CHECK(s_te_obj->sleep_handle, ESP_ERR_NO_MEM);
|
||||||
if (ret != ESP_OK) {
|
|
||||||
|
esp_err_t ret = ESP_OK;
|
||||||
|
touch_pad_sleep_channel_set_work_time(sleep_cycle, sample_count);
|
||||||
|
TE_CHECK_GOTO(esp_sleep_enable_touchpad_wakeup() == ESP_OK, cleanup);
|
||||||
|
|
||||||
|
TE_CHECK_GOTO(esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON) == ESP_OK, cleanup);
|
||||||
|
s_te_obj->sleep_handle->non_volatile_threshold = threshold_shadow;
|
||||||
|
|
||||||
|
#ifdef CONFIG_PM_ENABLE
|
||||||
|
TE_CHECK_GOTO(esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "touch_element", &s_te_obj->sleep_handle->pm_lock) == ESP_OK, cleanup);
|
||||||
|
TE_CHECK_GOTO(esp_pm_lock_acquire(s_te_obj->sleep_handle->pm_lock) == ESP_OK, cleanup);
|
||||||
|
#endif
|
||||||
|
//Only support one channel/element as the deep sleep wakeup channel/element
|
||||||
|
TE_CHECK(is_button_object_handle(wakeup_elem_handle), ESP_ERR_NOT_SUPPORTED);
|
||||||
|
s_te_obj->sleep_handle->wakeup_handle = wakeup_elem_handle;
|
||||||
|
te_button_handle_t button_handle = wakeup_elem_handle;
|
||||||
|
ret = touch_pad_sleep_channel_enable(button_handle->device->channel, true);
|
||||||
|
TE_CHECK(ret == ESP_OK, ret);
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
#ifdef CONFIG_PM_ENABLE
|
||||||
|
if (s_te_obj->sleep_handle->pm_lock != NULL) {
|
||||||
|
if (esp_pm_lock_delete(s_te_obj->sleep_handle->pm_lock) != ESP_OK) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s_te_obj->sleep_handle->pm_lock = NULL;
|
#endif
|
||||||
|
TE_FREE_AND_NULL(s_te_obj->sleep_handle);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t touch_element_disable_deep_sleep(void)
|
||||||
|
{
|
||||||
|
TE_CHECK(s_te_obj->sleep_handle, ESP_ERR_INVALID_STATE);
|
||||||
|
esp_err_t ret;
|
||||||
|
#ifdef CONFIG_PM_ENABLE
|
||||||
|
if (s_te_obj->sleep_handle->pm_lock != NULL) {
|
||||||
|
/* Sleep channel is going to uninstall, pm lock is not needed anymore,
|
||||||
|
but we need to make sure that pm lock has been released before delete it. */
|
||||||
|
while(esp_pm_lock_release(s_te_obj->sleep_handle->pm_lock) == ESP_OK);
|
||||||
|
ret = esp_pm_lock_delete(s_te_obj->sleep_handle->pm_lock);
|
||||||
|
TE_CHECK(ret == ESP_OK, ret);
|
||||||
|
s_te_obj->sleep_handle->pm_lock = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
te_button_handle_t button_handle = s_te_obj->sleep_handle->wakeup_handle;
|
||||||
|
ret = touch_pad_sleep_channel_enable(button_handle->device->channel, false);
|
||||||
|
TE_CHECK(ret == ESP_OK, ret);
|
||||||
|
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TOUCHPAD);
|
||||||
s_te_obj->sleep_handle->wakeup_handle = NULL;
|
s_te_obj->sleep_handle->wakeup_handle = NULL;
|
||||||
TE_FREE_AND_NULL(s_te_obj->sleep_handle);
|
TE_FREE_AND_NULL(s_te_obj->sleep_handle);
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t touch_element_sleep_add_wakeup(touch_elem_handle_t element_handle)
|
|
||||||
{
|
|
||||||
TE_CHECK(s_te_obj->sleep_handle != NULL, ESP_ERR_INVALID_STATE);
|
|
||||||
TE_CHECK(element_handle != NULL, ESP_ERR_INVALID_ARG);
|
|
||||||
if (s_te_obj->sleep_handle->wakeup_handle != NULL) {
|
|
||||||
ESP_LOGE(TE_TAG, "sleep not null");
|
|
||||||
return ESP_ERR_NOT_SUPPORTED; //Only support one channel/element as the deep sleep wakeup channel/element
|
|
||||||
}
|
|
||||||
if (!button_object_handle_check(element_handle)) {
|
|
||||||
ESP_LOGE(TE_TAG, "not button handle");
|
|
||||||
return ESP_ERR_NOT_SUPPORTED; //Only support button element as the deep sleep wakeup channel
|
|
||||||
}
|
|
||||||
s_te_obj->sleep_handle->wakeup_handle = element_handle;
|
|
||||||
te_button_handle_t button_handle = element_handle;
|
|
||||||
esp_err_t ret = touch_pad_sleep_channel_enable(button_handle->device->channel, true);
|
|
||||||
if (ret != ESP_OK) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t touch_element_sleep_remove_wakeup(touch_elem_handle_t element_handle)
|
esp_err_t touch_element_sleep_enable_wakeup_calibration(touch_elem_handle_t element_handle, bool en)
|
||||||
{
|
|
||||||
TE_CHECK(s_te_obj->sleep_handle != NULL, ESP_ERR_INVALID_STATE);
|
|
||||||
TE_CHECK(element_handle != NULL, ESP_ERR_INVALID_ARG);
|
|
||||||
TE_CHECK(s_te_obj->sleep_handle->wakeup_handle != NULL &&
|
|
||||||
s_te_obj->sleep_handle->wakeup_handle == element_handle,
|
|
||||||
ESP_ERR_NOT_FOUND);
|
|
||||||
s_te_obj->sleep_handle->wakeup_handle = NULL;
|
|
||||||
|
|
||||||
te_button_handle_t button_handle = element_handle; //Now we are sure it's absolutely a button element
|
|
||||||
esp_err_t ret = touch_pad_sleep_channel_enable(button_handle->device->channel, false);
|
|
||||||
if (ret != ESP_OK) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t touch_element_sleep_add_wakeup_channel(touch_pad_t wakeup_channel)
|
|
||||||
{
|
|
||||||
TE_CHECK(s_te_obj->sleep_handle != NULL, ESP_ERR_INVALID_STATE);
|
|
||||||
TE_CHECK(wakeup_channel > TOUCH_PAD_NUM0 && wakeup_channel < TOUCH_PAD_MAX, ESP_ERR_INVALID_ARG);
|
|
||||||
touch_pad_sleep_channel_t sleep_channel_info;
|
|
||||||
touch_pad_sleep_channel_get_info(&sleep_channel_info);
|
|
||||||
if (sleep_channel_info.touch_num == wakeup_channel) {
|
|
||||||
return ESP_ERR_INVALID_ARG;
|
|
||||||
}
|
|
||||||
esp_err_t ret = touch_pad_sleep_channel_enable(wakeup_channel, true);
|
|
||||||
if (ret != ESP_OK) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t touch_element_sleep_remove_wakeup_channel(touch_pad_t wakeup_channel)
|
|
||||||
{
|
|
||||||
TE_CHECK(s_te_obj->sleep_handle != NULL, ESP_ERR_INVALID_STATE);
|
|
||||||
TE_CHECK(wakeup_channel > TOUCH_PAD_NUM0 && wakeup_channel < TOUCH_PAD_MAX, ESP_ERR_INVALID_ARG);
|
|
||||||
esp_err_t ret = touch_pad_sleep_channel_enable(wakeup_channel, false);
|
|
||||||
if (ret != ESP_OK) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_TE_SKIP_DSLEEP_WAKEUP_CALIBRATION
|
|
||||||
esp_err_t touch_element_sleep_config_wakeup_calibration(touch_elem_handle_t element_handle, bool en)
|
|
||||||
{
|
{
|
||||||
TE_CHECK(element_handle != NULL, ESP_ERR_INVALID_ARG);
|
TE_CHECK(element_handle != NULL, ESP_ERR_INVALID_ARG);
|
||||||
if (button_object_handle_check(element_handle)) {
|
if (is_button_object_handle(element_handle)) {
|
||||||
button_config_wakeup_calibration(element_handle, en);
|
button_enable_wakeup_calibration(element_handle, en);
|
||||||
} else if (slider_object_handle_check(element_handle)) {
|
} else if (is_slider_object_handle(element_handle)) {
|
||||||
slider_config_wakeup_calibration(element_handle, en);
|
slider_enable_wakeup_calibration(element_handle, en);
|
||||||
} else if (matrix_object_handle_check(element_handle)) {
|
} else if (is_matrix_object_handle(element_handle)) {
|
||||||
matrix_config_wakeup_calibration(element_handle, en);
|
matrix_enable_wakeup_calibration(element_handle, en);
|
||||||
} else {
|
} else {
|
||||||
return ESP_ERR_NOT_FOUND;
|
return ESP_ERR_NOT_FOUND;
|
||||||
}
|
}
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -43,7 +43,6 @@ static bool matrix_object_check_channel(touch_pad_t channel_num);
|
|||||||
static esp_err_t matrix_object_set_threshold(void);
|
static esp_err_t matrix_object_set_threshold(void);
|
||||||
static void matrix_object_process_state(void);
|
static void matrix_object_process_state(void);
|
||||||
static void matrix_object_update_state(touch_pad_t channel_num, te_state_t channel_state);
|
static void matrix_object_update_state(touch_pad_t channel_num, te_state_t channel_state);
|
||||||
static te_matrix_handle_t matrix_object_search_channel_handle(touch_pad_t channel_num);
|
|
||||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
|
|
||||||
esp_err_t touch_matrix_install(const touch_matrix_global_config_t *global_config)
|
esp_err_t touch_matrix_install(const touch_matrix_global_config_t *global_config)
|
||||||
@ -308,24 +307,6 @@ static void matrix_object_update_state(touch_pad_t channel_num, te_state_t chann
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static te_matrix_handle_t matrix_object_search_channel_handle(touch_pad_t channel_num)
|
|
||||||
{
|
|
||||||
te_matrix_handle_list_t *item;
|
|
||||||
te_matrix_handle_t matrix_handle = NULL;
|
|
||||||
SLIST_FOREACH(item, &s_te_mat_obj->handle_list, next) {
|
|
||||||
for (int idx = 0; idx < item->matrix_handle->x_channel_num + item->matrix_handle->y_channel_num; idx++) {
|
|
||||||
touch_pad_t matrix_channel = item->matrix_handle->device[idx]->channel;
|
|
||||||
if (channel_num == matrix_channel) {
|
|
||||||
matrix_handle = item->matrix_handle;
|
|
||||||
goto found;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
found:
|
|
||||||
return matrix_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static esp_err_t matrix_object_add_instance(te_matrix_handle_t matrix_handle)
|
static esp_err_t matrix_object_add_instance(te_matrix_handle_t matrix_handle)
|
||||||
{
|
{
|
||||||
te_matrix_handle_list_t *item = (te_matrix_handle_list_t *)calloc(1, sizeof(te_matrix_handle_list_t));
|
te_matrix_handle_list_t *item = (te_matrix_handle_list_t *)calloc(1, sizeof(te_matrix_handle_list_t));
|
||||||
@ -354,7 +335,7 @@ static esp_err_t matrix_object_remove_instance(te_matrix_handle_t matrix_handle)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool matrix_object_handle_check(touch_elem_handle_t element_handle)
|
bool is_matrix_object_handle(touch_elem_handle_t element_handle)
|
||||||
{
|
{
|
||||||
te_matrix_handle_list_t *item;
|
te_matrix_handle_list_t *item;
|
||||||
xSemaphoreTake(s_te_mat_obj->mutex, portMAX_DELAY);
|
xSemaphoreTake(s_te_mat_obj->mutex, portMAX_DELAY);
|
||||||
@ -436,14 +417,12 @@ static inline void matrix_dispatch(te_matrix_handle_t matrix_handle, touch_elem_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_TE_SKIP_DSLEEP_WAKEUP_CALIBRATION
|
void matrix_enable_wakeup_calibration(te_matrix_handle_t matrix_handle, bool en)
|
||||||
void matrix_config_wakeup_calibration(te_matrix_handle_t matrix_handle, bool en)
|
|
||||||
{
|
{
|
||||||
for (int idx = 0; idx < matrix_handle->x_channel_num + matrix_handle->y_channel_num; ++idx) {
|
for (int idx = 0; idx < matrix_handle->x_channel_num + matrix_handle->y_channel_num; ++idx) {
|
||||||
matrix_handle->device[idx]->is_use_last_threshold = en;
|
matrix_handle->device[idx]->is_use_last_threshold = !en;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Scan the matrix channel
|
* @brief Scan the matrix channel
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -49,7 +49,6 @@ static bool slider_object_check_channel(touch_pad_t channel_num);
|
|||||||
static esp_err_t slider_object_set_threshold(void);
|
static esp_err_t slider_object_set_threshold(void);
|
||||||
static void slider_object_process_state(void);
|
static void slider_object_process_state(void);
|
||||||
static void slider_object_update_state(touch_pad_t channel_num, te_state_t channel_state);
|
static void slider_object_update_state(touch_pad_t channel_num, te_state_t channel_state);
|
||||||
static te_slider_handle_t slider_object_search_channel_handle(touch_pad_t channel_num);
|
|
||||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||||
|
|
||||||
esp_err_t touch_slider_install(const touch_slider_global_config_t *global_config)
|
esp_err_t touch_slider_install(const touch_slider_global_config_t *global_config)
|
||||||
@ -301,24 +300,6 @@ static void slider_object_update_state(touch_pad_t channel_num, te_state_t chann
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static te_slider_handle_t slider_object_search_channel_handle(touch_pad_t channel_num)
|
|
||||||
{
|
|
||||||
te_slider_handle_list_t *item;
|
|
||||||
te_slider_handle_t slider_handle = NULL;
|
|
||||||
SLIST_FOREACH(item, &s_te_sld_obj->handle_list, next) {
|
|
||||||
for (int idx = 0; idx < item->slider_handle->channel_sum; idx++) {
|
|
||||||
touch_pad_t slider_channel = item->slider_handle->device[idx]->channel;
|
|
||||||
if (channel_num == slider_channel) {
|
|
||||||
slider_handle = item->slider_handle;
|
|
||||||
goto found;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
found:
|
|
||||||
return slider_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static esp_err_t slider_object_add_instance(te_slider_handle_t slider_handle)
|
static esp_err_t slider_object_add_instance(te_slider_handle_t slider_handle)
|
||||||
{
|
{
|
||||||
te_slider_handle_list_t *item = (te_slider_handle_list_t *)calloc(1, sizeof(te_slider_handle_list_t));
|
te_slider_handle_list_t *item = (te_slider_handle_list_t *)calloc(1, sizeof(te_slider_handle_list_t));
|
||||||
@ -347,7 +328,7 @@ static esp_err_t slider_object_remove_instance(te_slider_handle_t slider_handle)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool slider_object_handle_check(touch_elem_handle_t element_handle)
|
bool is_slider_object_handle(touch_elem_handle_t element_handle)
|
||||||
{
|
{
|
||||||
te_slider_handle_list_t *item;
|
te_slider_handle_list_t *item;
|
||||||
xSemaphoreTake(s_te_sld_obj->mutex, portMAX_DELAY);
|
xSemaphoreTake(s_te_sld_obj->mutex, portMAX_DELAY);
|
||||||
@ -439,14 +420,12 @@ static inline void slider_dispatch(te_slider_handle_t slider_handle, touch_elem_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_TE_SKIP_DSLEEP_WAKEUP_CALIBRATION
|
void slider_enable_wakeup_calibration(te_slider_handle_t slider_handle, bool en)
|
||||||
void slider_config_wakeup_calibration(te_slider_handle_t slider_handle, bool en)
|
|
||||||
{
|
{
|
||||||
for (int idx = 0; idx < slider_handle->channel_sum; ++idx) {
|
for (int idx = 0; idx < slider_handle->channel_sum; ++idx) {
|
||||||
slider_handle->device[idx]->is_use_last_threshold = en;
|
slider_handle->device[idx]->is_use_last_threshold = !en;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Slider process
|
* @brief Slider process
|
||||||
|
@ -355,6 +355,34 @@ In code, the waterproof configuration may look like as follows:
|
|||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Wakeup from Light/Deep Sleep
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
Only Touch Button can be configured as wake up source.
|
||||||
|
|
||||||
|
Light or deep sleep are both supported to be waken up by touch sensor. For the light sleep, any installed touch button can wake it up. But only the sleep button can wake up from deep sleep, and the touch sensor will do a calibration immediately, the reference value will be calibrated to a wrong value if our finger doesn't remove timely. Though the wrong reference value will recover after the finger remove away and have no affect to the driver logic, if you don't want to see a wrong reference value while waking up from deep sleep, you can call :cpp:func:`touch_element_sleep_enable_wakeup_calibration` to disable the wakeup calibration.
|
||||||
|
|
||||||
|
The Touch Element Wakeup example is available in `example/system/light_sleep` directory.
|
||||||
|
|
||||||
|
.. code-block:: c
|
||||||
|
|
||||||
|
void app_main()
|
||||||
|
{
|
||||||
|
...
|
||||||
|
touch_element_install();
|
||||||
|
touch_button_install(); //Initialize the touch button
|
||||||
|
touch_button_create(&element_handle); //Create a new Touch element
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
// ESP_ERROR_CHECK(touch_element_enable_light_sleep(&sleep_config));
|
||||||
|
ESP_ERROR_CHECK(touch_element_enable_deep_sleep(button_handle[0], &sleep_config));
|
||||||
|
// ESP_ERROR_CHECK(touch_element_sleep_enable_wakeup_calibration(button_handle[0], false)); // (optional) Disable wakeup calibration to prevent updating the base line to a wrong value
|
||||||
|
|
||||||
|
touch_element_start();
|
||||||
|
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
Application Example
|
Application Example
|
||||||
-------------------
|
-------------------
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
# For more information about build system see
|
|
||||||
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
|
|
||||||
# The following five lines of boilerplate have to be in your project's
|
|
||||||
# CMakeLists in this exact order for cmake to work correctly
|
|
||||||
cmake_minimum_required(VERSION 3.5)
|
|
||||||
|
|
||||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
|
||||||
project(touch_elem_auto_sleep)
|
|
@ -1,2 +0,0 @@
|
|||||||
idf_component_register(SRCS "example_main.c"
|
|
||||||
INCLUDE_DIRS ".")
|
|
@ -1,17 +0,0 @@
|
|||||||
menu "Example Configuration"
|
|
||||||
|
|
||||||
config TE_PM_ENABLE
|
|
||||||
bool "Touch Element power management"
|
|
||||||
default y
|
|
||||||
|
|
||||||
config TE_MAX_CPU_FREQ
|
|
||||||
int "Touch Element sleep DFS maximum cpu frequency"
|
|
||||||
depends on PM_DFS_INIT_AUTO
|
|
||||||
default ESP32S2_DEFAULT_CPU_FREQ_MHZ
|
|
||||||
|
|
||||||
config TE_MIN_CPU_FREQ
|
|
||||||
int "Touch Element sleep DFS minimum cpu frequency"
|
|
||||||
depends on PM_DFS_INIT_AUTO
|
|
||||||
default 10
|
|
||||||
|
|
||||||
endmenu
|
|
@ -1,8 +0,0 @@
|
|||||||
# For more information about build system see
|
|
||||||
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
|
|
||||||
# The following five lines of boilerplate have to be in your project's
|
|
||||||
# CMakeLists in this exact order for cmake to work correctly
|
|
||||||
cmake_minimum_required(VERSION 3.5)
|
|
||||||
|
|
||||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
|
||||||
project(touch_elem_deep_sleep)
|
|
@ -1,2 +0,0 @@
|
|||||||
idf_component_register(SRCS "touch_elem_deep_sleep.c"
|
|
||||||
INCLUDE_DIRS ".")
|
|
@ -1,69 +0,0 @@
|
|||||||
menu "Example Configuration"
|
|
||||||
|
|
||||||
choice
|
|
||||||
|
|
||||||
prompt "Select a button as Deep Sleep wakeup source"
|
|
||||||
default TE_WAKEUP_USE_BUTTON_1
|
|
||||||
|
|
||||||
config TE_WAKEUP_USE_BUTTON_1
|
|
||||||
bool "Button 1"
|
|
||||||
|
|
||||||
config TE_WAKEUP_USE_BUTTON_2
|
|
||||||
bool "Button 2"
|
|
||||||
|
|
||||||
config TE_WAKEUP_USE_BUTTON_3
|
|
||||||
bool "Button 3"
|
|
||||||
|
|
||||||
config TE_WAKEUP_USE_BUTTON_4
|
|
||||||
bool "Button 4"
|
|
||||||
|
|
||||||
config TE_WAKEUP_USE_BUTTON_5
|
|
||||||
bool "Button 5"
|
|
||||||
|
|
||||||
endchoice
|
|
||||||
|
|
||||||
config TE_WAKEUP_BUTTON_INDEX
|
|
||||||
int
|
|
||||||
default 0 if TE_WAKEUP_USE_BUTTON_1
|
|
||||||
default 1 if TE_WAKEUP_USE_BUTTON_2
|
|
||||||
default 2 if TE_WAKEUP_USE_BUTTON_3
|
|
||||||
default 3 if TE_WAKEUP_USE_BUTTON_4
|
|
||||||
default 4 if TE_WAKEUP_USE_BUTTON_5
|
|
||||||
|
|
||||||
choice
|
|
||||||
|
|
||||||
prompt "Select a button as Deep Sleep entry"
|
|
||||||
default TE_ENTRY_USE_BUTTON_1
|
|
||||||
|
|
||||||
config TE_ENTRY_USE_BUTTON_1
|
|
||||||
bool "Button 1"
|
|
||||||
|
|
||||||
config TE_ENTRY_USE_BUTTON_2
|
|
||||||
bool "Button 2"
|
|
||||||
|
|
||||||
config TE_ENTRY_USE_BUTTON_3
|
|
||||||
bool "Button 3"
|
|
||||||
|
|
||||||
config TE_ENTRY_USE_BUTTON_4
|
|
||||||
bool "Button 4"
|
|
||||||
|
|
||||||
config TE_ENTRY_USE_BUTTON_5
|
|
||||||
bool "Button 5"
|
|
||||||
|
|
||||||
endchoice
|
|
||||||
|
|
||||||
config TE_ENTRY_BUTTON_INDEX
|
|
||||||
int
|
|
||||||
default 0 if TE_ENTRY_USE_BUTTON_1
|
|
||||||
default 1 if TE_ENTRY_USE_BUTTON_2
|
|
||||||
default 2 if TE_ENTRY_USE_BUTTON_3
|
|
||||||
default 3 if TE_ENTRY_USE_BUTTON_4
|
|
||||||
default 4 if TE_ENTRY_USE_BUTTON_5
|
|
||||||
|
|
||||||
config TE_SKIP_CALIBRATION
|
|
||||||
bool "Touch Element skip wakeup calibration"
|
|
||||||
depends on TE_SKIP_DSLEEP_WAKEUP_CALIBRATION
|
|
||||||
default y
|
|
||||||
|
|
||||||
|
|
||||||
endmenu
|
|
@ -1,130 +0,0 @@
|
|||||||
/* Touch Sensor - Example
|
|
||||||
|
|
||||||
For other examples please check:
|
|
||||||
https://github.com/espressif/esp-idf/tree/master/examples
|
|
||||||
|
|
||||||
See README.md file to get detailed usage of this example.
|
|
||||||
|
|
||||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, this
|
|
||||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
||||||
CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/task.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "esp_sleep.h"
|
|
||||||
#include "touch_element/touch_button.h"
|
|
||||||
|
|
||||||
static const char *TAG = "Touch Button Example";
|
|
||||||
|
|
||||||
#define TOUCH_BUTTON_NUM 5
|
|
||||||
|
|
||||||
/* Touch buttons handle */
|
|
||||||
static touch_button_handle_t button_handle[TOUCH_BUTTON_NUM];
|
|
||||||
static touch_button_handle_t wakeup_button_handle = NULL;
|
|
||||||
static touch_button_handle_t entry_button_handle = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
/* Touch buttons channel array */
|
|
||||||
static const touch_pad_t channel_array[TOUCH_BUTTON_NUM] = {
|
|
||||||
TOUCH_PAD_NUM1,
|
|
||||||
TOUCH_PAD_NUM2,
|
|
||||||
TOUCH_PAD_NUM3,
|
|
||||||
TOUCH_PAD_NUM4,
|
|
||||||
TOUCH_PAD_NUM5,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Touch buttons channel sensitivity array */
|
|
||||||
static const float channel_sens_array[TOUCH_BUTTON_NUM] = {
|
|
||||||
0.03F,
|
|
||||||
0.03F,
|
|
||||||
0.03F,
|
|
||||||
0.03F,
|
|
||||||
0.03F,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Button event handler task */
|
|
||||||
static void button_handler_task(void *arg)
|
|
||||||
{
|
|
||||||
(void) arg; //Unused
|
|
||||||
touch_elem_message_t element_message;
|
|
||||||
while (1) {
|
|
||||||
/* Waiting for touch element messages */
|
|
||||||
touch_element_message_receive(&element_message, portMAX_DELAY);
|
|
||||||
if (element_message.element_type != TOUCH_ELEM_TYPE_BUTTON) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* Decode message */
|
|
||||||
const touch_button_message_t *button_message = touch_button_get_message(&element_message);
|
|
||||||
|
|
||||||
if (element_message.handle == entry_button_handle) {
|
|
||||||
if (button_message->event == TOUCH_BUTTON_EVT_ON_PRESS) {
|
|
||||||
ESP_LOGI(TAG, "Entering Deep sleep ...");
|
|
||||||
fflush(stdout);
|
|
||||||
esp_deep_sleep_start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (button_message->event == TOUCH_BUTTON_EVT_ON_PRESS) {
|
|
||||||
ESP_LOGI(TAG, "Button[%d] Press", (uint32_t)element_message.arg);
|
|
||||||
} else if (button_message->event == TOUCH_BUTTON_EVT_ON_RELEASE) {
|
|
||||||
ESP_LOGI(TAG, "Button[%d] Release", (uint32_t)element_message.arg);
|
|
||||||
} else if (button_message->event == TOUCH_BUTTON_EVT_ON_LONGPRESS) {
|
|
||||||
ESP_LOGI(TAG, "Button[%d] LongPress", (uint32_t)element_message.arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void app_main(void)
|
|
||||||
{
|
|
||||||
esp_sleep_wakeup_cause_t wakeup_ret = esp_sleep_get_wakeup_cause();
|
|
||||||
printf("------%d\n", wakeup_ret);
|
|
||||||
/* Initialize Touch Element library */
|
|
||||||
touch_elem_global_config_t global_config = TOUCH_ELEM_GLOBAL_DEFAULT_CONFIG();
|
|
||||||
ESP_ERROR_CHECK(touch_element_install(&global_config));
|
|
||||||
ESP_LOGI(TAG, "Touch element library installed");
|
|
||||||
|
|
||||||
touch_button_global_config_t button_global_config = TOUCH_BUTTON_GLOBAL_DEFAULT_CONFIG();
|
|
||||||
ESP_ERROR_CHECK(touch_button_install(&button_global_config));
|
|
||||||
ESP_LOGI(TAG, "Touch button installed");
|
|
||||||
for (int i = 0; i < TOUCH_BUTTON_NUM; i++) {
|
|
||||||
touch_button_config_t button_config = {
|
|
||||||
.channel_num = channel_array[i],
|
|
||||||
.channel_sens = channel_sens_array[i]
|
|
||||||
};
|
|
||||||
/* Create Touch buttons */
|
|
||||||
ESP_ERROR_CHECK(touch_button_create(&button_config, &button_handle[i]));
|
|
||||||
/* Subscribe touch button events (On Press, On Release, On LongPress) */
|
|
||||||
if (i == CONFIG_TE_WAKEUP_BUTTON_INDEX || i == CONFIG_TE_ENTRY_BUTTON_INDEX) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i], TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE, (void *)channel_array[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set EVENT as the dispatch method */
|
|
||||||
ESP_ERROR_CHECK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_EVENT));
|
|
||||||
}
|
|
||||||
wakeup_button_handle = button_handle[CONFIG_TE_WAKEUP_BUTTON_INDEX];
|
|
||||||
entry_button_handle = button_handle[CONFIG_TE_ENTRY_BUTTON_INDEX];
|
|
||||||
ESP_ERROR_CHECK(touch_button_subscribe_event(entry_button_handle, TOUCH_ELEM_EVENT_ON_PRESS, (void *)channel_array[CONFIG_TE_ENTRY_BUTTON_INDEX]));
|
|
||||||
ESP_ERROR_CHECK(touch_button_set_dispatch_method(entry_button_handle, TOUCH_ELEM_DISP_EVENT));
|
|
||||||
ESP_LOGI(TAG, "Touch buttons created");
|
|
||||||
|
|
||||||
touch_elem_sleep_config_t sleep_config = {
|
|
||||||
.scan_time = global_config.hardware.sample_count,
|
|
||||||
.sleep_time = global_config.hardware.sleep_cycle,
|
|
||||||
};
|
|
||||||
ESP_ERROR_CHECK(touch_element_sleep_install(&sleep_config));
|
|
||||||
ESP_ERROR_CHECK(touch_element_sleep_add_wakeup(wakeup_button_handle));
|
|
||||||
#ifdef CONFIG_TE_SKIP_CALIBRATION
|
|
||||||
ESP_ERROR_CHECK(touch_element_sleep_config_wakeup_calibration(wakeup_button_handle, true));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
touch_element_start();
|
|
||||||
ESP_LOGI(TAG, "Touch element library start");
|
|
||||||
xTaskCreate(&button_handler_task, "button_handler_task", 4 * 1024, NULL, 5, NULL);
|
|
||||||
ESP_LOGI(TAG, "Press Button[%d] to enter sleep and press Button[%d] to wakeup system", channel_array[CONFIG_TE_ENTRY_BUTTON_INDEX], channel_array[CONFIG_TE_WAKEUP_BUTTON_INDEX]);
|
|
||||||
}
|
|
@ -144,8 +144,6 @@ static void tp_example_read_task(void *pvParameter)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "esp_sleep.h"
|
|
||||||
#include "hal/touch_sensor_ll.h"
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
if (que_touch == NULL) {
|
if (que_touch == NULL) {
|
||||||
@ -211,11 +209,4 @@ void app_main(void)
|
|||||||
|
|
||||||
// Start a task to show what pads have been touched
|
// Start a task to show what pads have been touched
|
||||||
xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 4096, NULL, 5, NULL);
|
xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 4096, NULL, 5, NULL);
|
||||||
|
|
||||||
touch_ll_sleep_low_power(true);
|
|
||||||
while (1) {
|
|
||||||
esp_sleep_enable_timer_wakeup(100 * 1000);
|
|
||||||
esp_light_sleep_start();
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,14 @@ Note #2: only UART0 and UART1 (if has) are supported to be configured as wake up
|
|||||||
|
|
||||||
Note #3: due to limitation of the HW, the bytes that received during light sleep is only used for waking up, and it will not be received by UART peripheral or passed to the driver.
|
Note #3: due to limitation of the HW, the bytes that received during light sleep is only used for waking up, and it will not be received by UART peripheral or passed to the driver.
|
||||||
|
|
||||||
|
### Wake-up by Touch Pad
|
||||||
|
|
||||||
|
For this example, pressing any registered touch buttons can wake up the chip.
|
||||||
|
|
||||||
|
Note #1: For light sleep, all registered touch buttons can wake up the chip. But only the channel which is configured as wake up channel can wake up the chip from deep sleep.
|
||||||
|
|
||||||
|
Note #2: Waking-up by touch pad relies on 'touch_element' driver, which can only support ESP32-S2 and ESP32-S3 currently.
|
||||||
|
|
||||||
```
|
```
|
||||||
Entering light sleep
|
Entering light sleep
|
||||||
Returned from light sleep, reason: timer, t=2713 ms, slept for 1999 ms
|
Returned from light sleep, reason: timer, t=2713 ms, slept for 1999 ms
|
||||||
@ -83,6 +91,11 @@ Entering light sleep
|
|||||||
Returned from light sleep, reason: pin, t=12564 ms, slept for 1 ms
|
Returned from light sleep, reason: pin, t=12564 ms, slept for 1 ms
|
||||||
Waiting for GPIO9 to go high...
|
Waiting for GPIO9 to go high...
|
||||||
Entering light sleep
|
Entering light sleep
|
||||||
|
...
|
||||||
|
I (361) touch_wakeup: Button[1] Press
|
||||||
|
Returned from light sleep, reason: touch, t=14471 ms, slept for 467 ms
|
||||||
|
Entering light sleep
|
||||||
|
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -3,5 +3,11 @@ set(srcs "light_sleep_example_main.c"
|
|||||||
"timer_wakeup.c"
|
"timer_wakeup.c"
|
||||||
"uart_wakeup.c")
|
"uart_wakeup.c")
|
||||||
|
|
||||||
|
set(TOUCH_ELEMENT_COMPATIBLE_TARGETS "esp32s2" "esp32s3")
|
||||||
|
|
||||||
|
if(IDF_TARGET IN_LIST TOUCH_ELEMENT_COMPATIBLE_TARGETS)
|
||||||
|
list(APPEND srcs "touch_wakeup.c")
|
||||||
|
endif()
|
||||||
|
|
||||||
idf_component_register(SRCS ${srcs}
|
idf_component_register(SRCS ${srcs}
|
||||||
INCLUDE_DIRS ".")
|
INCLUDE_DIRS ".")
|
||||||
|
@ -18,6 +18,10 @@ esp_err_t example_register_timer_wakeup(void);
|
|||||||
|
|
||||||
esp_err_t example_register_uart_wakeup(void);
|
esp_err_t example_register_uart_wakeup(void);
|
||||||
|
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||||
|
void example_register_touch_wakeup(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -50,6 +50,11 @@ static void light_sleep_task(void *args)
|
|||||||
* Otherwise the chip may fall sleep again before running uart task */
|
* Otherwise the chip may fall sleep again before running uart task */
|
||||||
vTaskDelay(1);
|
vTaskDelay(1);
|
||||||
break;
|
break;
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||||
|
case ESP_SLEEP_WAKEUP_TOUCHPAD:
|
||||||
|
wakeup_reason = "touch";
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
wakeup_reason = "other";
|
wakeup_reason = "other";
|
||||||
break;
|
break;
|
||||||
@ -72,6 +77,10 @@ void app_main(void)
|
|||||||
example_register_timer_wakeup();
|
example_register_timer_wakeup();
|
||||||
/* Enable wakeup from light sleep by uart */
|
/* Enable wakeup from light sleep by uart */
|
||||||
example_register_uart_wakeup();
|
example_register_uart_wakeup();
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||||
|
/* Enable wakeup from light sleep by touch element */
|
||||||
|
example_register_touch_wakeup();
|
||||||
|
#endif
|
||||||
|
|
||||||
xTaskCreate(light_sleep_task, "light_sleep_task", 4096, NULL, 6, NULL);
|
xTaskCreate(light_sleep_task, "light_sleep_task", 4096, NULL, 6, NULL);
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,22 @@
|
|||||||
/* Touch Sensor - Example
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
For other examples please check:
|
*
|
||||||
https://github.com/espressif/esp-idf/tree/master/examples
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
*/
|
||||||
See README.md file to get detailed usage of this example.
|
|
||||||
|
|
||||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, this
|
|
||||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
||||||
CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_pm.h"
|
#include "esp_sleep.h"
|
||||||
#include "touch_element/touch_button.h"
|
#include "touch_element/touch_button.h"
|
||||||
|
|
||||||
static const char *TAG = "Touch elem auto sleep";
|
static const char *TAG = "touch_wakeup";
|
||||||
|
|
||||||
#define TOUCH_BUTTON_NUM 5
|
#define TOUCH_BUTTON_NUM 5
|
||||||
|
|
||||||
/* Touch buttons handle */
|
/* Touch buttons handle */
|
||||||
static touch_button_handle_t button_handle[TOUCH_BUTTON_NUM];
|
static touch_button_handle_t button_handle[TOUCH_BUTTON_NUM];
|
||||||
|
|
||||||
|
|
||||||
/* Touch buttons channel array */
|
/* Touch buttons channel array */
|
||||||
static const touch_pad_t channel_array[TOUCH_BUTTON_NUM] = {
|
static const touch_pad_t channel_array[TOUCH_BUTTON_NUM] = {
|
||||||
TOUCH_PAD_NUM1,
|
TOUCH_PAD_NUM1,
|
||||||
@ -57,32 +49,18 @@ static void button_handler_task(void *arg)
|
|||||||
/* Decode message */
|
/* Decode message */
|
||||||
const touch_button_message_t *button_message = touch_button_get_message(&element_message);
|
const touch_button_message_t *button_message = touch_button_get_message(&element_message);
|
||||||
if (button_message->event == TOUCH_BUTTON_EVT_ON_PRESS) {
|
if (button_message->event == TOUCH_BUTTON_EVT_ON_PRESS) {
|
||||||
ESP_LOGI(TAG, "Button[%d] Press", (uint32_t)element_message.arg);
|
ESP_LOGI(TAG, "Button[%"PRIu32"] Press", (uint32_t)element_message.arg);
|
||||||
} else if (button_message->event == TOUCH_BUTTON_EVT_ON_RELEASE) {
|
} else if (button_message->event == TOUCH_BUTTON_EVT_ON_RELEASE) {
|
||||||
ESP_LOGI(TAG, "Button[%d] Release", (uint32_t)element_message.arg);
|
ESP_LOGI(TAG, "Button[%"PRIu32"] Release", (uint32_t)element_message.arg);
|
||||||
} else if (button_message->event == TOUCH_BUTTON_EVT_ON_LONGPRESS) {
|
} else if (button_message->event == TOUCH_BUTTON_EVT_ON_LONGPRESS) {
|
||||||
ESP_LOGI(TAG, "Button[%d] LongPress", (uint32_t)element_message.arg);
|
ESP_LOGI(TAG, "Button[%"PRIu32"] LongPress", (uint32_t)element_message.arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
esp_err_t example_register_touch_wakeup(void)
|
||||||
void app_main(void)
|
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_PM_ENABLE //System power management
|
|
||||||
esp_pm_config_esp32s2_t pm_config = {
|
|
||||||
#ifdef CONFIG_PM_DFS_INIT_AUTO //Power management dynamic frequency scaling
|
|
||||||
.max_freq_mhz = CONFIG_TE_MAX_CPU_FREQ,
|
|
||||||
.min_freq_mhz = CONFIG_TE_MIN_CPU_FREQ,
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_FREERTOS_USE_TICKLESS_IDLE //FreeRTOS tickless
|
|
||||||
.light_sleep_enable = true
|
|
||||||
#else
|
|
||||||
.light_sleep_enable = false
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
ESP_ERROR_CHECK( esp_pm_configure(&pm_config));
|
|
||||||
#endif
|
|
||||||
/* Initialize Touch Element library */
|
/* Initialize Touch Element library */
|
||||||
touch_elem_global_config_t global_config = TOUCH_ELEM_GLOBAL_DEFAULT_CONFIG();
|
touch_elem_global_config_t global_config = TOUCH_ELEM_GLOBAL_DEFAULT_CONFIG();
|
||||||
ESP_ERROR_CHECK(touch_element_install(&global_config));
|
ESP_ERROR_CHECK(touch_element_install(&global_config));
|
||||||
@ -98,26 +76,26 @@ void app_main(void)
|
|||||||
};
|
};
|
||||||
/* Create Touch buttons */
|
/* Create Touch buttons */
|
||||||
ESP_ERROR_CHECK(touch_button_create(&button_config, &button_handle[i]));
|
ESP_ERROR_CHECK(touch_button_create(&button_config, &button_handle[i]));
|
||||||
/* Subscribe touch button events (On Press, On Release, On LongPress) */
|
|
||||||
ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i], TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS,
|
|
||||||
(void *)channel_array[i]));
|
|
||||||
/* Set EVENT as the dispatch method */
|
/* Set EVENT as the dispatch method */
|
||||||
ESP_ERROR_CHECK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_EVENT));
|
ESP_ERROR_CHECK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_EVENT));
|
||||||
/* Set LongPress event trigger threshold time */
|
/* Subscribe touch button events (On Press, On Release, On LongPress) */
|
||||||
ESP_ERROR_CHECK(touch_button_set_longpress(button_handle[i], 1000));
|
ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i],
|
||||||
|
TOUCH_ELEM_EVENT_ON_PRESS |
|
||||||
|
TOUCH_ELEM_EVENT_ON_RELEASE |
|
||||||
|
TOUCH_ELEM_EVENT_ON_LONGPRESS,
|
||||||
|
(void *)channel_array[i]));
|
||||||
}
|
}
|
||||||
ESP_LOGI(TAG, "Touch buttons created");
|
ESP_LOGI(TAG, "Touch buttons created");
|
||||||
|
|
||||||
#ifdef CONFIG_TE_PM_ENABLE
|
|
||||||
touch_elem_sleep_config_t sleep_config = {
|
touch_elem_sleep_config_t sleep_config = {
|
||||||
.scan_time = global_config.hardware.sample_count,
|
.sample_count = global_config.hardware.sample_count,
|
||||||
.sleep_time = global_config.hardware.sleep_cycle,
|
.sleep_cycle = global_config.hardware.sleep_cycle,
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(touch_element_sleep_install(&sleep_config));
|
/* Enable one of registered touch button as light/deep sleep wake-up source */
|
||||||
#endif
|
ESP_ERROR_CHECK(touch_element_enable_light_sleep(&sleep_config));
|
||||||
|
|
||||||
touch_element_start();
|
touch_element_start();
|
||||||
ESP_LOGI(TAG, "Touch element library start");
|
xTaskCreate(&button_handler_task, "button_handler_task", 4 * 1024, NULL, 6, NULL);
|
||||||
xTaskCreate(&button_handler_task, "button_handler_task", 4 * 1024, NULL, 5, NULL);
|
ESP_LOGI(TAG, "touch wakeup source is ready");
|
||||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
return ESP_OK;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user