pub struct LowPower<'d> { /* private fields */ }unstable only.Expand description
Low-power management.
The sleep calls do not take the wakeup sources that end the sleep. Each driver enables the source that it owns, and the hardware wakeup-enable mask keeps that request until the driver clears it. The mask keeps it through a light sleep, and through a deep-sleep wake. A sleep call reads the mask back, and calculates the rest of the configuration from it.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Implementations§
Source§impl<'d> LowPower<'d>
impl<'d> LowPower<'d>
Sourcepub fn set_wakeup_deadline(&mut self, deadline: Instant)
pub fn set_wakeup_deadline(&mut self, deadline: Instant)
Arms the sleep alarm for deadline, and enables the timer wakeup source.
The deadline is absolute, so the time between this call and the sleep does not make the
sleep shorter. The deadline is a standing request. The wake that it causes does not
disarm it, a later call replaces it, and Self::clear_wakeup_deadline removes it.
A deadline in the past ends a light sleep immediately, and makes Self::sleep_deep panic.
Sourcepub fn clear_wakeup_deadline(&mut self)
pub fn clear_wakeup_deadline(&mut self)
Disarms the sleep alarm, and disables the timer wakeup source.
Sourcepub fn sleep_deep(&mut self, config: RtcSleepConfig) -> !
pub fn sleep_deep(&mut self, config: RtcSleepConfig) -> !
Enters deep sleep, and does not return.
In deep sleep the CPUs, most of the RAM, and all digital peripherals that are clocked from
APB_CLK are powered off. The wake resets the chip, so use the
#[esp_hal::ram(persistent)] attribute to keep a variable through the
sleep.
The hardware cannot reject this sleep, because the function cannot return to report the
rejection. Use Self::sleep_deep_with_rejection for that.
§Panics
Panics if no wakeup source is enabled, because then nothing can end the sleep. Panics also if the armed wakeup deadline is too near for the sleep transition to catch it. In both cases the chip never wakes again, and it gives no report of the cause.
Sourcepub fn sleep_deep_with_rejection(&mut self, config: RtcSleepConfig)
pub fn sleep_deep_with_rejection(&mut self, config: RtcSleepConfig)
Enters deep sleep, and returns only if the hardware rejects the request.
The hardware rejects a sleep if one of its wakeup sources is already asserted. Without the rejection, the chip sleeps through the event that the caller wants to wake on. The return of this function is the complete report, so it gives no other result.
A rejected request returns the wake pads to their drivers, but it cannot return every pad.
Sleep entry disconnects the pads that no hold keeps, on the chips that need that step to
reach the deep-sleep current, and it cannot know their earlier configuration. Configure
those pads again if this function returns. ESP-IDF has the same limit in
esp_deep_sleep_try_to_start.
§Panics
Panics if no wakeup source is enabled.
Sourcepub fn sleep_light(&mut self, config: RtcSleepConfig)
pub fn sleep_light(&mut self, config: RtcSleepConfig)
Enters light sleep, and returns when a wakeup source ends it.
Light sleep keeps the state of the digital domain, so the program continues at the same place.
The function also returns immediately, without a sleep, if no wakeup source is enabled, or if the hardware rejects the request because a wakeup source is already asserted. It reports neither case. For the caller, a refused sleep, a rejected sleep and a very short sleep have the same result.