Skip to content

Commit 6a92f6a

Browse files
committed
sdio & fsmc
1 parent 24e923d commit 6a92f6a

File tree

11 files changed

+532
-585
lines changed

11 files changed

+532
-585
lines changed

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/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/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...");

examples/st7789-lcd.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use embedded_graphics::prelude::*;
3030

3131
use embedded_graphics::primitives::{Circle, PrimitiveStyle};
3232
use st7789::ST7789;
33-
use stm32f4xx_hal::fsmc_lcd::{ChipSelect1, FsmcLcd, LcdPins, Timing};
33+
use stm32f4xx_hal::fsmc_lcd::{FsmcLcd, LcdPins, Timing};
3434
use stm32f4xx_hal::pac::{CorePeripherals, Peripherals};
3535
use stm32f4xx_hal::prelude::*;
3636

@@ -50,29 +50,30 @@ fn main() -> ! {
5050
let gpiof = dp.GPIOF.split();
5151

5252
// Pins connected to the LCD on the 32F412GDISCOVERY board
53+
use stm32f4xx_hal::gpio::alt::fsmc as alt;
5354
let lcd_pins = LcdPins {
5455
data: (
55-
gpiod.pd14.into_alternate(),
56-
gpiod.pd15.into_alternate(),
57-
gpiod.pd0.into_alternate(),
58-
gpiod.pd1.into_alternate(),
59-
gpioe.pe7.into_alternate(),
60-
gpioe.pe8.into_alternate(),
61-
gpioe.pe9.into_alternate(),
62-
gpioe.pe10.into_alternate(),
63-
gpioe.pe11.into_alternate(),
64-
gpioe.pe12.into_alternate(),
65-
gpioe.pe13.into_alternate(),
66-
gpioe.pe14.into_alternate(),
67-
gpioe.pe15.into_alternate(),
68-
gpiod.pd8.into_alternate(),
69-
gpiod.pd9.into_alternate(),
70-
gpiod.pd10.into_alternate(),
56+
gpiod.pd14.into(),
57+
gpiod.pd15.into(),
58+
gpiod.pd0.into(),
59+
gpiod.pd1.into(),
60+
gpioe.pe7.into(),
61+
gpioe.pe8.into(),
62+
gpioe.pe9.into(),
63+
gpioe.pe10.into(),
64+
gpioe.pe11.into(),
65+
gpioe.pe12.into(),
66+
gpioe.pe13.into(),
67+
gpioe.pe14.into(),
68+
gpioe.pe15.into(),
69+
gpiod.pd8.into(),
70+
gpiod.pd9.into(),
71+
gpiod.pd10.into(),
7172
),
72-
address: gpiof.pf0.into_alternate(),
73-
read_enable: gpiod.pd4.into_alternate(),
74-
write_enable: gpiod.pd5.into_alternate(),
75-
chip_select: ChipSelect1(gpiod.pd7.into_alternate()),
73+
address: alt::Address::from(gpiof.pf0),
74+
read_enable: gpiod.pd4.into(),
75+
write_enable: gpiod.pd5.into(),
76+
chip_select: alt::ChipSelect1::from(gpiod.pd7),
7677
};
7778
let lcd_reset = gpiod.pd11.into_push_pull_output();
7879
let backlight_control = gpiof.pf5.into_push_pull_output();

src/fsmc_lcd/mod.rs

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,7 @@ mod timing;
6565

6666
use core::marker::PhantomData;
6767

68-
pub use self::pins::{
69-
AddressPins, ChipSelect1, ChipSelect2, ChipSelect3, ChipSelect4, ChipSelectPins, DataPins,
70-
LcdPins, PinAddress, PinChipSelect1, PinChipSelect2, PinChipSelect3, PinChipSelect4, PinD0,
71-
PinD1, PinD10, PinD11, PinD12, PinD13, PinD14, PinD15, PinD2, PinD3, PinD4, PinD5, PinD6,
72-
PinD7, PinD8, PinD9, PinReadEnable, PinWriteEnable, Pins,
73-
};
68+
pub use self::pins::{AddressPins, ChipSelectPins, DataPins, LcdPins, Pins};
7469
pub use self::timing::{AccessMode, Timing};
7570

7671
use crate::pac::RCC;
@@ -157,39 +152,39 @@ where
157152
/// ```ignore
158153
/// let lcd_pins = LcdPins {
159154
/// data: (
160-
/// gpiod.pd14.into_alternate_af12(),
161-
/// gpiod.pd15.into_alternate_af12(),
162-
/// gpiod.pd0.into_alternate_af12(),
163-
/// gpiod.pd1.into_alternate_af12(),
164-
/// gpioe.pe7.into_alternate_af12(),
165-
/// gpioe.pe8.into_alternate_af12(),
166-
/// gpioe.pe9.into_alternate_af12(),
167-
/// gpioe.pe10.into_alternate_af12(),
168-
/// gpioe.pe11.into_alternate_af12(),
169-
/// gpioe.pe12.into_alternate_af12(),
170-
/// gpioe.pe13.into_alternate_af12(),
171-
/// gpioe.pe14.into_alternate_af12(),
172-
/// gpioe.pe15.into_alternate_af12(),
173-
/// gpiod.pd8.into_alternate_af12(),
174-
/// gpiod.pd9.into_alternate_af12(),
175-
/// gpiod.pd10.into_alternate_af12(),
155+
/// gpiod.pd14.into(),
156+
/// gpiod.pd15.into(),
157+
/// gpiod.pd0.into(),
158+
/// gpiod.pd1.into(),
159+
/// gpioe.pe7.into(),
160+
/// gpioe.pe8.into(),
161+
/// gpioe.pe9.into(),
162+
/// gpioe.pe10.into(),
163+
/// gpioe.pe11.into(),
164+
/// gpioe.pe12.into(),
165+
/// gpioe.pe13.into(),
166+
/// gpioe.pe14.into(),
167+
/// gpioe.pe15.into(),
168+
/// gpiod.pd8.into(),
169+
/// gpiod.pd9.into(),
170+
/// gpiod.pd10.into(),
176171
/// ),
177172
/// // Four address pins, one for each LCD
178173
/// // All of them will have the same output
179174
/// address: (
180-
/// gpiof.pf0.into_alternate_af12(),
181-
/// gpioe.pe2.into_alternate_af12(),
182-
/// gpioe.pe3.into_alternate_af12(),
183-
/// gpiof.pf14.into_alternate_af12(),
175+
/// gpiof.pf0.into(),
176+
/// gpioe.pe2.into(),
177+
/// gpioe.pe3.into(),
178+
/// gpiof.pf14.into(),
184179
/// ),
185-
/// read_enable: gpiod.pd4.into_alternate_af12(),
186-
/// write_enable: gpiod.pd5.into_alternate_af12(),
180+
/// read_enable: gpiod.pd4.into(),
181+
/// write_enable: gpiod.pd5.into(),
187182
/// // Four chip select pins, one for each LCD, controlled independently
188183
/// chip_select: (
189-
/// ChipSelect1(gpiod.pd7.into_alternate_af12()),
190-
/// ChipSelect2(gpiog.pg9.into_alternate_af12()),
191-
/// ChipSelect3(gpiog.pg10.into_alternate_af12()),
192-
/// ChipSelect4(gpiog.pg12.into_alternate_af12()),
184+
/// ChipSelect1::from(gpiod.pd7),
185+
/// ChipSelect2::from(gpiog.pg9),
186+
/// ChipSelect3::from(gpiog.pg10),
187+
/// ChipSelect4::from(gpiog.pg12),
193188
/// ),
194189
/// };
195190
///

0 commit comments

Comments
 (0)