Skip to content

Commit f946323

Browse files
committed
f4xx-hal like gpio
1 parent 8933e11 commit f946323

28 files changed

+1883
-1454
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
5656
- Missing `MosiPin` impl for `PB5` ([#322])
5757
- Read valid data from data register even if reception of next character
5858
has started ([#317])
59+
- Use const generics for pins. The MSRV was bumped to 1.59 ([#316])
5960

6061
## [v0.9.0] - 2022-03-06
6162

@@ -603,6 +604,7 @@ let clocks = rcc
603604
[#322]: https://github.com/stm32-rs/stm32f3xx-hal/pull/322
604605
[#318]: https://github.com/stm32-rs/stm32f3xx-hal/pull/318
605606
[#317]: https://github.com/stm32-rs/stm32f3xx-hal/pull/317
607+
[#316]: https://github.com/stm32-rs/stm32f3xx-hal/pull/316
606608
[#314]: https://github.com/stm32-rs/stm32f3xx-hal/pull/314
607609
[#309]: https://github.com/stm32-rs/stm32f3xx-hal/pull/309
608610
[#308]: https://github.com/stm32-rs/stm32f3xx-hal/pull/308

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ cortex-m = "0.7.4"
3333
cortex-m-rt = "0.7.3"
3434
defmt = { version = ">=0.2.3, <0.4.0", optional = true }
3535
embedded-dma = "0.2.0"
36-
embedded-hal = { version = "0.2.5", features = ["unproven"] }
36+
embedded-hal = { version = "0.2.7", features = ["unproven"] }
3737
embedded-time = "0.12.0"
3838
enumset = { version = "1.0.6", optional = true }
3939
nb = "1.0.0"

examples/can.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ fn main() -> ! {
4343
// Configure CAN RX and TX pins (AF9)
4444
let rx = gpioa
4545
.pa11
46-
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
46+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
4747
let tx = gpioa
4848
.pa12
49-
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
49+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
5050

5151
// Initialize the CAN peripheral
5252
// Use loopback mode: No pins need to be assigned to peripheral.

examples/gpio_erased.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,29 @@ fn main() -> ! {
2323
let mut gpioc = dp.GPIOC.split(&mut rcc.ahb);
2424
let mut gpiod = dp.GPIOD.split(&mut rcc.ahb);
2525

26-
let mut pin_array: [gpio::PXx<Input>; 4] = [
26+
let mut pin_array: [gpio::EPin<Input>; 4] = [
2727
gpiob
2828
.pb11
2929
.into_floating_input(&mut gpiob.moder, &mut gpiob.pupdr)
30-
.downgrade()
31-
.downgrade(),
30+
.erase(),
3231
gpioc
3332
.pc4
3433
.into_floating_input(&mut gpioc.moder, &mut gpioc.pupdr)
35-
.downgrade()
36-
.downgrade(),
34+
.erase(),
3735
gpiod
3836
.pd3
3937
.into_floating_input(&mut gpiod.moder, &mut gpiod.pupdr)
40-
.downgrade()
41-
.downgrade(),
38+
.erase(),
4239
gpiod
4340
.pd2
4441
.into_floating_input(&mut gpiod.moder, &mut gpiod.pupdr)
45-
.downgrade()
46-
.downgrade(),
42+
.erase(),
4743
];
4844

4945
hprintln!("Start scanning pin array");
5046
loop {
5147
for pin in pin_array.iter_mut() {
52-
hprintln!("Value is {}", pin.is_high().unwrap());
48+
hprintln!("Value is {}", pin.is_high());
5349
asm::delay(1_000_000);
5450
}
5551
}

examples/gpio_interrupts.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn main() -> ! {
3535
.pe9
3636
.into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
3737
// Turn the led on so we know the configuration step occurred.
38-
led.toggle().expect("unable to toggle led in configuration");
38+
led.toggle();
3939

4040
// Move the ownership of the led to the global LED
4141
cortex_m::interrupt::free(|cs| *LED.borrow(cs).borrow_mut() = Some(led));
@@ -69,12 +69,7 @@ fn main() -> ! {
6969
fn EXTI0() {
7070
cortex_m::interrupt::free(|cs| {
7171
// Toggle the LED
72-
LED.borrow(cs)
73-
.borrow_mut()
74-
.as_mut()
75-
.unwrap()
76-
.toggle()
77-
.unwrap();
72+
LED.borrow(cs).borrow_mut().as_mut().unwrap().toggle();
7873

7974
// Clear the interrupt pending bit so we don't infinitely call this routine
8075
BUTTON

examples/i2c_scanner.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@ fn main() -> ! {
2828
let mut gpiob = dp.GPIOB.split(&mut rcc.ahb);
2929

3030
// Configure I2C1
31-
let mut scl =
32-
gpiob
33-
.pb6
34-
.into_af_open_drain(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
35-
let mut sda =
36-
gpiob
37-
.pb7
38-
.into_af_open_drain(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
39-
scl.internal_pull_up(&mut gpiob.pupdr, true);
40-
sda.internal_pull_up(&mut gpiob.pupdr, true);
31+
let scl = gpiob
32+
.pb6
33+
.into_alternate_open_drain(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl)
34+
.internal_pull_up(&mut gpiob.pupdr, true);
35+
let sda = gpiob
36+
.pb7
37+
.into_alternate_open_drain(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl)
38+
.internal_pull_up(&mut gpiob.pupdr, true);
4139
let mut i2c = hal::i2c::I2c::new(
4240
dp.I2C1,
4341
(scl, sda),

examples/pwm.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,38 @@ fn main() -> ! {
3434
let mut gpioa = dp.GPIOA.split(&mut rcc.ahb);
3535
let pa4 = gpioa
3636
.pa4
37-
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
37+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
3838
let pa6 = gpioa
3939
.pa6
40-
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
40+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
4141
let pa7 = gpioa
4242
.pa7
43-
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
43+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
4444

4545
let mut gpiob = dp.GPIOB.split(&mut rcc.ahb);
4646
let pb0 = gpiob
4747
.pb0
48-
.into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
48+
.into_alternate(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
4949
let pb1 = gpiob
5050
.pb1
51-
.into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
51+
.into_alternate(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
5252
let pb4 = gpiob
5353
.pb4
54-
.into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
54+
.into_alternate(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
5555
let pb5 = gpiob
5656
.pb5
57-
.into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
57+
.into_alternate(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
5858
let pb8 = gpiob
5959
.pb8
60-
.into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrh);
60+
.into_alternate(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrh);
6161
let pb10 = gpiob
6262
.pb10
63-
.into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrh);
63+
.into_alternate(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrh);
6464

6565
let mut gpioc = dp.GPIOC.split(&mut rcc.ahb);
6666
let pc10 = gpioc
6767
.pc10
68-
.into_af_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh);
68+
.into_alternate(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh);
6969

7070
// TIM3
7171
//

examples/serial_dma.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ fn main() -> ! {
3535
let pins = (
3636
gpioa
3737
.pa9
38-
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
38+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
3939
gpioa
4040
.pa10
41-
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
41+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
4242
);
4343
let serial = Serial::new(dp.USART1, pins, 9600.Bd(), clocks, &mut rcc.apb2);
4444
let (tx, rx) = serial.split();

examples/serial_echo_rtic.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,30 @@ mod app {
5858
let mut dir: DirType = gpioe
5959
.pe13
6060
.into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
61-
dir.set_low().unwrap();
61+
dir.set_low();
6262

6363
// SERIAL
6464
let mut gpioa = cx.device.GPIOA.split(&mut rcc.ahb);
65-
let mut pins = (
65+
let pins = (
6666
gpioa
6767
// Tx pin
6868
.pa9
6969
// configure this pin to make use of its `USART1_TX` alternative function
7070
// (AF mapping taken from table 14 "Alternate functions for port A" of the datasheet at
7171
// https://www.st.com/en/microcontrollers-microprocessors/stm32f303vc.html)
72-
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
72+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
7373
gpioa
7474
// Rx pin
7575
.pa10
7676
// configure this pin to make use of its `USART1_RX` alternative function
7777
// (AF mapping taken from table 14 "Alternate functions for port A" of the datasheet at
7878
// https://www.st.com/en/microcontrollers-microprocessors/stm32f303vc.html)
79-
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh),
79+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh)
80+
.internal_pull_up(&mut gpioa.pupdr, true),
8081
);
81-
pins.1.internal_pull_up(&mut gpioa.pupdr, true);
8282
let mut serial: SerialType =
8383
Serial::new(cx.device.USART1, pins, 19200.Bd(), clocks, &mut rcc.apb2);
84-
serial.configure_interrupt(Event::ReceiveDataRegisterNotEmpty, Switch::On);
84+
serial.configure_interrupt(Event::ReceiveDataRegisterNotEmpty, Toggle::On);
8585

8686
rprintln!("post init");
8787

@@ -99,7 +99,7 @@ mod app {
9999
let dir = cx.local.dir;
100100

101101
if serial.is_event_triggered(Event::ReceiveDataRegisterNotEmpty) {
102-
dir.set_high().unwrap();
102+
dir.set_high();
103103
serial.configure_interrupt(Event::ReceiveDataRegisterNotEmpty, Switch::Off);
104104
match serial.read() {
105105
Ok(byte) => {
@@ -116,7 +116,7 @@ mod app {
116116
// and other functions enabled by the "enumset" feature.
117117
let events = serial.triggered_events();
118118
if events.contains(Event::TransmissionComplete) {
119-
dir.set_low().unwrap();
119+
dir.set_low();
120120
let interrupts = {
121121
let mut interrupts = enumset::EnumSet::new();
122122
interrupts.insert(Event::ReceiveDataRegisterNotEmpty);

examples/spi.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ fn main() -> ! {
3232
// Configure pins for SPI
3333
let sck = gpioc
3434
.pc10
35-
.into_af_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh);
35+
.into_alternate(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh);
3636
let miso = gpioc
3737
.pc11
38-
.into_af_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh);
38+
.into_alternate(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh);
3939
let mosi = gpioc
4040
.pc12
41-
.into_af_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh);
41+
.into_alternate(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh);
4242

4343
let mut spi = Spi::new(dp.SPI3, (sck, miso, mosi), 3.MHz(), clocks, &mut rcc.apb1);
4444

0 commit comments

Comments
 (0)