Closed
Description
Almost all the hal implementations:
- have the same time.rs module defining time object like
Hz
- implement (more or less right) a Delay object on each timer.
I think that this can be solved in embedded-hal by:
- Defining something like time.rs
- Having a trait
CalibratedCountDown
that provide the needed function to implement delay - A Wrapper type over a
CalibratedCountDown
that provide theDelay
implementation.
Then, the hal only have to provide a CalibratedCountDown
object that can be created from a timer and a Clock
object.
An idea of the implementation:
pub trait CalibratedCountDown {
/// The duration of a tick.
fn tick(&self) -> Duration;
/// Maximum ticks the counter can count.
fn max_ticks(&self) -> usize;
/// Start a new countdown of `count` ticks.
fn start<T>(&mut self, count: usize);
/// Non-blockingly "waits" until the count down finishes.
fn wait(&mut self) -> Result<(), Void>
}
Then you can generically implement Delay as atsamd-rs/atsamd#14