Struct LpTimer

Source
pub struct LpTimer<M: CountMode> { /* private fields */ }
Expand description

Low-Power Timer (LPTIM).

The Low-Power Timer is a 16-bit timer with a prescaler of up to 128. It can run off of the APB1, LSI, HSI16, or LSE clocks. With LSE, the slowest clock at 32.768 kHz, this results in a maximum timeout of 256 seconds, or 4 minutes and 16 seconds.

The timer can be initialized either in one-shot mode or in periodic mode, using init_oneshot or init_periodic respectively. In periodic mode, the embedded-hal Periodic marker trait is implemented and the CountDown implementation uses Hertz as the time unit. In one-shot mode, the CountDown implementation instead uses Microseconds, allowing for a multi-second timeout to be configured (with the tradeoff being a larger code size due to use of 64-bit arithmetic).

Implementations§

Source§

impl LpTimer<Periodic>

Source

pub fn init_periodic( lptim: LPTIM, pwr: &mut PWR, rcc: &mut Rcc, clk: ClockSrc, ) -> Self

Initializes the Low-Power Timer in periodic mode.

The timer needs to be started by calling .start(freq).

Source§

impl LpTimer<OneShot>

Source

pub fn init_oneshot( lptim: LPTIM, pwr: &mut PWR, rcc: &mut Rcc, clk: ClockSrc, ) -> Self

Initializes the Low-Power Timer in one-shot mode.

The timer needs to be started by calling .start(freq).

Source§

impl LpTimer<Encoder>

Source

pub fn init_encoder( lptim: LPTIM, pwr: &mut PWR, rcc: &mut Rcc, clk: ClockSrc, (pb5, pb7): (PB5<Analog>, PB7<Analog>), ) -> Self

Initializes the Low-Power Timer in encoder mode.

The start method must be called to enable the encoder input.

Source

pub fn enable(&mut self, arr: u16)

Enable the timer and begin counting encoder pulses.

The provided value is stored in the ARR (Auto Reload Register). The timer’s internal counter will wrap when this value is reached.

Source

pub fn disable(&mut self)

Disable the timer.

Source

pub fn count(&self) -> u16

Get the current count of the encoder.

Source

pub fn clear_flags(&self)

Clear all LPTIM interrupt flags

Source§

impl<M: CountMode> LpTimer<M>

Source

pub fn free(self) -> LPTIM

Disables and destructs the timer, returning the raw LPTIM peripheral.

Source

pub fn enable_interrupts(&mut self, interrupts: Interrupts)

Disables the timer and enables the given interrupts.

Source

pub fn disable_interrupts(&mut self, interrupts: Interrupts)

Disables the timer and disables the given interrupts.

Trait Implementations§

Source§

impl CountDown for LpTimer<OneShot>

Source§

type Time = Microseconds

The unit of time used by this timer
Source§

fn start<T>(&mut self, period: T)
where T: Into<Microseconds>,

Starts a new count down
Source§

fn wait(&mut self) -> Result<(), Void>

Non-blockingly “waits” until the count down finishes Read more
Source§

impl CountDown for LpTimer<Periodic>

Source§

type Time = Hertz

The unit of time used by this timer
Source§

fn start<T>(&mut self, freq: T)
where T: Into<Hertz>,

Starts a new count down
Source§

fn wait(&mut self) -> Result<(), Void>

Non-blockingly “waits” until the count down finishes Read more
Source§

impl Periodic for LpTimer<Periodic>

Auto Trait Implementations§

§

impl<M> Freeze for LpTimer<M>

§

impl<M> RefUnwindSafe for LpTimer<M>
where M: RefUnwindSafe,

§

impl<M> Send for LpTimer<M>
where M: Send,

§

impl<M> !Sync for LpTimer<M>

§

impl<M> Unpin for LpTimer<M>
where M: Unpin,

§

impl<M> UnwindSafe for LpTimer<M>
where M: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.