Skip to content

Commit

Permalink
add func
Browse files Browse the repository at this point in the history
  • Loading branch information
Nilolay committed Jan 1, 2025
1 parent 2b62579 commit 5619998
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions examples/rtic2-timer-input-capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ mod app {

#[task(binds = TIM5, local = [tim5, ch1, prev_capture: u32 = 0], priority = 3)]
fn tim5_interrupt(cx: tim5_interrupt::Context) {
let timer_clock = cx.local.tim5.get_timer_clock();

if cx.local.tim5.flags().contains(Flag::C1) {
let timer_clock = cx.local.tim5.get_timer_clock();
let max_auto_reload = cx.local.tim5.get_max_auto_reload();
let current_capture = cx.local.ch1.get_capture();

let delta = if current_capture >= *cx.local.prev_capture {
current_capture - *cx.local.prev_capture
} else {
(u32::MAX - *cx.local.prev_capture) + current_capture
(max_auto_reload - *cx.local.prev_capture) + current_capture
};

let freq = timer_clock as f32 / delta as f32;
Expand Down
6 changes: 5 additions & 1 deletion src/timer/capture_compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ where
);

self.tim.set_prescaler(psc as u16 - 1);
self.tim.set_auto_reload(1 << 16).unwrap();
self.tim.set_auto_reload(TIM::max_auto_reload()).unwrap();
self.tim.cnt_reset();
}

pub fn get_max_auto_reload(&mut self) -> u32 {
TIM::max_auto_reload()
}
}

0 comments on commit 5619998

Please sign in to comment.