2#include "soc/soc_caps.h"
3#include "driver/gpio.h"
6#include <esp_idf_version.h>
31static const char *
const TAG =
"deep_sleep";
33#ifdef USE_DEEP_SLEEP_ON_WAKE
35 switch (esp_sleep_get_wakeup_cause()) {
36 case ESP_SLEEP_WAKEUP_EXT0:
37 case ESP_SLEEP_WAKEUP_EXT1:
38 case ESP_SLEEP_WAKEUP_GPIO:
40 case ESP_SLEEP_WAKEUP_TIMER:
42 case ESP_SLEEP_WAKEUP_TOUCHPAD:
44 case ESP_SLEEP_WAKEUP_UNDEFINED:
54 esp_sleep_wakeup_cause_t wakeup_cause = esp_sleep_get_wakeup_cause();
55 switch (wakeup_cause) {
56 case ESP_SLEEP_WAKEUP_EXT0:
57 case ESP_SLEEP_WAKEUP_EXT1:
58 case ESP_SLEEP_WAKEUP_GPIO:
60 case ESP_SLEEP_WAKEUP_TOUCHPAD:
73#if !defined(USE_ESP32_VARIANT_ESP32C2) && !defined(USE_ESP32_VARIANT_ESP32C3)
77#if !defined(USE_ESP32_VARIANT_ESP32C2) && !defined(USE_ESP32_VARIANT_ESP32C3) && \
78 !defined(USE_ESP32_VARIANT_ESP32C5) && !defined(USE_ESP32_VARIANT_ESP32C6) && \
79 !defined(USE_ESP32_VARIANT_ESP32C61) && !defined(USE_ESP32_VARIANT_ESP32H2)
93 " Default Wakeup Run Duration: %" PRIu32
" ms\n"
94 " Touch Wakeup Run Duration: %" PRIu32
" ms\n"
95 " GPIO Wakeup Run Duration: %" PRIu32
" ms",
97 this->wakeup_cause_to_run_duration_->gpio_cause);
107 ESP_LOGW(TAG,
"Waiting for wakeup pin state change");
121#if !defined(USE_ESP32_VARIANT_ESP32C2) && !defined(USE_ESP32_VARIANT_ESP32C3) && \
122 !defined(USE_ESP32_VARIANT_ESP32C5) && !defined(USE_ESP32_VARIANT_ESP32C6) && \
123 !defined(USE_ESP32_VARIANT_ESP32C61) && !defined(USE_ESP32_VARIANT_ESP32H2)
127 gpio_sleep_set_pull_mode(gpio_pin, GPIO_PULLUP_ONLY);
129 gpio_sleep_set_pull_mode(gpio_pin, GPIO_PULLDOWN_ONLY);
131 gpio_sleep_set_direction(gpio_pin, GPIO_MODE_INPUT);
132 gpio_hold_en(gpio_pin);
133#if !SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP
136 gpio_deep_sleep_hold_en();
142 esp_sleep_enable_ext0_wakeup(gpio_pin, level);
147#if defined(USE_ESP32_VARIANT_ESP32C2) || defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C5) || \
148 defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32C61)
152 gpio_set_direction(gpio_pin, GPIO_MODE_INPUT);
159#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
160 esp_sleep_enable_gpio_wakeup_on_hp_periph_powerdown(1ULL << this->
wakeup_pin_->
get_pin(),
161 static_cast<esp_sleep_gpio_wake_up_mode_t
>(level));
164 static_cast<esp_deepsleep_gpio_wake_up_mode_t
>(level));
170#if !defined(USE_ESP32_VARIANT_ESP32C2) && !defined(USE_ESP32_VARIANT_ESP32C3)
172 esp_sleep_enable_ext1_wakeup(this->
ext1_wakeup_->mask, this->ext1_wakeup_->wakeup_mode);
177#if !defined(USE_ESP32_VARIANT_ESP32C2) && !defined(USE_ESP32_VARIANT_ESP32C3) && \
178 !defined(USE_ESP32_VARIANT_ESP32C5) && !defined(USE_ESP32_VARIANT_ESP32C6) && \
179 !defined(USE_ESP32_VARIANT_ESP32C61) && !defined(USE_ESP32_VARIANT_ESP32H2)
180 if (this->
touch_wakeup_.has_value() && *(this->touch_wakeup_)) {
181 esp_sleep_enable_touchpad_wakeup();
182 esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
186 esp_deep_sleep_start();
void status_set_warning()
virtual gpio::Flags get_flags() const =0
Retrieve GPIO pin flags.
virtual bool digital_read()=0
virtual uint8_t get_pin() const =0
virtual bool is_inverted() const =0
WakeupPinMode wakeup_pin_mode_
void set_run_duration(WakeupCauseToRunDuration wakeup_cause_to_run_duration)
void set_touch_wakeup(bool touch_wakeup)
InternalGPIOPin * wakeup_pin_
optional< Ext1Wakeup > ext1_wakeup_
optional< bool > touch_wakeup_
optional< uint64_t > sleep_duration_
optional< uint32_t > get_run_duration_() const
void set_wakeup_pin_mode(WakeupPinMode wakeup_pin_mode)
bool next_enter_deep_sleep_
optional< uint32_t > run_duration_
void dump_config_platform_()
void set_ext1_wakeup(Ext1Wakeup ext1_wakeup)
optional< WakeupCauseToRunDuration > wakeup_cause_to_run_duration_
WakeupPinMode
The values of this enum define what should be done if deep sleep is set up with a wakeup pin on the E...
@ WAKEUP_PIN_MODE_KEEP_AWAKE
As long as the wakeup pin is still in the wakeup state, keep awake.
@ WAKEUP_PIN_MODE_INVERT_WAKEUP
Automatically invert the wakeup level.
WakeupCause get_wakeup_cause()
Return why the device woke from deep sleep. Implemented per platform.
WakeupCause
Why the device woke from deep sleep. Passed to on_wake automations.
@ WAKEUP_CAUSE_TOUCH
The device was woken by a touch pad.
@ WAKEUP_CAUSE_GPIO
The device was woken by a GPIO pin (wakeup_pin or esp32_ext1_wakeup).
@ WAKEUP_CAUSE_TIMER
The device was woken by the sleep timer.
@ WAKEUP_CAUSE_UNKNOWN
The device woke from deep sleep, but the source could not be identified.
@ WAKEUP_CAUSE_NONE
The device did not wake from deep sleep (for example a cold boot, reset or OTA restart).