39#include <initializer_list>
41#include <soc/soc_caps.h>
93 std::chrono::microseconds
after;
112#if SOC_PM_SUPPORT_EXT0_WAKEUP
135 for (
const auto& pin :
pins) {
136 if (!pin.is_connected()) {
139 mask |=
uint64_t{1} <<
static_cast<unsigned>(pin.num());
147#if SOC_PM_SUPPORT_EXT1_WAKEUP
162#if CONFIG_IDF_TARGET_ESP32
191 : _pin_mask(detail::pin_mask_of(
pins))
217#if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
249 : _pin_mask(detail::pin_mask_of(
pins))
281#if SOC_PM_SUPPORT_EXT0_WAKEUP
285#if SOC_PM_SUPPORT_EXT1_WAKEUP
289#if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
291void disarm(
const deep_sleep_gpio_wake&
source)
noexcept;
301 ((r = arm(sources)) && ...);
306template<
typename... Sources>
307void disarm_all(
const Sources&... sources)
noexcept {
308 (disarm(sources), ...);
323 { detail::arm(
source) } -> std::same_as<result<void>>;
334#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
401 detail::disarm_all(
sources...);
404 auto cause = detail::do_light_sleep();
405 detail::disarm_all(
sources...);
409#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
447#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
474 detail::do_deep_sleep();
497template<wake_spec
First, wake_spec...
Rest>
503 detail::do_deep_sleep();
561#if SOC_PM_SUPPORT_EXT1_WAKEUP
577#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
591template<wake_spec Source>
611template<wake_spec Source>
613 return detail::arm(
source);
616#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
659#include "sdkconfig.h"
660#ifdef CONFIG_IDFXX_STD_FORMAT
669 template<
typename FormatContext>
671 auto s = to_string(source);
672 return std::copy(s.begin(), s.end(), ctx.out());
level
GPIO output/input level.
Wakes the chip from deep sleep on levels of one or more pins.
constexpr deep_sleep_gpio_wake(uint64_t pin_mask, deep_sleep_gpio_mode mode) noexcept
Specifies a deep-sleep GPIO wake on a mask of pins.
constexpr deep_sleep_gpio_wake(std::initializer_list< idfxx::gpio > pins, deep_sleep_gpio_mode mode) noexcept
Specifies a deep-sleep GPIO wake on a set of pins.
constexpr deep_sleep_gpio_mode mode() const noexcept
Whether high or low levels trigger the wake.
constexpr uint64_t pin_mask() const noexcept
Bit mask of GPIO numbers to wake on.
Wakes the chip on levels of one or more RTC-capable pins (EXT1).
constexpr ext1_wake(std::initializer_list< idfxx::gpio > pins, enum ext1_mode mode) noexcept
Specifies an EXT1 wake on a set of pins.
constexpr enum ext1_mode mode() const noexcept
Whether high or low levels trigger the wake.
constexpr uint64_t pin_mask() const noexcept
Bit mask of GPIO numbers to wake on.
constexpr ext1_wake(uint64_t pin_mask, enum ext1_mode mode) noexcept
Specifies an EXT1 wake on a mask of pins.
High-resolution timer with microsecond precision.
A wake-up source specification accepted by the sleep functions.
uint64_t ext1_wakeup_status() noexcept
Returns the pins that triggered the most recent EXT1 wake.
wakeup_source light_sleep(const Sources &... sources)
Enters light sleep until one of the given wake-up sources triggers.
std::string to_string(wakeup_source source)
Returns a string representation of a wake-up source.
ext1_mode
EXT1 wake-up trigger mode.
@ any_low
Wake when any selected pin goes low.
@ any_high
Wake when any selected pin goes high.
result< void > try_disable_wakeup_source(wakeup_source source)
Disarms a previously armed wake-up source.
void disable_wakeup_source(wakeup_source source)
Disarms a previously armed wake-up source.
void disable_all_wakeup_sources()
Disarms every armed wake-up source.
result< void > try_enable_wakeup(const Source &source)
Arms a wake-up source persistently.
wakeup_source light_sleep_for(std::chrono::microseconds duration)
Enters light sleep for a fixed duration.
std::optional< wakeup_source > wakeup_cause() noexcept
Returns the cause of the most recent wake from sleep.
result< void > try_disable_all_wakeup_sources()
Disarms every armed wake-up source.
deep_sleep_gpio_mode
Trigger level for deep-sleep GPIO wake-up.
@ wake_low
Wake when a selected pin goes low.
@ wake_high
Wake when a selected pin goes high.
void deep_sleep() noexcept
Enters deep sleep until a previously armed wake-up source triggers.
wakeup_source
Wake-up sources and causes.
@ cocpu
ULP-RISC-V coprocessor interrupt.
@ wifi
Wi-Fi beacon (light sleep only).
@ bt
Bluetooth activity (light sleep only).
@ ulp
ULP coprocessor program.
@ uart
UART activity (light sleep only).
@ cocpu_trap
ULP-RISC-V coprocessor crash.
@ other
A source not represented in this enumeration (chip-specific).
@ ext0
Level on a single RTC-capable pin (EXT0).
@ ext1
Level on one or more RTC-capable pins (EXT1).
result< wakeup_source > try_light_sleep_for(std::chrono::microseconds duration)
Enters light sleep for a fixed duration.
void enable_wakeup(const Source &source)
Arms a wake-up source persistently.
result< wakeup_source > try_light_sleep(const Sources &... sources)
Enters light sleep until one of the given wake-up sources triggers.
result< void > try_deep_sleep(const First &first, const Rest &... rest)
Enters deep sleep until one of the given wake-up sources triggers.
constexpr std::unexpected< std::error_code > error(E e) noexcept
Creates an unexpected error from an error code enum.
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Wakes the chip when a single RTC-capable pin is at a level (EXT0).
idfxx::gpio::level level
The level that triggers the wake.
idfxx::gpio pin
The pin to wake on; must be RTC-capable.
Wakes the chip from light sleep when a digital pin is at a level.
idfxx::gpio pin
The pin to wake on.
idfxx::gpio::level level
The level that triggers the wake.
Wakes the chip after a fixed duration of sleep.
std::chrono::microseconds after
Time to sleep before waking.