drogue-embedded-timer
When writing device drivers against embedded-hal
, a wall can be hit when attempting to work with CountDown
timers due to the Time
associated type.
The embedded-time
crate is attempting to homogenous the concept of time, clocks, durations and rates.
At this point the various HALs have not adopted embedded-time
, so this crate provides a simple macro to help accomodate drivers needing a consistent view of timers.
Usage
Generic drivers should be written in terms of CountDown
that uses embedded-time
flavors of time.
Application writers attempting to provision a concrete instance of the aforementioned drivers can use this macro to convert their HAL's timer into an embedded-time
-centric CountDown
.
Example
Use the embedded_countdown!(...)
macro to define a new struct that can consume a HAL-specific timer, and wrap it into an embedded-time
timer.
The macro takes a few arguments:
- The name of the struct to create.
- The exposed units (usually an
embedded-time
duration) expected by the driver. - The HAL's units expected by the built-in
CountDown
structure being wrapped. - The 1-argument conversion routine to handle the conversion.
embedded_countdown!;
Once a structure has been defined, you can then use it:
let mut hal_hz_timer = tim16;
let mut embedded_ms_timer = from;
Now the embedded_ms_timer
is a CountDown<Time=embedded_time::duration::Milliseconds>
and is no longer tied to a specific HAL implementation.