Skip to content

Commit 5be98c1

Browse files
committed
Fix i2c_scanner example and use integer method for time types
1 parent e9b49ac commit 5be98c1

File tree

9 files changed

+35
-35
lines changed

9 files changed

+35
-35
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
### Added
1313

14-
- Replace custom time based units with types defined in the [embedded-time][] crate ([#191])
14+
- Replace custom time based units with types defined in the [embedded-time][] crate ([#192])
1515

1616
### Breaking changes
1717

examples/i2c_scanner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn main() -> ! {
3838
let mut i2c = hal::i2c::I2c::new(
3939
dp.I2C1,
4040
pins,
41-
100_000u32.kHz().try_into().unwrap(),
41+
100u32.kHz().try_into().unwrap(),
4242
clocks,
4343
&mut rcc.apb1,
4444
);

src/i2c.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
hal::blocking::i2c::{Read, Write, WriteRead},
1313
pac::{i2c1::RegisterBlock, rcc::cfgr3::I2C1SW_A, I2C1, RCC},
1414
rcc::{Clocks, APB1},
15-
time::rate::Hertz,
15+
time::rate::*,
1616
};
1717

1818
#[cfg(not(feature = "gpio-f333"))]
@@ -117,7 +117,7 @@ impl<I2C, SCL, SDA> I2c<I2C, (SCL, SDA)> {
117117
SCL: SclPin<I2C>,
118118
SDA: SdaPin<I2C>,
119119
{
120-
crate::assert!(freq.0 <= 1_000_000);
120+
crate::assert!(*freq.integer() <= 1_000_000);
121121

122122
I2C::enable_clock(apb1);
123123

@@ -130,16 +130,16 @@ impl<I2C, SCL, SDA> I2c<I2C, (SCL, SDA)> {
130130
// t_SYNC1 + t_SYNC2 > 4 * t_I2CCLK
131131
// t_SCL ~= t_SYNC1 + t_SYNC2 + t_SCLL + t_SCLH
132132
let i2cclk = I2C::clock(&clocks).0;
133-
let ratio = i2cclk / freq.0 - 4;
134-
let (presc, scll, sclh, sdadel, scldel) = if freq.0 >= 100_000 {
133+
let ratio = i2cclk / *freq.integer() - 4;
134+
let (presc, scll, sclh, sdadel, scldel) = if *freq.integer() >= 100_000 {
135135
// fast-mode or fast-mode plus
136136
// here we pick SCLL + 1 = 2 * (SCLH + 1)
137137
let presc = ratio / 387;
138138

139139
let sclh = ((ratio / (presc + 1)) - 3) / 3;
140140
let scll = 2 * (sclh + 1) - 1;
141141

142-
let (sdadel, scldel) = if freq.0 > 400_000 {
142+
let (sdadel, scldel) = if *freq.integer() > 400_000 {
143143
// fast-mode plus
144144
let sdadel = 0;
145145
let scldel = i2cclk / 4_000_000 / (presc + 1) - 1;

src/pwm.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
```
1818
// (Other imports omitted)
19-
use stm32f3xx-hal::pwm::tim3;
19+
use stm32f3xx-hal::{pwm::tim3, time::rate::*};
2020
2121
let dp = stm32f303::Peripherals::take().unwrap();
2222
@@ -25,9 +25,9 @@
2525
let clocks = rcc.cfgr.freeze(&mut flash.acr);
2626
2727
// Set the resolution of our duty cycle to 9000 and our period to
28-
// 50hz.
28+
// 50Hz.
2929
let mut (c1_no_pins, _, _, c4_no_pins) =
30-
tim3(device.TIM3, 9000, 50.hz(), clocks);
30+
tim3(device.TIM3, 9000, 50.Hz(), clocks);
3131
```
3232
3333
In this case, we're only going to use channel 1 and channel 4.
@@ -65,7 +65,7 @@
6565
ch4.enable();
6666
```
6767
68-
All three pins will output a 50hz period. PA6 and PB4 will share a
68+
All three pins will output a 50Hz period. PA6 and PB4 will share a
6969
duty cycle, but the duty cycle for PB1 can be controlled
7070
independently.
7171
@@ -84,7 +84,7 @@
8484
8585
```
8686
// (Other imports omitted)
87-
use stm32f3xx-hal::pwm::tim16;
87+
use stm32f3xx-hal::{pwm::tim16, time::rate::*};
8888
8989
let dp = stm32f303::Peripherals::take().unwrap();
9090
@@ -93,8 +93,8 @@
9393
let clocks = rcc.cfgr.freeze(&mut flash.acr);
9494
9595
// Set the resolution of our duty cycle to 9000 and our period to
96-
// 50hz.
97-
let mut c1_no_pins = tim16(device.TIM3, 9000, 50.hz(), clocks);
96+
// 50Hz.
97+
let mut c1_no_pins = tim16(device.TIM3, 9000, 50.Hz(), clocks);
9898
```
9999
100100
## Complementary timers
@@ -109,7 +109,7 @@
109109
110110
```
111111
// (Other imports omitted)
112-
use stm32f3xx-hal::pwm::tim1;
112+
use stm32f3xx-hal::{pwm::tim1, time::rate::*};
113113
114114
let dp = stm32f303::Peripherals::take().unwrap();
115115
@@ -118,8 +118,8 @@
118118
let clocks = rcc.cfgr.freeze(&mut flash.acr);
119119
120120
// Set the resolution of our duty cycle to 9000 and our period to
121-
// 50hz.
122-
let mut (ch1_no_pins, _, _, _) = tim1(device.TIM3, 9000, 50.hz(), clocks);
121+
// 50Hz.
122+
let mut (ch1_no_pins, _, _, _) = tim1(device.TIM3, 9000, 50.Hz(), clocks);
123123
124124
let mut gpioa = dp.GPIOB.split(&mut rcc.ahb);
125125
let pa7 = gpioa.pa7.into_af6(&mut gpioa.moder, &mut gpioa.afrl);
@@ -160,7 +160,7 @@ use crate::{
160160
hal::PwmPin,
161161
pac::{RCC, TIM15, TIM16, TIM17, TIM2},
162162
rcc::Clocks,
163-
time::rate::Hertz,
163+
time::rate::*,
164164
};
165165
use core::marker::PhantomData;
166166

@@ -282,7 +282,7 @@ macro_rules! pwm_timer_private {
282282
// It might make sense to move into the clocks as a crate-only property.
283283
// TODO: ppre1 is used in timer.rs (never ppre2), should this be dynamic?
284284
let clock_freq = clocks.$pclkz().0 * if clocks.ppre1() == 1 { 1 } else { 2 };
285-
let prescale_factor = clock_freq / res as u32 / freq.0;
285+
let prescale_factor = clock_freq / res as u32 / *freq.integer();
286286
// NOTE(write): uses all bits of this register.
287287
tim.psc.write(|w| w.psc().bits(prescale_factor as u16 - 1));
288288

src/rcc.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
//!
99
//! ```
1010
//! # use cortex_m_rt::entry;
11-
//! # use stm32f3xx_hal::prelude::*;
12-
//! #use hal::time::rate::*;
11+
//! # use stm32f3xx-hal::{prelude::*, time::rate::*};
1312
//!
1413
//! # #[entry]
1514
//! # fn main() -> ! {
@@ -25,7 +24,8 @@
2524
//!
2625
//! ```
2726
//! # use cortex_m_rt::entry;
28-
//! # use stm32f3xx_hal::prelude::*;
27+
//! # use stm32f3xx-hal::{prelude::*, time::rate::*};
28+
//! #
2929
//! # #[entry]
3030
//! # fn main() -> ! {
3131
//! # let dp = pac::Peripherals::take().unwrap();
@@ -343,7 +343,7 @@ impl CFGR {
343343
/// Panics if conversion from `Megahertz` to `Hertz` produces a value greater then `u32::MAX`.
344344
pub fn use_hse(mut self, freq: Megahertz) -> Self {
345345
let freq: Hertz = crate::expect!(freq.try_into(), "ConversionError");
346-
self.hse = Some(freq.0);
346+
self.hse = Some(*freq.integer());
347347
self
348348
}
349349

@@ -376,7 +376,7 @@ impl CFGR {
376376
/// Panics if conversion from `Megahertz` to `Hertz` produces a value greater then `u32::MAX`.
377377
pub fn hclk(mut self, freq: Megahertz) -> Self {
378378
let freq: Hertz = crate::expect!(freq.try_into(), "ConversionError");
379-
self.hclk = Some(freq.0);
379+
self.hclk = Some(*freq.integer());
380380
self
381381
}
382382

@@ -392,7 +392,7 @@ impl CFGR {
392392
/// Panics if conversion from `Megahertz` to `Hertz` produces a value greater then `u32::MAX`.
393393
pub fn pclk1(mut self, freq: Megahertz) -> Self {
394394
let freq: Hertz = crate::expect!(freq.try_into(), "ConversionError");
395-
self.pclk1 = Some(freq.0);
395+
self.pclk1 = Some(*freq.integer());
396396
self
397397
}
398398

@@ -414,7 +414,7 @@ impl CFGR {
414414
/// Panics if conversion from `Megahertz` to `Hertz` produces a value greater then `u32::MAX`.
415415
pub fn pclk2(mut self, freq: Megahertz) -> Self {
416416
let freq: Hertz = crate::expect!(freq.try_into(), "ConversionError");
417-
self.pclk2 = Some(freq.0);
417+
self.pclk2 = Some(*freq.integer());
418418
self
419419
}
420420

@@ -439,7 +439,7 @@ impl CFGR {
439439
/// Panics if conversion from `Megahertz` to `Hertz` produces a value greater then `u32::MAX`.
440440
pub fn sysclk(mut self, freq: Megahertz) -> Self {
441441
let freq: Hertz = crate::expect!(freq.try_into(), "ConversionError");
442-
self.sysclk = Some(freq.0);
442+
self.sysclk = Some(*freq.integer());
443443
self
444444
}
445445

src/serial.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
hal::{blocking, serial},
66
pac::{USART1, USART2, USART3},
77
rcc::{Clocks, APB1, APB2},
8-
time::rate::Baud,
8+
time::rate::*,
99
};
1010

1111
use cfg_if::cfg_if;
@@ -125,7 +125,7 @@ macro_rules! hal {
125125
apb.rstr().modify(|_, w| w.$usartXrst().set_bit());
126126
apb.rstr().modify(|_, w| w.$usartXrst().clear_bit());
127127

128-
let brr = clocks.$pclkX().0 / baud_rate.0;
128+
let brr = clocks.$pclkX().0 / *baud_rate.integer();
129129
crate::assert!(brr >= 16, "impossible baud rate");
130130
// NOTE(write): uses all bits of this register.
131131
usart.brr.write(|w| unsafe { w.bits(brr) });

src/spi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ use crate::rcc::APB1;
131131
feature = "stm32f398"
132132
))]
133133
use crate::rcc::APB2;
134-
use crate::time::rate::Hertz;
134+
use crate::time::rate::*;
135135
use core::marker::PhantomData;
136136

137137
/// SPI error
@@ -503,7 +503,7 @@ macro_rules! hal {
503503

504504
fn compute_baud_rate(clocks: Hertz, freq: Hertz) -> spi1::cr1::BR_A {
505505
use spi1::cr1::BR_A;
506-
match clocks.0 / freq.0 {
506+
match clocks.0 / *freq.integer() {
507507
0 => crate::unreachable!(),
508508
1..=2 => BR_A::DIV2,
509509
3..=5 => BR_A::DIV4,

src/timer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use crate::pac::{TIM15, TIM16, TIM17, TIM2, TIM6};
5151
))]
5252
use crate::pac::{TIM3, TIM7};
5353
use crate::rcc::{Clocks, APB1, APB2};
54-
use crate::time::rate::Hertz;
54+
use crate::time::rate::*;
5555
use void::Void;
5656

5757
/// Associated clocks with timers
@@ -95,7 +95,7 @@ macro_rules! hal {
9595
{
9696
self.stop();
9797

98-
let frequency = timeout.into().0;
98+
let frequency = *timeout.into().integer();
9999
let timer_clock = $TIMX::get_clk(&self.clocks);
100100
let ticks = timer_clock.0 * if self.clocks.ppre1() == 1 { 1 } else { 2 }
101101
/ frequency;

src/watchdog.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use crate::hal::watchdog::{Watchdog, WatchdogEnable};
88

99
use crate::pac::{DBGMCU, IWDG};
10-
use crate::time::duration::Milliseconds;
10+
use crate::time::duration::*;
1111

1212
const LSI_KHZ: u32 = 40;
1313
const MAX_PR: u8 = 8;
@@ -96,7 +96,7 @@ impl WatchdogEnable for IndependentWatchDog {
9696
type Time = Milliseconds;
9797

9898
fn start<T: Into<Self::Time>>(&mut self, period: T) {
99-
self.setup(period.into().0);
99+
self.setup(*period.into().integer());
100100

101101
self.iwdg.kr.write(|w| w.key().start());
102102
}

0 commit comments

Comments
 (0)