Skip to content

Commit 74d18e1

Browse files
committed
count_down don't start at init
1 parent 44a087b commit 74d18e1

File tree

7 files changed

+21
-8
lines changed

7 files changed

+21
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Added
1111

12+
- `count_down` constructor for `Timer` -> `CountDownTimer` without start [#382]
1213
- Implementation of RTIC Monotonic for TIM2 & TIM5 under `rtic` feature [#380]
1314
- `IoPin` for `Output<OpenDrain>> <-> Input<Floating>>` [#374]
1415

16+
[#382]: https://github.com/stm32-rs/stm32f4xx-hal/pull/382
1517
[#380]: https://github.com/stm32-rs/stm32f4xx-hal/pull/380
1618
[#374]: https://github.com/stm32-rs/stm32f4xx-hal/pull/374
1719

1820
### Changed
1921

20-
- [breaking-change] Remove all deprecated
2122
- [breaking-change] Bump `stm32f4` to 0.14. Update RTIC based examples to use `rtic` 0.6 [#367]
2223
- [breaking-change] Bump `bxcan` to 0.6 [#371]
2324

examples/analog-stopwatch-with-spi-ssd1306.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ fn main() -> ! {
127127
disp.flush().unwrap();
128128

129129
// Create a 1ms periodic interrupt from TIM2
130-
let mut timer = Timer::new(dp.TIM2, &clocks).start_count_down(1.hz());
130+
let mut timer = Timer::new(dp.TIM2, &clocks).count_down();
131+
timer.start(1.hz());
131132
timer.listen(Event::TimeOut);
132133

133134
free(|cs| {

examples/blinky-timer-irq.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ fn main() -> ! {
7979
cortex_m::interrupt::free(|cs| *G_LED.borrow(cs).borrow_mut() = Some(led));
8080

8181
// Set up a timer expiring after 1s
82-
let mut timer = Timer::new(dp.TIM2, &clocks).start_count_down(1.hz());
82+
let mut timer = Timer::new(dp.TIM2, &clocks).count_down();
83+
timer.start(1.hz());
8384

8485
// Generate an interrupt when the timer expires
8586
timer.listen(Event::TimeOut);

examples/stopwatch-with-ssd1306-and-interrupts.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ fn main() -> ! {
9393
disp.flush().unwrap();
9494

9595
// Create a 1ms periodic interrupt from TIM2
96-
let mut timer = Timer::new(dp.TIM2, &clocks).start_count_down(1.hz());
96+
let mut timer = Timer::new(dp.TIM2, &clocks).count_down();
97+
timer.start(1.hz());
9798
timer.listen(Event::TimeOut);
9899

99100
free(|cs| {

examples/timer-periph.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ fn main() -> ! {
2929
let clocks = rcc.cfgr.sysclk(24.mhz()).freeze();
3030

3131
// Create a timer based on SysTick
32-
let mut timer = Timer::new(dp.TIM1, &clocks).start_count_down(1.hz());
32+
let mut timer = Timer::new(dp.TIM1, &clocks).count_down();
33+
timer.start(1.hz());
3334

3435
hprintln!("hello!").unwrap();
3536
// wait until timer expires

examples/timer-syst.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ fn main() -> ! {
3030
let clocks = rcc.cfgr.sysclk(24.mhz()).freeze();
3131

3232
// Create a timer based on SysTick
33-
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(24.hz());
33+
let mut timer = Timer::syst(cp.SYST, &clocks).count_down();
34+
timer.start(24.hz());
3435

3536
hprintln!("hello!").unwrap();
3637
// wait until timer expires

src/timer.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ pub struct CountDownTimer<TIM> {
3030
clk: Hertz,
3131
}
3232

33+
impl<TIM> Timer<TIM> {
34+
/// Creates CountDownTimer
35+
pub fn count_down(self) -> CountDownTimer<TIM> {
36+
let Self { tim, clk } = self;
37+
CountDownTimer { tim, clk }
38+
}
39+
}
40+
3341
impl<TIM> Timer<TIM>
3442
where
3543
CountDownTimer<TIM>: CountDown<Time = Hertz>,
@@ -39,8 +47,7 @@ where
3947
where
4048
T: Into<Hertz>,
4149
{
42-
let Self { tim, clk } = self;
43-
let mut timer = CountDownTimer { tim, clk };
50+
let mut timer = self.count_down();
4451
timer.start(timeout);
4552
timer
4653
}

0 commit comments

Comments
 (0)