Skip to content

Commit 348f947

Browse files
bors[bot]burrbull
andauthored
Merge #449
449: Yet another timer refactoring r=therealprof a=burrbull Should be last big one Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents 1460db9 + a26bfb0 commit 348f947

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1600
-1454
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2222
- Use fugit rate types instead of custom [#430]
2323
- Add channel events, make Event use bitflags (simplify interrupt handling) [#425]
2424
- reexport `digital::v2::PinState` again [#428]
25-
- Timer impls with time based on `fugit` moved to `fugit` module, added `Pwm` and `fugit-timer` impls [#423]
25+
- Timer impls with time based on `fugit::Duration` same as `Hertz` moved to `timer` module,
26+
added appropriate `Ext` traits implemented on peripherals directly,
27+
added `Pwm` and `fugit-timer` impls [#423] [#449]
2628

2729
### Fixed
2830

@@ -60,6 +62,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
6062
[#430]: https://github.com/stm32-rs/stm32f4xx-hal/pull/430
6163
[#447]: https://github.com/stm32-rs/stm32f4xx-hal/pull/447
6264
[#448]: https://github.com/stm32-rs/stm32f4xx-hal/pull/448
65+
[#449]: https://github.com/stm32-rs/stm32f4xx-hal/pull/449
6366

6467
### Changed
6568

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ use panic_semihosting as _;
1111
use stm32f4xx_hal as hal;
1212

1313
use crate::hal::{
14-
fugit::{CounterUs, Event, Timer},
1514
gpio::{Edge, Input, PullDown, PA0},
1615
interrupt, pac,
1716
prelude::*,
1817
rcc::{Clocks, Rcc},
1918
spi::Spi,
19+
timer::{CounterUs, Event, FTimer, Timer},
2020
};
2121

2222
use core::cell::{Cell, RefCell};
@@ -112,7 +112,7 @@ fn main() -> ! {
112112

113113
let dc = gpioe.pe3.into_push_pull_output();
114114
let mut ss = gpioe.pe4.into_push_pull_output();
115-
let mut delay = hal::delay::Delay::new(cp.SYST, &clocks);
115+
let mut delay = Timer::syst(cp.SYST, &clocks).delay();
116116

117117
ss.set_high();
118118
delay.delay_ms(100_u32);
@@ -126,7 +126,7 @@ fn main() -> ! {
126126
disp.flush().unwrap();
127127

128128
// Create a 1ms periodic interrupt from TIM2
129-
let mut timer = Timer::new(dp.TIM2, &clocks).counter();
129+
let mut timer = FTimer::new(dp.TIM2, &clocks).counter();
130130
timer.start(1.secs()).unwrap();
131131
timer.listen(Event::Update);
132132

examples/blinky-timer-irq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use panic_halt as _;
1111
use stm32f4xx_hal as hal;
1212

1313
use crate::hal::{
14-
fugit::{CounterUs, Event, Timer},
1514
gpio::{self, Output, PushPull},
1615
pac::{interrupt, Interrupt, Peripherals, TIM2},
1716
prelude::*,
17+
timer::{CounterUs, Event},
1818
};
1919

2020
use core::cell::RefCell;
@@ -78,7 +78,7 @@ fn main() -> ! {
7878
cortex_m::interrupt::free(|cs| *G_LED.borrow(cs).borrow_mut() = Some(led));
7979

8080
// Set up a timer expiring after 1s
81-
let mut timer = Timer::new(dp.TIM2, &clocks).counter();
81+
let mut timer = dp.TIM2.counter(&clocks);
8282
timer.start(1.secs()).unwrap();
8383

8484
// Generate an interrupt when the timer expires

examples/delay-syst-blinky.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn main() -> ! {
2828
let clocks = rcc.cfgr.sysclk(48.MHz()).freeze();
2929

3030
// Create a delay abstraction based on SysTick
31-
let mut delay = hal::delay::Delay::new(cp.SYST, &clocks);
31+
let mut delay = cp.SYST.delay(&clocks);
3232

3333
loop {
3434
// On for 1s, off for 1s.

examples/delay-timer-blinky.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ fn main() -> ! {
3333
loop {
3434
// On for 1s, off for 3s.
3535
led.set_high();
36-
delay.delay(1.secs()).unwrap();
36+
// Use `embedded_hal::DelayMs` trait
37+
delay.delay_ms(1000_u32);
3738
led.set_low();
39+
// or use `fugit::ExtU32` trait
3840
delay.delay(3.secs()).unwrap();
3941
}
4042
}

examples/dynamic_gpio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn main() -> ! {
2929

3030
let mut pin = gpioc.pc13.into_dynamic();
3131
// Configure the syst timer to trigger an update every second
32-
let mut timer = Timer::syst(cp.SYST, &clocks).counter();
32+
let mut timer = Timer::syst(cp.SYST, &clocks).counter_us();
3333
timer.start(1.secs()).unwrap();
3434

3535
// Wait for the timer to trigger an update and change the state of the LED

examples/f413disco_lcd_ferris.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::hal::{
1919
fsmc_lcd::{ChipSelect3, FsmcLcd, LcdPins, Timing},
2020
gpio::Speed,
2121
pac::{CorePeripherals, Peripherals},
22-
{delay::Delay, prelude::*},
22+
prelude::*,
2323
};
2424

2525
use embedded_graphics::geometry::Size;
@@ -747,7 +747,7 @@ fn main() -> ! {
747747
gpioe.pe5.into_push_pull_output().set_high();
748748

749749
// Get delay provider
750-
let mut delay = Delay::new(cp.SYST, &clocks);
750+
let mut delay = cp.SYST.delay(&clocks);
751751

752752
// Set up timing
753753
let write_timing = Timing::default().data(3).address_setup(3).bus_turnaround(0);

examples/i2s-audio-out-dma.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ use cortex_m_rt::entry;
4848
use stm32_i2s_v12x::format::{Data16Frame16, FrameFormat};
4949
use stm32_i2s_v12x::{MasterClock, MasterConfig, Polarity, TransmitMode};
5050

51-
use stm32f4xx_hal::delay::Delay;
5251
use stm32f4xx_hal::dma::config::DmaConfig;
5352
use stm32f4xx_hal::dma::MemoryToPeripheral;
5453
use stm32f4xx_hal::dma::{Stream5, StreamsTuple, Transfer};
@@ -100,7 +99,7 @@ fn main() -> ! {
10099
let gpioc = dp.GPIOC.split();
101100
let gpiod = dp.GPIOD.split();
102101

103-
let mut delay = Delay::new(cp.SYST, &clocks);
102+
let mut delay = cp.SYST.delay(&clocks);
104103

105104
let i2c = I2c::new(
106105
dp.I2C1,

examples/i2s-audio-out.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ use cortex_m_rt::entry;
4545
use stm32_i2s_v12x::format::{Data16Frame16, FrameFormat};
4646
use stm32_i2s_v12x::{MasterClock, MasterConfig, Polarity};
4747

48-
use stm32f4xx_hal::delay::Delay;
4948
use stm32f4xx_hal::i2c::I2c;
5049
use stm32f4xx_hal::i2s::I2s;
5150
use stm32f4xx_hal::nb::block;
@@ -100,7 +99,7 @@ fn main() -> ! {
10099
// The 86 MHz frequency can be divided to get a sample rate very close to 48 kHz.
101100
let clocks = rcc.cfgr.use_hse(8.MHz()).i2s_clk(86.MHz()).freeze();
102101

103-
let mut delay = Delay::new(cp.SYST, &clocks);
102+
let mut delay = cp.SYST.delay(&clocks);
104103

105104
let i2c = I2c::new(
106105
dp.I2C1,

examples/ist7920_bidi_normal_spi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use cortex_m_rt::entry;
77

88
use stm32f4xx_hal as hal;
99

10-
use crate::hal::{pac, prelude::*};
10+
use crate::hal::{pac, prelude::*, timer::Timer};
1111

1212
use hal::spi::{Mode, NoMiso, Phase, Polarity};
1313

@@ -36,7 +36,7 @@ fn main() -> ! {
3636
let mut res = gpiob.pb10.into_push_pull_output();
3737
let cs = gpiob.pb13.into_push_pull_output();
3838

39-
let mut delay = hal::delay::Delay::new(cp.SYST, &clocks);
39+
let mut delay = Timer::syst(cp.SYST, &clocks).delay();
4040

4141
let mode = Mode {
4242
polarity: Polarity::IdleLow,

0 commit comments

Comments
 (0)