Skip to content

Commit f566a4f

Browse files
committed
BusClock + &Clock
1 parent 4a55dd4 commit f566a4f

23 files changed

+217
-155
lines changed

CHANGELOG.md

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

1414
### Changed
1515

16-
- Usw `fugit`-based time types instead of `embedded-time`
16+
- split `GetBusFreq` on `BusClock` & `BusTimerClock`, use `&Clock` everywhere
17+
- Use `fugit`-based time types instead of `embedded-time`
1718
- Update gpios: add `DynamicPin`, add default modes, reexport pins, resort generics, etc.
1819
- Improved RCC infrastructure.
1920
- RTC support has been rewritten.

examples/blinky_delay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn main() -> ! {
2525
let clocks = rcc.cfgr.sysclk(216.MHz()).freeze();
2626

2727
// Get delay provider
28-
let mut delay = Delay::new(cp.SYST, clocks);
28+
let mut delay = Delay::new(cp.SYST, &clocks);
2929

3030
loop {
3131
led.set_high();

examples/fmc.rs

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

4545
// Get the delay provider.
4646
let clocks = dp.RCC.constrain().cfgr.sysclk(216_000_000.Hz()).freeze();
47-
let mut delay = Delay::new(cp.SYST, clocks);
47+
let mut delay = Delay::new(cp.SYST, &clocks);
4848

4949
// IO
5050
let gpioc = dp.GPIOC.split();

examples/i2c_scanner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() -> ! {
3131
dp.I2C1,
3232
(scl, sda),
3333
hal::i2c::Mode::fast(100_000.Hz()),
34-
clocks,
34+
&clocks,
3535
&mut rcc.apb1,
3636
50_000,
3737
);

examples/serial_delay.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main() -> ! {
2727
let rcc = p.RCC.constrain();
2828
let clocks = rcc.cfgr.sysclk(216_000_000.Hz()).freeze();
2929

30-
let mut delay = Delay::new(cp.SYST, clocks);
30+
let mut delay = Delay::new(cp.SYST, &clocks);
3131

3232
let gpioa = p.GPIOA.split();
3333
let gpiob = p.GPIOB.split();
@@ -38,11 +38,12 @@ fn main() -> ! {
3838
let serial = Serial::new(
3939
p.USART1,
4040
(tx, rx),
41-
clocks,
41+
&clocks,
4242
serial::Config {
4343
baud_rate: 115_200.bps(),
4444
oversampling: serial::Oversampling::By16,
4545
character_match: None,
46+
sysclock: false,
4647
},
4748
);
4849
let (mut tx, _) = serial.split();

examples/serial_dma.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ fn main() -> ! {
4545
let serial = Serial::new(
4646
p.USART3,
4747
(tx, rx),
48-
clocks,
48+
&clocks,
4949
serial::Config {
5050
baud_rate: 115_200.bps(),
5151
oversampling: serial::Oversampling::By16,
5252
character_match: None,
53+
sysclock: false,
5354
},
5455
);
5556
let (mut tx, mut rx) = serial.split();

examples/serial_echo.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ fn main() -> ! {
3434
let serial = Serial::new(
3535
p.USART1,
3636
(tx, rx),
37-
clocks,
37+
&clocks,
3838
serial::Config {
3939
baud_rate: 115_200.bps(),
4040
oversampling: serial::Oversampling::By16,
4141
character_match: None,
42+
sysclock: false,
4243
},
4344
);
4445

examples/spi.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn main() -> ! {
1515
let p = pac::Peripherals::take().unwrap();
1616

1717
let mut rcc = p.RCC.constrain();
18+
let clocks = rcc.cfgr.freeze();
1819

1920
let gpiob = p.GPIOB.split();
2021
let gpioc = p.GPIOC.split();
@@ -35,12 +36,13 @@ fn main() -> ! {
3536

3637
// Initialize SPI
3738
let mut spi = Spi::new(p.SPI3, (sck, miso, mosi)).enable::<u8>(
38-
&mut rcc.apb1,
39-
spi::ClockDivider::DIV32,
4039
spi::Mode {
4140
polarity: spi::Polarity::IdleHigh,
4241
phase: spi::Phase::CaptureOnSecondTransition,
4342
},
43+
250.kHz(),
44+
&clocks,
45+
&mut rcc.apb1,
4446
);
4547

4648
loop {

examples/spi_16.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn main() -> ! {
1515
let p = pac::Peripherals::take().unwrap();
1616

1717
let mut rcc = p.RCC.constrain();
18+
let clocks = rcc.cfgr.freeze();
1819

1920
let gpioa = p.GPIOA.split();
2021
let gpioc = p.GPIOC.split();
@@ -34,9 +35,10 @@ fn main() -> ! {
3435

3536
// Initialize SPI
3637
let mut spi = Spi::new(p.SPI1, (sck, spi::NoMiso, mosi)).enable::<u16>(
37-
&mut rcc.apb2,
38-
spi::ClockDivider::DIV32,
3938
embedded_hal::spi::MODE_0,
39+
250.kHz(),
40+
&clocks,
41+
&mut rcc.apb2,
4042
);
4143

4244
// Use a button to control output via the Maxim Integrated MAX5214 DAC.

examples/spi_dma.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fn main() -> ! {
1919
let p = pac::Peripherals::take().unwrap();
2020

2121
let mut rcc = p.RCC.constrain();
22+
let clocks = rcc.cfgr.freeze();
2223

2324
let dma = DMA::new(p.DMA1);
2425
let gpiob = p.GPIOB.split();
@@ -46,12 +47,13 @@ fn main() -> ! {
4647

4748
// Initialize SPI
4849
let mut spi = Spi::new(p.SPI3, (sck, miso, mosi)).enable(
49-
&mut rcc.apb1,
50-
spi::ClockDivider::DIV32,
5150
spi::Mode {
5251
polarity: spi::Polarity::IdleHigh,
5352
phase: spi::Phase::CaptureOnSecondTransition,
5453
},
54+
250.kHz(),
55+
&clocks,
56+
&mut rcc.apb1,
5557
);
5658

5759
// Create the buffer we're going to use for DMA. This is safe, as this

examples/spi_dma_16.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fn main() -> ! {
1919
let p = pac::Peripherals::take().unwrap();
2020

2121
let mut rcc = p.RCC.constrain();
22+
let clocks = rcc.cfgr.freeze();
2223

2324
let dma = DMA::new(p.DMA2);
2425
let gpioa = p.GPIOA.split();
@@ -45,9 +46,10 @@ fn main() -> ! {
4546

4647
// Initialize SPI
4748
let mut spi = Spi::new(p.SPI1, (sck, spi::NoMiso, mosi)).enable(
48-
&mut rcc.apb2,
49-
spi::ClockDivider::DIV32,
5049
embedded_hal::spi::MODE_0,
50+
250.kHz(),
51+
&clocks,
52+
&mut rcc.apb2,
5153
);
5254

5355
// Create the buffer we're going to use for DMA. This is safe, as this

examples/timer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn main() -> ! {
3434
let mut rcc = dp.RCC.constrain();
3535
let clocks = rcc.cfgr.freeze();
3636

37-
let mut timer = Timer::tim2(dp.TIM2, 1.Hz(), clocks, &mut rcc.apb1);
37+
let mut timer = Timer::tim2(dp.TIM2, 1.Hz(), &clocks, &mut rcc.apb1);
3838
timer.listen(Event::TimeOut);
3939

4040
// Save information needed by the interrupt handler to the global variable

examples/usb_serial.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ fn main() -> ! {
5151
dp.OTG_FS_DEVICE,
5252
dp.OTG_FS_PWRCLK,
5353
(gpioa.pa11.into_alternate(), gpioa.pa12.into_alternate()),
54-
clocks,
54+
&clocks,
5555
);
5656
#[cfg(all(feature = "usb_hs", not(feature = "usb_hs_phy")))]
5757
let usb = USB::new(
5858
dp.OTG_HS_GLOBAL,
5959
dp.OTG_HS_DEVICE,
6060
dp.OTG_HS_PWRCLK,
6161
(gpiob.pb14.into_alternate(), gpiob.pb15.into_alternate()),
62-
clocks,
62+
&clocks,
6363
);
6464
#[cfg(all(feature = "usb_hs", feature = "usb_hs_phy"))]
6565
let usb = USB::new_with_internal_hs_phy(
@@ -68,7 +68,7 @@ fn main() -> ! {
6868
dp.OTG_HS_PWRCLK,
6969
dp.USBPHYC,
7070
(gpiob.pb14.into_alternate(), gpiob.pb15.into_alternate()),
71-
clocks,
71+
&clocks,
7272
);
7373

7474
static mut EP_MEMORY: [u32; 1024] = [0; 1024];

src/adc.rs

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::gpio::{self, Analog};
99
use crate::pac::{ADC1, ADC2, ADC3, ADC_COMMON};
1010

1111
use cortex_m::asm::delay;
12+
use fugit::HertzU32 as Hertz;
1213

1314
use embedded_hal::adc::{Channel, OneShot};
1415

@@ -89,7 +90,7 @@ impl From<Align> for bool {
8990
/////////////////////////////////
9091

9192
macro_rules! adc_pins {
92-
($ADC:ident, $($pin:ty => $chan:expr),+ $(,)*) => {
93+
($ADC:ident, $($pin:ty => $chan:literal),+ $(,)*) => {
9394
$(
9495
impl Channel<$ADC> for $pin {
9596
type ID = u8;
@@ -103,60 +104,60 @@ macro_rules! adc_pins {
103104
// See "Datasheet - production data"
104105
// Pinouts and pin description (page 66..)
105106
adc_pins!(ADC1,
106-
gpio::PA0<Analog> => 0_u8,
107-
gpio::PA1<Analog> => 1_u8,
108-
gpio::PA2<Analog> => 2_u8,
109-
gpio::PA3<Analog> => 3_u8,
110-
gpio::PA4<Analog> => 4_u8,
111-
gpio::PA5<Analog> => 5_u8,
112-
gpio::PA6<Analog> => 6_u8,
113-
gpio::PA7<Analog> => 7_u8,
114-
gpio::PB0<Analog> => 8_u8,
115-
gpio::PB1<Analog> => 9_u8,
116-
gpio::PC0<Analog> => 10_u8,
117-
gpio::PC1<Analog> => 11_u8,
118-
gpio::PC2<Analog> => 12_u8,
119-
gpio::PC3<Analog> => 13_u8,
120-
gpio::PC4<Analog> => 14_u8,
121-
gpio::PC5<Analog> => 15_u8,
107+
gpio::PA0<Analog> => 0,
108+
gpio::PA1<Analog> => 1,
109+
gpio::PA2<Analog> => 2,
110+
gpio::PA3<Analog> => 3,
111+
gpio::PA4<Analog> => 4,
112+
gpio::PA5<Analog> => 5,
113+
gpio::PA6<Analog> => 6,
114+
gpio::PA7<Analog> => 7,
115+
gpio::PB0<Analog> => 8,
116+
gpio::PB1<Analog> => 9,
117+
gpio::PC0<Analog> => 10,
118+
gpio::PC1<Analog> => 11,
119+
gpio::PC2<Analog> => 12,
120+
gpio::PC3<Analog> => 13,
121+
gpio::PC4<Analog> => 14,
122+
gpio::PC5<Analog> => 15,
122123
);
123124

124125
adc_pins!(ADC2,
125-
gpio::PA0<Analog> => 0_u8,
126-
gpio::PA1<Analog> => 1_u8,
127-
gpio::PA2<Analog> => 2_u8,
128-
gpio::PA3<Analog> => 3_u8,
129-
gpio::PA4<Analog> => 4_u8,
130-
gpio::PA5<Analog> => 5_u8,
131-
gpio::PA6<Analog> => 6_u8,
132-
gpio::PA7<Analog> => 7_u8,
133-
gpio::PB0<Analog> => 8_u8,
134-
gpio::PB1<Analog> => 9_u8,
135-
gpio::PC0<Analog> => 10_u8,
136-
gpio::PC1<Analog> => 11_u8,
137-
gpio::PC2<Analog> => 12_u8,
138-
gpio::PC3<Analog> => 13_u8,
139-
gpio::PC4<Analog> => 14_u8,
140-
gpio::PC5<Analog> => 15_u8,
126+
gpio::PA0<Analog> => 0,
127+
gpio::PA1<Analog> => 1,
128+
gpio::PA2<Analog> => 2,
129+
gpio::PA3<Analog> => 3,
130+
gpio::PA4<Analog> => 4,
131+
gpio::PA5<Analog> => 5,
132+
gpio::PA6<Analog> => 6,
133+
gpio::PA7<Analog> => 7,
134+
gpio::PB0<Analog> => 8,
135+
gpio::PB1<Analog> => 9,
136+
gpio::PC0<Analog> => 10,
137+
gpio::PC1<Analog> => 11,
138+
gpio::PC2<Analog> => 12,
139+
gpio::PC3<Analog> => 13,
140+
gpio::PC4<Analog> => 14,
141+
gpio::PC5<Analog> => 15,
141142
);
142143

143144
adc_pins!(ADC3,
144-
gpio::PA0<Analog> => 0_u8,
145-
gpio::PA1<Analog> => 1_u8,
146-
gpio::PA2<Analog> => 2_u8,
147-
gpio::PA3<Analog> => 3_u8,
148-
gpio::PF6<Analog> => 4_u8,
149-
gpio::PF7<Analog> => 5_u8,
150-
gpio::PF8<Analog> => 6_u8,
151-
gpio::PF9<Analog> => 7_u8,
152-
gpio::PF10<Analog> => 8_u8,
153-
gpio::PF3<Analog> => 9_u8,
154-
gpio::PC0<Analog> => 10_u8,
155-
gpio::PC1<Analog> => 11_u8,
156-
gpio::PC2<Analog> => 12_u8,
157-
gpio::PC3<Analog> => 13_u8,
158-
gpio::PF4<Analog> => 14_u8,
159-
gpio::PF5<Analog> => 15_u8,
145+
gpio::PA0<Analog> => 0,
146+
gpio::PA1<Analog> => 1,
147+
gpio::PA2<Analog> => 2,
148+
gpio::PA3<Analog> => 3,
149+
gpio::PF6<Analog> => 4,
150+
gpio::PF7<Analog> => 5,
151+
gpio::PF8<Analog> => 6,
152+
gpio::PF9<Analog> => 7,
153+
gpio::PF10<Analog> => 8,
154+
gpio::PF3<Analog> => 9,
155+
gpio::PC0<Analog> => 10,
156+
gpio::PC1<Analog> => 11,
157+
gpio::PC2<Analog> => 12,
158+
gpio::PC3<Analog> => 13,
159+
gpio::PF4<Analog> => 14,
160+
gpio::PF5<Analog> => 15,
160161
);
161162

162163
////////////////////////////////////
@@ -166,7 +167,7 @@ pub struct Adc<ADC> {
166167
rb: ADC,
167168
sample_time: SampleTime,
168169
align: Align,
169-
clocks: Clocks,
170+
sysclk: Hertz,
170171
}
171172

172173
/// Stored ADC config can be restored using the `Adc::restore_cfg` method
@@ -182,15 +183,15 @@ macro_rules! adc_hal {
182183
pub fn $adc(
183184
adc: $ADC,
184185
apb2: &mut APB2,
185-
clocks: Clocks,
186+
clocks: &Clocks,
186187
nb_resolution_bits: u8,
187188
reset: bool,
188189
) -> Self {
189190
let mut s = Self {
190191
rb: adc,
191192
sample_time: SampleTime::default(),
192193
align: Align::default(),
193-
clocks,
194+
sysclk: clocks.sysclk(),
194195
};
195196
<$ADC>::enable(apb2);
196197
if reset {
@@ -257,7 +258,7 @@ macro_rules! adc_hal {
257258
// The reference manual says that a stabilization time is needed after power_up,
258259
// this time can be found in the datasheets.
259260
// for STM32F7xx : delay(216_000_000/800_000)= delay(270 cycles) = 1.25us
260-
delay(self.clocks.sysclk().raw() / 800_000);
261+
delay(self.sysclk.raw() / 800_000);
261262
}
262263

263264
// 15.3.1 ADC on-off control
@@ -466,7 +467,7 @@ impl Adc<ADC1> {
466467

467468
// The reference manual says that a stabilization time is needed after the powering the
468469
// sensor, this time can be found in the datasheets.
469-
delay(self.clocks.sysclk().raw() / 80_000);
470+
delay(self.sysclk.raw() / 80_000);
470471
true
471472
} else {
472473
false

0 commit comments

Comments
 (0)