Skip to content

Commit d2aa379

Browse files
committed
Use fugit for time related types to make the crate more consistent with stm32g0xx-hal
1 parent c765117 commit d2aa379

File tree

18 files changed

+214
-242
lines changed

18 files changed

+214
-242
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ paste = "1.0"
1818
bitflags = "1.2"
1919
vcell = "0.1"
2020
static_assertions = "1.1"
21+
fugit = "0.3.5"
2122

2223
[dependencies.cortex-m]
2324
version = "0.7.7"

examples/blinky_delay.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use hal::prelude::*;
88
use hal::rcc::Config;
99
use hal::stm32;
1010
use hal::timer::Timer;
11+
use hal::time::ExtU32;
1112
use stm32g4xx_hal as hal;
1213

1314
use cortex_m_rt::entry;
@@ -34,13 +35,13 @@ fn main() -> ! {
3435

3536
info!("Init Timer2 delay");
3637
let timer2 = Timer::new(dp.TIM2, &rcc.clocks);
37-
let mut delay_tim2 = DelayFromCountDownTimer::new(timer2.start_count_down(100.ms()));
38+
let mut delay_tim2 = DelayFromCountDownTimer::new(timer2.start_count_down(100.millis()));
3839

3940
loop {
4041
info!("Toggle");
4142
led.toggle().unwrap();
4243
info!("SYST delay");
43-
delay_syst.delay(1000.ms());
44+
delay_syst.delay(1000.millis());
4445
info!("Toggle");
4546
led.toggle().unwrap();
4647
info!("TIM2 delay");

examples/can-echo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::hal::{
77
nb::block,
88
rcc::{Config, RccExt, SysClockSrc},
99
stm32::Peripherals,
10-
time::U32Ext,
10+
time::RateExtU32,
1111
};
1212
use fdcan::{
1313
config::NominalBitTiming,
@@ -47,7 +47,7 @@ fn main() -> ! {
4747
let dp = Peripherals::take().unwrap();
4848
let _cp = cortex_m::Peripherals::take().expect("cannot take core peripherals");
4949
let rcc = dp.RCC.constrain();
50-
let mut rcc = rcc.freeze(Config::new(SysClockSrc::HSE(24.mhz())));
50+
let mut rcc = rcc.freeze(Config::new(SysClockSrc::HSE(24.MHz())));
5151

5252
info!("Split GPIO");
5353

examples/i2c-bme680.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use hal::prelude::*;
1212
use hal::stm32;
1313
use hal::timer::Timer;
1414
use stm32g4xx_hal as hal;
15+
use hal::time::{ExtU32, RateExtU32};
1516

1617
use cortex_m_rt::entry;
1718
use log::info;
@@ -32,11 +33,11 @@ fn main() -> ! {
3233
let sda = gpiob.pb9.into_alternate_open_drain();
3334
let scl = gpiob.pb8.into_alternate_open_drain();
3435

35-
let i2c = dp.I2C1.i2c(sda, scl, Config::new(100.khz()), &mut rcc);
36+
let i2c = dp.I2C1.i2c(sda, scl, Config::new(100.kHz()), &mut rcc);
3637

3738
let mut delayer = cp.SYST.delay(&rcc.clocks);
3839
let timer2 = Timer::new(dp.TIM2, &rcc.clocks);
39-
let mut delay = DelayFromCountDownTimer::new(timer2.start_count_down(100.ms()));
40+
let mut delay = DelayFromCountDownTimer::new(timer2.start_count_down(100.millis()));
4041

4142
let mut dev =
4243
Bme680::init(i2c, &mut delayer, I2CAddress::Secondary).expect("Init function failed");

examples/i2c-mpu6050.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use hal::i2c::Config;
77
use hal::prelude::*;
88
use hal::stm32;
99
use stm32g4xx_hal as hal;
10+
use hal::time::{ExtU32, RateExtU32};
1011

1112
use cortex_m_rt::entry;
1213
use log::info;
@@ -28,7 +29,7 @@ fn main() -> ! {
2829
let sda = gpiob.pb9.into_alternate_open_drain();
2930
let scl = gpiob.pb8.into_alternate_open_drain();
3031

31-
let i2c = dp.I2C1.i2c(sda, scl, Config::new(100.khz()), &mut rcc);
32+
let i2c = dp.I2C1.i2c(sda, scl, Config::new(100.kHz()), &mut rcc);
3233

3334
let mut mpu = Mpu6050::new(i2c);
3435
let mut delay = cp.SYST.delay(&rcc.clocks);
@@ -39,6 +40,6 @@ fn main() -> ! {
3940
let gyro = mpu.get_gyro().expect("cannot read gyro");
4041
let temp = mpu.get_temp().expect("cannot read temperature");
4142
info!("acc: {:?}, gyro: {:?}, temp: {:?}C", acc, gyro, temp);
42-
delay.delay(250.ms());
43+
delay.delay(250.millis());
4344
}
4445
}

examples/i2c.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use hal::i2c::Config;
77
use hal::prelude::*;
88
use hal::stm32;
99
use stm32g4xx_hal as hal;
10+
use hal::time::RateExtU32;
1011

1112
use cortex_m_rt::entry;
1213
use log::info;
@@ -25,7 +26,7 @@ fn main() -> ! {
2526
let sda = gpiob.pb9.into_alternate_open_drain();
2627
let scl = gpiob.pb8.into_alternate_open_drain();
2728

28-
let mut i2c = dp.I2C1.i2c(sda, scl, Config::new(40.khz()), &mut rcc);
29+
let mut i2c = dp.I2C1.i2c(sda, scl, Config::new(40.kHz()), &mut rcc);
2930
// Alternatively, it is possible to specify the exact timing as follows (see the documentation
3031
// of with_timing() for an explanation of the constant):
3132
//let mut i2c = dp

examples/pwm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use hal::gpio::AF6;
99
use hal::prelude::*;
1010
use hal::stm32;
1111
use stm32g4xx_hal as hal;
12+
use hal::time::RateExtU32;
1213
mod utils;
1314
extern crate cortex_m_rt as rt;
1415

@@ -19,7 +20,7 @@ fn main() -> ! {
1920
let gpioa = dp.GPIOA.split(&mut rcc);
2021
let pin: PA8<Alternate<AF6>> = gpioa.pa8.into_alternate();
2122

22-
let mut pwm = dp.TIM1.pwm(pin, 100.hz(), &mut rcc);
23+
let mut pwm = dp.TIM1.pwm(pin, 100.Hz(), &mut rcc);
2324

2425
pwm.set_duty(pwm.get_max_duty() / 2);
2526
pwm.enable();

examples/spi-example.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use crate::hal::{
99
block, delay::DelayFromCountDownTimer, gpio::gpioa::PA5, gpio::gpioa::PA6, gpio::gpioa::PA7,
10-
gpio::Alternate, gpio::AF5, prelude::*, rcc::Config, spi, stm32::Peripherals, timer::Timer,
10+
gpio::Alternate, gpio::AF5, prelude::*, rcc::Config, spi, stm32::Peripherals, timer::Timer, time::{ExtU32, RateExtU32}
1111
};
1212

1313
use cortex_m_rt::entry;
@@ -25,7 +25,7 @@ fn main() -> ! {
2525
let rcc = dp.RCC.constrain();
2626
let mut rcc = rcc.freeze(Config::hsi());
2727
let timer2 = Timer::new(dp.TIM2, &rcc.clocks);
28-
let mut delay_tim2 = DelayFromCountDownTimer::new(timer2.start_count_down(100.ms()));
28+
let mut delay_tim2 = DelayFromCountDownTimer::new(timer2.start_count_down(100.millis()));
2929

3030
let gpioa = dp.GPIOA.split(&mut rcc);
3131
let sclk: PA5<Alternate<AF5>> = gpioa.pa5.into_alternate();
@@ -34,7 +34,7 @@ fn main() -> ! {
3434

3535
let mut spi = dp
3636
.SPI1
37-
.spi((sclk, miso, mosi), spi::MODE_0, 400.khz(), &mut rcc);
37+
.spi((sclk, miso, mosi), spi::MODE_0, 400.kHz(), &mut rcc);
3838
let mut cs = gpioa.pa8.into_push_pull_output();
3939
cs.set_high().unwrap();
4040

examples/spi-sd.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use hal::stm32;
1818
use hal::stm32::Peripherals;
1919
use hal::timer::Timer;
2020
use stm32g4xx_hal as hal;
21+
use hal::time::RateExtU32;
2122

2223
use embedded_sdmmc::{
2324
Block, BlockCount, BlockDevice, BlockIdx, Controller, Error, Mode, TimeSource, Timestamp,
@@ -50,7 +51,7 @@ fn main() -> ! {
5051

5152
let mut spi = dp
5253
.SPI2
53-
.spi((sck, miso, mosi), spi::MODE_0, 400.khz(), &mut rcc);
54+
.spi((sck, miso, mosi), spi::MODE_0, 400.kHz(), &mut rcc);
5455

5556
struct Clock;
5657

examples/uart-dma.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use hal::prelude::*;
1212
use hal::serial::*;
1313
use hal::{rcc, stm32};
1414
use stm32g4xx_hal as hal;
15+
use hal::time::ExtU32;
1516

1617
use cortex_m_rt::entry;
1718
use log::info;
@@ -70,7 +71,7 @@ fn main() -> ! {
7071
loop {
7172
while !transfer.get_transfer_complete_flag() {}
7273

73-
delay_syst.delay(1000.ms());
74+
delay_syst.delay(1000.millis());
7475
led.toggle().unwrap();
7576
transfer.restart(|_tx| {});
7677
}

0 commit comments

Comments
 (0)