Skip to content

Commit c508256

Browse files
authored
Merge pull request #403 from stm32-rs/cleanups
reexport gpio, other cleanups
2 parents 62ee387 + 808049f commit c508256

File tree

17 files changed

+236
-239
lines changed

17 files changed

+236
-239
lines changed

CHANGELOG.md

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

1010
### Added
1111

12+
- Reexport gpio pins to `gpio` mod
1213
- Added the ability to specify the word size (8 or 9 bits) for `Serial` (USART). When using parity, the parity bit is included in the number of bits of the word.
1314
- `blocking::serial::Write` for `Tx` and `Serial`. `core::fmt::Write` for `Serial`
1415
- `Instance` for Timer's, rtic-monotonic fugit impl

examples/delay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn main() -> ! {
3030
#[cfg(any(feature = "stm32f103", feature = "stm32f105", feature = "stm32f107"))]
3131
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
3232

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

3535
loop {
3636
led.set_high();

examples/enc28j60-coap.rs.disabled

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

9797
// ENC28J60
98-
let mut delay = Delay::new(cp.SYST, clocks);
98+
let mut delay = Delay::new(cp.SYST, &clocks);
9999
let mut enc28j60 = Enc28j60::new(
100100
spi,
101101
ncs,

examples/enc28j60.rs.disabled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn main() -> ! {
8989
// ENC28J60
9090
let mut reset = gpioa.pa3.into_push_pull_output(&mut gpioa.crl);
9191
reset.set_high();
92-
let mut delay = Delay::new(cp.SYST, clocks);
92+
let mut delay = Delay::new(cp.SYST, &clocks);
9393
let mut enc28j60 = Enc28j60::new(
9494
spi,
9595
ncs,

examples/gpio_input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn main() -> ! {
5353
// The key_up for check buttons if long press.
5454
// if key_up is true, and buttons were not long press.
5555
let mut key_up: bool = true;
56-
let mut delay = Delay::new(cp.SYST, clock);
56+
let mut delay = Delay::new(cp.SYST, &clock);
5757
loop {
5858
let key_result = (key_0.is_low(), key_1.is_low());
5959
if key_up && (key_result.0 || key_result.1) {

examples/i2c-bme280/src/main.rs

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

8181
// The Adafruit boards have address 0x77 without closing the jumper on the back, the BME280 lib connects to 0x77 with `new_secondary`, use
8282
// `new_primary` for 0x76 if you close the jumper/solder bridge.
83-
let mut bme280 = BME280::new_secondary(i2c, Delay::new(cp.SYST, clocks));
83+
let mut bme280 = BME280::new_secondary(i2c, Delay::new(cp.SYST, &clocks));
8484
bme280
8585
.init()
8686
.map_err(|error| {

examples/mpu9250.rs.disabled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn main() -> ! {
5555
clocks,
5656
);
5757

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

6060
let mut mpu9250 = Mpu9250::marg(spi, nss, &mut delay).unwrap();
6161

examples/qei.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn main() -> ! {
3939
let c2 = gpiob.pb7;
4040

4141
let qei = Timer::new(dp.TIM4, &clocks).qei((c1, c2), &mut afio.mapr, QeiOptions::default());
42-
let mut delay = Delay::new(cp.SYST, clocks);
42+
let mut delay = Delay::new(cp.SYST, &clocks);
4343

4444
loop {
4545
let before = qei.count();

src/adc.rs

Lines changed: 64 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,14 @@ use embedded_hal::adc::{Channel, OneShot};
66
#[cfg(all(feature = "stm32f103", any(feature = "high", feature = "xl",),))]
77
use crate::dma::dma2;
88
use crate::dma::{dma1, CircBuffer, Receive, RxDma, Transfer, TransferPayload, W};
9-
#[cfg(all(feature = "stm32f103", any(feature = "high", feature = "xl",),))]
10-
use crate::gpio::gpiof;
11-
use crate::gpio::Analog;
12-
use crate::gpio::{gpioa, gpiob, gpioc};
9+
use crate::gpio::{self, Analog};
1310
use crate::rcc::{Clocks, Enable, Reset};
1411
use crate::time::kHz;
1512
use core::sync::atomic::{self, Ordering};
1613
use cortex_m::asm::delay;
1714
use embedded_dma::StaticWriteBuffer;
1815

19-
#[cfg(any(feature = "stm32f103", feature = "connectivity"))]
20-
use crate::pac::ADC2;
21-
#[cfg(all(feature = "stm32f103", any(feature = "high", feature = "xl")))]
22-
use crate::pac::ADC3;
23-
use crate::pac::{ADC1, RCC};
16+
use crate::pac::{self, RCC};
2417

2518
/// Continuous mode
2619
pub struct Continuous;
@@ -108,7 +101,7 @@ impl From<Align> for bool {
108101
}
109102

110103
macro_rules! adc_pins {
111-
($ADC:ident, $($pin:ty => $chan:expr),+ $(,)*) => {
104+
($ADC:ty, $($pin:ty => $chan:expr),+ $(,)*) => {
112105
$(
113106
impl Channel<$ADC> for $pin {
114107
type ID = u8;
@@ -119,60 +112,60 @@ macro_rules! adc_pins {
119112
};
120113
}
121114

122-
adc_pins!(ADC1,
123-
gpioa::PA0<Analog> => 0_u8,
124-
gpioa::PA1<Analog> => 1_u8,
125-
gpioa::PA2<Analog> => 2_u8,
126-
gpioa::PA3<Analog> => 3_u8,
127-
gpioa::PA4<Analog> => 4_u8,
128-
gpioa::PA5<Analog> => 5_u8,
129-
gpioa::PA6<Analog> => 6_u8,
130-
gpioa::PA7<Analog> => 7_u8,
131-
gpiob::PB0<Analog> => 8_u8,
132-
gpiob::PB1<Analog> => 9_u8,
133-
gpioc::PC0<Analog> => 10_u8,
134-
gpioc::PC1<Analog> => 11_u8,
135-
gpioc::PC2<Analog> => 12_u8,
136-
gpioc::PC3<Analog> => 13_u8,
137-
gpioc::PC4<Analog> => 14_u8,
138-
gpioc::PC5<Analog> => 15_u8,
115+
adc_pins!(pac::ADC1,
116+
gpio::PA0<Analog> => 0_u8,
117+
gpio::PA1<Analog> => 1_u8,
118+
gpio::PA2<Analog> => 2_u8,
119+
gpio::PA3<Analog> => 3_u8,
120+
gpio::PA4<Analog> => 4_u8,
121+
gpio::PA5<Analog> => 5_u8,
122+
gpio::PA6<Analog> => 6_u8,
123+
gpio::PA7<Analog> => 7_u8,
124+
gpio::PB0<Analog> => 8_u8,
125+
gpio::PB1<Analog> => 9_u8,
126+
gpio::PC0<Analog> => 10_u8,
127+
gpio::PC1<Analog> => 11_u8,
128+
gpio::PC2<Analog> => 12_u8,
129+
gpio::PC3<Analog> => 13_u8,
130+
gpio::PC4<Analog> => 14_u8,
131+
gpio::PC5<Analog> => 15_u8,
139132
);
140133

141134
#[cfg(any(feature = "stm32f103", feature = "connectivity"))]
142-
adc_pins!(ADC2,
143-
gpioa::PA0<Analog> => 0_u8,
144-
gpioa::PA1<Analog> => 1_u8,
145-
gpioa::PA2<Analog> => 2_u8,
146-
gpioa::PA3<Analog> => 3_u8,
147-
gpioa::PA4<Analog> => 4_u8,
148-
gpioa::PA5<Analog> => 5_u8,
149-
gpioa::PA6<Analog> => 6_u8,
150-
gpioa::PA7<Analog> => 7_u8,
151-
gpiob::PB0<Analog> => 8_u8,
152-
gpiob::PB1<Analog> => 9_u8,
153-
gpioc::PC0<Analog> => 10_u8,
154-
gpioc::PC1<Analog> => 11_u8,
155-
gpioc::PC2<Analog> => 12_u8,
156-
gpioc::PC3<Analog> => 13_u8,
157-
gpioc::PC4<Analog> => 14_u8,
158-
gpioc::PC5<Analog> => 15_u8,
135+
adc_pins!(pac::ADC2,
136+
gpio::PA0<Analog> => 0_u8,
137+
gpio::PA1<Analog> => 1_u8,
138+
gpio::PA2<Analog> => 2_u8,
139+
gpio::PA3<Analog> => 3_u8,
140+
gpio::PA4<Analog> => 4_u8,
141+
gpio::PA5<Analog> => 5_u8,
142+
gpio::PA6<Analog> => 6_u8,
143+
gpio::PA7<Analog> => 7_u8,
144+
gpio::PB0<Analog> => 8_u8,
145+
gpio::PB1<Analog> => 9_u8,
146+
gpio::PC0<Analog> => 10_u8,
147+
gpio::PC1<Analog> => 11_u8,
148+
gpio::PC2<Analog> => 12_u8,
149+
gpio::PC3<Analog> => 13_u8,
150+
gpio::PC4<Analog> => 14_u8,
151+
gpio::PC5<Analog> => 15_u8,
159152
);
160153

161154
#[cfg(all(feature = "stm32f103", any(feature = "high", feature = "xl",),))]
162-
adc_pins!(ADC3,
163-
gpioa::PA0<Analog> => 0_u8,
164-
gpioa::PA1<Analog> => 1_u8,
165-
gpioa::PA2<Analog> => 2_u8,
166-
gpioa::PA3<Analog> => 3_u8,
167-
gpiof::PF6<Analog> => 4_u8,
168-
gpiof::PF7<Analog> => 5_u8,
169-
gpiof::PF8<Analog> => 6_u8,
170-
gpiof::PF9<Analog> => 7_u8,
171-
gpiof::PF10<Analog> => 8_u8,
172-
gpioc::PC0<Analog> => 10_u8,
173-
gpioc::PC1<Analog> => 11_u8,
174-
gpioc::PC2<Analog> => 12_u8,
175-
gpioc::PC3<Analog> => 13_u8,
155+
adc_pins!(pac::ADC3,
156+
gpio::PA0<Analog> => 0_u8,
157+
gpio::PA1<Analog> => 1_u8,
158+
gpio::PA2<Analog> => 2_u8,
159+
gpio::PA3<Analog> => 3_u8,
160+
gpio::PF6<Analog> => 4_u8,
161+
gpio::PF7<Analog> => 5_u8,
162+
gpio::PF8<Analog> => 6_u8,
163+
gpio::PF9<Analog> => 7_u8,
164+
gpio::PF10<Analog> => 8_u8,
165+
gpio::PC0<Analog> => 10_u8,
166+
gpio::PC1<Analog> => 11_u8,
167+
gpio::PC2<Analog> => 12_u8,
168+
gpio::PC3<Analog> => 13_u8,
176169
);
177170

178171
/// Stored ADC config can be restored using the `Adc::restore_cfg` method
@@ -181,7 +174,7 @@ pub struct StoredConfig(SampleTime, Align);
181174

182175
macro_rules! adc_hal {
183176
($(
184-
$ADC:ident: ($adc:ident),
177+
$ADC:ty: ($adc:ident),
185178
)+) => {
186179
$(
187180

@@ -279,17 +272,17 @@ macro_rules! adc_hal {
279272

280273
fn reset(&mut self) {
281274
let rcc = unsafe { &(*RCC::ptr()) };
282-
$ADC::reset(rcc);
275+
<$ADC>::reset(rcc);
283276
}
284277

285278
fn enable_clock(&mut self) {
286279
let rcc = unsafe { &(*RCC::ptr()) };
287-
$ADC::enable(rcc);
280+
<$ADC>::enable(rcc);
288281
}
289282

290283
fn disable_clock(&mut self) {
291284
let rcc = unsafe { &(*RCC::ptr()) };
292-
$ADC::disable(rcc);
285+
<$ADC>::disable(rcc);
293286
}
294287

295288
fn calibrate(&mut self) {
@@ -461,7 +454,7 @@ macro_rules! adc_hal {
461454
}
462455
}
463456

464-
impl Adc<ADC1> {
457+
impl Adc<pac::ADC1> {
465458
fn read_aux(&mut self, chan: u8) -> u16 {
466459
let tsv_off = if self.rb.cr2.read().tsvrefe().bit_is_clear() {
467460
self.rb.cr2.modify(|_, w| w.tsvrefe().set_bit());
@@ -545,17 +538,17 @@ impl Adc<ADC1> {
545538
}
546539

547540
adc_hal! {
548-
ADC1: (adc1),
541+
pac::ADC1: (adc1),
549542
}
550543

551544
#[cfg(any(feature = "stm32f103", feature = "connectivity"))]
552545
adc_hal! {
553-
ADC2: (adc2),
546+
pac::ADC2: (adc2),
554547
}
555548

556549
#[cfg(all(feature = "stm32f103", any(feature = "high", feature = "xl",),))]
557550
adc_hal! {
558-
ADC3: (adc3),
551+
pac::ADC3: (adc3),
559552
}
560553

561554
pub struct AdcPayload<ADC, PINS, MODE> {
@@ -608,7 +601,7 @@ pub trait SetChannels<PINS>: ChannelTimeSequence {
608601
pub type AdcDma<ADC, PINS, MODE, CHANNEL> = RxDma<AdcPayload<ADC, PINS, MODE>, CHANNEL>;
609602

610603
macro_rules! adcdma {
611-
($ADCX:ident: (
604+
($ADCX:ty: (
612605
$rxdma:ident,
613606
$dmarxch:ty,
614607
)) => {
@@ -750,7 +743,7 @@ macro_rules! adcdma {
750743
// until the end of the transfer.
751744
let (ptr, len) = unsafe { buffer.static_write_buffer() };
752745
self.channel.set_peripheral_address(
753-
unsafe { &(*$ADCX::ptr()).dr as *const _ as u32 },
746+
unsafe { &(*<$ADCX>::ptr()).dr as *const _ as u32 },
754747
false,
755748
);
756749
self.channel.set_memory_address(ptr as u32, true);
@@ -789,7 +782,7 @@ macro_rules! adcdma {
789782
// until the end of the transfer.
790783
let (ptr, len) = unsafe { buffer.static_write_buffer() };
791784
self.channel.set_peripheral_address(
792-
unsafe { &(*$ADCX::ptr()).dr as *const _ as u32 },
785+
unsafe { &(*<$ADCX>::ptr()).dr as *const _ as u32 },
793786
false,
794787
);
795788
self.channel.set_memory_address(ptr as u32, true);
@@ -819,15 +812,15 @@ macro_rules! adcdma {
819812
}
820813

821814
adcdma! {
822-
ADC1: (
815+
pac::ADC1: (
823816
AdcDma1,
824817
dma1::C1,
825818
)
826819
}
827820

828821
#[cfg(all(feature = "stm32f103", any(feature = "high", feature = "xl",),))]
829822
adcdma! {
830-
ADC3: (
823+
pac::ADC3: (
831824
AdcDma3,
832825
dma2::C5,
833826
)

src/afio.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use crate::pac::{afio, AFIO, RCC};
44
use crate::rcc::{Enable, Reset};
55

66
use crate::gpio::{
7-
gpioa::PA15,
8-
gpiob::{PB3, PB4},
9-
Debugger, Floating, Input,
7+
Debugger, Floating, Input, PA15, {PB3, PB4},
108
};
119

1210
pub trait AfioExt {

0 commit comments

Comments
 (0)