Skip to main content

Timer

Struct Timer 

Source
pub struct Timer<TIMERX> { /* private fields */ }
Expand description

A stopped timer, holding the peripheral and the frequency feeding it.

Clocked and reset on construction, but the counter is not running.

Implementations§

Source§

impl<TIMERX: Instance> Timer<TIMERX>

Source

pub fn release(self, rcu: &mut Rcu) -> TIMERX

Returns the peripheral with its clock stopped.

Source

pub fn start(self, psc: u16, car: u16) -> CountDownTimer<TIMERX>

Starts the counter, which then rolls over every car + 1 ticks of clk / (psc + 1).

The dividers reach the counter before it runs, so the first wait already measures the full interval.

Source

pub fn start_interval<const NOM: u64, const DENOM: u64>( self, interval: Duration<u32, NOM, DENOM>, ) -> CountDownTimer<TIMERX>

Starts the counter, which then rolls over once per interval.

Any scale works with no conversion at the call site — 5.secs(), 500.millis(), 100.micros(). Truncating, so the realised interval is at most one prescaler cycle short. Intervals past what the 16-bit dividers span (just under a minute at 72 MHz) saturate; zero becomes one tick.

Source

pub fn into_delay(self) -> Delay<TIMERX>

Hands the timer over to blocking delays; every delay sets up its own interval and tears it down again.

Source

pub fn into_pwm(self, psc: u16, car: u16) -> Pwm<TIMERX>

Hands the timer over to PWM and starts it on the given period.

The counter cycle is shared by every channel, and car + 1 is also their duty resolution: a larger reload buys finer steps at a lower frequency.

Source

pub fn into_pwm_interval<const NOM: u64, const DENOM: u64>( self, interval: Duration<u32, NOM, DENOM>, ) -> Pwm<TIMERX>

Hands the timer over to PWM, taking the period as a duration.

Splits it like start_interval, keeping the reload large — here that is what leaves the duty the most steps.

Source

pub fn into_capture(self, psc: u16) -> Capture<TIMERX>

Sets the counter free running and hands out the input capture role.

Only the prescaler is a choice: it trades resolution against the longest interval that still fits between two rollovers. The reload is pinned to the maximum.

Auto Trait Implementations§

§

impl<TIMERX> Freeze for Timer<TIMERX>
where TIMERX: Freeze,

§

impl<TIMERX> RefUnwindSafe for Timer<TIMERX>
where TIMERX: RefUnwindSafe,

§

impl<TIMERX> Send for Timer<TIMERX>
where TIMERX: Send,

§

impl<TIMERX> Sync for Timer<TIMERX>
where TIMERX: Sync,

§

impl<TIMERX> Unpin for Timer<TIMERX>
where TIMERX: Unpin,

§

impl<TIMERX> UnsafeUnpin for Timer<TIMERX>
where TIMERX: UnsafeUnpin,

§

impl<TIMERX> UnwindSafe for Timer<TIMERX>
where TIMERX: 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.