aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-rp/src/pio_programs/spi.rs21
-rw-r--r--examples/rp/src/bin/pio_spi.rs11
-rw-r--r--examples/rp/src/bin/pio_spi_async.rs13
3 files changed, 19 insertions, 26 deletions
diff --git a/embassy-rp/src/pio_programs/spi.rs b/embassy-rp/src/pio_programs/spi.rs
index 27d401fc9..a1b36c1c8 100644
--- a/embassy-rp/src/pio_programs/spi.rs
+++ b/embassy-rp/src/pio_programs/spi.rs
@@ -5,24 +5,23 @@ use core::marker::PhantomData;
5use embassy_futures::join::join; 5use embassy_futures::join::join;
6use embassy_hal_internal::Peri; 6use embassy_hal_internal::Peri;
7use embedded_hal_02::spi::{Phase, Polarity}; 7use embedded_hal_02::spi::{Phase, Polarity};
8use fixed::{traits::ToFixed, types::extra::U8}; 8use fixed::traits::ToFixed;
9use fixed::types::extra::U8;
9 10
10use crate::{ 11use crate::clocks::clk_sys_freq;
11 clocks::clk_sys_freq, 12use crate::dma::{AnyChannel, Channel};
12 dma::{AnyChannel, Channel}, 13use crate::gpio::Level;
13 gpio::Level, 14use crate::pio::{Common, Direction, Instance, LoadedProgram, PioPin, ShiftDirection, StateMachine};
14 pio::{Common, Direction, Instance, LoadedProgram, PioPin, ShiftDirection, StateMachine}, 15use crate::spi::{Async, Blocking, Mode};
15 spi::{Async, Blocking, Mode},
16};
17 16
18/// This struct represents a uart tx program loaded into pio instruction memory. 17/// This struct represents a uart tx program loaded into pio instruction memory.
19pub struct PioSpiProgram<'d, PIO: crate::pio::Instance> { 18pub struct PioSpiProgram<'d, PIO: Instance> {
20 prg: LoadedProgram<'d, PIO>, 19 prg: LoadedProgram<'d, PIO>,
21} 20}
22 21
23impl<'d, PIO: crate::pio::Instance> PioSpiProgram<'d, PIO> { 22impl<'d, PIO: Instance> PioSpiProgram<'d, PIO> {
24 /// Load the spi program into the given pio 23 /// Load the spi program into the given pio
25 pub fn new(common: &mut crate::pio::Common<'d, PIO>, phase: Phase) -> Self { 24 pub fn new(common: &mut Common<'d, PIO>, phase: Phase) -> Self {
26 // These PIO programs are taken straight from the datasheet (3.6.1 in 25 // These PIO programs are taken straight from the datasheet (3.6.1 in
27 // RP2040 datasheet, 11.6.1 in RP2350 datasheet) 26 // RP2040 datasheet, 11.6.1 in RP2350 datasheet)
28 27
diff --git a/examples/rp/src/bin/pio_spi.rs b/examples/rp/src/bin/pio_spi.rs
index 1fbe235e5..0164e4c81 100644
--- a/examples/rp/src/bin/pio_spi.rs
+++ b/examples/rp/src/bin/pio_spi.rs
@@ -9,13 +9,10 @@
9 9
10use defmt::*; 10use defmt::*;
11use embassy_executor::Spawner; 11use embassy_executor::Spawner;
12use embassy_rp::{ 12use embassy_rp::peripherals::PIO0;
13 bind_interrupts, 13use embassy_rp::pio_programs::spi::{Config, PioSpiProgram, Spi};
14 peripherals::PIO0, 14use embassy_rp::spi::Phase;
15 pio, 15use embassy_rp::{bind_interrupts, pio};
16 pio_programs::spi::{Config, PioSpiProgram, Spi},
17 spi::Phase,
18};
19use embassy_time::Timer; 16use embassy_time::Timer;
20use {defmt_rtt as _, panic_probe as _}; 17use {defmt_rtt as _, panic_probe as _};
21 18
diff --git a/examples/rp/src/bin/pio_spi_async.rs b/examples/rp/src/bin/pio_spi_async.rs
index 5abf6fc71..1dbdff609 100644
--- a/examples/rp/src/bin/pio_spi_async.rs
+++ b/examples/rp/src/bin/pio_spi_async.rs
@@ -9,13 +9,10 @@
9 9
10use defmt::*; 10use defmt::*;
11use embassy_executor::Spawner; 11use embassy_executor::Spawner;
12use embassy_rp::{ 12use embassy_rp::peripherals::PIO0;
13 bind_interrupts, 13use embassy_rp::pio_programs::spi::{Config, PioSpiProgram, Spi};
14 peripherals::PIO0, 14use embassy_rp::spi::Phase;
15 pio, 15use embassy_rp::{bind_interrupts, pio};
16 pio_programs::spi::{Config, PioSpiProgram, Spi},
17 spi::Phase,
18};
19use embassy_time::Timer; 16use embassy_time::Timer;
20use {defmt_rtt as _, panic_probe as _}; 17use {defmt_rtt as _, panic_probe as _};
21 18
@@ -32,7 +29,7 @@ async fn main(_spawner: Spawner) {
32 // use them together regardless 29 // use them together regardless
33 let mosi = p.PIN_6; // SPI0 SCLK 30 let mosi = p.PIN_6; // SPI0 SCLK
34 let miso = p.PIN_7; // SPI0 MOSI 31 let miso = p.PIN_7; // SPI0 MOSI
35 let clk = p.PIN_8; // SPI1 MISO 32 let clk = p.PIN_8; // SPI1 MISO
36 33
37 let pio::Pio { mut common, sm0, .. } = pio::Pio::new(p.PIO0, Irqs); 34 let pio::Pio { mut common, sm0, .. } = pio::Pio::new(p.PIO0, Irqs);
38 35