Skip to content

Commit dc51e2d

Browse files
authored
Merge pull request #263 from burrbull/gpio-cg
const generics gpio (from F4)
2 parents e3a1333 + 2f5b395 commit dc51e2d

38 files changed

+1637
-1025
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased]
77

8+
## Changed
9+
10+
- Use const-generics for GPIO (require Rust 1.51)
11+
812
## [v0.6.0] - 2020-12-11
913

1014
### Added

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ default-features = false
4444
version = "1.1"
4545

4646
[dependencies.embedded-hal]
47-
version = "0.2.3"
47+
version = "0.2.6"
4848
features = ["unproven"]
4949

5050
[dependencies.stm32-usbd]

examples/blinky.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ fn main() -> ! {
5252
loop {
5353
// block!(timer.wait()).unwrap();
5454
timer.delay_ms(1000_u32);
55-
led.set_high().ok();
55+
led.set_high();
5656
// block!(timer.wait()).unwrap();
5757
timer.delay_ms(1000_u32);
58-
led.set_low().ok();
58+
led.set_low();
5959
}
6060
}
6161

examples/can-loopback.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ const APP: () = {
3636
let rx =
3737
gpioa
3838
.pa11
39-
.into_af9_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
39+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
4040
let tx =
4141
gpioa
4242
.pa12
43-
.into_af9_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
43+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
4444

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

examples/i2c_write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ fn main() -> ! {
4040
let mut scl =
4141
gpioa
4242
.pa9
43-
.into_af4_opendrain(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
43+
.into_alternate_open_drain(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
4444
scl.internal_pull_up(&mut gpioa.pupdr, true);
4545

4646
let mut sda =
4747
gpioa
4848
.pa10
49-
.into_af4_opendrain(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
49+
.into_alternate_open_drain(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
5050
sda.internal_pull_up(&mut gpioa.pupdr, true);
5151

5252
let mut i2c = I2c::i2c1(

examples/lptim_rtic.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extern crate panic_rtt_target;
99
use rtt_target::rprintln;
1010
use stm32l4xx_hal::{
1111
flash::ACR,
12-
gpio::{gpiob::PB13, Output, PushPull, State},
12+
gpio::{gpiob::PB13, Output, PinState, PushPull},
1313
lptimer::{ClockSource, Event, LowPowerTimer, LowPowerTimerConfig, PreScaler},
1414
pac::LPTIM1,
1515
prelude::*,
@@ -49,10 +49,10 @@ const APP: () = {
4949
let clocks = configure_clock_tree(rcc.cfgr, &mut flash.acr, &mut pwr);
5050

5151
// PB13 is a user led on Nucleo-L452-P board
52-
let led = gpiob.pb13.into_push_pull_output_with_state(
52+
let led = gpiob.pb13.into_push_pull_output_in_state(
5353
&mut gpiob.moder,
5454
&mut gpiob.otyper,
55-
State::Low,
55+
PinState::Low,
5656
);
5757
rprintln!("Clocks = {:#?}", clocks);
5858
let lptim_config = LowPowerTimerConfig::default()
@@ -77,11 +77,7 @@ const APP: () = {
7777
lptim.clear_event_flag(Event::AutoReloadMatch);
7878
rprintln!("LPTIM1 tick");
7979

80-
if led.is_set_high().unwrap() {
81-
led.set_low().unwrap();
82-
} else {
83-
led.set_high().unwrap();
84-
}
80+
led.toggle();
8581
}
8682
}
8783

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_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh)
148+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh)
149149
.set_speed(Speed::VeryHigh),
150150
pin_dp: gpioa
151151
.pa12
152-
.into_af10_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh)
152+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh)
153153
.set_speed(Speed::VeryHigh),
154154
};
155155

examples/pll_config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ fn main() -> ! {
4545
// TRY the commented out, different pin configurations
4646
let tx = gpioa
4747
.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);
48+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
49+
// let tx = gpiob.pb6.into_alternate(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
5050

5151
let rx = gpioa
5252
.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);
53+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh);
54+
// let rx = gpiob.pb7.into_alternate(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl);
5555

5656
// TRY using a different USART peripheral here
5757
let serial = Serial::usart1(

examples/pwm.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ fn main() -> ! {
2727
// TIM2
2828
let c1 = gpioa
2929
.pa0
30-
.into_af1_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
30+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
3131
let c2 = gpioa
3232
.pa1
33-
.into_af1_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
33+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
3434
let c3 = gpioa
3535
.pa2
36-
.into_af1_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
36+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
3737
let c4 = gpioa
3838
.pa3
39-
.into_af1_pushpull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
39+
.into_alternate(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
4040

4141
let mut pwm = p
4242
.TIM2

examples/qspi.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,24 @@ fn main() -> ! {
4949
let mut id_arr: [u8; 3] = [0; 3];
5050

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

0 commit comments

Comments
 (0)