Skip to content

Commit dd4832e

Browse files
committed
CounterHz
1 parent 1460db9 commit dd4832e

21 files changed

+628
-479
lines changed

examples/delay-syst-blinky.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use panic_halt as _; // panic handler
1111
use cortex_m_rt::entry;
1212
use stm32f4xx_hal as hal;
1313

14-
use crate::hal::{pac, prelude::*};
14+
use crate::hal::{pac, prelude::*, timer::Timer};
1515

1616
#[entry]
1717
fn main() -> ! {
@@ -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 = Timer::syst(cp.SYST, &clocks).delay();
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/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,

examples/qei.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use panic_halt as _;
1414

1515
use cortex_m_rt::entry;
1616
use embedded_hal::Direction as RotaryDirection;
17-
use stm32f4xx_hal::{delay::Delay, pac, prelude::*, qei::Qei};
17+
use stm32f4xx_hal::{pac, prelude::*, qei::Qei, timer::Timer};
1818

1919
#[entry]
2020
fn main() -> ! {
@@ -31,7 +31,7 @@ fn main() -> ! {
3131
let clocks = rcc.cfgr.freeze();
3232

3333
// Create a delay abstraction based on SysTick.
34-
let mut delay = Delay::new(cp.SYST, &clocks);
34+
let mut delay = Timer::syst(cp.SYST, &clocks).delay();
3535

3636
let gpioa = dp.GPIOA.split();
3737

examples/serial-9bit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use panic_halt as _;
3434
use cortex_m_rt::entry;
3535
use stm32f4xx_hal as hal;
3636

37-
use crate::hal::{block, pac, prelude::*, serial::config::Config};
37+
use crate::hal::{block, pac, prelude::*, serial::config::Config, timer::Timer};
3838

3939
use core::ops::Range;
4040

@@ -55,7 +55,7 @@ fn main() -> ! {
5555

5656
let clocks = rcc.cfgr.use_hse(8.MHz()).freeze();
5757

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

6060
// define RX/TX pins
6161
let tx_pin = gpioa.pa2.into_alternate();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ use panic_semihosting as _; // logs messages to the host stderr; requires a debu
2222
use stm32f4xx_hal as hal;
2323

2424
use crate::hal::{
25-
delay::Delay,
26-
fugit::{CounterUs, Event, Timer},
25+
fugit::{CounterUs, Event},
2726
gpio::{Edge, Input, PullUp, PC13},
2827
i2c::I2c,
2928
interrupt, pac,
3029
prelude::*,
3130
rcc::{Clocks, Rcc},
31+
timer::Timer,
3232
};
3333
use core::cell::{Cell, RefCell};
3434
use core::fmt::Write;
@@ -92,7 +92,7 @@ fn main() -> ! {
9292
disp.flush().unwrap();
9393

9494
// Create a 1ms periodic interrupt from TIM2
95-
let mut timer = Timer::new(dp.TIM2, &clocks).counter();
95+
let mut timer = dp.TIM2.counter(&clocks);
9696
timer.start(1.secs()).unwrap();
9797
timer.listen(Event::Update);
9898

@@ -108,7 +108,7 @@ fn main() -> ! {
108108
pac::NVIC::unmask(hal::pac::Interrupt::EXTI15_10);
109109
};
110110

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

113113
loop {
114114
let elapsed = free(|cs| ELAPSED_MS.borrow(cs).get());

src/fugit/hal_02.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use super::{Channel, Counter, Delay, Error, Instance, Pins, Pwm, SysCounter, WithPwm};
1+
use super::{Channel, Counter, Delay, Error, Instance, Pins, Pwm, WithPwm};
22

33
use embedded_hal::blocking::delay::{DelayMs, DelayUs};
4-
use fugit::{ExtU32, MicrosDurationU32, TimerDurationU32};
4+
use fugit::{ExtU32, TimerDurationU32};
55
use void::Void;
66

77
impl<TIM: Instance, const FREQ: u32> DelayUs<u32> for Delay<TIM, FREQ> {
@@ -74,32 +74,6 @@ impl<TIM: Instance, const FREQ: u32> Cancel for Counter<TIM, FREQ> {
7474
}
7575
}
7676

77-
impl CountDown for SysCounter {
78-
type Time = MicrosDurationU32;
79-
80-
fn start<T>(&mut self, timeout: T)
81-
where
82-
T: Into<Self::Time>,
83-
{
84-
self.start(timeout.into()).unwrap()
85-
}
86-
87-
fn wait(&mut self) -> nb::Result<(), Void> {
88-
match self.wait() {
89-
Err(nb::Error::WouldBlock) => Err(nb::Error::WouldBlock),
90-
_ => Ok(()),
91-
}
92-
}
93-
}
94-
95-
impl Cancel for SysCounter {
96-
type Error = Error;
97-
98-
fn cancel(&mut self) -> Result<(), Self::Error> {
99-
self.cancel()
100-
}
101-
}
102-
10377
impl<TIM, P, PINS, const FREQ: u32> embedded_hal::Pwm for Pwm<TIM, P, PINS, FREQ>
10478
where
10579
TIM: Instance + WithPwm,

src/fugit/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
33
use crate::pac::RCC;
44
use crate::rcc::Clocks;
5-
pub use crate::timer::{Channel, Error, Event, Instance, Ocm, SysEvent};
5+
pub use crate::timer::{
6+
CPin, Channel, Error, Event, Instance, Ocm, Pins, PwmChannel, C1, C2, C3, C4,
7+
};
68
use crate::timer::{MasterTimer, WithPwm};
79
use cast::u16;
810

@@ -11,8 +13,6 @@ pub use delay::*;
1113

1214
pub mod counter;
1315
pub use counter::*;
14-
pub mod syscounter;
15-
pub use syscounter::*;
1616

1717
#[cfg(feature = "rtic")]
1818
#[cfg(not(feature = "stm32f410"))]

src/fugit/pwm.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use core::marker::PhantomData;
44
use core::ops::{Deref, DerefMut};
55
use fugit::TimerDurationU32;
66

7-
pub use crate::pwm::{Pins, PwmChannel};
8-
pub use crate::timer::{CPin, C1, C2, C3, C4};
7+
pub use super::{CPin, Pins, PwmChannel, C1, C2, C3, C4};
98

109
pub trait PwmExt<P, PINS>
1110
where

0 commit comments

Comments
 (0)