Skip to content

Commit 01c6afb

Browse files
bors[bot]burrbull
andauthored
Merge #594
594: Alt enums r=burrbull a=burrbull Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents 5a30cb0 + 6c04442 commit 01c6afb

37 files changed

+2719
-2127
lines changed

CHANGELOG.md

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

88
## [Unreleased]
99

10+
- Use `enum`s for alternate peripheral pins
1011
- Added missing U(S)ART DMA traits for HAL serial types [#593]
1112
- Improve SPI::new* docs [#587]
1213
- Add advanced timer dead time insertion example [#585]

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ stm32f446 = ["stm32f4/stm32f446", "device-selected", "gpio-f446",
279279
"otg-fs",
280280
"otg-hs",
281281
"sai",
282+
#"sdio",
282283
"spi3", "spi4",
283284
"tim2", "tim8",
284285
"usart3", "uart4", "uart5",

examples/analog-stopwatch-with-spi-ssd1306.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ fn draw_face() -> impl Iterator<Item = Pixel<BinaryColor>> {
352352
Circle::new(CENTER, SIZE * 2).into_styled(PrimitiveStyle::with_stroke(BinaryColor::On, 1));
353353

354354
// Create 12 `Line`s starting from the outer edge and drawing inwards by `tic_len` pixels
355-
let tics = (0..12).into_iter().map(move |index| {
355+
let tics = (0..12).map(move |index| {
356356
// Start angle around the circle, in radians
357357
let angle = START + (PI * 2.0 / 12.0) * index as f32;
358358

@@ -369,7 +369,7 @@ fn draw_face() -> impl Iterator<Item = Pixel<BinaryColor>> {
369369

370370
// Create a single iterator of pixels, first iterating over the circle, then over the 12 lines
371371
// generated
372-
face.pixels().into_iter().chain(tics.flatten())
372+
face.pixels().chain(tics.flatten())
373373
}
374374

375375
/// Draw the seconds hand given a seconds value (0 - 59)
@@ -395,9 +395,7 @@ fn draw_seconds_hand(seconds: u32) -> impl Iterator<Item = Pixel<BinaryColor>> {
395395
// Add a fancy circle near the end of the hand
396396
let decoration = Circle::new(decoration_position, 3).into_styled(decoration_style);
397397

398-
hand.pixels()
399-
.into_iter()
400-
.chain(decoration.pixels().into_iter())
398+
hand.pixels().chain(decoration.pixels())
401399
}
402400

403401
#[exception]

examples/display-touch.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
use cortex_m;
1818
use cortex_m_rt::entry;
1919
use rtt_target::{rprintln, rtt_init_print};
20-
#[cfg(feature = "stm32f412")]
21-
use stm32f4xx_hal::fsmc_lcd::ChipSelect1;
22-
#[cfg(feature = "stm32f413")]
23-
use stm32f4xx_hal::fsmc_lcd::ChipSelect3;
2420
use stm32f4xx_hal::{
2521
fsmc_lcd::{FsmcLcd, LcdPins, Timing},
2622
gpio::Speed,
@@ -70,32 +66,33 @@ fn main() -> ! {
7066
let gpiog = p.GPIOG.split();
7167

7268
// Pins connected to the LCD on the board
69+
use stm32f4xx_hal::gpio::alt::fsmc as alt;
7370
let lcd_pins = LcdPins {
7471
data: (
75-
gpiod.pd14.into_alternate(),
76-
gpiod.pd15.into_alternate(),
77-
gpiod.pd0.into_alternate(),
78-
gpiod.pd1.into_alternate(),
79-
gpioe.pe7.into_alternate(),
80-
gpioe.pe8.into_alternate(),
81-
gpioe.pe9.into_alternate(),
82-
gpioe.pe10.into_alternate(),
83-
gpioe.pe11.into_alternate(),
84-
gpioe.pe12.into_alternate(),
85-
gpioe.pe13.into_alternate(),
86-
gpioe.pe14.into_alternate(),
87-
gpioe.pe15.into_alternate(),
88-
gpiod.pd8.into_alternate(),
89-
gpiod.pd9.into_alternate(),
90-
gpiod.pd10.into_alternate(),
72+
gpiod.pd14.into(),
73+
gpiod.pd15.into(),
74+
gpiod.pd0.into(),
75+
gpiod.pd1.into(),
76+
gpioe.pe7.into(),
77+
gpioe.pe8.into(),
78+
gpioe.pe9.into(),
79+
gpioe.pe10.into(),
80+
gpioe.pe11.into(),
81+
gpioe.pe12.into(),
82+
gpioe.pe13.into(),
83+
gpioe.pe14.into(),
84+
gpioe.pe15.into(),
85+
gpiod.pd8.into(),
86+
gpiod.pd9.into(),
87+
gpiod.pd10.into(),
9188
),
92-
address: gpiof.pf0.into_alternate(),
93-
read_enable: gpiod.pd4.into_alternate(),
94-
write_enable: gpiod.pd5.into_alternate(),
89+
address: alt::Address::from(gpiof.pf0),
90+
read_enable: gpiod.pd4.into(),
91+
write_enable: gpiod.pd5.into(),
9592
#[cfg(feature = "stm32f413")]
96-
chip_select: ChipSelect3(gpiog.pg10.into_alternate()),
93+
chip_select: alt::ChipSelect3::from(gpiog.pg10),
9794
#[cfg(feature = "stm32f412")]
98-
chip_select: ChipSelect1(gpiod.pd7.into_alternate()),
95+
chip_select: alt::ChipSelect1::from(gpiod.pd7),
9996
};
10097

10198
// Enable backlight

examples/f413disco-lcd-ferris.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rtt_target::{self, rtt_init_print};
1616
use stm32f4xx_hal as hal;
1717

1818
use crate::hal::{
19-
fsmc_lcd::{ChipSelect3, FsmcLcd, LcdPins, Timing},
19+
fsmc_lcd::{FsmcLcd, LcdPins, Timing},
2020
gpio::Speed,
2121
pac::{CorePeripherals, Peripherals},
2222
prelude::*,
@@ -709,29 +709,30 @@ fn main() -> ! {
709709
let clocks = rcc.cfgr.sysclk(100.MHz()).freeze();
710710

711711
// Define the pins we need for our 16bit parallel bus
712+
use stm32f4xx_hal::gpio::alt::fsmc as alt;
712713
let lcd_pins = LcdPins {
713714
data: (
714-
gpiod.pd14.into_alternate(),
715-
gpiod.pd15.into_alternate(),
716-
gpiod.pd0.into_alternate(),
717-
gpiod.pd1.into_alternate(),
718-
gpioe.pe7.into_alternate(),
719-
gpioe.pe8.into_alternate(),
720-
gpioe.pe9.into_alternate(),
721-
gpioe.pe10.into_alternate(),
722-
gpioe.pe11.into_alternate(),
723-
gpioe.pe12.into_alternate(),
724-
gpioe.pe13.into_alternate(),
725-
gpioe.pe14.into_alternate(),
726-
gpioe.pe15.into_alternate(),
727-
gpiod.pd8.into_alternate(),
728-
gpiod.pd9.into_alternate(),
729-
gpiod.pd10.into_alternate(),
715+
gpiod.pd14.into(),
716+
gpiod.pd15.into(),
717+
gpiod.pd0.into(),
718+
gpiod.pd1.into(),
719+
gpioe.pe7.into(),
720+
gpioe.pe8.into(),
721+
gpioe.pe9.into(),
722+
gpioe.pe10.into(),
723+
gpioe.pe11.into(),
724+
gpioe.pe12.into(),
725+
gpioe.pe13.into(),
726+
gpioe.pe14.into(),
727+
gpioe.pe15.into(),
728+
gpiod.pd8.into(),
729+
gpiod.pd9.into(),
730+
gpiod.pd10.into(),
730731
),
731-
address: gpiof.pf0.into_alternate(),
732-
read_enable: gpiod.pd4.into_alternate(),
733-
write_enable: gpiod.pd5.into_alternate(),
734-
chip_select: ChipSelect3(gpiog.pg10.into_alternate()),
732+
address: alt::Address::from(gpiof.pf0),
733+
read_enable: gpiod.pd4.into(),
734+
write_enable: gpiod.pd5.into(),
735+
chip_select: alt::ChipSelect3::from(gpiog.pg10),
735736
};
736737

737738
// Setup the RESET pin

examples/rtic-i2s-audio-in-out.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ mod app {
8080

8181
use super::hal;
8282

83-
use hal::gpio::gpioa::*;
84-
use hal::gpio::gpiob::*;
85-
use hal::gpio::gpioc::*;
8683
use hal::gpio::Edge;
8784
use hal::gpio::NoPin;
8885
use hal::i2s::stm32_i2s_v12x::driver::*;
@@ -95,8 +92,8 @@ mod app {
9592

9693
use rtt_target::{rprintln, rtt_init, set_print_channel};
9794

98-
type I2s2Driver = I2sDriver<I2s<SPI2, (PB12, PB13, PC6, PB15)>, Master, Receive, Philips>;
99-
type I2s3Driver = I2sDriver<I2s<SPI3, (PA4, PC10, NoPin, PC12)>, Slave, Transmit, Philips>;
95+
type I2s2Driver = I2sDriver<I2s<SPI2>, Master, Receive, Philips>;
96+
type I2s3Driver = I2sDriver<I2s<SPI3>, Slave, Transmit, Philips>;
10097

10198
// Part of the frame we currently transmit or receive
10299
#[derive(Copy, Clone)]

examples/rtic-usart-shell-ssd1306.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ mod usart_shell {
2121
use ssd1306::{mode::BufferedGraphicsMode, prelude::*, I2CDisplayInterface, Ssd1306};
2222

2323
use stm32f4xx_hal::{
24-
gpio::{
25-
gpioa::PA0, gpioa::PA10, gpioa::PA9, gpiob::PB8, gpiob::PB9, gpioc::PC13, Alternate,
26-
Edge, Input, OpenDrain, Output, PushPull,
27-
},
24+
gpio::{gpioa::PA0, gpioc::PC13, Edge, Input, Output, PushPull},
2825
i2c::I2c,
2926
pac::I2C1,
3027
pac::USART1,
@@ -40,14 +37,9 @@ mod usart_shell {
4037

4138
type LedType = PC13<Output<PushPull>>;
4239
type ButtonType = PA0<Input>;
43-
type ShellType = UShell<
44-
Serial<USART1, (PA9<Alternate<7>>, PA10<Alternate<7>>)>,
45-
StaticAutocomplete<5>,
46-
LRUHistory<32, 4>,
47-
32,
48-
>;
40+
type ShellType = UShell<Serial<USART1>, StaticAutocomplete<5>, LRUHistory<32, 4>, 32>;
4941
type DisplayType = Ssd1306<
50-
I2CInterface<I2c<I2C1, (PB8<Alternate<4, OpenDrain>>, PB9<Alternate<4, OpenDrain>>)>>,
42+
I2CInterface<I2c<I2C1>>,
5143
DisplaySize128x64,
5244
BufferedGraphicsMode<DisplaySize128x64>,
5345
>;

examples/rtic-usart-shell.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ mod usart_shell {
1010
use core::fmt::Write;
1111
use dwt_systick_monotonic::DwtSystick;
1212
use stm32f4xx_hal::{
13-
gpio::{
14-
gpioa::PA0, gpioa::PA10, gpioa::PA9, gpioc::PC13, Alternate, Edge, Input, Output,
15-
PushPull,
16-
},
13+
gpio::{gpioa::PA0, gpioc::PC13, Edge, Input, Output, PushPull},
1714
pac::USART1,
1815
prelude::*,
1916
serial::{config::Config, Event::Rxne, Serial},
@@ -26,12 +23,7 @@ mod usart_shell {
2623

2724
type LedType = PC13<Output<PushPull>>;
2825
type ButtonType = PA0<Input>;
29-
type ShellType = UShell<
30-
Serial<USART1, (PA9<Alternate<7>>, PA10<Alternate<7>>)>,
31-
StaticAutocomplete<5>,
32-
LRUHistory<32, 4>,
33-
32,
34-
>;
26+
type ShellType = UShell<Serial<USART1>, StaticAutocomplete<5>, LRUHistory<32, 4>, 32>;
3527

3628
const SHELL_PROMPT: &str = "#> ";
3729
const CR: &str = "\r\n";

examples/rtic-usb-cdc-echo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ mod app {
6060
usb_global: dp.OTG_FS_GLOBAL,
6161
usb_device: dp.OTG_FS_DEVICE,
6262
usb_pwrclk: dp.OTG_FS_PWRCLK,
63-
pin_dm: gpioa.pa11.into_alternate(),
64-
pin_dp: gpioa.pa12.into_alternate(),
63+
pin_dm: gpioa.pa11.into(),
64+
pin_dp: gpioa.pa12.into(),
6565
hclk: clocks.hclk(),
6666
};
6767
unsafe {

examples/sd.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ fn main() -> ! {
3434
let gpioc = device.GPIOC.split();
3535
let gpiod = device.GPIOD.split();
3636

37-
let d0 = gpioc.pc8.into_alternate().internal_pull_up(true);
38-
let d1 = gpioc.pc9.into_alternate().internal_pull_up(true);
39-
let d2 = gpioc.pc10.into_alternate().internal_pull_up(true);
40-
let d3 = gpioc.pc11.into_alternate().internal_pull_up(true);
41-
let clk = gpioc.pc12.into_alternate().internal_pull_up(false);
42-
let cmd = gpiod.pd2.into_alternate().internal_pull_up(true);
37+
let d0 = gpioc.pc8.internal_pull_up(true);
38+
let d1 = gpioc.pc9.internal_pull_up(true);
39+
let d2 = gpioc.pc10.internal_pull_up(true);
40+
let d3 = gpioc.pc11.internal_pull_up(true);
41+
let clk = gpioc.pc12;
42+
let cmd = gpiod.pd2.internal_pull_up(true);
4343
let mut sdio: Sdio<SdCard> = Sdio::new(device.SDIO, (clk, cmd, d0, d1, d2, d3), &clocks);
4444

4545
hprintln!("Waiting for card...");

0 commit comments

Comments
 (0)