|
idfxx 1.0.0
Modern C++23 components for ESP-IDF
|
Classes | |
| class | deep_sleep_gpio_wake |
| Wakes the chip from deep sleep on levels of one or more pins. More... | |
| struct | ext0_wake |
| Wakes the chip when a single RTC-capable pin is at a level (EXT0). More... | |
| class | ext1_wake |
| Wakes the chip on levels of one or more RTC-capable pins (EXT1). More... | |
| struct | gpio_wake |
| Wakes the chip from light sleep when a digital pin is at a level. More... | |
| struct | timer_wake |
| Wakes the chip after a fixed duration of sleep. More... | |
Concepts | |
| concept | wake_spec |
| A wake-up source specification accepted by the sleep functions. | |
Enumerations | |
| enum class | wakeup_source : int { ext0 = 2 , ext1 = 3 , timer = 4 , touchpad = 5 , ulp = 6 , gpio = 7 , uart = 8 , wifi = 9 , cocpu = 10 , cocpu_trap = 11 , bt = 12 , other = 13 } |
| Wake-up sources and causes. More... | |
| enum class | ext1_mode : int { any_low = 0 , any_high = 1 } |
| EXT1 wake-up trigger mode. More... | |
| enum class | deep_sleep_gpio_mode : int { wake_low = 0 , wake_high = 1 } |
| Trigger level for deep-sleep GPIO wake-up. More... | |
Functions | |
| std::string | to_string (wakeup_source source) |
| Returns a string representation of a wake-up source. | |
| template<wake_spec... Sources> | |
| result< wakeup_source > | try_light_sleep (const Sources &... sources) |
| Enters light sleep until one of the given wake-up sources triggers. | |
| template<wake_spec... Sources> | |
| wakeup_source | light_sleep (const Sources &... sources) |
| Enters light sleep until one of the given wake-up sources triggers. | |
| wakeup_source | light_sleep_for (std::chrono::microseconds duration) |
| Enters light sleep for a fixed duration. | |
| result< wakeup_source > | try_light_sleep_for (std::chrono::microseconds duration) |
| Enters light sleep for a fixed duration. | |
| template<wake_spec First, wake_spec... Rest> | |
| result< void > | try_deep_sleep (const First &first, const Rest &... rest) |
| Enters deep sleep until one of the given wake-up sources triggers. | |
| template<wake_spec First, wake_spec... Rest> | |
| void | deep_sleep (const First &first, const Rest &... rest) |
| Enters deep sleep until one of the given wake-up sources triggers. | |
| void | deep_sleep () noexcept |
| Enters deep sleep until a previously armed wake-up source triggers. | |
| void | deep_sleep (std::chrono::microseconds duration) noexcept |
| Enters deep sleep for a fixed duration. | |
| std::optional< wakeup_source > | wakeup_cause () noexcept |
| Returns the cause of the most recent wake from sleep. | |
| uint64_t | ext1_wakeup_status () noexcept |
| Returns the pins that triggered the most recent EXT1 wake. | |
| template<wake_spec Source> | |
| void | enable_wakeup (const Source &source) |
| Arms a wake-up source persistently. | |
| template<wake_spec Source> | |
| result< void > | try_enable_wakeup (const Source &source) |
| Arms a wake-up source persistently. | |
| 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_disable_wakeup_source (wakeup_source source) |
| Disarms a previously armed wake-up source. | |
| result< void > | try_disable_all_wakeup_sources () |
| Disarms every armed wake-up source. | |
|
strong |
|
strong |
EXT1 wake-up trigger mode.
The low trigger is chip-specific, and only the enumerator matching the hardware is defined for a given target: the original ESP32 wakes only when all selected pins are low (ext1_mode::all_low), whereas every other EXT1-capable chip wakes when any selected pin is low (ext1_mode::any_low). Selecting the wrong one for the target is a compile error rather than a silent change in behaviour; portable code picks the enumerator under #if CONFIG_IDF_TARGET_ESP32. For a single wake pin the two are equivalent.
| Enumerator | |
|---|---|
| any_low | Wake when any selected pin goes low. |
| any_high | Wake when any selected pin goes high. |
|
strong |
Wake-up sources and causes.
Identifies what woke the chip from sleep (see wakeup_cause), and selects a configured source to disable (see try_disable_wakeup_source).
|
noexcept |
Enters deep sleep until a previously armed wake-up source triggers.
Powers down the CPU and most peripherals, waking on the sources armed with the enable_* functions. Waking restarts the application from the beginning; use wakeup_cause to detect the wake and its source after the restart.
Does not return: with no armed (or no functioning) wake-up source the chip simply sleeps until reset.
| void idfxx::sleep::deep_sleep | ( | const First & | first, |
| const Rest &... | rest | ||
| ) |
Enters deep sleep until one of the given wake-up sources triggers.
Arms each source, then powers down the CPU and most peripherals. Waking restarts the application from the beginning; use wakeup_cause to detect the wake and its source after the restart.
| First | First wake-up source specification type (see wake_spec). |
| Rest | Additional wake-up source specification types. |
| first | The source that may wake the chip. |
| rest | Additional sources that may wake the chip. |
| std::system_error | if a source is invalid; otherwise does not return. |
Definition at line 472 of file sleep.hpp.
References try_deep_sleep(), and idfxx::unwrap().
|
noexcept |
Enters deep sleep for a fixed duration.
Equivalent to enabling a timer wake-up for duration and calling deep_sleep(). Any other previously armed wake-up sources remain active and may wake the chip sooner.
Powers down the CPU and most peripherals. Waking restarts the application from the beginning; use wakeup_cause to detect the wake and its source after the restart.
| duration | Time to sleep before waking. Negative values are treated as zero. |
| void idfxx::sleep::disable_all_wakeup_sources | ( | ) |
Disarms every armed wake-up source.
| std::system_error | on failure. |
| void idfxx::sleep::disable_wakeup_source | ( | wakeup_source | source | ) |
Disarms a previously armed wake-up source.
| source | The source to disarm. |
| std::system_error | on failure. |
Arms a wake-up source persistently.
The source stays armed across any number of sleeps until disarmed with disable_wakeup_source. Use this instead of passing sources to the sleep functions when the same sources are reused across many sleep cycles.
| Source | Wake-up source specification type (see wake_spec). |
| source | The source that may wake the chip. |
| std::system_error | if the source is invalid. |
Definition at line 592 of file sleep.hpp.
References idfxx::unwrap().
|
noexcept |
Returns the pins that triggered the most recent EXT1 wake.
SOC_PM_SUPPORT_EXT1_WAKEUP). | wakeup_source idfxx::sleep::light_sleep | ( | const Sources &... | sources | ) |
Enters light sleep until one of the given wake-up sources triggers.
Arms each source, sleeps, then disarms them again before returning. The CPU is suspended and execution resumes here on wake. Peripheral and memory state is retained, but digital interrupts (including GPIO edge interrupts) are not delivered while sleeping — re-check any interrupt-driven state after waking.
With no arguments, sleeps on the wake-up sources previously armed with the enable_* functions. Such sources stay armed afterwards, unless a source of the same kind (or the same pin, for pin-level sources) is passed here, in which case it is replaced for this sleep and disarmed on return.
| Sources | Wake-up source specification types (see wake_spec). |
| sources | The sources that may wake the chip. |
| std::system_error | if a source is invalid or sleep is rejected (e.g. a wake-up source triggered before sleep was entered). |
Definition at line 368 of file sleep.hpp.
References try_light_sleep(), and idfxx::unwrap().
| wakeup_source idfxx::sleep::light_sleep_for | ( | std::chrono::microseconds | duration | ) |
Enters light sleep for a fixed duration.
Equivalent to light_sleep(timer_wake{duration}) — a low-power counterpart to std::this_thread::sleep_for. Wake-up sources previously armed with the enable_* functions may wake the chip sooner.
| duration | Time to sleep before waking. |
| std::system_error | if the duration is invalid or sleep is rejected. |
| std::string idfxx::sleep::to_string | ( | wakeup_source | source | ) |
Returns a string representation of a wake-up source.
| source | The wake-up source to convert. |
| result< void > idfxx::sleep::try_deep_sleep | ( | const First & | first, |
| const Rest &... | rest | ||
| ) |
Enters deep sleep until one of the given wake-up sources triggers.
Arms each source, then powers down the CPU and most peripherals. Waking restarts the application from the beginning; use wakeup_cause to detect the wake and its source after the restart.
Returns only on failure — on success the chip is powered down and the call never returns.
| First | First wake-up source specification type (see wake_spec). |
| Rest | Additional wake-up source specification types. |
| first | The source that may wake the chip. |
| rest | Additional sources that may wake the chip. |
| idfxx::errc::invalid_arg | if a source is invalid (e.g. an unconnected pin or a pin that cannot wake the chip from deep sleep). |
Definition at line 498 of file sleep.hpp.
References idfxx::error().
Referenced by deep_sleep().
Disarms every armed wake-up source.
| result< void > idfxx::sleep::try_disable_wakeup_source | ( | wakeup_source | source | ) |
Disarms a previously armed wake-up source.
| source | The source to disarm. |
| idfxx::errc::invalid_arg | if the source cannot be disarmed (wakeup_source::other). |
| idfxx::errc::invalid_state | if the source was not armed. |
Arms a wake-up source persistently.
The source stays armed across any number of sleeps until disarmed with try_disable_wakeup_source. Use this instead of passing sources to the sleep functions when the same sources are reused across many sleep cycles.
| Source | Wake-up source specification type (see wake_spec). |
| source | The source that may wake the chip. |
| idfxx::errc::invalid_arg | if the source is invalid (e.g. an unconnected pin or a negative duration). |
| result< wakeup_source > idfxx::sleep::try_light_sleep | ( | const Sources &... | sources | ) |
Enters light sleep until one of the given wake-up sources triggers.
Arms each source, sleeps, then disarms them again before returning. The CPU is suspended and execution resumes here on wake. Peripheral and memory state is retained, but digital interrupts (including GPIO edge interrupts) are not delivered while sleeping — re-check any interrupt-driven state after waking.
With no arguments, sleeps on the wake-up sources previously armed with the try_enable_* functions. Such sources stay armed afterwards, unless a source of the same kind (or the same pin, for pin-level sources) is passed here, in which case it is replaced for this sleep and disarmed on return.
| Sources | Wake-up source specification types (see wake_spec). |
| sources | The sources that may wake the chip. |
| idfxx::errc::invalid_arg | if a source is invalid (e.g. an unconnected pin, a negative duration, or a timer too short to enter sleep at all). |
| idfxx::errc::invalid_state | if sleep was rejected (e.g. a wake-up source triggered before sleep was entered). |
Definition at line 399 of file sleep.hpp.
References idfxx::error().
Referenced by light_sleep().
| result< wakeup_source > idfxx::sleep::try_light_sleep_for | ( | std::chrono::microseconds | duration | ) |
Enters light sleep for a fixed duration.
Equivalent to try_light_sleep(timer_wake{duration}) — a low-power counterpart to std::this_thread::sleep_for. Wake-up sources previously armed with the try_enable_* functions may wake the chip sooner.
| duration | Time to sleep before waking. |
| idfxx::errc::invalid_arg | if the duration is negative or too short to enter sleep at all. |
| idfxx::errc::invalid_state | if sleep was rejected (e.g. a wake-up source triggered before sleep was entered). |
|
noexcept |
Returns the cause of the most recent wake from sleep.
After waking from deep sleep (which restarts the application), this identifies the wake-up source. Returns std::nullopt when the chip did not wake from sleep (e.g. cold boot or reset).
std::nullopt.