Trait crabik_board::timer::CountDown[][src]

pub trait CountDown {
    type Time;
    pub fn start<T>(&mut self, count: T)
    where
        T: Into<Self::Time>
;
pub fn wait(&mut self) -> Result<(), Error<Void>>; }

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();
}

Associated Types

type Time[src]

The unit of time used by this timer

Loading content...

Required methods

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

Starts a new count down

pub fn wait(&mut self) -> Result<(), Error<Void>>[src]

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.
Loading content...

Implementations on Foreign Types

impl<T, U> CountDown for Timer<T, U> where
    T: Instance
[src]

type Time = u32

pub fn start<Time>(&mut self, cycles: Time) where
    Time: Into<<Timer<T, U> as CountDown>::Time>, 
[src]

Start the timer.

The timer will run for the given number of cycles, then it will stop and reset.

pub fn wait(&mut self) -> Result<(), Error<Void>>[src]

Wait for the timer to stop.

Will return Err(nb::Error::WouldBlock) while the timer is still running. Once the timer reached the number of cycles given in the start method, it will return Ok(()).

To block until the timer has stopped, use the block! macro from the nb crate. Please refer to the documentation of nb for other options.

Loading content...

Implementors

Loading content...