stm32f1_hal/common/timer/
fix_timer.rs1use super::*;
2
3pub struct FTimer<TIM, const FREQ: u32> {
7 pub(crate) tim: TIM,
8 clk: HertzU32,
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: HertzU32) -> 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> {
35 Counter(self)
36 }
37
38 pub fn release(self) -> TIM {
40 self.tim
41 }
42
43 pub fn listen(&mut self, event: Event) {
48 self.tim.listen_interrupt(event, true);
49 }
50
51 pub fn clear_interrupt(&mut self, event: Event) {
56 self.tim.clear_interrupt_flag(event);
57 }
58
59 pub fn get_interrupt(&mut self) -> Event {
60 self.tim.get_interrupt_flag()
61 }
62
63 pub fn unlisten(&mut self, event: Event) {
65 self.tim.listen_interrupt(event, false);
66 }
67
68 pub fn stop_in_debug(&mut self, state: bool) {
70 self.tim.stop_in_debug(state);
71 }
72}
73
74impl<TIM: MasterTimer, const FREQ: u32> FTimer<TIM, FREQ> {
75 pub fn set_master_mode(&mut self, mode: MasterMode) {
76 self.tim.master_mode(mode)
77 }
78}