Skip to content

Commit 0e34084

Browse files
authored
Merge pull request #250 from DrTobe/gpio-cleanup
Remove weird alternate function typestates
2 parents 7b2e212 + 104b568 commit 0e34084

29 files changed

+290
-220
lines changed

examples/can-loopback.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ const APP: () = {
3333
rprintln!(" - CAN init");
3434

3535
let mut can = {
36-
let rx = gpioa.pa11.into_af9(&mut gpioa.moder, &mut gpioa.afrh);
37-
let tx = gpioa.pa12.into_af9(&mut gpioa.moder, &mut gpioa.afrh);
36+
let rx =
37+
gpioa
38+
.pa11
39+
.into_af9_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
40+
let tx =
41+
gpioa
42+
.pa12
43+
.into_af9_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
3844

3945
let can = Can::new(&mut rcc.apb1r1, dp.CAN1, (tx, rx));
4046

examples/i2c_write.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ fn main() -> ! {
3939

4040
let mut gpioa = dp.GPIOA.split(&mut rcc.ahb2);
4141

42-
let mut scl = gpioa
43-
.pa9
44-
.into_open_drain_output(&mut gpioa.moder, &mut gpioa.otyper);
42+
let mut scl =
43+
gpioa
44+
.pa9
45+
.into_af4_opendrain(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
4546
scl.internal_pull_up(&mut gpioa.pupdr, true);
46-
let scl = scl.into_af4(&mut gpioa.moder, &mut gpioa.afrh);
4747

48-
let mut sda = gpioa
49-
.pa10
50-
.into_open_drain_output(&mut gpioa.moder, &mut gpioa.otyper);
48+
let mut sda =
49+
gpioa
50+
.pa10
51+
.into_af4_opendrain(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
5152
sda.internal_pull_up(&mut gpioa.pupdr, true);
52-
let sda = sda.into_af4(&mut gpioa.moder, &mut gpioa.afrh);
5353

5454
let mut i2c = I2c::i2c1(
5555
dp.I2C1,

examples/otg_fs_serial.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ unsafe fn main() -> ! {
145145
hclk: clocks.hclk(),
146146
pin_dm: gpioa
147147
.pa11
148-
.into_af10(&mut gpioa.moder, &mut gpioa.afrh)
148+
.into_af10_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh)
149149
.set_speed(Speed::VeryHigh),
150150
pin_dp: gpioa
151151
.pa12
152-
.into_af10(&mut gpioa.moder, &mut gpioa.afrh)
152+
.into_af10_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh)
153153
.set_speed(Speed::VeryHigh),
154154
};
155155

examples/pll_config.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ fn main() -> ! {
4444

4545
// The Serial API is highly generic
4646
// TRY the commented out, different pin configurations
47-
let tx = gpioa.pa9.into_af7(&mut gpioa.moder, &mut gpioa.afrh);
48-
// let tx = gpiob.pb6.into_af7(&mut gpiob.moder, &mut gpiob.afrl);
49-
50-
let rx = gpioa.pa10.into_af7(&mut gpioa.moder, &mut gpioa.afrh);
51-
// let rx = gpiob.pb7.into_af7(&mut gpiob.moder, &mut gpiob.afrl);
47+
let tx = gpioa
48+
.pa9
49+
.into_af7_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
50+
// let tx = gpiob.pb6.into_af7_pushpull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
51+
52+
let rx = gpioa
53+
.pa10
54+
.into_af7_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
55+
// let rx = gpiob.pb7.into_af7_pushpull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
5256

5357
// TRY using a different USART peripheral here
5458
let serial = Serial::usart1(

examples/pwm.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,16 @@ fn main() -> ! {
2727
// TIM2
2828
let c1 = gpioa
2929
.pa0
30-
.into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper)
31-
.into_af1(&mut gpioa.moder, &mut gpioa.afrl);
30+
.into_af1_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
3231
let c2 = gpioa
3332
.pa1
34-
.into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper)
35-
.into_af1(&mut gpioa.moder, &mut gpioa.afrl);
33+
.into_af1_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
3634
let c3 = gpioa
3735
.pa2
38-
.into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper)
39-
.into_af1(&mut gpioa.moder, &mut gpioa.afrl);
36+
.into_af1_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
4037
let c4 = gpioa
4138
.pa3
42-
.into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper)
43-
.into_af1(&mut gpioa.moder, &mut gpioa.afrl);
39+
.into_af1_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
4440

4541
let mut pwm = p
4642
.TIM2

examples/qspi.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,30 @@ fn main() -> ! {
5151
let mut id_arr: [u8; 3] = [0; 3];
5252

5353
let qspi = {
54-
let clk = gpioe.pe10.into_af10(&mut gpioe.moder, &mut gpioe.afrh);
55-
let ncs = gpioe.pe11.into_af10(&mut gpioe.moder, &mut gpioe.afrh);
56-
let io_0 = gpioe.pe12.into_af10(&mut gpioe.moder, &mut gpioe.afrh);
57-
let io_1 = gpioe.pe13.into_af10(&mut gpioe.moder, &mut gpioe.afrh);
58-
let io_2 = gpioe.pe14.into_af10(&mut gpioe.moder, &mut gpioe.afrh);
59-
let io_3 = gpioe.pe15.into_af10(&mut gpioe.moder, &mut gpioe.afrh);
54+
let clk =
55+
gpioe
56+
.pe10
57+
.into_af10_pushpull(&mut gpioe.moder, &mut gpioe.otyper, &mut gpioe.afrh);
58+
let ncs =
59+
gpioe
60+
.pe11
61+
.into_af10_pushpull(&mut gpioe.moder, &mut gpioe.otyper, &mut gpioe.afrh);
62+
let io_0 =
63+
gpioe
64+
.pe12
65+
.into_af10_pushpull(&mut gpioe.moder, &mut gpioe.otyper, &mut gpioe.afrh);
66+
let io_1 =
67+
gpioe
68+
.pe13
69+
.into_af10_pushpull(&mut gpioe.moder, &mut gpioe.otyper, &mut gpioe.afrh);
70+
let io_2 =
71+
gpioe
72+
.pe14
73+
.into_af10_pushpull(&mut gpioe.moder, &mut gpioe.otyper, &mut gpioe.afrh);
74+
let io_3 =
75+
gpioe
76+
.pe15
77+
.into_af10_pushpull(&mut gpioe.moder, &mut gpioe.otyper, &mut gpioe.afrh);
6078
Qspi::new(
6179
p.QUADSPI,
6280
(clk, ncs, io_0, io_1, io_2, io_3),

examples/rng.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ fn main() -> ! {
4646

4747
// setup usart
4848
let mut gpioa = device.GPIOA.split(&mut rcc.ahb2);
49-
let tx = gpioa.pa9.into_af7(&mut gpioa.moder, &mut gpioa.afrh);
50-
let rx = gpioa.pa10.into_af7(&mut gpioa.moder, &mut gpioa.afrh);
49+
let tx = gpioa
50+
.pa9
51+
.into_af7_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
52+
let rx = gpioa
53+
.pa10
54+
.into_af7_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
5155

5256
let baud_rate = 9_600; // 115_200;
5357
let serial = Serial::usart1(

examples/rtic_frame_serial_dma.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ const APP: () = {
6363
.freeze(&mut flash.acr, &mut pwr);
6464

6565
// USART2 pins
66-
let tx2 = gpioa.pa2.into_af7(&mut gpioa.moder, &mut gpioa.afrl);
67-
let rx2 = gpioa.pa3.into_af7(&mut gpioa.moder, &mut gpioa.afrl);
66+
let tx2 = gpioa
67+
.pa2
68+
.into_af7_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
69+
let rx2 = gpioa
70+
.pa3
71+
.into_af7_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
6872

6973
// We will listen for the character `a`, this can be changed to any character such as `\0`
7074
// if using COBS encoding, or `\n` if using string encoding.

examples/serial.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ fn main() -> ! {
4545

4646
// The Serial API is highly generic
4747
// TRY the commented out, different pin configurations
48-
// let tx = gpioa.pa9.into_af7(&mut gpioa.moder, &mut gpioa.afrh);
49-
let tx = gpioa.pa2.into_af7(&mut gpioa.moder, &mut gpioa.afrl);
50-
// let tx = gpiob.pb6.into_af7(&mut gpiob.moder, &mut gpiob.afrl);
51-
52-
// let rx = gpioa.pa10.into_af7(&mut gpioa.moder, &mut gpioa.afrh);
53-
let rx = gpioa.pa3.into_af7(&mut gpioa.moder, &mut gpioa.afrl);
54-
// let rx = gpiob.pb7.into_af7(&mut gpiob.moder, &mut gpiob.afrl);
48+
// let tx = gpioa.pa9.into_af7_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
49+
let tx = gpioa
50+
.pa2
51+
.into_af7_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
52+
// let tx = gpiob.pb6.into_af7_pushpull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
53+
54+
// let rx = gpioa.pa10.into_af7_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
55+
let rx = gpioa
56+
.pa3
57+
.into_af7_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
58+
// let rx = gpiob.pb7.into_af7_pushpull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
5559

5660
// TRY using a different USART peripheral here
5761
let serial = Serial::usart2(

examples/serial_dma.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ fn main() -> ! {
4343

4444
// The Serial API is highly generic
4545
// TRY the commented out, different pin configurations
46-
let tx = gpioa.pa9.into_af7(&mut gpioa.moder, &mut gpioa.afrh);
47-
// let tx = gpiob.pb6.into_af7(&mut gpiob.moder, &mut gpiob.afrl);
46+
let tx = gpioa
47+
.pa9
48+
.into_af7_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
49+
// let tx = gpiob.pb6.into_af7_pushpull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
4850

49-
let rx = gpioa.pa10.into_af7(&mut gpioa.moder, &mut gpioa.afrh);
50-
// let rx = gpiob.pb7.into_af7(&mut gpiob.moder, &mut gpiob.afrl);
51+
let rx = gpioa
52+
.pa10
53+
.into_af7_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
54+
// let rx = gpiob.pb7.into_af7_pushpull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
5155

5256
// TRY using a different USART peripheral here
5357
let serial = Serial::usart1(
@@ -136,7 +140,7 @@ fn send(tx: &mut impl embedded_hal::serial::Write<u8>, data: &[u8]) {
136140
}
137141

138142
// waste some time so that the data will be received completely
139-
for i in 0..10000 {
143+
for _ in 0..10000 {
140144
cortex_m::asm::nop();
141145
}
142146
}

0 commit comments

Comments
 (0)