mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
fix: reduce the consumption of touch sensor during deep sleep
This commit is contained in:
parent
bda9e1fda7
commit
e310fb1393
@ -579,6 +579,22 @@ esp_err_t touch_pad_sleep_channel_reset_benchmark(void);
|
||||
*/
|
||||
esp_err_t touch_pad_sleep_channel_read_proximity_cnt(touch_pad_t pad_num, uint32_t *proximity_cnt);
|
||||
|
||||
/**
|
||||
* @brief Change the operating frequency of touch pad in deep sleep state. Reducing the operating frequency can effectively reduce power consumption.
|
||||
* If this function is not called, the working frequency of touch in the deep sleep state is the same as that in the wake-up state.
|
||||
*
|
||||
* @param sleep_cycle The touch sensor will sleep after each measurement.
|
||||
* sleep_cycle decide the interval between each measurement.
|
||||
* t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
|
||||
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
|
||||
* @param meas_times The times of charge and discharge in each measure process of touch channels.
|
||||
* The timer frequency is 8Mhz. Range: 0 ~ 0xffff.
|
||||
* Recommended typical value: Modify this value to make the measurement time around 1ms.
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t touch_pad_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -629,3 +629,9 @@ esp_err_t touch_pad_sleep_channel_read_proximity_cnt(touch_pad_t pad_num, uint32
|
||||
touch_hal_sleep_read_proximity_cnt(approach_cnt);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t touch_pad_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times)
|
||||
{
|
||||
touch_hal_sleep_channel_set_work_time(sleep_cycle, meas_times);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
@ -577,6 +577,22 @@ esp_err_t touch_pad_sleep_channel_reset_benchmark(void);
|
||||
*/
|
||||
esp_err_t touch_pad_sleep_channel_read_proximity_cnt(touch_pad_t pad_num, uint32_t *proximity_cnt);
|
||||
|
||||
/**
|
||||
* @brief Change the operating frequency of touch pad in deep sleep state. Reducing the operating frequency can effectively reduce power consumption.
|
||||
* If this function is not called, the working frequency of touch in the deep sleep state is the same as that in the wake-up state.
|
||||
*
|
||||
* @param sleep_cycle The touch sensor will sleep after each measurement.
|
||||
* sleep_cycle decide the interval between each measurement.
|
||||
* t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
|
||||
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
|
||||
* @param meas_times The times of charge and discharge in each measure process of touch channels.
|
||||
* The timer frequency is 8Mhz. Range: 0 ~ 0xffff.
|
||||
* Recommended typical value: Modify this value to make the measurement time around 1ms.
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t touch_pad_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -286,7 +286,8 @@ void esp_set_deep_sleep_wake_stub(esp_deep_sleep_wake_stub_fn_t new_stub)
|
||||
REG_WRITE(RTC_ENTRY_ADDR_REG, (uint32_t)new_stub);
|
||||
}
|
||||
|
||||
void RTC_IRAM_ATTR esp_default_wake_deep_sleep(void) {
|
||||
void RTC_IRAM_ATTR esp_default_wake_deep_sleep(void)
|
||||
{
|
||||
/* Clear MMU for CPU 0 */
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
_DPORT_REG_WRITE(DPORT_PRO_CACHE_CTRL1_REG,
|
||||
@ -332,7 +333,9 @@ static void IRAM_ATTR suspend_uarts(void)
|
||||
{
|
||||
for (int i = 0; i < SOC_UART_NUM; ++i) {
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32
|
||||
if (!periph_ll_periph_enabled(PERIPH_UART0_MODULE + i)) continue;
|
||||
if (!periph_ll_periph_enabled(PERIPH_UART0_MODULE + i)) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
uart_ll_force_xoff(i);
|
||||
#if SOC_UART_SUPPORT_FSM_TX_WAIT_SEND
|
||||
@ -350,7 +353,9 @@ static void IRAM_ATTR resume_uarts(void)
|
||||
{
|
||||
for (int i = 0; i < SOC_UART_NUM; ++i) {
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32
|
||||
if (!periph_ll_periph_enabled(PERIPH_UART0_MODULE + i)) continue;
|
||||
if (!periph_ll_periph_enabled(PERIPH_UART0_MODULE + i)) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
uart_ll_force_xon(i);
|
||||
}
|
||||
@ -905,12 +910,17 @@ static void timer_wakeup_prepare(void)
|
||||
/* In deep sleep mode, only the sleep channel is supported, and other touch channels should be turned off. */
|
||||
static void touch_wakeup_prepare(void)
|
||||
{
|
||||
uint16_t sleep_cycle = 0;
|
||||
uint16_t meas_times = 0;
|
||||
touch_pad_t touch_num = TOUCH_PAD_NUM0;
|
||||
touch_ll_sleep_get_channel_num(&touch_num); // Check if the sleep pad is enabled.
|
||||
if ((touch_num > TOUCH_PAD_NUM0) && (touch_num < TOUCH_PAD_MAX) && touch_ll_get_fsm_state()) {
|
||||
touch_ll_stop_fsm();
|
||||
touch_ll_clear_channel_mask(TOUCH_PAD_BIT_MASK_ALL);
|
||||
touch_ll_intr_clear(TOUCH_PAD_INTR_MASK_ALL); // Clear state from previous wakeup
|
||||
touch_hal_sleep_channel_get_work_time(&sleep_cycle, &meas_times);
|
||||
touch_ll_set_meas_times(meas_times);
|
||||
touch_ll_set_sleep_time(sleep_cycle);
|
||||
touch_ll_set_channel_mask(BIT(touch_num));
|
||||
touch_ll_start_fsm();
|
||||
}
|
||||
|
@ -608,6 +608,33 @@ void touch_hal_sleep_channel_enable(touch_pad_t pad_num, bool enable);
|
||||
*/
|
||||
#define touch_hal_get_wakeup_status(pad_num) touch_ll_get_wakeup_status(pad_num)
|
||||
|
||||
/**
|
||||
* Change the operating frequency of touch pad in deep sleep state. Reducing the operating frequency can effectively reduce power consumption.
|
||||
* If this function is not called, the working frequency of touch in the deep sleep state is the same as that in the wake-up state.
|
||||
*
|
||||
* @param sleep_cycle The touch sensor will sleep after each measurement.
|
||||
* sleep_cycle decide the interval between each measurement.
|
||||
* t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
|
||||
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
|
||||
* @param meas_times The times of charge and discharge in each measure process of touch channels.
|
||||
* The timer frequency is 8Mhz. Range: 0 ~ 0xffff.
|
||||
* Recommended typical value: Modify this value to make the measurement time around 1ms.
|
||||
*/
|
||||
void touch_hal_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times);
|
||||
|
||||
/**
|
||||
* Get the operating frequency of touch pad in deep sleep state. Reducing the operating frequency can effectively reduce power consumption.
|
||||
*
|
||||
* @param sleep_cycle The touch sensor will sleep after each measurement.
|
||||
* sleep_cycle decide the interval between each measurement.
|
||||
* t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
|
||||
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
|
||||
* @param meas_times The times of charge and discharge in each measure process of touch channels.
|
||||
* The timer frequency is 8Mhz. Range: 0 ~ 0xffff.
|
||||
* Recommended typical value: Modify this value to make the measurement time around 1ms.
|
||||
*/
|
||||
void touch_hal_sleep_channel_get_work_time(uint16_t *sleep_cycle, uint16_t *meas_times);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -18,6 +18,9 @@
|
||||
#include "hal/touch_sensor_hal.h"
|
||||
#include "hal/touch_sensor_types.h"
|
||||
|
||||
static int s_sleep_cycle = -1;
|
||||
static int s_meas_times = -1;
|
||||
|
||||
void touch_hal_init(void)
|
||||
{
|
||||
touch_ll_stop_fsm();
|
||||
@ -157,3 +160,23 @@ void touch_hal_sleep_channel_get_config(touch_pad_sleep_channel_t *slp_config)
|
||||
touch_ll_sleep_get_channel_num(&slp_config->touch_num);
|
||||
slp_config->en_proximity = touch_ll_sleep_get_approach_status();
|
||||
}
|
||||
|
||||
void touch_hal_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times)
|
||||
{
|
||||
s_sleep_cycle = (int)sleep_cycle;
|
||||
s_meas_times = (int)meas_times;
|
||||
}
|
||||
|
||||
void touch_hal_sleep_channel_get_work_time(uint16_t *sleep_cycle, uint16_t *meas_times)
|
||||
{
|
||||
if (s_meas_times < 0) {
|
||||
touch_ll_get_measure_times(meas_times);
|
||||
} else {
|
||||
*meas_times = (uint16_t)s_meas_times;
|
||||
}
|
||||
if (s_sleep_cycle < 0) {
|
||||
touch_ll_get_sleep_time(sleep_cycle);
|
||||
} else {
|
||||
*sleep_cycle = (uint16_t)s_sleep_cycle;
|
||||
}
|
||||
}
|
||||
|
@ -608,6 +608,33 @@ void touch_hal_sleep_channel_enable(touch_pad_t pad_num, bool enable);
|
||||
*/
|
||||
#define touch_hal_get_wakeup_status(pad_num) touch_ll_get_wakeup_status(pad_num)
|
||||
|
||||
/**
|
||||
* Change the operating frequency of touch pad in deep sleep state. Reducing the operating frequency can effectively reduce power consumption.
|
||||
* If this function is not called, the working frequency of touch in the deep sleep state is the same as that in the wake-up state.
|
||||
*
|
||||
* @param sleep_cycle The touch sensor will sleep after each measurement.
|
||||
* sleep_cycle decide the interval between each measurement.
|
||||
* t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
|
||||
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
|
||||
* @param meas_times The times of charge and discharge in each measure process of touch channels.
|
||||
* The timer frequency is 8Mhz. Range: 0 ~ 0xffff.
|
||||
* Recommended typical value: Modify this value to make the measurement time around 1ms.
|
||||
*/
|
||||
void touch_hal_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times);
|
||||
|
||||
/**
|
||||
* Get the operating frequency of touch pad in deep sleep state. Reducing the operating frequency can effectively reduce power consumption.
|
||||
*
|
||||
* @param sleep_cycle The touch sensor will sleep after each measurement.
|
||||
* sleep_cycle decide the interval between each measurement.
|
||||
* t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
|
||||
* The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
|
||||
* @param meas_times The times of charge and discharge in each measure process of touch channels.
|
||||
* The timer frequency is 8Mhz. Range: 0 ~ 0xffff.
|
||||
* Recommended typical value: Modify this value to make the measurement time around 1ms.
|
||||
*/
|
||||
void touch_hal_sleep_channel_get_work_time(uint16_t *sleep_cycle, uint16_t *meas_times);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -18,6 +18,9 @@
|
||||
#include "hal/touch_sensor_types.h"
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
static int s_sleep_cycle = -1;
|
||||
static int s_meas_times = -1;
|
||||
|
||||
void touch_hal_init(void)
|
||||
{
|
||||
touch_ll_stop_fsm();
|
||||
@ -157,3 +160,23 @@ void touch_hal_sleep_channel_get_config(touch_pad_sleep_channel_t *slp_config)
|
||||
touch_ll_sleep_get_channel_num(&slp_config->touch_num);
|
||||
slp_config->en_proximity = touch_ll_sleep_get_approach_status();
|
||||
}
|
||||
|
||||
void touch_hal_sleep_channel_set_work_time(uint16_t sleep_cycle, uint16_t meas_times)
|
||||
{
|
||||
s_sleep_cycle = (int)sleep_cycle;
|
||||
s_meas_times = (int)meas_times;
|
||||
}
|
||||
|
||||
void touch_hal_sleep_channel_get_work_time(uint16_t *sleep_cycle, uint16_t *meas_times)
|
||||
{
|
||||
if (s_meas_times < 0) {
|
||||
touch_ll_get_measure_times(meas_times);
|
||||
} else {
|
||||
*meas_times = (uint16_t)s_meas_times;
|
||||
}
|
||||
if (s_sleep_cycle < 0) {
|
||||
touch_ll_get_sleep_time(sleep_cycle);
|
||||
} else {
|
||||
*sleep_cycle = (uint16_t)s_sleep_cycle;
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ set sleep_init default param
|
||||
#define RTC_CNTL_DBG_ATTEN_MONITOR_DEFAULT 0
|
||||
#define RTC_CNTL_BIASSLP_MONITOR_DEFAULT 0
|
||||
#define RTC_CNTL_BIASSLP_SLEEP_DEFAULT 1
|
||||
#define RTC_CNTL_PD_CUR_MONITOR_DEFAULT 0
|
||||
#define RTC_CNTL_PD_CUR_MONITOR_DEFAULT 1
|
||||
#define RTC_CNTL_PD_CUR_SLEEP_DEFAULT 1
|
||||
|
||||
#define APLL_SDM_STOP_VAL_1 0x09
|
||||
|
@ -123,7 +123,7 @@ set sleep_init default param
|
||||
#define RTC_CNTL_DBG_ATTEN_MONITOR_DEFAULT 0
|
||||
#define RTC_CNTL_BIASSLP_MONITOR_DEFAULT 0
|
||||
#define RTC_CNTL_BIASSLP_SLEEP_DEFAULT 1
|
||||
#define RTC_CNTL_PD_CUR_MONITOR_DEFAULT 0
|
||||
#define RTC_CNTL_PD_CUR_MONITOR_DEFAULT 1
|
||||
#define RTC_CNTL_PD_CUR_SLEEP_DEFAULT 1
|
||||
|
||||
/**
|
||||
|
@ -239,6 +239,8 @@ void app_main(void)
|
||||
/* Set sleep touch pad. */
|
||||
touch_pad_sleep_channel_enable(TOUCH_PAD_NUM9, true);
|
||||
touch_pad_sleep_channel_enable_proximity(TOUCH_PAD_NUM9, false);
|
||||
/* Reducing the operating frequency can effectively reduce power consumption. */
|
||||
touch_pad_sleep_channel_set_work_time(1000, TOUCH_PAD_MEASURE_CYCLE_DEFAULT);
|
||||
/* Enable touch sensor clock. Work mode is "timer trigger". */
|
||||
touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
|
||||
touch_pad_fsm_start();
|
||||
|
Loading…
Reference in New Issue
Block a user