~ruther/simple-clock

ref: b92738752d8b6cc66a2b634b6528a7f5d3f2a315 simple-clock/source/src/count_down.rs -rw-r--r-- 714 bytes
b9273875 — František Boháček feat(src): add meaningful message to panic in Calendar::days_in_month 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