Skip to content

Commit

Permalink
Use newer GPIO API
Browse files Browse the repository at this point in the history
  • Loading branch information
ithinuel committed May 31, 2023
1 parent e0588ce commit f565818
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 170 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ embedded-hal = "0.2.6"
nb = "1.0.0"
pio = "0.2.0"
pio-proc = "0.2.0"
rp2040-hal = "0.8.0"
rp2040-hal = "0.9.0"
fugit = "0.3.5"
defmt = { version = "0.3.0", optional = true }

Expand Down
40 changes: 5 additions & 35 deletions examples/pico_spi_pio_sd_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,6 @@
//!
//! $ mkfs.fat /dev/sdj1
//!
//! In the following ASCII art the SD card is also connected to 5 strong pull up
//! resistors. I've found varying values for these, from 50kOhm, 10kOhm
//! down to 5kOhm.
//! Stronger pull up resistors will eat more amperes, but also allow faster
//! data rates.
//!
//! ```text
//! +3.3V
//! Pull Ups ->||||
//! 4x[5kOhm]
//! ||| \
//! _______________ ||| \
//! | DAT2/NC 9\---o|| \ _|USB|_
//! | S DAT3/CS 1|---o+----+------SS--\ |1 R 40|
//! | D CMD/DI 2|----o----+-----MOSI-+-\ |2 P 39|
//! | VSS1 3|-- GND | | | GND-|3 38|- GND
//! | C VDD 4|-- +3.3V | /--SCK--+-+----SPI0 SCK-|4 P 37|
//! | A CLK/SCK 5|---------+-/ | \----SPI0 TX--|5 I 36|- +3.3V
//! | R VSS2 6|-- GND | /--MISO-+------SPI0 RX--|6 C |
//! | D DAT0/DO 7|---------o-/ \------SPI0 CSn-|7 O |
//! | DAT1/IRQ 8|-[5k]- +3.3V | |
//! """""""""""""""" | |
//! | |
//! .........
//! |20 21|
//! """""""
//! Symbols:
//! - (+) crossing lines, not connected
//! - (o) connected lines
//! ```
//!
//! The example can either be used with a probe to receive debug output
//! and also the LED is used as status output. There are different blinking
//! patterns.
Expand Down Expand Up @@ -104,7 +73,7 @@ use defmt_rtt as _;
use panic_halt as _;

// Pull in any important traits
use rp_pico::hal::prelude::*;
use rp_pico::hal::{gpio::PullUp, prelude::*};

// Embed the `Hz` function/trait:
use fugit::RateExtU32;
Expand Down Expand Up @@ -191,8 +160,6 @@ fn blink_signals_loop(

#[entry]
fn main() -> ! {
info!("Program start");

// Grab our singleton objects
let mut pac = pac::Peripherals::take().unwrap();
let core = pac::CorePeripherals::take().unwrap();
Expand Down Expand Up @@ -232,11 +199,14 @@ fn main() -> ! {
// Setup a delay for the LED blink signals:
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());

// Enable internal pull up on MISO
let gpio4 = pins.gpio4.into_pull_type::<PullUp>();

// These are implicitly used by the spi driver if they are in the correct mode
let (mut pio, sm0, _, _, _) = pac.PIO0.split(&mut pac.RESETS);
let spi: spi_pio::Spi<'_, _, _, _, _, _, 8> = spi_pio::Spi::new(
(&mut pio, sm0),
(pins.gpio4, pins.gpio3, pins.gpio2),
(gpio4, pins.gpio3, pins.gpio2),
embedded_hal::spi::MODE_0,
16u32.MHz(),
clocks.peripheral_clock.freq(),
Expand Down
Loading

0 comments on commit f565818

Please sign in to comment.