Skip to content

Commit 214b426

Browse files
bors[bot]burrbull
andauthored
Merge #401
401: use fugit::Rate types instead of custom r=therealprof a=burrbull Goodby, `Into<Hertz>` Remove `cast` Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents ab33c09 + c1fa57b commit 214b426

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

+238
-396
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ nb = "1"
2222
stm32f1 = "0.14.0"
2323
embedded-dma = "0.1.2"
2424
bxcan = "0.6"
25-
cast = { default-features = false, version = "0.3.0" }
2625
void = { default-features = false, version = "1.0.2" }
2726
embedded-hal = { features = ["unproven"], version = "0.2.6" }
28-
fugit = "0.3.0"
27+
fugit = "0.3.5"
2928
rtic-monotonic = { version = "1.0", optional = true }
3029

3130
[dependencies.stm32-usbd]

examples/adc-dma-circ.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() -> ! {
2323
// clock is configurable. So its frequency may be tweaked to meet certain
2424
// practical needs. User specified value is be approximated using supported
2525
// prescaler values 2/4/6/8.
26-
let clocks = rcc.cfgr.adcclk(2.mhz()).freeze(&mut flash.acr);
26+
let clocks = rcc.cfgr.adcclk(2.MHz()).freeze(&mut flash.acr);
2727

2828
let dma_ch1 = p.DMA1.split().1;
2929

examples/adc-dma-rx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() -> ! {
2323
// clock is configurable. So its frequency may be tweaked to meet certain
2424
// practical needs. User specified value is be approximated using supported
2525
// prescaler values 2/4/6/8.
26-
let clocks = rcc.cfgr.adcclk(2.mhz()).freeze(&mut flash.acr);
26+
let clocks = rcc.cfgr.adcclk(2.MHz()).freeze(&mut flash.acr);
2727

2828
let dma_ch1 = p.DMA1.split().1;
2929

examples/adc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ fn main() -> ! {
2121
// clock is configurable. So its frequency may be tweaked to meet certain
2222
// practical needs. User specified value is be approximated using supported
2323
// prescaler values 2/4/6/8.
24-
let clocks = rcc.cfgr.adcclk(2.mhz()).freeze(&mut flash.acr);
25-
hprintln!("adc freq: {}", clocks.adcclk().0).unwrap();
24+
let clocks = rcc.cfgr.adcclk(2.MHz()).freeze(&mut flash.acr);
25+
hprintln!("adc freq: {}", clocks.adcclk()).unwrap();
2626

2727
// Setup ADC
2828
let mut adc1 = adc::Adc::adc1(p.ADC1, clocks);

examples/adc_temperature.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ fn main() -> ! {
1818

1919
let clocks = rcc
2020
.cfgr
21-
.use_hse(8.mhz())
22-
.sysclk(56.mhz())
23-
.pclk1(28.mhz())
24-
.adcclk(14.mhz())
21+
.use_hse(8.MHz())
22+
.sysclk(56.MHz())
23+
.pclk1(28.MHz())
24+
.adcclk(14.MHz())
2525
.freeze(&mut flash.acr);
2626
/*
2727
// Alternative configuration using dividers and multipliers directly
@@ -34,8 +34,8 @@ fn main() -> ! {
3434
usbpre: rcc::UsbPre::DIV1_5,
3535
adcpre: rcc::AdcPre::DIV2,
3636
}, &mut flash.acr);*/
37-
hprintln!("sysclk freq: {}", clocks.sysclk().0).unwrap();
38-
hprintln!("adc freq: {}", clocks.adcclk().0).unwrap();
37+
hprintln!("sysclk freq: {}", clocks.sysclk()).unwrap();
38+
hprintln!("adc freq: {}", clocks.adcclk()).unwrap();
3939

4040
// Setup ADC
4141
let mut adc = adc::Adc::adc1(p.ADC1, clocks);

examples/blinky.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn main() -> ! {
3939
// in order to configure the port. For pins 0-7, crl should be passed instead.
4040
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
4141
// Configure the syst timer to trigger an update every second
42-
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.hz());
42+
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.Hz());
4343

4444
// Wait for the timer to trigger an update and change the state of the LED
4545
loop {

examples/blinky_generic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() -> ! {
2626
let mut gpioc = dp.GPIOC.split();
2727

2828
// Configure the syst timer to trigger an update every second
29-
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.hz());
29+
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.Hz());
3030

3131
// Create an array of LEDS to blink
3232
let mut leds = [

examples/blinky_timer_irq.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ fn main() -> ! {
7373
let mut flash = dp.FLASH.constrain();
7474
let clocks = rcc
7575
.cfgr
76-
.sysclk(8.mhz())
77-
.pclk1(8.mhz())
76+
.sysclk(8.MHz())
77+
.pclk1(8.MHz())
7878
.freeze(&mut flash.acr);
7979

8080
// Configure PC13 pin to blink LED
@@ -86,7 +86,7 @@ fn main() -> ! {
8686
cortex_m::interrupt::free(|cs| *G_LED.borrow(cs).borrow_mut() = Some(led));
8787

8888
// Set up a timer expiring after 1s
89-
let mut timer = Timer::new(dp.TIM2, &clocks).start_count_down(1.hz());
89+
let mut timer = Timer::new(dp.TIM2, &clocks).start_count_down(1.Hz());
9090

9191
// Generate an interrupt when the timer expires
9292
timer.listen(Event::Update);

examples/can-echo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn main() -> ! {
2121
// To meet CAN clock accuracy requirements an external crystal or ceramic
2222
// resonator must be used. The blue pill has a 8MHz external crystal.
2323
// Other boards might have a crystal with another frequency or none at all.
24-
rcc.cfgr.use_hse(8.mhz()).freeze(&mut flash.acr);
24+
rcc.cfgr.use_hse(8.MHz()).freeze(&mut flash.acr);
2525

2626
let mut afio = dp.AFIO.constrain();
2727

examples/can-loopback.rs

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

2424
// To meet CAN clock accuracy requirements, an external crystal or ceramic
2525
// resonator must be used.
26-
rcc.cfgr.use_hse(8.mhz()).freeze(&mut flash.acr);
26+
rcc.cfgr.use_hse(8.MHz()).freeze(&mut flash.acr);
2727

2828
#[cfg(not(feature = "connectivity"))]
2929
let can = Can::new(dp.CAN1, dp.USB);

examples/can-rtic.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ mod app {
7575

7676
let _clocks = rcc
7777
.cfgr
78-
.use_hse(8.mhz())
79-
.sysclk(64.mhz())
80-
.hclk(64.mhz())
81-
.pclk1(16.mhz())
82-
.pclk2(64.mhz())
78+
.use_hse(8.MHz())
79+
.sysclk(64.MHz())
80+
.hclk(64.MHz())
81+
.pclk1(16.MHz())
82+
.pclk2(64.MHz())
8383
.freeze(&mut flash.acr);
8484

8585
#[cfg(not(feature = "connectivity"))]

examples/dynamic_gpio.rs

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

3333
let mut pin = gpioc.pc13.into_dynamic(&mut gpioc.crh);
3434
// Configure the syst timer to trigger an update every second
35-
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.hz());
35+
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.Hz());
3636

3737
// Wait for the timer to trigger an update and change the state of the LED
3838
loop {

examples/enc28j60-coap.rs.disabled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn main() -> ! {
9090
(sck, miso, mosi),
9191
&mut afio.mapr,
9292
enc28j60::MODE,
93-
1.mhz(),
93+
1.MHz(),
9494
clocks,
9595
);
9696

examples/enc28j60.rs.disabled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn main() -> ! {
8282
(sck, miso, mosi),
8383
&mut afio.mapr,
8484
enc28j60::MODE,
85-
1.mhz(),
85+
1.MHz(),
8686
clocks,
8787
);
8888

examples/i2c-bme280/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ fn main() -> ! {
4545
// Freeze the configuration of all the clocks in the system and store the frozen frequencies in
4646
// `clocks`
4747
let clocks = if 1 == 1 {
48-
rcc.cfgr.use_hse(8.mhz()).freeze(&mut flash.acr)
48+
rcc.cfgr.use_hse(8.MHz()).freeze(&mut flash.acr)
4949
} else {
5050
// My blue pill with a stm32f103 clone dose not seem to respect rcc so will not compensate its pulse legths
5151
// with a faster clock like this. And so the sensor dose not have time to respond to the START pulse.
5252
// I would be interested if others with real stm32f103's can use this program with the faster clocks.
5353
rcc.cfgr
54-
.use_hse(8.mhz())
55-
.sysclk(48.mhz())
56-
.pclk1(6.mhz())
54+
.use_hse(8.MHz())
55+
.sysclk(48.MHz())
56+
.pclk1(6.MHz())
5757
.freeze(&mut flash.acr)
5858
};
5959

@@ -68,7 +68,7 @@ fn main() -> ! {
6868
(scl, sda),
6969
&mut afio.mapr,
7070
Mode::Fast {
71-
frequency: 400_000.hz(),
71+
frequency: 400.kHz(),
7272
duty_cycle: DutyCycle::Ratio16to9,
7373
},
7474
clocks,

examples/mfrc522.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn main() -> ! {
3333
(sck, miso, mosi),
3434
&mut afio.mapr,
3535
mfrc522::MODE,
36-
1.mhz(),
36+
1.MHz(),
3737
clocks,
3838
);
3939

examples/motor.rs.disabled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn main() -> ! {
5151
let pwm = p.TIM2.pwm(
5252
gpioa.pa0.into_alternate_push_pull(&mut gpioa.crl),
5353
&mut afio.mapr,
54-
1.khz(),
54+
1.kHz(),
5555
clocks,
5656
);
5757

examples/mpu9250.rs.disabled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn main() -> ! {
5151
(sck, miso, mosi),
5252
&mut afio.mapr,
5353
mpu9250::MODE,
54-
1.mhz(),
54+
1.MHz(),
5555
clocks,
5656
);
5757

examples/multi_mode_gpio.rs

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

3232
let mut pin = gpioc.pc13.into_floating_input(&mut gpioc.crh);
3333
// Configure the syst timer to trigger an update every second
34-
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.hz());
34+
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.Hz());
3535

3636
// Wait for the timer to trigger an update and change the state of the LED
3737
loop {

examples/pwm.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use stm32f1xx_hal::{
1313
pac,
1414
prelude::*,
1515
pwm::Channel,
16-
time::U32Ext,
16+
time::ms,
1717
timer::{Tim2NoRemap, Timer},
1818
};
1919

@@ -52,7 +52,7 @@ fn main() -> ! {
5252
// let c4 = gpiob.pb9.into_alternate_push_pull(&mut gpiob.crh);
5353

5454
let mut pwm =
55-
Timer::new(p.TIM2, &clocks).pwm::<Tim2NoRemap, _, _, _>(pins, &mut afio.mapr, 1.khz());
55+
Timer::new(p.TIM2, &clocks).pwm::<Tim2NoRemap, _, _>(pins, &mut afio.mapr, 1.kHz());
5656

5757
// Enable clock on each of the channels
5858
pwm.enable(Channel::C1);
@@ -62,12 +62,12 @@ fn main() -> ! {
6262
//// Operations affecting all defined channels on the Timer
6363

6464
// Adjust period to 0.5 seconds
65-
pwm.set_period(500.ms());
65+
pwm.set_period(ms(500).into_rate());
6666

6767
asm::bkpt();
6868

6969
// Return to the original frequency
70-
pwm.set_period(1.khz());
70+
pwm.set_period(1.kHz());
7171

7272
asm::bkpt();
7373

examples/pwm_custom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn main() -> ! {
3030
let p0 = pb4.into_alternate_push_pull(&mut gpiob.crl);
3131
let p1 = gpiob.pb5.into_alternate_push_pull(&mut gpiob.crl);
3232

33-
let pwm = Timer::new(p.TIM3, &clocks).pwm((p0, p1), &mut afio.mapr, 1.khz());
33+
let pwm = Timer::new(p.TIM3, &clocks).pwm((p0, p1), &mut afio.mapr, 1.kHz());
3434

3535
let max = pwm.get_max_duty();
3636

examples/pwm_input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() -> ! {
3131
(pb4, pb5),
3232
&mut afio.mapr,
3333
&mut dbg,
34-
Configuration::Frequency(10.khz()),
34+
Configuration::Frequency(10.kHz()),
3535
);
3636

3737
loop {

examples/spi-dma.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn main() -> ! {
4040
polarity: Polarity::IdleLow,
4141
phase: Phase::CaptureOnFirstTransition,
4242
};
43-
let spi = Spi::spi2(dp.SPI2, pins, spi_mode, 100.khz(), clocks);
43+
let spi = Spi::spi2(dp.SPI2, pins, spi_mode, 100.kHz(), clocks);
4444

4545
// Set up the DMA device
4646
let dma = dp.DMA1.split();

examples/spi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn setup() -> (
4545
(sck, miso, mosi),
4646
&mut afio.mapr,
4747
MODE,
48-
1_u32.mhz(),
48+
1.MHz(),
4949
clocks,
5050
);
5151

examples/timer-interrupt-rtic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ mod app {
4949
.pc13
5050
.into_push_pull_output_with_state(&mut gpioc.crh, PinState::High);
5151
// Configure the syst timer to trigger an update every second and enables interrupt
52-
let mut timer = Timer::new(cx.device.TIM1, &clocks).start_count_down(1.hz());
52+
let mut timer = Timer::new(cx.device.TIM1, &clocks).start_count_down(1.Hz());
5353
timer.listen(Event::Update);
5454

5555
// Init the static resources to use them later through RTIC
@@ -93,9 +93,9 @@ mod app {
9393

9494
if *cx.local.count == 4 {
9595
// Changes timer update frequency
96-
cx.local.timer_handler.start(2.hz());
96+
cx.local.timer_handler.start(2.Hz());
9797
} else if *cx.local.count == 12 {
98-
cx.local.timer_handler.start(1.hz());
98+
cx.local.timer_handler.start(1.Hz());
9999
*cx.local.count = 0;
100100
}
101101

examples/usb_serial.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ fn main() -> ! {
2727

2828
let clocks = rcc
2929
.cfgr
30-
.use_hse(8.mhz())
31-
.sysclk(48.mhz())
32-
.pclk1(24.mhz())
30+
.use_hse(8.MHz())
31+
.sysclk(48.MHz())
32+
.pclk1(24.MHz())
3333
.freeze(&mut flash.acr);
3434

3535
assert!(clocks.usbclk_valid());
@@ -47,7 +47,7 @@ fn main() -> ! {
4747
// will not reset your device when you upload new firmware.
4848
let mut usb_dp = gpioa.pa12.into_push_pull_output(&mut gpioa.crh);
4949
usb_dp.set_low();
50-
delay(clocks.sysclk().0 / 100);
50+
delay(clocks.sysclk().raw() / 100);
5151

5252
let usb = Peripheral {
5353
usb: dp.USB,

examples/usb_serial_interrupt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ fn main() -> ! {
2626

2727
let clocks = rcc
2828
.cfgr
29-
.use_hse(8.mhz())
30-
.sysclk(48.mhz())
31-
.pclk1(24.mhz())
29+
.use_hse(8.MHz())
30+
.sysclk(48.MHz())
31+
.pclk1(24.MHz())
3232
.freeze(&mut flash.acr);
3333

3434
assert!(clocks.usbclk_valid());
@@ -41,7 +41,7 @@ fn main() -> ! {
4141
// will not reset your device when you upload new firmware.
4242
let mut usb_dp = gpioa.pa12.into_push_pull_output(&mut gpioa.crh);
4343
usb_dp.set_low();
44-
delay(clocks.sysclk().0 / 100);
44+
delay(clocks.sysclk().raw() / 100);
4545

4646
let usb_dm = gpioa.pa11;
4747
let usb_dp = usb_dp.into_floating_input(&mut gpioa.crh);

examples/usb_serial_rtic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ mod app {
3131

3232
let clocks = rcc
3333
.cfgr
34-
.use_hse(8.mhz())
35-
.sysclk(48.mhz())
36-
.pclk1(24.mhz())
34+
.use_hse(8.MHz())
35+
.sysclk(48.MHz())
36+
.pclk1(24.MHz())
3737
.freeze(&mut flash.acr);
3838

3939
assert!(clocks.usbclk_valid());
@@ -46,7 +46,7 @@ mod app {
4646
// will not reset your device when you upload new firmware.
4747
let mut usb_dp = gpioa.pa12.into_push_pull_output(&mut gpioa.crh);
4848
usb_dp.set_low();
49-
delay(clocks.sysclk().0 / 100);
49+
delay(clocks.sysclk().raw() / 100);
5050

5151
let usb_dm = gpioa.pa11;
5252
let usb_dp = usb_dp.into_floating_input(&mut gpioa.crh);

0 commit comments

Comments
 (0)