_embedded_hal_timer_CountDown

Trait _embedded_hal_timer_CountDown 

Source
pub trait _embedded_hal_timer_CountDown {
    type Time;

    // Required methods
    fn start<T>(&mut self, count: T)
       where T: Into<Self::Time>;
    fn wait(&mut self) -> Result<(), Error<Void>>;
}
Expand description

A count down timer

§Contract

  • self.start(count); block!(self.wait()); MUST block for AT LEAST the time specified by count.

Note that the implementer doesn’t necessarily have to be a downcounting timer; it could also be an upcounting timer as long as the above contract is upheld.

§Examples

You can use this timer to create delays

extern crate embedded_hal as hal;
#[macro_use(block)]
extern crate nb;

use hal::prelude::*;

fn main() {
    let mut led: Led = {
        // ..
    };
    let mut timer: Timer6 = {
        // ..
    };

    Led.on();
    timer.start(1.s());
    block!(timer.wait()); // blocks for 1 second
    Led.off();
}

Required Associated Types§

Source

type Time

The unit of time used by this timer

Required Methods§

Source

fn start<T>(&mut self, count: T)
where T: Into<Self::Time>,

Starts a new count down

Source

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

Non-blockingly “waits” until the count down finishes

§Contract
  • If Self: Periodic, the timer will start a new count down right after the last one finishes.
  • Otherwise the behavior of calling wait after the last call returned Ok is UNSPECIFIED. Implementers are suggested to panic on this scenario to signal a programmer error.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl CountDown for Timer<SYST>

Use the systick as a timer

Be aware that intervals less than 4 Hertz may not function properly

Source§

impl CountDown for Timer<TIM1>

Source§

impl CountDown for Timer<TIM2>

Source§

impl CountDown for Timer<TIM3>

Source§

impl CountDown for Timer<TIM14>

Source§

impl CountDown for Timer<TIM16>

Source§

impl CountDown for Timer<TIM17>