diff options
| -rw-r--r-- | embassy-rp/src/pio_programs/spi.rs | 21 | ||||
| -rw-r--r-- | examples/rp/src/bin/pio_spi.rs | 11 | ||||
| -rw-r--r-- | examples/rp/src/bin/pio_spi_async.rs | 13 |
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; | |||
| 5 | use embassy_futures::join::join; | 5 | use embassy_futures::join::join; |
| 6 | use embassy_hal_internal::Peri; | 6 | use embassy_hal_internal::Peri; |
| 7 | use embedded_hal_02::spi::{Phase, Polarity}; | 7 | use embedded_hal_02::spi::{Phase, Polarity}; |
| 8 | use fixed::{traits::ToFixed, types::extra::U8}; | 8 | use fixed::traits::ToFixed; |
| 9 | use fixed::types::extra::U8; | ||
| 9 | 10 | ||
| 10 | use crate::{ | 11 | use crate::clocks::clk_sys_freq; |
| 11 | clocks::clk_sys_freq, | 12 | use crate::dma::{AnyChannel, Channel}; |
| 12 | dma::{AnyChannel, Channel}, | 13 | use crate::gpio::Level; |
| 13 | gpio::Level, | 14 | use crate::pio::{Common, Direction, Instance, LoadedProgram, PioPin, ShiftDirection, StateMachine}; |
| 14 | pio::{Common, Direction, Instance, LoadedProgram, PioPin, ShiftDirection, StateMachine}, | 15 | use 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. |
| 19 | pub struct PioSpiProgram<'d, PIO: crate::pio::Instance> { | 18 | pub struct PioSpiProgram<'d, PIO: Instance> { |
| 20 | prg: LoadedProgram<'d, PIO>, | 19 | prg: LoadedProgram<'d, PIO>, |
| 21 | } | 20 | } |
| 22 | 21 | ||
| 23 | impl<'d, PIO: crate::pio::Instance> PioSpiProgram<'d, PIO> { | 22 | impl<'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 | ||
| 10 | use defmt::*; | 10 | use defmt::*; |
| 11 | use embassy_executor::Spawner; | 11 | use embassy_executor::Spawner; |
| 12 | use embassy_rp::{ | 12 | use embassy_rp::peripherals::PIO0; |
| 13 | bind_interrupts, | 13 | use embassy_rp::pio_programs::spi::{Config, PioSpiProgram, Spi}; |
| 14 | peripherals::PIO0, | 14 | use embassy_rp::spi::Phase; |
| 15 | pio, | 15 | use embassy_rp::{bind_interrupts, pio}; |
| 16 | pio_programs::spi::{Config, PioSpiProgram, Spi}, | ||
| 17 | spi::Phase, | ||
| 18 | }; | ||
| 19 | use embassy_time::Timer; | 16 | use embassy_time::Timer; |
| 20 | use {defmt_rtt as _, panic_probe as _}; | 17 | use {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 | ||
| 10 | use defmt::*; | 10 | use defmt::*; |
| 11 | use embassy_executor::Spawner; | 11 | use embassy_executor::Spawner; |
| 12 | use embassy_rp::{ | 12 | use embassy_rp::peripherals::PIO0; |
| 13 | bind_interrupts, | 13 | use embassy_rp::pio_programs::spi::{Config, PioSpiProgram, Spi}; |
| 14 | peripherals::PIO0, | 14 | use embassy_rp::spi::Phase; |
| 15 | pio, | 15 | use embassy_rp::{bind_interrupts, pio}; |
| 16 | pio_programs::spi::{Config, PioSpiProgram, Spi}, | ||
| 17 | spi::Phase, | ||
| 18 | }; | ||
| 19 | use embassy_time::Timer; | 16 | use embassy_time::Timer; |
| 20 | use {defmt_rtt as _, panic_probe as _}; | 17 | use {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 | ||
