pub trait CountDown {
    type Error: Debug;
    type Time;

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

A count down timer

Note that this is borrowed from embedded-hal 0.2.x and will be in use until the 1.x version provides one.

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

use std::time::Duration;
use nb::block;
use linux_embedded_hal::{CountDown, SysTimer};

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

    Led.on();
    timer.start(Duration::from_millis(1000)).unwrap();
    block!(timer.wait()); // blocks for 1 second
    Led.off();
}

Required Associated Types§

source

type Error: Debug

An enumeration of CountDown errors.

For infallible implementations, will be Infallible

source

type Time

The unit of time used by this timer

Required Methods§

source

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

Starts a new count down

source

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

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T: CountDown> CountDown for &mut T

§

type Error = <T as CountDown>::Error

§

type Time = <T as CountDown>::Time

source§

fn start<TIME>(&mut self, count: TIME) -> Result<(), Self::Error>
where TIME: Into<Self::Time>,

source§

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

Implementors§