use super::*;
pub struct FTimer<TIM, const FREQ: u32> {
pub(crate) tim: TIM,
clk: HertzU32,
}
pub type FTimerUs<TIM> = FTimer<TIM, 1_000_000>;
pub type FTimerMs<TIM> = FTimer<TIM, 1_000>;
impl<TIM: GeneralTimer, const FREQ: u32> FTimer<TIM, FREQ> {
pub fn new(tim: TIM, clk: HertzU32) -> Self {
let mut t = Self { tim, clk };
t.configure();
t
}
pub fn configure(&mut self) {
assert!(self.clk.raw() % FREQ == 0);
let psc = self.clk.raw() / FREQ;
self.tim.set_prescaler(u16::try_from(psc - 1).unwrap());
}
pub fn counter(self) -> Counter<TIM, FREQ> {
Counter(self)
}
pub fn release(self) -> TIM {
self.tim
}
pub fn listen(&mut self, event: Event) {
self.tim.listen_interrupt(event, true);
}
pub fn clear_interrupt(&mut self, event: Event) {
self.tim.clear_interrupt_flag(event);
}
pub fn get_interrupt(&mut self) -> Event {
self.tim.get_interrupt_flag()
}
pub fn unlisten(&mut self, event: Event) {
self.tim.listen_interrupt(event, false);
}
pub fn stop_in_debug(&mut self, state: bool) {
self.tim.stop_in_debug(state);
}
}
impl<TIM: MasterTimer, const FREQ: u32> FTimer<TIM, FREQ> {
pub fn set_master_mode(&mut self, mode: MasterMode) {
self.tim.master_mode(mode)
}
}