~ruther/simple-clock

ref: 994a92fe69cfc8bbe5ebd05303695c8cf877eb7c simple-clock/source/src/count_down.rs -rw-r--r-- 714 bytes
994a92fe — František Boháček chore(src): format with cargo-fmt 1 year, 8 months ago
                                                                                
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
use fugit::MicrosDurationU32;
use nb::Result;
use stm32f1xx_hal::timer::{self, CounterUs, Instance};

pub trait CountDown {
    type Time;

    fn start(&mut self, count: Self::Time);
    fn wait(&mut self) -> Result<(), timer::Error>;
}

pub struct CountDowner<T> {
    counter: CounterUs<T>,
}

impl<T> CountDowner<T>
where
    T: Instance,
{
    pub fn new(counter: CounterUs<T>) -> Self {
        Self { counter }
    }
}

impl<T> CountDown for CountDowner<T>
where
    T: Instance,
{
    type Time = MicrosDurationU32;

    fn start(&mut self, count: Self::Time) {
        self.counter.start(count).unwrap();
    }

    fn wait(&mut self) -> nb::Result<(), timer::Error> {
        self.counter.wait()
    }
}
Do not follow this link