Skip to main content

LowPower

Struct LowPower 

Source
pub struct LowPower<'d> { /* private fields */ }
Available on crate feature 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>

Source

pub fn new(lpwr: LPWR<'d>) -> Self

Creates a new LowPower driver.

Source

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.

Source

pub fn clear_wakeup_deadline(&mut self)

Disarms the sleep alarm, and disables the timer wakeup source.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'d> !UnwindSafe for LowPower<'d>

§

impl<'d> Freeze for LowPower<'d>

§

impl<'d> RefUnwindSafe for LowPower<'d>

§

impl<'d> Send for LowPower<'d>

§

impl<'d> Sync for LowPower<'d>

§

impl<'d> Unpin for LowPower<'d>

§

impl<'d> UnsafeUnpin for LowPower<'d>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.