Skip to content

Commit

Permalink
more smaller improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Sep 17, 2024
1 parent 3d6a492 commit a9185ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions examples/simple/examples/timer-ticks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use core::cell::Cell;
use cortex_m_rt::entry;
use critical_section::Mutex;
use embedded_hal::delay::DelayNs;
use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print};
use simple_examples::peb1;
Expand Down Expand Up @@ -35,7 +36,7 @@ fn main() -> ! {
.xtal_n_clk_with_src_freq(peb1::EXTCLK_FREQ)
.freeze(&mut dp.sysconfig)
.unwrap();
let _ = set_up_ms_tick(&mut dp.sysconfig, dp.tim0, &clocks);
let mut delay_provider = set_up_ms_tick(&mut dp.sysconfig, dp.tim0, &clocks);
let mut second_timer = CountdownTimer::new(&mut dp.sysconfig, dp.tim1, &clocks);
second_timer.start(1.Hz());
second_timer.listen();
Expand All @@ -47,7 +48,7 @@ fn main() -> ! {
let second = critical_section::with(|cs| SEC_COUNTER.borrow(cs).get());
rprintln!("Second counter: {}", second);
}
cortex_m::asm::delay(10000);
delay_provider.delay_ms(1000);
}
}

Expand Down
4 changes: 2 additions & 2 deletions va416xx-hal/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ impl<Tim: ValidTim> CountdownTimer<Tim> {
pub fn load(&mut self, timeout: impl Into<Hertz>) {
self.tim.reg().ctrl().modify(|_, w| w.enable().clear_bit());
self.curr_freq = timeout.into();
self.rst_val = self.clock.raw() / self.curr_freq.raw();
self.rst_val = self.clock.raw() / self.curr_freq.raw() - 1;
self.set_reload(self.rst_val);
// Decrementing counter, to set the reset value.
self.set_count(0);
Expand All @@ -610,7 +610,7 @@ impl<Tim: ValidTim> CountdownTimer<Tim> {

#[inline(always)]
pub fn enable(&mut self) {
self.tim.reg().ctrl().modify(|_, w| w.enable().set_bit());
self.tim.reg().enable().write(|w| unsafe { w.bits(1) });
}

#[inline(always)]
Expand Down

0 comments on commit a9185ff

Please sign in to comment.