Trait embedded_hal::timer::nb::CountDown [−][src]
pub trait CountDown {
type Error: Debug;
type Time;
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
Contract
self.start(count); block!(self.wait());
MUST block for AT LEAST the time specified bycount
.
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::timer::nb::CountDown;
fn main() {
let mut led: Led = {
// ..
};
let mut timer: Timer6 = {
// ..
};
Led.on();
timer.start(1.s()).unwrap();
block!(timer.wait()); // blocks for 1 second
Led.off();
}
Associated Types
An enumeration of CountDown
errors.
For infallible implementations, will be Infallible
Required methods
Starts a new count down
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 returnedOk
is UNSPECIFIED. Implementers are suggested to panic on this scenario to signal a programmer error.