stm32f1_hal/common/timer/
fix_timer.rs1use super::*;
2
3pub struct FTimer<TIM, const FREQ: u32> {
7 pub(crate) tim: TIM,
8 clk: Hertz,
9}
10
11pub type FTimerUs<TIM> = FTimer<TIM, 1_000_000>;
13
14pub type FTimerMs<TIM> = FTimer<TIM, 1_000>;
18
19impl<TIM: GeneralTimer, const FREQ: u32> FTimer<TIM, FREQ> {
20 pub fn new(tim: TIM, clk: Hertz) -> Self {
22 let mut t = Self { tim, clk };
23 t.configure();
24 t
25 }
26
27 pub fn configure(&mut self) {
29 assert!(self.clk.raw() % FREQ == 0);
30 let psc = self.clk.raw() / FREQ;
31 self.tim.set_prescaler(u16::try_from(psc - 1).unwrap());
32 }
33
34 pub fn counter(self) -> Counter<TIM, FREQ> {
36 Counter(self)
37 }
38
39 pub fn release(self) -> TIM {
41 self.tim
42 }
43
44 pub fn listen(&mut self, event: Event) {
49 self.tim.listen_interrupt(event, true);
50 }
51
52 pub fn clear_interrupt(&mut self, event: Event) {
57 self.tim.clear_interrupt_flag(event);
58 }
59
60 pub fn get_interrupt(&mut self) -> Event {
61 self.tim.get_interrupt_flag()
62 }
63
64 pub fn unlisten(&mut self, event: Event) {
66 self.tim.listen_interrupt(event, false);
67 }
68
69 pub fn stop_in_debug(&mut self, state: bool) {
71 self.tim.stop_in_debug(state);
72 }
73}
74
75impl<TIM: MasterTimer, const FREQ: u32> FTimer<TIM, FREQ> {
76 pub fn set_master_mode(&mut self, mode: MasterMode) {
77 self.tim.master_mode(mode)
78 }
79}