Merge branch 'bugfix/touch_sensor_reading_error_in_light_sleep_process' into 'master'

driver(touch): fix touch sensor false trigger in sleep mode

See merge request espressif/esp-idf!10983
pull/6365/head
Michael (XIAO Xufeng) 2020-12-14 14:51:51 +08:00
commit 40b08e33c9
3 zmienionych plików z 50 dodań i 29 usunięć

Wyświetl plik

@ -29,7 +29,6 @@
#include "driver/touch_sensor.h"
#include "driver/touch_sensor_common.h"
#include "soc/soc_caps.h"
#include "driver/rtc_io.h"
#include "hal/rtc_io_hal.h"
@ -166,9 +165,7 @@ static uint32_t get_power_down_flags(void);
static void ext0_wakeup_prepare(void);
static void ext1_wakeup_prepare(void);
static void timer_wakeup_prepare(void);
#ifdef CONFIG_IDF_TARGET_ESP32S2
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
static void touch_wakeup_prepare(void);
#endif
@ -313,10 +310,22 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags)
}
#endif
#ifdef CONFIG_IDF_TARGET_ESP32S2
// Enable Touch wakeup
if (s_config.wakeup_triggers & RTC_TOUCH_TRIG_EN) {
touch_wakeup_prepare();
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
if (deep_sleep) {
if (s_config.wakeup_triggers & RTC_TOUCH_TRIG_EN) {
touch_wakeup_prepare();
/* Workaround: In deep sleep, for ESP32S2, Power down the RTC_PERIPH will change the slope configuration of Touch sensor sleep pad.
* The configuration change will change the reading of the sleep pad, which will cause the touch wake-up sensor to trigger falsely.
*/
pd_flags &= ~RTC_SLEEP_PD_RTC_PERIPH;
}
} else {
/* In light sleep, the RTC_PERIPH power domain should be in the power-on state (Power on the touch circuit in light sleep),
* otherwise the touch sensor FSM will be cleared, causing touch sensor false triggering.
*/
if (touch_ll_get_fsm_state()) { // Check if the touch sensor is working properly.
pd_flags &= ~RTC_SLEEP_PD_RTC_PERIPH;
}
}
#endif
uint32_t reject_triggers = 0;
@ -603,16 +612,18 @@ static void timer_wakeup_prepare(void)
}
#ifdef CONFIG_IDF_TARGET_ESP32S2
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
/* In deep sleep mode, only the sleep channel is supported, and other touch channels should be turned off. */
static void touch_wakeup_prepare(void)
{
touch_pad_sleep_channel_t slp_config;
touch_pad_fsm_stop();
touch_pad_clear_channel_mask(TOUCH_PAD_BIT_MASK_ALL);
touch_pad_sleep_channel_get_info(&slp_config);
touch_pad_set_channel_mask(BIT(slp_config.touch_num));
touch_pad_fsm_start();
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_set_channel_mask(BIT(touch_num));
touch_ll_start_fsm();
}
}
#endif

Wyświetl plik

@ -289,6 +289,17 @@ static inline void touch_ll_stop_fsm(void)
RTCCNTL.touch_ctrl2.touch_timer_force_done = TOUCH_LL_TIMER_DONE;
}
/**
* Get touch sensor FSM timer state.
* @return
* - true: FSM enabled
* - false: FSM disabled
*/
static inline bool touch_ll_get_fsm_state(void)
{
return (bool)RTCCNTL.touch_ctrl2.touch_slp_timer_en;
}
/**
* Trigger a touch sensor measurement, only support in SW mode of FSM.
*/
@ -298,18 +309,12 @@ static inline void touch_ll_start_sw_meas(void)
RTCCNTL.touch_ctrl2.touch_start_en = 1;
}
/**
* Set touch sensor interrupt threshold.
*
* @param touch_num touch pad index.
* @param threshold threshold of touchpad count.
*/
/**
* Set the trigger threshold of touch sensor.
* The threshold determines the sensitivity of the touch sensor.
* The threshold is the original value of the trigger state minus the benchmark value.
*
* @note If set "TOUCH_PAD_THRESHOLD_MAX", the touch is never be trigered.
* @note If set "TOUCH_PAD_THRESHOLD_MAX", the touch is never be triggered.
* @param touch_num touch pad index
* @param threshold threshold of touch sensor.
*/

Wyświetl plik

@ -289,6 +289,17 @@ static inline void touch_ll_stop_fsm(void)
RTCCNTL.touch_ctrl2.touch_timer_force_done = TOUCH_LL_TIMER_DONE;
}
/**
* Get touch sensor FSM timer state.
* @return
* - true: FSM enabled
* - false: FSM disabled
*/
static inline bool touch_ll_get_fsm_state(void)
{
return (bool)RTCCNTL.touch_ctrl2.touch_slp_timer_en;
}
/**
* Trigger a touch sensor measurement, only support in SW mode of FSM.
*/
@ -298,18 +309,12 @@ static inline void touch_ll_start_sw_meas(void)
RTCCNTL.touch_ctrl2.touch_start_en = 1;
}
/**
* Set touch sensor interrupt threshold.
*
* @param touch_num touch pad index.
* @param threshold threshold of touchpad count.
*/
/**
* Set the trigger threshold of touch sensor.
* The threshold determines the sensitivity of the touch sensor.
* The threshold is the original value of the trigger state minus the benchmark value.
*
* @note If set "TOUCH_PAD_THRESHOLD_MAX", the touch is never be trigered.
* @note If set "TOUCH_PAD_THRESHOLD_MAX", the touch is never be triggered.
* @param touch_num touch pad index
* @param threshold threshold of touch sensor.
*/