1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#![cfg_attr(not(test), no_std)]
mod clock;
mod delay;
pub use clock::*;
pub use delay::*;
#[macro_export]
macro_rules! embedded_countdown {
($name:ident, $from_unit:ty, $to_unit:ty => ($arg:tt) $convert:tt) => {
pub struct $name<CD: CountDown<Time = $to_unit>> {
t: CD,
}
impl<CD: CountDown<Time = $to_unit>> $name<CD> {
pub fn from(t: CD) -> Self {
Self { t }
}
}
impl<CD> embedded_hal::timer::CountDown for $name<CD>
where
CD: CountDown<Time = $to_unit>,
{
type Time = $from_unit;
fn start<T>(&mut self, count: T)
where
T: Into<Self::Time>,
{
let $arg: $from_unit = count.into();
let to_count = $convert;
self.t.start(to_count);
}
fn wait(&mut self) -> nb::Result<(), void::Void> {
self.t.wait()
}
}
};
}