Trait linux_embedded_hal::CountDown
source · 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 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
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§
Required Methods§
sourcefn wait(&mut self) -> Result<(), Self::Error>
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 returnedOk
is UNSPECIFIED. Implementers are suggested to panic on this scenario to signal a programmer error.
Object Safety§
This trait is not object safe.