aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-07-11 02:51:06 +0000
committerGitHub <[email protected]>2022-07-11 02:51:06 +0000
commit2adee4af3878cb0e8027752c9d29a6ce236f4ab3 (patch)
treee6f2700ab17bcb62d0195debade2df44c54b03b4
parent99f4fd33b493f11ec3202eb98fc3ae9e18b9d589 (diff)
parent5ecbe5c9181d2392540a3273f21d53c01474d341 (diff)
Merge #858
858: embassy-stm32: Simplify time r=Dirbaio a=GrantM11235 - Remove unused `MilliSeconds`, `MicroSeconds`, and `NanoSeconds` types - Remove `Bps`, `KiloHertz`, and `MegaHertz` types that were only used for converting to `Hertz` - Replace all instances of `impl Into<Hertz>` with `Hertz` - Add `hz`, `khz`, and `mhz` methods to `Hertz`, as well as free function shortcuts - Remove `U32Ext` extension trait Co-authored-by: Grant Miller <[email protected]>
-rw-r--r--embassy-stm32/src/adc/v4.rs10
-rw-r--r--embassy-stm32/src/i2c/v1.rs9
-rw-r--r--embassy-stm32/src/i2c/v2.rs9
-rw-r--r--embassy-stm32/src/pwm/simple_pwm.rs20
-rw-r--r--embassy-stm32/src/rcc/g0.rs12
-rw-r--r--embassy-stm32/src/rcc/g4.rs18
-rw-r--r--embassy-stm32/src/rcc/l0.rs16
-rw-r--r--embassy-stm32/src/rcc/l1.rs14
-rw-r--r--embassy-stm32/src/rcc/l4.rs18
-rw-r--r--embassy-stm32/src/rcc/l5.rs18
-rw-r--r--embassy-stm32/src/rcc/u5.rs20
-rw-r--r--embassy-stm32/src/rcc/wb.rs18
-rw-r--r--embassy-stm32/src/rcc/wl.rs20
-rw-r--r--embassy-stm32/src/sdmmc/mod.rs2
-rw-r--r--embassy-stm32/src/spi/mod.rs36
-rw-r--r--embassy-stm32/src/time.rs124
-rw-r--r--embassy-stm32/src/timer/mod.rs12
-rw-r--r--examples/stm32f3/src/bin/usb_serial.rs10
-rw-r--r--examples/stm32f4/src/bin/pwm.rs4
-rw-r--r--examples/stm32f4/src/bin/sdmmc.rs6
-rw-r--r--examples/stm32f7/src/bin/eth.rs4
-rw-r--r--examples/stm32f7/src/bin/sdmmc.rs6
-rw-r--r--examples/stm32g4/src/bin/pwm.rs4
-rw-r--r--examples/stm32h7/src/bin/adc.rs8
-rw-r--r--examples/stm32h7/src/bin/camera.rs18
-rw-r--r--examples/stm32h7/src/bin/dac.rs8
-rw-r--r--examples/stm32h7/src/bin/eth.rs8
-rw-r--r--examples/stm32h7/src/bin/fmc.rs8
-rw-r--r--examples/stm32h7/src/bin/low_level_timer_api.rs24
-rw-r--r--examples/stm32h7/src/bin/pwm.rs18
-rw-r--r--examples/stm32h7/src/bin/sdmmc.rs6
-rw-r--r--examples/stm32h7/src/bin/spi.rs10
-rw-r--r--examples/stm32h7/src/bin/spi_dma.rs10
-rw-r--r--examples/stm32l0/src/bin/lorawan.rs4
34 files changed, 211 insertions, 321 deletions
diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs
index cdb79f517..3f933f4fc 100644
--- a/embassy-stm32/src/adc/v4.rs
+++ b/embassy-stm32/src/adc/v4.rs
@@ -6,7 +6,7 @@ use pac::adc::vals::{Adcaldif, Boost, Difsel, Exten, Pcsel};
6use pac::adccommon::vals::Presc; 6use pac::adccommon::vals::Presc;
7 7
8use super::{AdcPin, Instance}; 8use super::{AdcPin, Instance};
9use crate::time::{Hertz, U32Ext}; 9use crate::time::Hertz;
10use crate::{pac, Unborrow}; 10use crate::{pac, Unborrow};
11 11
12pub enum Resolution { 12pub enum Resolution {
@@ -336,14 +336,14 @@ impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> {
336 let frequency = Hertz(T::frequency().0 / prescaler.divisor()); 336 let frequency = Hertz(T::frequency().0 / prescaler.divisor());
337 info!("ADC frequency set to {} Hz", frequency.0); 337 info!("ADC frequency set to {} Hz", frequency.0);
338 338
339 if frequency > 50.mhz().into() { 339 if frequency > Hertz::mhz(50) {
340 panic!("Maximal allowed frequency for the ADC is 50 MHz and it varies with different packages, refer to ST docs for more information."); 340 panic!("Maximal allowed frequency for the ADC is 50 MHz and it varies with different packages, refer to ST docs for more information.");
341 } 341 }
342 let boost = if frequency < 6_250.khz().into() { 342 let boost = if frequency < Hertz::khz(6_250) {
343 Boost::LT6_25 343 Boost::LT6_25
344 } else if frequency < 12_500.khz().into() { 344 } else if frequency < Hertz::khz(12_500) {
345 Boost::LT12_5 345 Boost::LT12_5
346 } else if frequency < 25.mhz().into() { 346 } else if frequency < Hertz::mhz(25) {
347 Boost::LT25 347 Boost::LT25
348 } else { 348 } else {
349 Boost::LT50 349 Boost::LT50
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs
index c328224fa..65c918780 100644
--- a/embassy-stm32/src/i2c/v1.rs
+++ b/embassy-stm32/src/i2c/v1.rs
@@ -22,15 +22,12 @@ pub struct I2c<'d, T: Instance> {
22} 22}
23 23
24impl<'d, T: Instance> I2c<'d, T> { 24impl<'d, T: Instance> I2c<'d, T> {
25 pub fn new<F>( 25 pub fn new(
26 _peri: impl Unborrow<Target = T> + 'd, 26 _peri: impl Unborrow<Target = T> + 'd,
27 scl: impl Unborrow<Target = impl SclPin<T>> + 'd, 27 scl: impl Unborrow<Target = impl SclPin<T>> + 'd,
28 sda: impl Unborrow<Target = impl SdaPin<T>> + 'd, 28 sda: impl Unborrow<Target = impl SdaPin<T>> + 'd,
29 freq: F, 29 freq: Hertz,
30 ) -> Self 30 ) -> Self {
31 where
32 F: Into<Hertz>,
33 {
34 unborrow!(scl, sda); 31 unborrow!(scl, sda);
35 32
36 T::enable(); 33 T::enable();
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs
index 672f09399..108ea7e34 100644
--- a/embassy-stm32/src/i2c/v2.rs
+++ b/embassy-stm32/src/i2c/v2.rs
@@ -39,18 +39,15 @@ pub struct I2c<'d, T: Instance, TXDMA = NoDma, RXDMA = NoDma> {
39} 39}
40 40
41impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { 41impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
42 pub fn new<F>( 42 pub fn new(
43 _peri: impl Unborrow<Target = T> + 'd, 43 _peri: impl Unborrow<Target = T> + 'd,
44 scl: impl Unborrow<Target = impl SclPin<T>> + 'd, 44 scl: impl Unborrow<Target = impl SclPin<T>> + 'd,
45 sda: impl Unborrow<Target = impl SdaPin<T>> + 'd, 45 sda: impl Unborrow<Target = impl SdaPin<T>> + 'd,
46 irq: impl Unborrow<Target = T::Interrupt> + 'd, 46 irq: impl Unborrow<Target = T::Interrupt> + 'd,
47 tx_dma: impl Unborrow<Target = TXDMA> + 'd, 47 tx_dma: impl Unborrow<Target = TXDMA> + 'd,
48 rx_dma: impl Unborrow<Target = RXDMA> + 'd, 48 rx_dma: impl Unborrow<Target = RXDMA> + 'd,
49 freq: F, 49 freq: Hertz,
50 ) -> Self 50 ) -> Self {
51 where
52 F: Into<Hertz>,
53 {
54 unborrow!(irq, scl, sda, tx_dma, rx_dma); 51 unborrow!(irq, scl, sda, tx_dma, rx_dma);
55 52
56 T::enable(); 53 T::enable();
diff --git a/embassy-stm32/src/pwm/simple_pwm.rs b/embassy-stm32/src/pwm/simple_pwm.rs
index 049a64027..60aa110c7 100644
--- a/embassy-stm32/src/pwm/simple_pwm.rs
+++ b/embassy-stm32/src/pwm/simple_pwm.rs
@@ -29,53 +29,53 @@ macro_rules! config_pins {
29} 29}
30 30
31impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { 31impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> {
32 pub fn new_1ch<F: Into<Hertz>>( 32 pub fn new_1ch(
33 tim: impl Unborrow<Target = T> + 'd, 33 tim: impl Unborrow<Target = T> + 'd,
34 ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd, 34 ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd,
35 freq: F, 35 freq: Hertz,
36 ) -> Self { 36 ) -> Self {
37 Self::new_inner(tim, freq, move || { 37 Self::new_inner(tim, freq, move || {
38 config_pins!(ch1); 38 config_pins!(ch1);
39 }) 39 })
40 } 40 }
41 41
42 pub fn new_2ch<F: Into<Hertz>>( 42 pub fn new_2ch(
43 tim: impl Unborrow<Target = T> + 'd, 43 tim: impl Unborrow<Target = T> + 'd,
44 ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd, 44 ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd,
45 ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd, 45 ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd,
46 freq: F, 46 freq: Hertz,
47 ) -> Self { 47 ) -> Self {
48 Self::new_inner(tim, freq, move || { 48 Self::new_inner(tim, freq, move || {
49 config_pins!(ch1, ch2); 49 config_pins!(ch1, ch2);
50 }) 50 })
51 } 51 }
52 52
53 pub fn new_3ch<F: Into<Hertz>>( 53 pub fn new_3ch(
54 tim: impl Unborrow<Target = T> + 'd, 54 tim: impl Unborrow<Target = T> + 'd,
55 ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd, 55 ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd,
56 ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd, 56 ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd,
57 ch3: impl Unborrow<Target = impl Channel3Pin<T>> + 'd, 57 ch3: impl Unborrow<Target = impl Channel3Pin<T>> + 'd,
58 freq: F, 58 freq: Hertz,
59 ) -> Self { 59 ) -> Self {
60 Self::new_inner(tim, freq, move || { 60 Self::new_inner(tim, freq, move || {
61 config_pins!(ch1, ch2, ch3); 61 config_pins!(ch1, ch2, ch3);
62 }) 62 })
63 } 63 }
64 64
65 pub fn new_4ch<F: Into<Hertz>>( 65 pub fn new_4ch(
66 tim: impl Unborrow<Target = T> + 'd, 66 tim: impl Unborrow<Target = T> + 'd,
67 ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd, 67 ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd,
68 ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd, 68 ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd,
69 ch3: impl Unborrow<Target = impl Channel3Pin<T>> + 'd, 69 ch3: impl Unborrow<Target = impl Channel3Pin<T>> + 'd,
70 ch4: impl Unborrow<Target = impl Channel4Pin<T>> + 'd, 70 ch4: impl Unborrow<Target = impl Channel4Pin<T>> + 'd,
71 freq: F, 71 freq: Hertz,
72 ) -> Self { 72 ) -> Self {
73 Self::new_inner(tim, freq, move || { 73 Self::new_inner(tim, freq, move || {
74 config_pins!(ch1, ch2, ch3, ch4); 74 config_pins!(ch1, ch2, ch3, ch4);
75 }) 75 })
76 } 76 }
77 77
78 fn new_inner<F: Into<Hertz>>(tim: impl Unborrow<Target = T> + 'd, freq: F, configure_pins: impl FnOnce()) -> Self { 78 fn new_inner(tim: impl Unborrow<Target = T> + 'd, freq: Hertz, configure_pins: impl FnOnce()) -> Self {
79 unborrow!(tim); 79 unborrow!(tim);
80 80
81 T::enable(); 81 T::enable();
@@ -118,7 +118,7 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> {
118 } 118 }
119 } 119 }
120 120
121 pub fn set_freq<F: Into<Hertz>>(&mut self, freq: F) { 121 pub fn set_freq(&mut self, freq: Hertz) {
122 self.inner.set_frequency(freq); 122 self.inner.set_frequency(freq);
123 } 123 }
124 124
diff --git a/embassy-stm32/src/rcc/g0.rs b/embassy-stm32/src/rcc/g0.rs
index 6bfae46bd..3e138c7ab 100644
--- a/embassy-stm32/src/rcc/g0.rs
+++ b/embassy-stm32/src/rcc/g0.rs
@@ -2,7 +2,7 @@ use crate::pac::flash::vals::Latency;
2use crate::pac::rcc::vals::{self, Hpre, Hsidiv, Ppre, Sw}; 2use crate::pac::rcc::vals::{self, Hpre, Hsidiv, Ppre, Sw};
3use crate::pac::{FLASH, PWR, RCC}; 3use crate::pac::{FLASH, PWR, RCC};
4use crate::rcc::{set_freqs, Clocks}; 4use crate::rcc::{set_freqs, Clocks};
5use crate::time::{Hertz, U32Ext}; 5use crate::time::Hertz;
6 6
7/// HSI speed 7/// HSI speed
8pub const HSI_FREQ: Hertz = Hertz(16_000_000); 8pub const HSI_FREQ: Hertz = Hertz(16_000_000);
@@ -449,14 +449,14 @@ pub(crate) unsafe fn init(config: Config) {
449 }; 449 };
450 450
451 if config.low_power_run { 451 if config.low_power_run {
452 assert!(sys_clk.hz() <= 2_000_000.hz()); 452 assert!(sys_clk <= 2_000_000);
453 PWR.cr1().modify(|w| w.set_lpr(true)); 453 PWR.cr1().modify(|w| w.set_lpr(true));
454 } 454 }
455 455
456 set_freqs(Clocks { 456 set_freqs(Clocks {
457 sys: sys_clk.hz(), 457 sys: Hertz(sys_clk),
458 ahb1: ahb_freq.hz(), 458 ahb1: Hertz(ahb_freq),
459 apb1: apb_freq.hz(), 459 apb1: Hertz(apb_freq),
460 apb1_tim: apb_tim_freq.hz(), 460 apb1_tim: Hertz(apb_tim_freq),
461 }); 461 });
462} 462}
diff --git a/embassy-stm32/src/rcc/g4.rs b/embassy-stm32/src/rcc/g4.rs
index d9c15727b..0f078d328 100644
--- a/embassy-stm32/src/rcc/g4.rs
+++ b/embassy-stm32/src/rcc/g4.rs
@@ -1,6 +1,6 @@
1use crate::pac::{PWR, RCC}; 1use crate::pac::{PWR, RCC};
2use crate::rcc::{set_freqs, Clocks}; 2use crate::rcc::{set_freqs, Clocks};
3use crate::time::{Hertz, U32Ext}; 3use crate::time::Hertz;
4 4
5/// HSI speed 5/// HSI speed
6pub const HSI_FREQ: Hertz = Hertz(16_000_000); 6pub const HSI_FREQ: Hertz = Hertz(16_000_000);
@@ -144,17 +144,17 @@ pub(crate) unsafe fn init(config: Config) {
144 }; 144 };
145 145
146 if config.low_power_run { 146 if config.low_power_run {
147 assert!(sys_clk.hz() <= 2_000_000.hz()); 147 assert!(sys_clk <= 2_000_000);
148 PWR.cr1().modify(|w| w.set_lpr(true)); 148 PWR.cr1().modify(|w| w.set_lpr(true));
149 } 149 }
150 150
151 set_freqs(Clocks { 151 set_freqs(Clocks {
152 sys: sys_clk.hz(), 152 sys: Hertz(sys_clk),
153 ahb1: ahb_freq.hz(), 153 ahb1: Hertz(ahb_freq),
154 ahb2: ahb_freq.hz(), 154 ahb2: Hertz(ahb_freq),
155 apb1: apb1_freq.hz(), 155 apb1: Hertz(apb1_freq),
156 apb1_tim: apb1_tim_freq.hz(), 156 apb1_tim: Hertz(apb1_tim_freq),
157 apb2: apb2_freq.hz(), 157 apb2: Hertz(apb2_freq),
158 apb2_tim: apb2_tim_freq.hz(), 158 apb2_tim: Hertz(apb2_tim_freq),
159 }); 159 });
160} 160}
diff --git a/embassy-stm32/src/rcc/l0.rs b/embassy-stm32/src/rcc/l0.rs
index 2ca25aa2d..c3d29f164 100644
--- a/embassy-stm32/src/rcc/l0.rs
+++ b/embassy-stm32/src/rcc/l0.rs
@@ -3,7 +3,7 @@ use crate::pac::RCC;
3#[cfg(crs)] 3#[cfg(crs)]
4use crate::pac::{CRS, SYSCFG}; 4use crate::pac::{CRS, SYSCFG};
5use crate::rcc::{set_freqs, Clocks}; 5use crate::rcc::{set_freqs, Clocks};
6use crate::time::{Hertz, U32Ext}; 6use crate::time::Hertz;
7 7
8/// HSI speed 8/// HSI speed
9pub const HSI_FREQ: Hertz = Hertz(16_000_000); 9pub const HSI_FREQ: Hertz = Hertz(16_000_000);
@@ -266,7 +266,7 @@ pub(crate) unsafe fn init(config: Config) {
266 PLLDiv::Div3 => freq / 3, 266 PLLDiv::Div3 => freq / 3,
267 PLLDiv::Div4 => freq / 4, 267 PLLDiv::Div4 => freq / 4,
268 }; 268 };
269 assert!(freq <= 32_u32.mhz().0); 269 assert!(freq <= 32_000_000);
270 270
271 RCC.cfgr().write(move |w| { 271 RCC.cfgr().write(move |w| {
272 w.set_pllmul(mul.into()); 272 w.set_pllmul(mul.into());
@@ -359,11 +359,11 @@ pub(crate) unsafe fn init(config: Config) {
359 } 359 }
360 360
361 set_freqs(Clocks { 361 set_freqs(Clocks {
362 sys: sys_clk.hz(), 362 sys: Hertz(sys_clk),
363 ahb1: ahb_freq.hz(), 363 ahb1: Hertz(ahb_freq),
364 apb1: apb1_freq.hz(), 364 apb1: Hertz(apb1_freq),
365 apb2: apb2_freq.hz(), 365 apb2: Hertz(apb2_freq),
366 apb1_tim: apb1_tim_freq.hz(), 366 apb1_tim: Hertz(apb1_tim_freq),
367 apb2_tim: apb2_tim_freq.hz(), 367 apb2_tim: Hertz(apb2_tim_freq),
368 }); 368 });
369} 369}
diff --git a/embassy-stm32/src/rcc/l1.rs b/embassy-stm32/src/rcc/l1.rs
index 8c315f293..e0180b24f 100644
--- a/embassy-stm32/src/rcc/l1.rs
+++ b/embassy-stm32/src/rcc/l1.rs
@@ -1,7 +1,7 @@
1use crate::pac::rcc::vals::{Hpre, Msirange, Plldiv, Pllmul, Pllsrc, Ppre, Sw}; 1use crate::pac::rcc::vals::{Hpre, Msirange, Plldiv, Pllmul, Pllsrc, Ppre, Sw};
2use crate::pac::{FLASH, RCC}; 2use crate::pac::{FLASH, RCC};
3use crate::rcc::{set_freqs, Clocks}; 3use crate::rcc::{set_freqs, Clocks};
4use crate::time::{Hertz, U32Ext}; 4use crate::time::Hertz;
5 5
6/// HSI speed 6/// HSI speed
7pub const HSI_FREQ: Hertz = Hertz(16_000_000); 7pub const HSI_FREQ: Hertz = Hertz(16_000_000);
@@ -320,11 +320,11 @@ pub(crate) unsafe fn init(config: Config) {
320 }; 320 };
321 321
322 set_freqs(Clocks { 322 set_freqs(Clocks {
323 sys: sys_clk.hz(), 323 sys: Hertz(sys_clk),
324 ahb1: ahb_freq.hz(), 324 ahb1: Hertz(ahb_freq),
325 apb1: apb1_freq.hz(), 325 apb1: Hertz(apb1_freq),
326 apb2: apb2_freq.hz(), 326 apb2: Hertz(apb2_freq),
327 apb1_tim: apb1_tim_freq.hz(), 327 apb1_tim: Hertz(apb1_tim_freq),
328 apb2_tim: apb2_tim_freq.hz(), 328 apb2_tim: Hertz(apb2_tim_freq),
329 }); 329 });
330} 330}
diff --git a/embassy-stm32/src/rcc/l4.rs b/embassy-stm32/src/rcc/l4.rs
index fedfb0edc..c820018ac 100644
--- a/embassy-stm32/src/rcc/l4.rs
+++ b/embassy-stm32/src/rcc/l4.rs
@@ -1,7 +1,7 @@
1use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw}; 1use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw};
2use crate::pac::{FLASH, RCC}; 2use crate::pac::{FLASH, RCC};
3use crate::rcc::{set_freqs, Clocks}; 3use crate::rcc::{set_freqs, Clocks};
4use crate::time::{Hertz, U32Ext}; 4use crate::time::Hertz;
5 5
6/// HSI speed 6/// HSI speed
7pub const HSI_FREQ: Hertz = Hertz(16_000_000); 7pub const HSI_FREQ: Hertz = Hertz(16_000_000);
@@ -489,13 +489,13 @@ pub(crate) unsafe fn init(config: Config) {
489 }; 489 };
490 490
491 set_freqs(Clocks { 491 set_freqs(Clocks {
492 sys: sys_clk.hz(), 492 sys: Hertz(sys_clk),
493 ahb1: ahb_freq.hz(), 493 ahb1: Hertz(ahb_freq),
494 ahb2: ahb_freq.hz(), 494 ahb2: Hertz(ahb_freq),
495 ahb3: ahb_freq.hz(), 495 ahb3: Hertz(ahb_freq),
496 apb1: apb1_freq.hz(), 496 apb1: Hertz(apb1_freq),
497 apb2: apb2_freq.hz(), 497 apb2: Hertz(apb2_freq),
498 apb1_tim: apb1_tim_freq.hz(), 498 apb1_tim: Hertz(apb1_tim_freq),
499 apb2_tim: apb2_tim_freq.hz(), 499 apb2_tim: Hertz(apb2_tim_freq),
500 }); 500 });
501} 501}
diff --git a/embassy-stm32/src/rcc/l5.rs b/embassy-stm32/src/rcc/l5.rs
index edcdafe08..81bf36be0 100644
--- a/embassy-stm32/src/rcc/l5.rs
+++ b/embassy-stm32/src/rcc/l5.rs
@@ -3,7 +3,7 @@ use stm32_metapac::PWR;
3use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw}; 3use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw};
4use crate::pac::{FLASH, RCC}; 4use crate::pac::{FLASH, RCC};
5use crate::rcc::{set_freqs, Clocks}; 5use crate::rcc::{set_freqs, Clocks};
6use crate::time::{Hertz, U32Ext}; 6use crate::time::Hertz;
7 7
8/// HSI speed 8/// HSI speed
9pub const HSI_FREQ: Hertz = Hertz(16_000_000); 9pub const HSI_FREQ: Hertz = Hertz(16_000_000);
@@ -487,13 +487,13 @@ pub(crate) unsafe fn init(config: Config) {
487 }; 487 };
488 488
489 set_freqs(Clocks { 489 set_freqs(Clocks {
490 sys: sys_clk.hz(), 490 sys: Hertz(sys_clk),
491 ahb1: ahb_freq.hz(), 491 ahb1: Hertz(ahb_freq),
492 ahb2: ahb_freq.hz(), 492 ahb2: Hertz(ahb_freq),
493 ahb3: ahb_freq.hz(), 493 ahb3: Hertz(ahb_freq),
494 apb1: apb1_freq.hz(), 494 apb1: Hertz(apb1_freq),
495 apb2: apb2_freq.hz(), 495 apb2: Hertz(apb2_freq),
496 apb1_tim: apb1_tim_freq.hz(), 496 apb1_tim: Hertz(apb1_tim_freq),
497 apb2_tim: apb2_tim_freq.hz(), 497 apb2_tim: Hertz(apb2_tim_freq),
498 }); 498 });
499} 499}
diff --git a/embassy-stm32/src/rcc/u5.rs b/embassy-stm32/src/rcc/u5.rs
index 701eeb893..1f7e39070 100644
--- a/embassy-stm32/src/rcc/u5.rs
+++ b/embassy-stm32/src/rcc/u5.rs
@@ -2,7 +2,7 @@ use stm32_metapac::rcc::vals::{Hpre, Msirange, Msirgsel, Pllm, Pllsrc, Ppre, Sw}
2 2
3use crate::pac::{FLASH, RCC}; 3use crate::pac::{FLASH, RCC};
4use crate::rcc::{set_freqs, Clocks}; 4use crate::rcc::{set_freqs, Clocks};
5use crate::time::{Hertz, U32Ext}; 5use crate::time::Hertz;
6 6
7/// HSI speed 7/// HSI speed
8pub const HSI_FREQ: Hertz = Hertz(16_000_000); 8pub const HSI_FREQ: Hertz = Hertz(16_000_000);
@@ -483,14 +483,14 @@ pub(crate) unsafe fn init(config: Config) {
483 }; 483 };
484 484
485 set_freqs(Clocks { 485 set_freqs(Clocks {
486 sys: sys_clk.hz(), 486 sys: Hertz(sys_clk),
487 ahb1: ahb_freq.hz(), 487 ahb1: Hertz(ahb_freq),
488 ahb2: ahb_freq.hz(), 488 ahb2: Hertz(ahb_freq),
489 ahb3: ahb_freq.hz(), 489 ahb3: Hertz(ahb_freq),
490 apb1: apb1_freq.hz(), 490 apb1: Hertz(apb1_freq),
491 apb2: apb2_freq.hz(), 491 apb2: Hertz(apb2_freq),
492 apb3: apb3_freq.hz(), 492 apb3: Hertz(apb3_freq),
493 apb1_tim: apb1_tim_freq.hz(), 493 apb1_tim: Hertz(apb1_tim_freq),
494 apb2_tim: apb2_tim_freq.hz(), 494 apb2_tim: Hertz(apb2_tim_freq),
495 }); 495 });
496} 496}
diff --git a/embassy-stm32/src/rcc/wb.rs b/embassy-stm32/src/rcc/wb.rs
index aec74c4b0..f6a5feea6 100644
--- a/embassy-stm32/src/rcc/wb.rs
+++ b/embassy-stm32/src/rcc/wb.rs
@@ -1,6 +1,6 @@
1use crate::pac::RCC; 1use crate::pac::RCC;
2use crate::rcc::{set_freqs, Clocks}; 2use crate::rcc::{set_freqs, Clocks};
3use crate::time::{Hertz, U32Ext}; 3use crate::time::Hertz;
4 4
5/// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC, 5/// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC,
6/// and with the addition of the init function to configure a system clock. 6/// and with the addition of the init function to configure a system clock.
@@ -157,13 +157,13 @@ pub(crate) unsafe fn init(config: Config) {
157 }; 157 };
158 158
159 set_freqs(Clocks { 159 set_freqs(Clocks {
160 sys: sys_clk.hz(), 160 sys: Hertz(sys_clk),
161 ahb1: ahb_freq.hz(), 161 ahb1: Hertz(ahb_freq),
162 ahb2: ahb_freq.hz(), 162 ahb2: Hertz(ahb_freq),
163 ahb3: ahb_freq.hz(), 163 ahb3: Hertz(ahb_freq),
164 apb1: apb1_freq.hz(), 164 apb1: Hertz(apb1_freq),
165 apb2: apb2_freq.hz(), 165 apb2: Hertz(apb2_freq),
166 apb1_tim: apb1_tim_freq.hz(), 166 apb1_tim: Hertz(apb1_tim_freq),
167 apb2_tim: apb2_tim_freq.hz(), 167 apb2_tim: Hertz(apb2_tim_freq),
168 }); 168 });
169} 169}
diff --git a/embassy-stm32/src/rcc/wl.rs b/embassy-stm32/src/rcc/wl.rs
index 33ecaa361..69c192c67 100644
--- a/embassy-stm32/src/rcc/wl.rs
+++ b/embassy-stm32/src/rcc/wl.rs
@@ -1,6 +1,6 @@
1use crate::pac::{FLASH, RCC}; 1use crate::pac::{FLASH, RCC};
2use crate::rcc::{set_freqs, Clocks}; 2use crate::rcc::{set_freqs, Clocks};
3use crate::time::{Hertz, U32Ext}; 3use crate::time::Hertz;
4 4
5/// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC, 5/// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC,
6/// and with the addition of the init function to configure a system clock. 6/// and with the addition of the init function to configure a system clock.
@@ -320,14 +320,14 @@ pub(crate) unsafe fn init(config: Config) {
320 while FLASH.acr().read().latency() != ws {} 320 while FLASH.acr().read().latency() != ws {}
321 321
322 set_freqs(Clocks { 322 set_freqs(Clocks {
323 sys: sys_clk.hz(), 323 sys: Hertz(sys_clk),
324 ahb1: ahb_freq.hz(), 324 ahb1: Hertz(ahb_freq),
325 ahb2: ahb_freq.hz(), 325 ahb2: Hertz(ahb_freq),
326 ahb3: shd_ahb_freq.hz(), 326 ahb3: Hertz(shd_ahb_freq),
327 apb1: apb1_freq.hz(), 327 apb1: Hertz(apb1_freq),
328 apb2: apb2_freq.hz(), 328 apb2: Hertz(apb2_freq),
329 apb3: apb3_freq.hz(), 329 apb3: Hertz(apb3_freq),
330 apb1_tim: apb1_tim_freq.hz(), 330 apb1_tim: Hertz(apb1_tim_freq),
331 apb2_tim: apb2_tim_freq.hz(), 331 apb2_tim: Hertz(apb2_tim_freq),
332 }); 332 });
333} 333}
diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs
index 1ebf91b3f..d94509748 100644
--- a/embassy-stm32/src/sdmmc/mod.rs
+++ b/embassy-stm32/src/sdmmc/mod.rs
@@ -261,7 +261,7 @@ impl<'d, T: Instance, P: Pins<T>> Sdmmc<'d, T, P, NoDma> {
261 261
262impl<'d, T: Instance, P: Pins<T>, Dma: SdmmcDma<T>> Sdmmc<'d, T, P, Dma> { 262impl<'d, T: Instance, P: Pins<T>, Dma: SdmmcDma<T>> Sdmmc<'d, T, P, Dma> {
263 #[inline(always)] 263 #[inline(always)]
264 pub async fn init_card(&mut self, freq: impl Into<Hertz>) -> Result<(), Error> { 264 pub async fn init_card(&mut self, freq: Hertz) -> Result<(), Error> {
265 let inner = T::inner(); 265 let inner = T::inner();
266 let freq = freq.into(); 266 let freq = freq.into();
267 267
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs
index a839bb41e..a02f4492f 100644
--- a/embassy-stm32/src/spi/mod.rs
+++ b/embassy-stm32/src/spi/mod.rs
@@ -83,19 +83,16 @@ pub struct Spi<'d, T: Instance, Tx, Rx> {
83} 83}
84 84
85impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { 85impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
86 pub fn new<F>( 86 pub fn new(
87 peri: impl Unborrow<Target = T> + 'd, 87 peri: impl Unborrow<Target = T> + 'd,
88 sck: impl Unborrow<Target = impl SckPin<T>> + 'd, 88 sck: impl Unborrow<Target = impl SckPin<T>> + 'd,
89 mosi: impl Unborrow<Target = impl MosiPin<T>> + 'd, 89 mosi: impl Unborrow<Target = impl MosiPin<T>> + 'd,
90 miso: impl Unborrow<Target = impl MisoPin<T>> + 'd, 90 miso: impl Unborrow<Target = impl MisoPin<T>> + 'd,
91 txdma: impl Unborrow<Target = Tx> + 'd, 91 txdma: impl Unborrow<Target = Tx> + 'd,
92 rxdma: impl Unborrow<Target = Rx> + 'd, 92 rxdma: impl Unborrow<Target = Rx> + 'd,
93 freq: F, 93 freq: Hertz,
94 config: Config, 94 config: Config,
95 ) -> Self 95 ) -> Self {
96 where
97 F: Into<Hertz>,
98 {
99 unborrow!(sck, mosi, miso); 96 unborrow!(sck, mosi, miso);
100 unsafe { 97 unsafe {
101 sck.set_as_af(sck.af_num(), AFType::OutputPushPull); 98 sck.set_as_af(sck.af_num(), AFType::OutputPushPull);
@@ -121,18 +118,15 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
121 ) 118 )
122 } 119 }
123 120
124 pub fn new_rxonly<F>( 121 pub fn new_rxonly(
125 peri: impl Unborrow<Target = T> + 'd, 122 peri: impl Unborrow<Target = T> + 'd,
126 sck: impl Unborrow<Target = impl SckPin<T>> + 'd, 123 sck: impl Unborrow<Target = impl SckPin<T>> + 'd,
127 miso: impl Unborrow<Target = impl MisoPin<T>> + 'd, 124 miso: impl Unborrow<Target = impl MisoPin<T>> + 'd,
128 txdma: impl Unborrow<Target = Tx> + 'd, // TODO remove 125 txdma: impl Unborrow<Target = Tx> + 'd, // TODO remove
129 rxdma: impl Unborrow<Target = Rx> + 'd, 126 rxdma: impl Unborrow<Target = Rx> + 'd,
130 freq: F, 127 freq: Hertz,
131 config: Config, 128 config: Config,
132 ) -> Self 129 ) -> Self {
133 where
134 F: Into<Hertz>,
135 {
136 unborrow!(sck, miso); 130 unborrow!(sck, miso);
137 unsafe { 131 unsafe {
138 sck.set_as_af(sck.af_num(), AFType::OutputPushPull); 132 sck.set_as_af(sck.af_num(), AFType::OutputPushPull);
@@ -155,18 +149,15 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
155 ) 149 )
156 } 150 }
157 151
158 pub fn new_txonly<F>( 152 pub fn new_txonly(
159 peri: impl Unborrow<Target = T> + 'd, 153 peri: impl Unborrow<Target = T> + 'd,
160 sck: impl Unborrow<Target = impl SckPin<T>> + 'd, 154 sck: impl Unborrow<Target = impl SckPin<T>> + 'd,
161 mosi: impl Unborrow<Target = impl MosiPin<T>> + 'd, 155 mosi: impl Unborrow<Target = impl MosiPin<T>> + 'd,
162 txdma: impl Unborrow<Target = Tx> + 'd, 156 txdma: impl Unborrow<Target = Tx> + 'd,
163 rxdma: impl Unborrow<Target = Rx> + 'd, // TODO remove 157 rxdma: impl Unborrow<Target = Rx> + 'd, // TODO remove
164 freq: F, 158 freq: Hertz,
165 config: Config, 159 config: Config,
166 ) -> Self 160 ) -> Self {
167 where
168 F: Into<Hertz>,
169 {
170 unborrow!(sck, mosi); 161 unborrow!(sck, mosi);
171 unsafe { 162 unsafe {
172 sck.set_as_af(sck.af_num(), AFType::OutputPushPull); 163 sck.set_as_af(sck.af_num(), AFType::OutputPushPull);
@@ -189,19 +180,16 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
189 ) 180 )
190 } 181 }
191 182
192 fn new_inner<F>( 183 fn new_inner(
193 _peri: impl Unborrow<Target = T> + 'd, 184 _peri: impl Unborrow<Target = T> + 'd,
194 sck: Option<AnyPin>, 185 sck: Option<AnyPin>,
195 mosi: Option<AnyPin>, 186 mosi: Option<AnyPin>,
196 miso: Option<AnyPin>, 187 miso: Option<AnyPin>,
197 txdma: impl Unborrow<Target = Tx> + 'd, 188 txdma: impl Unborrow<Target = Tx> + 'd,
198 rxdma: impl Unborrow<Target = Rx> + 'd, 189 rxdma: impl Unborrow<Target = Rx> + 'd,
199 freq: F, 190 freq: Hertz,
200 config: Config, 191 config: Config,
201 ) -> Self 192 ) -> Self {
202 where
203 F: Into<Hertz>,
204 {
205 unborrow!(txdma, rxdma); 193 unborrow!(txdma, rxdma);
206 194
207 let pclk = T::frequency(); 195 let pclk = T::frequency();
diff --git a/embassy-stm32/src/time.rs b/embassy-stm32/src/time.rs
index ac03ce5c4..49140bbe0 100644
--- a/embassy-stm32/src/time.rs
+++ b/embassy-stm32/src/time.rs
@@ -1,126 +1,34 @@
1//! Time units 1//! Time units
2 2
3/// Bits per second
4#[derive(PartialEq, PartialOrd, Clone, Copy, Debug)]
5pub struct Bps(pub u32);
6
7/// Hertz 3/// Hertz
8#[derive(PartialEq, PartialOrd, Clone, Copy, Debug, Eq)] 4#[derive(PartialEq, PartialOrd, Clone, Copy, Debug, Eq)]
9pub struct Hertz(pub u32); 5pub struct Hertz(pub u32);
10 6
11/// KiloHertz 7impl Hertz {
12#[derive(PartialEq, PartialOrd, Clone, Copy, Debug)] 8 pub fn hz(hertz: u32) -> Self {
13pub struct KiloHertz(pub u32); 9 Self(hertz)
14
15/// MegaHertz
16#[derive(PartialEq, PartialOrd, Clone, Copy, Debug)]
17pub struct MegaHertz(pub u32);
18
19/// MilliSeconds
20#[derive(PartialEq, PartialOrd, Clone, Copy, Debug)]
21pub struct MilliSeconds(pub u32);
22
23/// MicroSeconds
24#[derive(PartialEq, PartialOrd, Clone, Copy, Debug)]
25pub struct MicroSeconds(pub u32);
26
27/// NanoSeconds
28#[derive(PartialEq, PartialOrd, Clone, Copy, Debug)]
29pub struct NanoSeconds(pub u32);
30
31/// Extension trait that adds convenience methods to the `u32` type
32pub trait U32Ext {
33 /// Wrap in `Bps`
34 fn bps(self) -> Bps;
35
36 /// Wrap in `Hertz`
37 fn hz(self) -> Hertz;
38
39 /// Wrap in `KiloHertz`
40 fn khz(self) -> KiloHertz;
41
42 /// Wrap in `MegaHertz`
43 fn mhz(self) -> MegaHertz;
44
45 /// Wrap in "MilliSeconds"
46 fn ms(self) -> MilliSeconds;
47
48 /// Wrap in "MicroSeconds"
49 fn us(self) -> MicroSeconds;
50
51 /// Wrap in "NanoSeconds"
52 fn ns(self) -> NanoSeconds;
53}
54
55impl U32Ext for u32 {
56 fn bps(self) -> Bps {
57 Bps(self)
58 } 10 }
59 11
60 fn hz(self) -> Hertz { 12 pub fn khz(kilohertz: u32) -> Self {
61 Hertz(self) 13 Self(kilohertz * 1_000)
62 } 14 }
63 15
64 fn khz(self) -> KiloHertz { 16 pub fn mhz(megahertz: u32) -> Self {
65 KiloHertz(self) 17 Self(megahertz * 1_000_000)
66 }
67
68 fn mhz(self) -> MegaHertz {
69 MegaHertz(self)
70 }
71
72 fn ms(self) -> MilliSeconds {
73 MilliSeconds(self)
74 }
75
76 fn us(self) -> MicroSeconds {
77 MicroSeconds(self)
78 }
79
80 fn ns(self) -> NanoSeconds {
81 NanoSeconds(self)
82 }
83}
84
85// Unit conversions
86impl Into<Hertz> for Bps {
87 fn into(self) -> Hertz {
88 Hertz(self.0)
89 }
90}
91
92impl Into<Hertz> for KiloHertz {
93 fn into(self) -> Hertz {
94 Hertz(self.0 * 1_000)
95 } 18 }
96} 19}
97 20
98impl Into<Hertz> for MegaHertz { 21/// This is a convenience shortcut for [`Hertz::hz`]
99 fn into(self) -> Hertz { 22pub fn hz(hertz: u32) -> Hertz {
100 Hertz(self.0 * 1_000_000) 23 Hertz::hz(hertz)
101 }
102} 24}
103 25
104impl Into<KiloHertz> for MegaHertz { 26/// This is a convenience shortcut for [`Hertz::khz`]
105 fn into(self) -> KiloHertz { 27pub fn khz(kilohertz: u32) -> Hertz {
106 KiloHertz(self.0 * 1_000) 28 Hertz::khz(kilohertz)
107 }
108}
109
110impl Into<NanoSeconds> for MicroSeconds {
111 fn into(self) -> NanoSeconds {
112 NanoSeconds(self.0 * 1_000)
113 }
114} 29}
115 30
116impl Into<NanoSeconds> for MilliSeconds { 31/// This is a convenience shortcut for [`Hertz::mhz`]
117 fn into(self) -> NanoSeconds { 32pub fn mhz(megahertz: u32) -> Hertz {
118 NanoSeconds(self.0 * 1_000_000) 33 Hertz::mhz(megahertz)
119 }
120}
121
122impl Into<MicroSeconds> for MilliSeconds {
123 fn into(self) -> MicroSeconds {
124 MicroSeconds(self.0 * 1_000)
125 }
126} 34}
diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs
index 9067fa462..e92015ee9 100644
--- a/embassy-stm32/src/timer/mod.rs
+++ b/embassy-stm32/src/timer/mod.rs
@@ -23,7 +23,7 @@ pub(crate) mod sealed {
23 23
24 fn reset(&mut self); 24 fn reset(&mut self);
25 25
26 fn set_frequency<F: Into<Hertz>>(&mut self, frequency: F); 26 fn set_frequency(&mut self, frequency: Hertz);
27 27
28 fn clear_update_interrupt(&mut self) -> bool; 28 fn clear_update_interrupt(&mut self) -> bool;
29 29
@@ -37,7 +37,7 @@ pub(crate) mod sealed {
37 pub trait GeneralPurpose32bitInstance: GeneralPurpose16bitInstance { 37 pub trait GeneralPurpose32bitInstance: GeneralPurpose16bitInstance {
38 fn regs_gp32() -> crate::pac::timer::TimGp32; 38 fn regs_gp32() -> crate::pac::timer::TimGp32;
39 39
40 fn set_frequency<F: Into<Hertz>>(&mut self, frequency: F); 40 fn set_frequency(&mut self, frequency: Hertz);
41 } 41 }
42 42
43 pub trait AdvancedControlInstance: Basic16bitInstance { 43 pub trait AdvancedControlInstance: Basic16bitInstance {
@@ -81,9 +81,9 @@ macro_rules! impl_basic_16bit_timer {
81 } 81 }
82 } 82 }
83 83
84 fn set_frequency<F: Into<Hertz>>(&mut self, frequency: F) { 84 fn set_frequency(&mut self, frequency: Hertz) {
85 use core::convert::TryInto; 85 use core::convert::TryInto;
86 let f = frequency.into().0; 86 let f = frequency.0;
87 let timer_f = Self::frequency().0; 87 let timer_f = Self::frequency().0;
88 let pclk_ticks_per_timer_period = timer_f / f; 88 let pclk_ticks_per_timer_period = timer_f / f;
89 let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 16)).try_into()); 89 let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 16)).try_into());
@@ -132,9 +132,9 @@ macro_rules! impl_32bit_timer {
132 crate::pac::$inst 132 crate::pac::$inst
133 } 133 }
134 134
135 fn set_frequency<F: Into<Hertz>>(&mut self, frequency: F) { 135 fn set_frequency(&mut self, frequency: Hertz) {
136 use core::convert::TryInto; 136 use core::convert::TryInto;
137 let f = frequency.into().0; 137 let f = frequency.0;
138 let timer_f = Self::frequency().0; 138 let timer_f = Self::frequency().0;
139 let pclk_ticks_per_timer_period = (timer_f / f) as u64; 139 let pclk_ticks_per_timer_period = (timer_f / f) as u64;
140 let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 32)).try_into()); 140 let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 32)).try_into());
diff --git a/examples/stm32f3/src/bin/usb_serial.rs b/examples/stm32f3/src/bin/usb_serial.rs
index 8a76d4546..463d561ec 100644
--- a/examples/stm32f3/src/bin/usb_serial.rs
+++ b/examples/stm32f3/src/bin/usb_serial.rs
@@ -6,7 +6,7 @@ use defmt::{panic, *};
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::time::U32Ext; 9use embassy_stm32::time::mhz;
10use embassy_stm32::usb::{Driver, Instance}; 10use embassy_stm32::usb::{Driver, Instance};
11use embassy_stm32::{interrupt, Config, Peripherals}; 11use embassy_stm32::{interrupt, Config, Peripherals};
12use embassy_usb::driver::EndpointError; 12use embassy_usb::driver::EndpointError;
@@ -18,10 +18,10 @@ use {defmt_rtt as _, panic_probe as _};
18fn config() -> Config { 18fn config() -> Config {
19 let mut config = Config::default(); 19 let mut config = Config::default();
20 20
21 config.rcc.hse = Some(8.mhz().into()); 21 config.rcc.hse = Some(mhz(8));
22 config.rcc.sysclk = Some(48.mhz().into()); 22 config.rcc.sysclk = Some(mhz(48));
23 config.rcc.pclk1 = Some(24.mhz().into()); 23 config.rcc.pclk1 = Some(mhz(24));
24 config.rcc.pclk2 = Some(24.mhz().into()); 24 config.rcc.pclk2 = Some(mhz(24));
25 config.rcc.pll48 = true; 25 config.rcc.pll48 = true;
26 26
27 config 27 config
diff --git a/examples/stm32f4/src/bin/pwm.rs b/examples/stm32f4/src/bin/pwm.rs
index cd20c68bb..c99f3cc26 100644
--- a/examples/stm32f4/src/bin/pwm.rs
+++ b/examples/stm32f4/src/bin/pwm.rs
@@ -7,7 +7,7 @@ use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_stm32::pwm::simple_pwm::SimplePwm; 8use embassy_stm32::pwm::simple_pwm::SimplePwm;
9use embassy_stm32::pwm::Channel; 9use embassy_stm32::pwm::Channel;
10use embassy_stm32::time::U32Ext; 10use embassy_stm32::time::khz;
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
@@ -15,7 +15,7 @@ use {defmt_rtt as _, panic_probe as _};
15async fn main(_spawner: Spawner, p: Peripherals) { 15async fn main(_spawner: Spawner, p: Peripherals) {
16 info!("Hello World!"); 16 info!("Hello World!");
17 17
18 let mut pwm = SimplePwm::new_1ch(p.TIM1, p.PE9, 10000.hz()); 18 let mut pwm = SimplePwm::new_1ch(p.TIM1, p.PE9, khz(10));
19 let max = pwm.get_max_duty(); 19 let max = pwm.get_max_duty();
20 pwm.enable(Channel::Ch1); 20 pwm.enable(Channel::Ch1);
21 21
diff --git a/examples/stm32f4/src/bin/sdmmc.rs b/examples/stm32f4/src/bin/sdmmc.rs
index b08d26f49..665670261 100644
--- a/examples/stm32f4/src/bin/sdmmc.rs
+++ b/examples/stm32f4/src/bin/sdmmc.rs
@@ -5,13 +5,13 @@
5use defmt::*; 5use defmt::*;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy_stm32::sdmmc::Sdmmc; 7use embassy_stm32::sdmmc::Sdmmc;
8use embassy_stm32::time::U32Ext; 8use embassy_stm32::time::mhz;
9use embassy_stm32::{interrupt, Config, Peripherals}; 9use embassy_stm32::{interrupt, Config, Peripherals};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12fn config() -> Config { 12fn config() -> Config {
13 let mut config = Config::default(); 13 let mut config = Config::default();
14 config.rcc.sys_ck = Some(48.mhz().into()); 14 config.rcc.sys_ck = Some(mhz(48));
15 config 15 config
16} 16}
17 17
@@ -32,7 +32,7 @@ async fn main(_spawner: Spawner, p: Peripherals) -> ! {
32 // Should print 400kHz for initialization 32 // Should print 400kHz for initialization
33 info!("Configured clock: {}", sdmmc.clock().0); 33 info!("Configured clock: {}", sdmmc.clock().0);
34 34
35 unwrap!(sdmmc.init_card(25.mhz()).await); 35 unwrap!(sdmmc.init_card(mhz(25)).await);
36 36
37 let card = unwrap!(sdmmc.card()); 37 let card = unwrap!(sdmmc.card());
38 38
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs
index dc0b3c605..177683c3a 100644
--- a/examples/stm32f7/src/bin/eth.rs
+++ b/examples/stm32f7/src/bin/eth.rs
@@ -12,7 +12,7 @@ use embassy_stm32::eth::generic_smi::GenericSMI;
12use embassy_stm32::eth::{Ethernet, State}; 12use embassy_stm32::eth::{Ethernet, State};
13use embassy_stm32::peripherals::ETH; 13use embassy_stm32::peripherals::ETH;
14use embassy_stm32::rng::Rng; 14use embassy_stm32::rng::Rng;
15use embassy_stm32::time::U32Ext; 15use embassy_stm32::time::mhz;
16use embassy_stm32::{interrupt, Config, Peripherals}; 16use embassy_stm32::{interrupt, Config, Peripherals};
17use embedded_io::asynch::Write; 17use embedded_io::asynch::Write;
18use rand_core::RngCore; 18use rand_core::RngCore;
@@ -35,7 +35,7 @@ async fn net_task(stack: &'static Stack<Device>) -> ! {
35 35
36fn config() -> Config { 36fn config() -> Config {
37 let mut config = Config::default(); 37 let mut config = Config::default();
38 config.rcc.sys_ck = Some(200.mhz().into()); 38 config.rcc.sys_ck = Some(mhz(200));
39 config 39 config
40} 40}
41 41
diff --git a/examples/stm32f7/src/bin/sdmmc.rs b/examples/stm32f7/src/bin/sdmmc.rs
index 1af1061ba..011e1fd95 100644
--- a/examples/stm32f7/src/bin/sdmmc.rs
+++ b/examples/stm32f7/src/bin/sdmmc.rs
@@ -5,13 +5,13 @@
5use defmt::*; 5use defmt::*;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy_stm32::sdmmc::Sdmmc; 7use embassy_stm32::sdmmc::Sdmmc;
8use embassy_stm32::time::U32Ext; 8use embassy_stm32::time::mhz;
9use embassy_stm32::{interrupt, Config, Peripherals}; 9use embassy_stm32::{interrupt, Config, Peripherals};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12fn config() -> Config { 12fn config() -> Config {
13 let mut config = Config::default(); 13 let mut config = Config::default();
14 config.rcc.sys_ck = Some(200.mhz().into()); 14 config.rcc.sys_ck = Some(mhz(200));
15 config 15 config
16} 16}
17 17
@@ -32,7 +32,7 @@ async fn main(_spawner: Spawner, p: Peripherals) -> ! {
32 // Should print 400kHz for initialization 32 // Should print 400kHz for initialization
33 info!("Configured clock: {}", sdmmc.clock().0); 33 info!("Configured clock: {}", sdmmc.clock().0);
34 34
35 unwrap!(sdmmc.init_card(25.mhz()).await); 35 unwrap!(sdmmc.init_card(mhz(25)).await);
36 36
37 let card = unwrap!(sdmmc.card()); 37 let card = unwrap!(sdmmc.card());
38 38
diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs
index 525b6001f..579e289b0 100644
--- a/examples/stm32g4/src/bin/pwm.rs
+++ b/examples/stm32g4/src/bin/pwm.rs
@@ -7,7 +7,7 @@ use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_stm32::pwm::simple_pwm::SimplePwm; 8use embassy_stm32::pwm::simple_pwm::SimplePwm;
9use embassy_stm32::pwm::Channel; 9use embassy_stm32::pwm::Channel;
10use embassy_stm32::time::U32Ext; 10use embassy_stm32::time::khz;
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
@@ -15,7 +15,7 @@ use {defmt_rtt as _, panic_probe as _};
15async fn main(_spawner: Spawner, p: Peripherals) { 15async fn main(_spawner: Spawner, p: Peripherals) {
16 info!("Hello World!"); 16 info!("Hello World!");
17 17
18 let mut pwm = SimplePwm::new_1ch(p.TIM2, p.PA5, 10000.hz()); 18 let mut pwm = SimplePwm::new_1ch(p.TIM2, p.PA5, khz(10));
19 let max = pwm.get_max_duty(); 19 let max = pwm.get_max_duty();
20 pwm.enable(Channel::Ch1); 20 pwm.enable(Channel::Ch1);
21 21
diff --git a/examples/stm32h7/src/bin/adc.rs b/examples/stm32h7/src/bin/adc.rs
index e24390741..ce73364c0 100644
--- a/examples/stm32h7/src/bin/adc.rs
+++ b/examples/stm32h7/src/bin/adc.rs
@@ -7,15 +7,15 @@ use embassy::executor::Spawner;
7use embassy::time::{Delay, Duration, Timer}; 7use embassy::time::{Delay, Duration, Timer};
8use embassy_stm32::adc::{Adc, SampleTime}; 8use embassy_stm32::adc::{Adc, SampleTime};
9use embassy_stm32::rcc::AdcClockSource; 9use embassy_stm32::rcc::AdcClockSource;
10use embassy_stm32::time::U32Ext; 10use embassy_stm32::time::mhz;
11use embassy_stm32::{Config, Peripherals}; 11use embassy_stm32::{Config, Peripherals};
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
14pub fn config() -> Config { 14pub fn config() -> Config {
15 let mut config = Config::default(); 15 let mut config = Config::default();
16 config.rcc.sys_ck = Some(400.mhz().into()); 16 config.rcc.sys_ck = Some(mhz(400));
17 config.rcc.hclk = Some(200.mhz().into()); 17 config.rcc.hclk = Some(mhz(200));
18 config.rcc.per_ck = Some(64.mhz().into()); 18 config.rcc.per_ck = Some(mhz(64));
19 config.rcc.adc_clock_source = AdcClockSource::PerCk; 19 config.rcc.adc_clock_source = AdcClockSource::PerCk;
20 config 20 config
21} 21}
diff --git a/examples/stm32h7/src/bin/camera.rs b/examples/stm32h7/src/bin/camera.rs
index 918eab659..0d0179e62 100644
--- a/examples/stm32h7/src/bin/camera.rs
+++ b/examples/stm32h7/src/bin/camera.rs
@@ -8,20 +8,20 @@ use embassy_stm32::dcmi::{self, *};
8use embassy_stm32::gpio::{Level, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::i2c::I2c; 9use embassy_stm32::i2c::I2c;
10use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; 10use embassy_stm32::rcc::{Mco, Mco1Source, McoClock};
11use embassy_stm32::time::U32Ext; 11use embassy_stm32::time::{khz, mhz};
12use embassy_stm32::{interrupt, Config, Peripherals}; 12use embassy_stm32::{interrupt, Config, Peripherals};
13use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
14 14
15#[allow(unused)] 15#[allow(unused)]
16pub fn config() -> Config { 16pub fn config() -> Config {
17 let mut config = Config::default(); 17 let mut config = Config::default();
18 config.rcc.sys_ck = Some(400.mhz().into()); 18 config.rcc.sys_ck = Some(mhz(400));
19 config.rcc.hclk = Some(400.mhz().into()); 19 config.rcc.hclk = Some(mhz(400));
20 config.rcc.pll1.q_ck = Some(100.mhz().into()); 20 config.rcc.pll1.q_ck = Some(mhz(100));
21 config.rcc.pclk1 = Some(100.mhz().into()); 21 config.rcc.pclk1 = Some(mhz(100));
22 config.rcc.pclk2 = Some(100.mhz().into()); 22 config.rcc.pclk2 = Some(mhz(100));
23 config.rcc.pclk3 = Some(100.mhz().into()); 23 config.rcc.pclk3 = Some(mhz(100));
24 config.rcc.pclk4 = Some(100.mhz().into()); 24 config.rcc.pclk4 = Some(mhz(100));
25 config 25 config
26} 26}
27 27
@@ -39,7 +39,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
39 39
40 let mut led = Output::new(p.PE3, Level::High, Speed::Low); 40 let mut led = Output::new(p.PE3, Level::High, Speed::Low);
41 let i2c_irq = interrupt::take!(I2C1_EV); 41 let i2c_irq = interrupt::take!(I2C1_EV);
42 let cam_i2c = I2c::new(p.I2C1, p.PB8, p.PB9, i2c_irq, p.DMA1_CH1, p.DMA1_CH2, 100u32.khz()); 42 let cam_i2c = I2c::new(p.I2C1, p.PB8, p.PB9, i2c_irq, p.DMA1_CH1, p.DMA1_CH2, khz(100));
43 43
44 let mut camera = Ov7725::new(cam_i2c, mco); 44 let mut camera = Ov7725::new(cam_i2c, mco);
45 45
diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs
index 8ed33350c..dece74bba 100644
--- a/examples/stm32h7/src/bin/dac.rs
+++ b/examples/stm32h7/src/bin/dac.rs
@@ -5,15 +5,15 @@
5use cortex_m_rt::entry; 5use cortex_m_rt::entry;
6use defmt::*; 6use defmt::*;
7use embassy_stm32::dac::{Channel, Dac, Value}; 7use embassy_stm32::dac::{Channel, Dac, Value};
8use embassy_stm32::time::U32Ext; 8use embassy_stm32::time::mhz;
9use embassy_stm32::Config; 9use embassy_stm32::Config;
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12pub fn config() -> Config { 12pub fn config() -> Config {
13 let mut config = Config::default(); 13 let mut config = Config::default();
14 config.rcc.sys_ck = Some(400.mhz().into()); 14 config.rcc.sys_ck = Some(mhz(400));
15 config.rcc.hclk = Some(200.mhz().into()); 15 config.rcc.hclk = Some(mhz(200));
16 config.rcc.pll1.q_ck = Some(100.mhz().into()); 16 config.rcc.pll1.q_ck = Some(mhz(100));
17 config 17 config
18} 18}
19 19
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs
index 6dabadc4b..556d472bd 100644
--- a/examples/stm32h7/src/bin/eth.rs
+++ b/examples/stm32h7/src/bin/eth.rs
@@ -12,7 +12,7 @@ use embassy_stm32::eth::generic_smi::GenericSMI;
12use embassy_stm32::eth::{Ethernet, State}; 12use embassy_stm32::eth::{Ethernet, State};
13use embassy_stm32::peripherals::ETH; 13use embassy_stm32::peripherals::ETH;
14use embassy_stm32::rng::Rng; 14use embassy_stm32::rng::Rng;
15use embassy_stm32::time::U32Ext; 15use embassy_stm32::time::mhz;
16use embassy_stm32::{interrupt, Config, Peripherals}; 16use embassy_stm32::{interrupt, Config, Peripherals};
17use embedded_io::asynch::Write; 17use embedded_io::asynch::Write;
18use rand_core::RngCore; 18use rand_core::RngCore;
@@ -35,9 +35,9 @@ async fn net_task(stack: &'static Stack<Device>) -> ! {
35 35
36pub fn config() -> Config { 36pub fn config() -> Config {
37 let mut config = Config::default(); 37 let mut config = Config::default();
38 config.rcc.sys_ck = Some(400.mhz().into()); 38 config.rcc.sys_ck = Some(mhz(400));
39 config.rcc.hclk = Some(200.mhz().into()); 39 config.rcc.hclk = Some(mhz(200));
40 config.rcc.pll1.q_ck = Some(100.mhz().into()); 40 config.rcc.pll1.q_ck = Some(mhz(100));
41 config 41 config
42} 42}
43 43
diff --git a/examples/stm32h7/src/bin/fmc.rs b/examples/stm32h7/src/bin/fmc.rs
index 2f55479c1..27c715ab0 100644
--- a/examples/stm32h7/src/bin/fmc.rs
+++ b/examples/stm32h7/src/bin/fmc.rs
@@ -6,15 +6,15 @@ use defmt::*;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Delay, Duration, Timer}; 7use embassy::time::{Delay, Duration, Timer};
8use embassy_stm32::fmc::Fmc; 8use embassy_stm32::fmc::Fmc;
9use embassy_stm32::time::U32Ext; 9use embassy_stm32::time::mhz;
10use embassy_stm32::{Config, Peripherals}; 10use embassy_stm32::{Config, Peripherals};
11use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
12 12
13pub fn config() -> Config { 13pub fn config() -> Config {
14 let mut config = Config::default(); 14 let mut config = Config::default();
15 config.rcc.sys_ck = Some(400.mhz().into()); 15 config.rcc.sys_ck = Some(mhz(400));
16 config.rcc.hclk = Some(200.mhz().into()); 16 config.rcc.hclk = Some(mhz(200));
17 config.rcc.pll1.q_ck = Some(100.mhz().into()); 17 config.rcc.pll1.q_ck = Some(mhz(100));
18 config 18 config
19} 19}
20 20
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs
index 3a728a0dd..fc19d84e4 100644
--- a/examples/stm32h7/src/bin/low_level_timer_api.rs
+++ b/examples/stm32h7/src/bin/low_level_timer_api.rs
@@ -10,19 +10,19 @@ use embassy::time::{Duration, Timer};
10use embassy_stm32::gpio::low_level::AFType; 10use embassy_stm32::gpio::low_level::AFType;
11use embassy_stm32::gpio::Speed; 11use embassy_stm32::gpio::Speed;
12use embassy_stm32::pwm::*; 12use embassy_stm32::pwm::*;
13use embassy_stm32::time::{Hertz, U32Ext}; 13use embassy_stm32::time::{khz, mhz, Hertz};
14use embassy_stm32::{unborrow, Config, Peripherals, Unborrow}; 14use embassy_stm32::{unborrow, Config, Peripherals, Unborrow};
15use {defmt_rtt as _, panic_probe as _}; 15use {defmt_rtt as _, panic_probe as _};
16 16
17pub fn config() -> Config { 17pub fn config() -> Config {
18 let mut config = Config::default(); 18 let mut config = Config::default();
19 config.rcc.sys_ck = Some(400.mhz().into()); 19 config.rcc.sys_ck = Some(mhz(400));
20 config.rcc.hclk = Some(400.mhz().into()); 20 config.rcc.hclk = Some(mhz(400));
21 config.rcc.pll1.q_ck = Some(100.mhz().into()); 21 config.rcc.pll1.q_ck = Some(mhz(100));
22 config.rcc.pclk1 = Some(100.mhz().into()); 22 config.rcc.pclk1 = Some(mhz(100));
23 config.rcc.pclk2 = Some(100.mhz().into()); 23 config.rcc.pclk2 = Some(mhz(100));
24 config.rcc.pclk3 = Some(100.mhz().into()); 24 config.rcc.pclk3 = Some(mhz(100));
25 config.rcc.pclk4 = Some(100.mhz().into()); 25 config.rcc.pclk4 = Some(mhz(100));
26 config 26 config
27} 27}
28 28
@@ -30,7 +30,7 @@ pub fn config() -> Config {
30async fn main(_spawner: Spawner, p: Peripherals) { 30async fn main(_spawner: Spawner, p: Peripherals) {
31 info!("Hello World!"); 31 info!("Hello World!");
32 32
33 let mut pwm = SimplePwm32::new(p.TIM5, p.PA0, p.PA1, p.PA2, p.PA3, 10000.hz()); 33 let mut pwm = SimplePwm32::new(p.TIM5, p.PA0, p.PA1, p.PA2, p.PA3, khz(10));
34 let max = pwm.get_max_duty(); 34 let max = pwm.get_max_duty();
35 pwm.enable(Channel::Ch1); 35 pwm.enable(Channel::Ch1);
36 36
@@ -54,13 +54,13 @@ pub struct SimplePwm32<'d, T: CaptureCompare32bitInstance> {
54} 54}
55 55
56impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { 56impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> {
57 pub fn new<F: Into<Hertz>>( 57 pub fn new(
58 tim: impl Unborrow<Target = T> + 'd, 58 tim: impl Unborrow<Target = T> + 'd,
59 ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd, 59 ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd,
60 ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd, 60 ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd,
61 ch3: impl Unborrow<Target = impl Channel3Pin<T>> + 'd, 61 ch3: impl Unborrow<Target = impl Channel3Pin<T>> + 'd,
62 ch4: impl Unborrow<Target = impl Channel4Pin<T>> + 'd, 62 ch4: impl Unborrow<Target = impl Channel4Pin<T>> + 'd,
63 freq: F, 63 freq: Hertz,
64 ) -> Self { 64 ) -> Self {
65 unborrow!(tim, ch1, ch2, ch3, ch4); 65 unborrow!(tim, ch1, ch2, ch3, ch4);
66 66
@@ -115,7 +115,7 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> {
115 } 115 }
116 } 116 }
117 117
118 pub fn set_freq<F: Into<Hertz>>(&mut self, freq: F) { 118 pub fn set_freq(&mut self, freq: Hertz) {
119 <T as embassy_stm32::timer::low_level::GeneralPurpose32bitInstance>::set_frequency(&mut self.inner, freq); 119 <T as embassy_stm32::timer::low_level::GeneralPurpose32bitInstance>::set_frequency(&mut self.inner, freq);
120 } 120 }
121 121
diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs
index 0e85b8d80..f072c5375 100644
--- a/examples/stm32h7/src/bin/pwm.rs
+++ b/examples/stm32h7/src/bin/pwm.rs
@@ -7,19 +7,19 @@ use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_stm32::pwm::simple_pwm::SimplePwm; 8use embassy_stm32::pwm::simple_pwm::SimplePwm;
9use embassy_stm32::pwm::Channel; 9use embassy_stm32::pwm::Channel;
10use embassy_stm32::time::U32Ext; 10use embassy_stm32::time::{khz, mhz};
11use embassy_stm32::{Config, Peripherals}; 11use embassy_stm32::{Config, Peripherals};
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
14pub fn config() -> Config { 14pub fn config() -> Config {
15 let mut config = Config::default(); 15 let mut config = Config::default();
16 config.rcc.sys_ck = Some(400.mhz().into()); 16 config.rcc.sys_ck = Some(mhz(400));
17 config.rcc.hclk = Some(400.mhz().into()); 17 config.rcc.hclk = Some(mhz(400));
18 config.rcc.pll1.q_ck = Some(100.mhz().into()); 18 config.rcc.pll1.q_ck = Some(mhz(100));
19 config.rcc.pclk1 = Some(100.mhz().into()); 19 config.rcc.pclk1 = Some(mhz(100));
20 config.rcc.pclk2 = Some(100.mhz().into()); 20 config.rcc.pclk2 = Some(mhz(100));
21 config.rcc.pclk3 = Some(100.mhz().into()); 21 config.rcc.pclk3 = Some(mhz(100));
22 config.rcc.pclk4 = Some(100.mhz().into()); 22 config.rcc.pclk4 = Some(mhz(100));
23 config 23 config
24} 24}
25 25
@@ -27,7 +27,7 @@ pub fn config() -> Config {
27async fn main(_spawner: Spawner, p: Peripherals) { 27async fn main(_spawner: Spawner, p: Peripherals) {
28 info!("Hello World!"); 28 info!("Hello World!");
29 29
30 let mut pwm = SimplePwm::new_1ch(p.TIM3, p.PA6, 10000.hz()); 30 let mut pwm = SimplePwm::new_1ch(p.TIM3, p.PA6, khz(10));
31 let max = pwm.get_max_duty(); 31 let max = pwm.get_max_duty();
32 pwm.enable(Channel::Ch1); 32 pwm.enable(Channel::Ch1);
33 33
diff --git a/examples/stm32h7/src/bin/sdmmc.rs b/examples/stm32h7/src/bin/sdmmc.rs
index 4a74780f4..787f700ae 100644
--- a/examples/stm32h7/src/bin/sdmmc.rs
+++ b/examples/stm32h7/src/bin/sdmmc.rs
@@ -5,13 +5,13 @@
5use defmt::*; 5use defmt::*;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy_stm32::sdmmc::Sdmmc; 7use embassy_stm32::sdmmc::Sdmmc;
8use embassy_stm32::time::U32Ext; 8use embassy_stm32::time::mhz;
9use embassy_stm32::{interrupt, Config, Peripherals}; 9use embassy_stm32::{interrupt, Config, Peripherals};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12fn config() -> Config { 12fn config() -> Config {
13 let mut config = Config::default(); 13 let mut config = Config::default();
14 config.rcc.sys_ck = Some(200.mhz().into()); 14 config.rcc.sys_ck = Some(mhz(200));
15 config 15 config
16} 16}
17 17
@@ -31,7 +31,7 @@ async fn main(_spawner: Spawner, p: Peripherals) -> ! {
31 // Should print 400kHz for initialization 31 // Should print 400kHz for initialization
32 info!("Configured clock: {}", sdmmc.clock().0); 32 info!("Configured clock: {}", sdmmc.clock().0);
33 33
34 unwrap!(sdmmc.init_card(25.mhz()).await); 34 unwrap!(sdmmc.init_card(mhz(25)).await);
35 35
36 let card = unwrap!(sdmmc.card()); 36 let card = unwrap!(sdmmc.card());
37 37
diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs
index d4ee44292..f2eb5a3be 100644
--- a/examples/stm32h7/src/bin/spi.rs
+++ b/examples/stm32h7/src/bin/spi.rs
@@ -11,16 +11,16 @@ use embassy::executor::Executor;
11use embassy::util::Forever; 11use embassy::util::Forever;
12use embassy_stm32::dma::NoDma; 12use embassy_stm32::dma::NoDma;
13use embassy_stm32::peripherals::SPI3; 13use embassy_stm32::peripherals::SPI3;
14use embassy_stm32::time::U32Ext; 14use embassy_stm32::time::mhz;
15use embassy_stm32::{spi, Config}; 15use embassy_stm32::{spi, Config};
16use heapless::String; 16use heapless::String;
17use {defmt_rtt as _, panic_probe as _}; 17use {defmt_rtt as _, panic_probe as _};
18 18
19pub fn config() -> Config { 19pub fn config() -> Config {
20 let mut config = Config::default(); 20 let mut config = Config::default();
21 config.rcc.sys_ck = Some(400.mhz().into()); 21 config.rcc.sys_ck = Some(mhz(400));
22 config.rcc.hclk = Some(200.mhz().into()); 22 config.rcc.hclk = Some(mhz(200));
23 config.rcc.pll1.q_ck = Some(100.mhz().into()); 23 config.rcc.pll1.q_ck = Some(mhz(100));
24 config 24 config
25} 25}
26 26
@@ -54,7 +54,7 @@ fn main() -> ! {
54 p.PB4, 54 p.PB4,
55 NoDma, 55 NoDma,
56 NoDma, 56 NoDma,
57 1.mhz(), 57 mhz(1),
58 spi::Config::default(), 58 spi::Config::default(),
59 ); 59 );
60 60
diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs
index 003bc7add..d72051fda 100644
--- a/examples/stm32h7/src/bin/spi_dma.rs
+++ b/examples/stm32h7/src/bin/spi_dma.rs
@@ -10,16 +10,16 @@ use defmt::*;
10use embassy::executor::Executor; 10use embassy::executor::Executor;
11use embassy::util::Forever; 11use embassy::util::Forever;
12use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3}; 12use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3};
13use embassy_stm32::time::U32Ext; 13use embassy_stm32::time::mhz;
14use embassy_stm32::{spi, Config}; 14use embassy_stm32::{spi, Config};
15use heapless::String; 15use heapless::String;
16use {defmt_rtt as _, panic_probe as _}; 16use {defmt_rtt as _, panic_probe as _};
17 17
18pub fn config() -> Config { 18pub fn config() -> Config {
19 let mut config = Config::default(); 19 let mut config = Config::default();
20 config.rcc.sys_ck = Some(400.mhz().into()); 20 config.rcc.sys_ck = Some(mhz(400));
21 config.rcc.hclk = Some(200.mhz().into()); 21 config.rcc.hclk = Some(mhz(200));
22 config.rcc.pll1.q_ck = Some(100.mhz().into()); 22 config.rcc.pll1.q_ck = Some(mhz(100));
23 config 23 config
24} 24}
25 25
@@ -50,7 +50,7 @@ fn main() -> ! {
50 p.PB4, 50 p.PB4,
51 p.DMA1_CH3, 51 p.DMA1_CH3,
52 p.DMA1_CH4, 52 p.DMA1_CH4,
53 1.mhz(), 53 mhz(1),
54 spi::Config::default(), 54 spi::Config::default(),
55 ); 55 );
56 56
diff --git a/examples/stm32l0/src/bin/lorawan.rs b/examples/stm32l0/src/bin/lorawan.rs
index 8b7e8f824..da58e2f72 100644
--- a/examples/stm32l0/src/bin/lorawan.rs
+++ b/examples/stm32l0/src/bin/lorawan.rs
@@ -11,7 +11,7 @@ use embassy_lora::LoraTimer;
11use embassy_stm32::exti::ExtiInput; 11use embassy_stm32::exti::ExtiInput;
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_stm32::rng::Rng; 13use embassy_stm32::rng::Rng;
14use embassy_stm32::time::U32Ext; 14use embassy_stm32::time::khz;
15use embassy_stm32::{spi, Peripherals}; 15use embassy_stm32::{spi, Peripherals};
16use lorawan::default_crypto::DefaultFactory as Crypto; 16use lorawan::default_crypto::DefaultFactory as Crypto;
17use lorawan_device::async_device::{region, Device, JoinMode}; 17use lorawan_device::async_device::{region, Device, JoinMode};
@@ -34,7 +34,7 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
34 p.PA6, 34 p.PA6,
35 p.DMA1_CH3, 35 p.DMA1_CH3,
36 p.DMA1_CH2, 36 p.DMA1_CH2,
37 200_000.hz(), 37 khz(200),
38 spi::Config::default(), 38 spi::Config::default(),
39 ); 39 );
40 40