Merge pull request #3865 from embassy-rs/pio2

rp/pio: update pio-rs, reexport, move instr methods to SM.
This commit is contained in:
Dario Nieuwenhuis 2025-02-18 22:02:20 +01:00 committed by GitHub
commit f3b98a8748
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 137 additions and 133 deletions

View File

@ -12,8 +12,6 @@ documentation = "https://docs.embassy.dev/cyw43-pio"
[dependencies] [dependencies]
cyw43 = { version = "0.3.0", path = "../cyw43" } cyw43 = { version = "0.3.0", path = "../cyw43" }
embassy-rp = { version = "0.3.0", path = "../embassy-rp" } embassy-rp = { version = "0.3.0", path = "../embassy-rp" }
pio-proc = { git = "https://github.com/rp-rs/pio-rs", rev = "fa586448b0b223217eec8c92c19fe6823dd04cc4" }
pio = { git = "https://github.com/rp-rs/pio-rs", rev = "fa586448b0b223217eec8c92c19fe6823dd04cc4" }
fixed = "1.23.1" fixed = "1.23.1"
defmt = { version = "0.3", optional = true } defmt = { version = "0.3", optional = true }

View File

@ -8,11 +8,11 @@ use core::slice;
use cyw43::SpiBusCyw43; use cyw43::SpiBusCyw43;
use embassy_rp::dma::Channel; use embassy_rp::dma::Channel;
use embassy_rp::gpio::{Drive, Level, Output, Pull, SlewRate}; use embassy_rp::gpio::{Drive, Level, Output, Pull, SlewRate};
use embassy_rp::pio::{instr, Common, Config, Direction, Instance, Irq, PioPin, ShiftDirection, StateMachine}; use embassy_rp::pio::program::pio_asm;
use embassy_rp::pio::{Common, Config, Direction, Instance, Irq, PioPin, ShiftDirection, StateMachine};
use embassy_rp::{Peripheral, PeripheralRef}; use embassy_rp::{Peripheral, PeripheralRef};
use fixed::types::extra::U8; use fixed::types::extra::U8;
use fixed::FixedU32; use fixed::FixedU32;
use pio_proc::pio_asm;
/// SPI comms driven by PIO. /// SPI comms driven by PIO.
pub struct PioSpi<'d, PIO: Instance, const SM: usize, DMA> { pub struct PioSpi<'d, PIO: Instance, const SM: usize, DMA> {
@ -161,10 +161,10 @@ where
defmt::trace!("write={} read={}", write_bits, read_bits); defmt::trace!("write={} read={}", write_bits, read_bits);
unsafe { unsafe {
instr::set_x(&mut self.sm, write_bits as u32); self.sm.set_x(write_bits as u32);
instr::set_y(&mut self.sm, read_bits as u32); self.sm.set_y(read_bits as u32);
instr::set_pindir(&mut self.sm, 0b1); self.sm.set_pindir(0b1);
instr::exec_jmp(&mut self.sm, self.wrap_target); self.sm.exec_jmp(self.wrap_target);
} }
self.sm.set_enable(true); self.sm.set_enable(true);
@ -192,10 +192,10 @@ where
defmt::trace!("cmd_read cmd = {:02x} len = {}", cmd, read.len()); defmt::trace!("cmd_read cmd = {:02x} len = {}", cmd, read.len());
unsafe { unsafe {
instr::set_y(&mut self.sm, read_bits as u32); self.sm.set_y(read_bits as u32);
instr::set_x(&mut self.sm, write_bits as u32); self.sm.set_x(write_bits as u32);
instr::set_pindir(&mut self.sm, 0b1); self.sm.set_pindir(0b1);
instr::exec_jmp(&mut self.sm, self.wrap_target); self.sm.exec_jmp(self.wrap_target);
} }
// self.cs.set_low(); // self.cs.set_low();

View File

@ -157,15 +157,14 @@ embedded-storage-async = { version = "0.4.1" }
rand_core = "0.6.4" rand_core = "0.6.4"
fixed = "1.28.0" fixed = "1.28.0"
rp-pac = { version = "7.0.0", feature = ["rt"] } rp-pac = { version = "7.0.0" }
embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] }
embedded-hal-1 = { package = "embedded-hal", version = "1.0" } embedded-hal-1 = { package = "embedded-hal", version = "1.0" }
embedded-hal-async = { version = "1.0" } embedded-hal-async = { version = "1.0" }
embedded-hal-nb = { version = "1.0" } embedded-hal-nb = { version = "1.0" }
pio-proc = { git = "https://github.com/rp-rs/pio-rs", rev = "fa586448b0b223217eec8c92c19fe6823dd04cc4" } pio = { git = "https://github.com/rp-rs/pio-rs", rev = "506a51b9bc135845e8544a0debd75847b73754dc" }
pio = { git = "https://github.com/rp-rs/pio-rs", rev = "fa586448b0b223217eec8c92c19fe6823dd04cc4" }
rp2040-boot2 = "0.3" rp2040-boot2 = "0.3"
document-features = "0.2.10" document-features = "0.2.10"
sha2-const-stable = "0.1" sha2-const-stable = "0.1"

View File

@ -3,99 +3,101 @@ use pio::{InSource, InstructionOperands, JmpCondition, OutDestination, SetDestin
use crate::pio::{Instance, StateMachine}; use crate::pio::{Instance, StateMachine};
/// Set value of scratch register X. impl<'d, PIO: Instance, const SM: usize> StateMachine<'d, PIO, SM> {
pub unsafe fn set_x<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, value: u32) { /// Set value of scratch register X.
const OUT: u16 = InstructionOperands::OUT { pub unsafe fn set_x(&mut self, value: u32) {
destination: OutDestination::X, const OUT: u16 = InstructionOperands::OUT {
bit_count: 32, destination: OutDestination::X,
bit_count: 32,
}
.encode();
self.tx().push(value);
self.exec_instr(OUT);
} }
.encode();
sm.tx().push(value);
sm.exec_instr(OUT);
}
/// Get value of scratch register X. /// Get value of scratch register X.
pub unsafe fn get_x<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>) -> u32 { pub unsafe fn get_x(&mut self) -> u32 {
const IN: u16 = InstructionOperands::IN { const IN: u16 = InstructionOperands::IN {
source: InSource::X, source: InSource::X,
bit_count: 32, bit_count: 32,
}
.encode();
self.exec_instr(IN);
self.rx().pull()
} }
.encode();
sm.exec_instr(IN);
sm.rx().pull()
}
/// Set value of scratch register Y. /// Set value of scratch register Y.
pub unsafe fn set_y<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, value: u32) { pub unsafe fn set_y(&mut self, value: u32) {
const OUT: u16 = InstructionOperands::OUT { const OUT: u16 = InstructionOperands::OUT {
destination: OutDestination::Y, destination: OutDestination::Y,
bit_count: 32, bit_count: 32,
}
.encode();
self.tx().push(value);
self.exec_instr(OUT);
} }
.encode();
sm.tx().push(value);
sm.exec_instr(OUT);
}
/// Get value of scratch register Y. /// Get value of scratch register Y.
pub unsafe fn get_y<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>) -> u32 { pub unsafe fn get_y(&mut self) -> u32 {
const IN: u16 = InstructionOperands::IN { const IN: u16 = InstructionOperands::IN {
source: InSource::Y, source: InSource::Y,
bit_count: 32, bit_count: 32,
}
.encode();
self.exec_instr(IN);
self.rx().pull()
} }
.encode();
sm.exec_instr(IN);
sm.rx().pull() /// Set instruction for pindir destination.
} pub unsafe fn set_pindir(&mut self, data: u8) {
let set: u16 = InstructionOperands::SET {
/// Set instruction for pindir destination. destination: SetDestination::PINDIRS,
pub unsafe fn set_pindir<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u8) { data,
let set: u16 = InstructionOperands::SET { }
destination: SetDestination::PINDIRS, .encode();
data, self.exec_instr(set);
} }
.encode();
sm.exec_instr(set);
}
/// Set instruction for pin destination. /// Set instruction for pin destination.
pub unsafe fn set_pin<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u8) { pub unsafe fn set_pin(&mut self, data: u8) {
let set: u16 = InstructionOperands::SET { let set: u16 = InstructionOperands::SET {
destination: SetDestination::PINS, destination: SetDestination::PINS,
data, data,
}
.encode();
self.exec_instr(set);
} }
.encode();
sm.exec_instr(set);
}
/// Out instruction for pin destination. /// Out instruction for pin destination.
pub unsafe fn set_out_pin<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u32) { pub unsafe fn set_out_pin(&mut self, data: u32) {
const OUT: u16 = InstructionOperands::OUT { const OUT: u16 = InstructionOperands::OUT {
destination: OutDestination::PINS, destination: OutDestination::PINS,
bit_count: 32, bit_count: 32,
}
.encode();
self.tx().push(data);
self.exec_instr(OUT);
} }
.encode();
sm.tx().push(data);
sm.exec_instr(OUT);
}
/// Out instruction for pindir destination. /// Out instruction for pindir destination.
pub unsafe fn set_out_pindir<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u32) { pub unsafe fn set_out_pindir(&mut self, data: u32) {
const OUT: u16 = InstructionOperands::OUT { const OUT: u16 = InstructionOperands::OUT {
destination: OutDestination::PINDIRS, destination: OutDestination::PINDIRS,
bit_count: 32, bit_count: 32,
}
.encode();
self.tx().push(data);
self.exec_instr(OUT);
} }
.encode();
sm.tx().push(data);
sm.exec_instr(OUT);
}
/// Jump instruction to address. /// Jump instruction to address.
pub unsafe fn exec_jmp<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, to_addr: u8) { pub unsafe fn exec_jmp(&mut self, to_addr: u8) {
let jmp: u16 = InstructionOperands::JMP { let jmp: u16 = InstructionOperands::JMP {
address: to_addr, address: to_addr,
condition: JmpCondition::Always, condition: JmpCondition::Always,
}
.encode();
self.exec_instr(jmp);
} }
.encode();
sm.exec_instr(jmp);
} }

View File

@ -18,7 +18,10 @@ use crate::interrupt::typelevel::{Binding, Handler, Interrupt};
use crate::relocate::RelocatedProgram; use crate::relocate::RelocatedProgram;
use crate::{pac, peripherals, RegExt}; use crate::{pac, peripherals, RegExt};
pub mod instr; mod instr;
#[doc(inline)]
pub use pio as program;
/// Wakers for interrupts and FIFOs. /// Wakers for interrupts and FIFOs.
pub struct Wakers([AtomicWaker; 12]); pub struct Wakers([AtomicWaker; 12]);
@ -812,7 +815,7 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> {
} }
if let Some(origin) = config.origin { if let Some(origin) = config.origin {
unsafe { instr::exec_jmp(self, origin) } unsafe { self.exec_jmp(origin) }
} }
} }

View File

@ -15,7 +15,7 @@ pub struct PioHD44780CommandWordProgram<'a, PIO: Instance> {
impl<'a, PIO: Instance> PioHD44780CommandWordProgram<'a, PIO> { impl<'a, PIO: Instance> PioHD44780CommandWordProgram<'a, PIO> {
/// Load the program into the given pio /// Load the program into the given pio
pub fn new(common: &mut Common<'a, PIO>) -> Self { pub fn new(common: &mut Common<'a, PIO>) -> Self {
let prg = pio_proc::pio_asm!( let prg = pio::pio_asm!(
r#" r#"
.side_set 1 opt .side_set 1 opt
.origin 20 .origin 20
@ -46,7 +46,7 @@ impl<'a, PIO: Instance> PioHD44780CommandSequenceProgram<'a, PIO> {
/// Load the program into the given pio /// Load the program into the given pio
pub fn new(common: &mut Common<'a, PIO>) -> Self { pub fn new(common: &mut Common<'a, PIO>) -> Self {
// many side sets are only there to free up a delay bit! // many side sets are only there to free up a delay bit!
let prg = pio_proc::pio_asm!( let prg = pio::pio_asm!(
r#" r#"
.origin 27 .origin 27
.side_set 1 .side_set 1

View File

@ -16,7 +16,7 @@ pub struct PioI2sOutProgram<'a, PIO: Instance> {
impl<'a, PIO: Instance> PioI2sOutProgram<'a, PIO> { impl<'a, PIO: Instance> PioI2sOutProgram<'a, PIO> {
/// Load the program into the given pio /// Load the program into the given pio
pub fn new(common: &mut Common<'a, PIO>) -> Self { pub fn new(common: &mut Common<'a, PIO>) -> Self {
let prg = pio_proc::pio_asm!( let prg = pio::pio_asm!(
".side_set 2", ".side_set 2",
" set x, 14 side 0b01", // side 0bWB - W = Word Clock, B = Bit Clock " set x, 14 side 0b01", // side 0bWB - W = Word Clock, B = Bit Clock
"left_data:", "left_data:",

View File

@ -1,6 +1,6 @@
//! OneWire pio driver //! OneWire pio driver
use crate::pio::{self, Common, Config, Instance, LoadedProgram, PioPin, ShiftConfig, ShiftDirection, StateMachine}; use crate::pio::{Common, Config, Instance, LoadedProgram, PioPin, ShiftConfig, ShiftDirection, StateMachine};
/// This struct represents an onewire driver program /// This struct represents an onewire driver program
pub struct PioOneWireProgram<'a, PIO: Instance> { pub struct PioOneWireProgram<'a, PIO: Instance> {
@ -10,7 +10,7 @@ pub struct PioOneWireProgram<'a, PIO: Instance> {
impl<'a, PIO: Instance> PioOneWireProgram<'a, PIO> { impl<'a, PIO: Instance> PioOneWireProgram<'a, PIO> {
/// Load the program into the given pio /// Load the program into the given pio
pub fn new(common: &mut Common<'a, PIO>) -> Self { pub fn new(common: &mut Common<'a, PIO>) -> Self {
let prg = pio_proc::pio_asm!( let prg = pio::pio_asm!(
r#" r#"
.wrap_target .wrap_target
again: again:
@ -60,11 +60,11 @@ impl<'a, PIO: Instance> PioOneWireProgram<'a, PIO> {
} }
/// Pio backed OneWire driver /// Pio backed OneWire driver
pub struct PioOneWire<'d, PIO: pio::Instance, const SM: usize> { pub struct PioOneWire<'d, PIO: Instance, const SM: usize> {
sm: StateMachine<'d, PIO, SM>, sm: StateMachine<'d, PIO, SM>,
} }
impl<'d, PIO: pio::Instance, const SM: usize> PioOneWire<'d, PIO, SM> { impl<'d, PIO: Instance, const SM: usize> PioOneWire<'d, PIO, SM> {
/// Create a new instance the driver /// Create a new instance the driver
pub fn new( pub fn new(
common: &mut Common<'d, PIO>, common: &mut Common<'d, PIO>,

View File

@ -21,7 +21,7 @@ pub struct PioPwmProgram<'a, PIO: Instance> {
impl<'a, PIO: Instance> PioPwmProgram<'a, PIO> { impl<'a, PIO: Instance> PioPwmProgram<'a, PIO> {
/// Load the program into the given pio /// Load the program into the given pio
pub fn new(common: &mut Common<'a, PIO>) -> Self { pub fn new(common: &mut Common<'a, PIO>) -> Self {
let prg = pio_proc::pio_asm!( let prg = pio::pio_asm!(
".side_set 1 opt" ".side_set 1 opt"
"pull noblock side 0" "pull noblock side 0"
"mov x, osr" "mov x, osr"

View File

@ -3,7 +3,9 @@
use fixed::traits::ToFixed; use fixed::traits::ToFixed;
use crate::gpio::Pull; use crate::gpio::Pull;
use crate::pio::{self, Common, Config, FifoJoin, Instance, LoadedProgram, PioPin, ShiftDirection, StateMachine}; use crate::pio::{
Common, Config, Direction as PioDirection, FifoJoin, Instance, LoadedProgram, PioPin, ShiftDirection, StateMachine,
};
/// This struct represents an Encoder program loaded into pio instruction memory. /// This struct represents an Encoder program loaded into pio instruction memory.
pub struct PioEncoderProgram<'a, PIO: Instance> { pub struct PioEncoderProgram<'a, PIO: Instance> {
@ -13,7 +15,7 @@ pub struct PioEncoderProgram<'a, PIO: Instance> {
impl<'a, PIO: Instance> PioEncoderProgram<'a, PIO> { impl<'a, PIO: Instance> PioEncoderProgram<'a, PIO> {
/// Load the program into the given pio /// Load the program into the given pio
pub fn new(common: &mut Common<'a, PIO>) -> Self { pub fn new(common: &mut Common<'a, PIO>) -> Self {
let prg = pio_proc::pio_asm!("wait 1 pin 1", "wait 0 pin 1", "in pins, 2", "push",); let prg = pio::pio_asm!("wait 1 pin 1", "wait 0 pin 1", "in pins, 2", "push",);
let prg = common.load_program(&prg.program); let prg = common.load_program(&prg.program);
@ -39,7 +41,7 @@ impl<'d, T: Instance, const SM: usize> PioEncoder<'d, T, SM> {
let mut pin_b = pio.make_pio_pin(pin_b); let mut pin_b = pio.make_pio_pin(pin_b);
pin_a.set_pull(Pull::Up); pin_a.set_pull(Pull::Up);
pin_b.set_pull(Pull::Up); pin_b.set_pull(Pull::Up);
sm.set_pin_dirs(pio::Direction::In, &[&pin_a, &pin_b]); sm.set_pin_dirs(PioDirection::In, &[&pin_a, &pin_b]);
let mut cfg = Config::default(); let mut cfg = Config::default();
cfg.set_in_pins(&[&pin_a, &pin_b]); cfg.set_in_pins(&[&pin_a, &pin_b]);

View File

@ -16,7 +16,7 @@ pub struct PioStepperProgram<'a, PIO: Instance> {
impl<'a, PIO: Instance> PioStepperProgram<'a, PIO> { impl<'a, PIO: Instance> PioStepperProgram<'a, PIO> {
/// Load the program into the given pio /// Load the program into the given pio
pub fn new(common: &mut Common<'a, PIO>) -> Self { pub fn new(common: &mut Common<'a, PIO>) -> Self {
let prg = pio_proc::pio_asm!( let prg = pio::pio_asm!(
"pull block", "pull block",
"mov x, osr", "mov x, osr",
"pull block", "pull block",

View File

@ -19,7 +19,7 @@ pub struct PioUartTxProgram<'a, PIO: Instance> {
impl<'a, PIO: Instance> PioUartTxProgram<'a, PIO> { impl<'a, PIO: Instance> PioUartTxProgram<'a, PIO> {
/// Load the uart tx program into the given pio /// Load the uart tx program into the given pio
pub fn new(common: &mut Common<'a, PIO>) -> Self { pub fn new(common: &mut Common<'a, PIO>) -> Self {
let prg = pio_proc::pio_asm!( let prg = pio::pio_asm!(
r#" r#"
.side_set 1 opt .side_set 1 opt
@ -99,7 +99,7 @@ pub struct PioUartRxProgram<'a, PIO: Instance> {
impl<'a, PIO: Instance> PioUartRxProgram<'a, PIO> { impl<'a, PIO: Instance> PioUartRxProgram<'a, PIO> {
/// Load the uart rx program into the given pio /// Load the uart rx program into the given pio
pub fn new(common: &mut Common<'a, PIO>) -> Self { pub fn new(common: &mut Common<'a, PIO>) -> Self {
let prg = pio_proc::pio_asm!( let prg = pio::pio_asm!(
r#" r#"
; Slightly more fleshed-out 8n1 UART receiver which handles framing errors and ; Slightly more fleshed-out 8n1 UART receiver which handles framing errors and
; break conditions more gracefully. ; break conditions more gracefully.

View File

@ -55,8 +55,6 @@ embedded-storage = { version = "0.3" }
static_cell = "2.1" static_cell = "2.1"
portable-atomic = { version = "1.5", features = ["critical-section"] } portable-atomic = { version = "1.5", features = ["critical-section"] }
log = "0.4" log = "0.4"
pio-proc = { git = "https://github.com/rp-rs/pio-rs", rev = "fa586448b0b223217eec8c92c19fe6823dd04cc4" }
pio = { git = "https://github.com/rp-rs/pio-rs", rev = "fa586448b0b223217eec8c92c19fe6823dd04cc4" }
rand = { version = "0.8.5", default-features = false } rand = { version = "0.8.5", default-features = false }
embedded-sdmmc = "0.7.0" embedded-sdmmc = "0.7.0"

View File

@ -6,6 +6,7 @@ use defmt::info;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_rp::bind_interrupts; use embassy_rp::bind_interrupts;
use embassy_rp::peripherals::PIO0; use embassy_rp::peripherals::PIO0;
use embassy_rp::pio::program::pio_asm;
use embassy_rp::pio::{Common, Config, InterruptHandler, Irq, Pio, PioPin, ShiftDirection, StateMachine}; use embassy_rp::pio::{Common, Config, InterruptHandler, Irq, Pio, PioPin, ShiftDirection, StateMachine};
use fixed::traits::ToFixed; use fixed::traits::ToFixed;
use fixed_macro::types::U56F8; use fixed_macro::types::U56F8;
@ -19,7 +20,7 @@ fn setup_pio_task_sm0<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a,
// Setup sm0 // Setup sm0
// Send data serially to pin // Send data serially to pin
let prg = pio_proc::pio_asm!( let prg = pio_asm!(
".origin 16", ".origin 16",
"set pindirs, 1", "set pindirs, 1",
".wrap_target", ".wrap_target",
@ -53,7 +54,7 @@ fn setup_pio_task_sm1<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a,
// Setupm sm1 // Setupm sm1
// Read 0b10101 repeatedly until ISR is full // Read 0b10101 repeatedly until ISR is full
let prg = pio_proc::pio_asm!( let prg = pio_asm!(
// //
".origin 8", ".origin 8",
"set x, 0x15", "set x, 0x15",
@ -83,7 +84,7 @@ fn setup_pio_task_sm2<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a,
// Setup sm2 // Setup sm2
// Repeatedly trigger IRQ 3 // Repeatedly trigger IRQ 3
let prg = pio_proc::pio_asm!( let prg = pio_asm!(
".origin 0", ".origin 0",
".wrap_target", ".wrap_target",
"set x,10", "set x,10",

View File

@ -6,6 +6,7 @@ use defmt::info;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_futures::join::join; use embassy_futures::join::join;
use embassy_rp::peripherals::PIO0; use embassy_rp::peripherals::PIO0;
use embassy_rp::pio::program::pio_asm;
use embassy_rp::pio::{Config, InterruptHandler, Pio, ShiftConfig, ShiftDirection}; use embassy_rp::pio::{Config, InterruptHandler, Pio, ShiftConfig, ShiftDirection};
use embassy_rp::{bind_interrupts, Peripheral}; use embassy_rp::{bind_interrupts, Peripheral};
use fixed::traits::ToFixed; use fixed::traits::ToFixed;
@ -32,7 +33,7 @@ async fn main(_spawner: Spawner) {
.. ..
} = Pio::new(pio, Irqs); } = Pio::new(pio, Irqs);
let prg = pio_proc::pio_asm!( let prg = pio_asm!(
".origin 0", ".origin 0",
"set pindirs,1", "set pindirs,1",
".wrap_target", ".wrap_target",

View File

@ -55,8 +55,6 @@ embedded-storage = { version = "0.3" }
static_cell = "2.1" static_cell = "2.1"
portable-atomic = { version = "1.5", features = ["critical-section"] } portable-atomic = { version = "1.5", features = ["critical-section"] }
log = "0.4" log = "0.4"
pio-proc = { git = "https://github.com/rp-rs/pio-rs", rev = "fa586448b0b223217eec8c92c19fe6823dd04cc4" }
pio = { git = "https://github.com/rp-rs/pio-rs", rev = "fa586448b0b223217eec8c92c19fe6823dd04cc4" }
rand = { version = "0.8.5", default-features = false } rand = { version = "0.8.5", default-features = false }
embedded-sdmmc = "0.7.0" embedded-sdmmc = "0.7.0"

View File

@ -6,6 +6,7 @@ use defmt::info;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_rp::bind_interrupts; use embassy_rp::bind_interrupts;
use embassy_rp::peripherals::PIO0; use embassy_rp::peripherals::PIO0;
use embassy_rp::pio::program::pio_asm;
use embassy_rp::pio::{Common, Config, InterruptHandler, Irq, Pio, PioPin, ShiftDirection, StateMachine}; use embassy_rp::pio::{Common, Config, InterruptHandler, Irq, Pio, PioPin, ShiftDirection, StateMachine};
use fixed::traits::ToFixed; use fixed::traits::ToFixed;
use fixed_macro::types::U56F8; use fixed_macro::types::U56F8;
@ -19,7 +20,7 @@ fn setup_pio_task_sm0<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a,
// Setup sm0 // Setup sm0
// Send data serially to pin // Send data serially to pin
let prg = pio_proc::pio_asm!( let prg = pio_asm!(
".origin 16", ".origin 16",
"set pindirs, 1", "set pindirs, 1",
".wrap_target", ".wrap_target",
@ -53,7 +54,7 @@ fn setup_pio_task_sm1<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a,
// Setupm sm1 // Setupm sm1
// Read 0b10101 repeatedly until ISR is full // Read 0b10101 repeatedly until ISR is full
let prg = pio_proc::pio_asm!( let prg = pio_asm!(
// //
".origin 8", ".origin 8",
"set x, 0x15", "set x, 0x15",
@ -83,7 +84,7 @@ fn setup_pio_task_sm2<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a,
// Setup sm2 // Setup sm2
// Repeatedly trigger IRQ 3 // Repeatedly trigger IRQ 3
let prg = pio_proc::pio_asm!( let prg = pio_asm!(
".origin 0", ".origin 0",
".wrap_target", ".wrap_target",
"set x,10", "set x,10",

View File

@ -6,6 +6,7 @@ use defmt::info;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_futures::join::join; use embassy_futures::join::join;
use embassy_rp::peripherals::PIO0; use embassy_rp::peripherals::PIO0;
use embassy_rp::pio::program::pio_asm;
use embassy_rp::pio::{Config, InterruptHandler, Pio, ShiftConfig, ShiftDirection}; use embassy_rp::pio::{Config, InterruptHandler, Pio, ShiftConfig, ShiftDirection};
use embassy_rp::{bind_interrupts, Peripheral}; use embassy_rp::{bind_interrupts, Peripheral};
use fixed::traits::ToFixed; use fixed::traits::ToFixed;
@ -32,7 +33,7 @@ async fn main(_spawner: Spawner) {
.. ..
} = Pio::new(pio, Irqs); } = Pio::new(pio, Irqs);
let prg = pio_proc::pio_asm!( let prg = pio_asm!(
".origin 0", ".origin 0",
"set pindirs,1", "set pindirs,1",
".wrap_target", ".wrap_target",

View File

@ -8,6 +8,7 @@ use defmt::info;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_rp::gpio::Pull; use embassy_rp::gpio::Pull;
use embassy_rp::peripherals::PIO0; use embassy_rp::peripherals::PIO0;
use embassy_rp::pio::program::pio_asm;
use embassy_rp::{bind_interrupts, pio}; use embassy_rp::{bind_interrupts, pio};
use embassy_time::Timer; use embassy_time::Timer;
use fixed::traits::ToFixed; use fixed::traits::ToFixed;
@ -46,7 +47,7 @@ impl<'d, T: Instance, const SM: usize> PioEncoder<'d, T, SM> {
sm.set_pin_dirs(pio::Direction::In, &[&pin_a, &pin_b]); sm.set_pin_dirs(pio::Direction::In, &[&pin_a, &pin_b]);
let prg = pio_proc::pio_asm!( let prg = pio_asm!(
"start:" "start:"
// encoder count is stored in X // encoder count is stored in X
"mov isr, x" "mov isr, x"

View File

@ -33,8 +33,6 @@ embedded-io-async = { version = "0.6.1" }
embedded-storage = { version = "0.3" } embedded-storage = { version = "0.3" }
static_cell = "2" static_cell = "2"
portable-atomic = { version = "1.5", features = ["critical-section"] } portable-atomic = { version = "1.5", features = ["critical-section"] }
pio-proc = { git = "https://github.com/rp-rs/pio-rs", rev = "fa586448b0b223217eec8c92c19fe6823dd04cc4" }
pio = { git = "https://github.com/rp-rs/pio-rs", rev = "fa586448b0b223217eec8c92c19fe6823dd04cc4" }
rand = { version = "0.8.5", default-features = false } rand = { version = "0.8.5", default-features = false }
[profile.dev] [profile.dev]

View File

@ -6,6 +6,7 @@ use defmt::info;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_rp::bind_interrupts; use embassy_rp::bind_interrupts;
use embassy_rp::peripherals::PIO0; use embassy_rp::peripherals::PIO0;
use embassy_rp::pio::program::pio_asm;
use embassy_rp::pio::{Config, InterruptHandler, Pio}; use embassy_rp::pio::{Config, InterruptHandler, Pio};
use {defmt_rtt as _, panic_probe as _}; use {defmt_rtt as _, panic_probe as _};
@ -24,7 +25,7 @@ async fn main(_spawner: Spawner) {
.. ..
} = Pio::new(pio, Irqs); } = Pio::new(pio, Irqs);
let prg = pio_proc::pio_asm!( let prg = pio_asm!(
"irq set 0", "irq set 0",
"irq wait 0", "irq wait 0",
"irq set 1", "irq set 1",

View File

@ -6,6 +6,7 @@ use defmt::info;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_rp::bind_interrupts; use embassy_rp::bind_interrupts;
use embassy_rp::peripherals::PIO0; use embassy_rp::peripherals::PIO0;
use embassy_rp::pio::program::pio_asm;
use embassy_rp::pio::{Config, InterruptHandler, LoadError, Pio}; use embassy_rp::pio::{Config, InterruptHandler, LoadError, Pio};
use {defmt_rtt as _, panic_probe as _}; use {defmt_rtt as _, panic_probe as _};
@ -27,7 +28,7 @@ async fn main(_spawner: Spawner) {
} = Pio::new(pio, Irqs); } = Pio::new(pio, Irqs);
// load with explicit origin works // load with explicit origin works
let prg1 = pio_proc::pio_asm!( let prg1 = pio_asm!(
".origin 4" ".origin 4"
"nop", "nop",
"nop", "nop",
@ -46,15 +47,14 @@ async fn main(_spawner: Spawner) {
assert_eq!(loaded1.wrap.target, 4); assert_eq!(loaded1.wrap.target, 4);
// load without origin chooses a free space // load without origin chooses a free space
let prg2 = pio_proc::pio_asm!("nop", "nop", "nop", "nop", "nop", "nop", "nop", "irq 1", "nop", "nop",); let prg2 = pio_asm!("nop", "nop", "nop", "nop", "nop", "nop", "nop", "irq 1", "nop", "nop",);
let loaded2 = common.load_program(&prg2.program); let loaded2 = common.load_program(&prg2.program);
assert_eq!(loaded2.origin, 14); assert_eq!(loaded2.origin, 14);
assert_eq!(loaded2.wrap.source, 23); assert_eq!(loaded2.wrap.source, 23);
assert_eq!(loaded2.wrap.target, 14); assert_eq!(loaded2.wrap.target, 14);
// wrapping around the end of program space automatically works // wrapping around the end of program space automatically works
let prg3 = let prg3 = pio_asm!("nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "irq 2",);
pio_proc::pio_asm!("nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "nop", "irq 2",);
let loaded3 = common.load_program(&prg3.program); let loaded3 = common.load_program(&prg3.program);
assert_eq!(loaded3.origin, 24); assert_eq!(loaded3.origin, 24);
assert_eq!(loaded3.wrap.source, 3); assert_eq!(loaded3.wrap.source, 3);
@ -88,13 +88,13 @@ async fn main(_spawner: Spawner) {
// instruction memory is full now. all loads should fail. // instruction memory is full now. all loads should fail.
{ {
let prg = pio_proc::pio_asm!(".origin 0", "nop"); let prg = pio_asm!(".origin 0", "nop");
match common.try_load_program(&prg.program) { match common.try_load_program(&prg.program) {
Err(LoadError::AddressInUse(0)) => (), Err(LoadError::AddressInUse(0)) => (),
_ => panic!("program loaded when it shouldn't"), _ => panic!("program loaded when it shouldn't"),
}; };
let prg = pio_proc::pio_asm!("nop"); let prg = pio_asm!("nop");
match common.try_load_program(&prg.program) { match common.try_load_program(&prg.program) {
Err(LoadError::InsufficientSpace) => (), Err(LoadError::InsufficientSpace) => (),
_ => panic!("program loaded when it shouldn't"), _ => panic!("program loaded when it shouldn't"),
@ -106,13 +106,13 @@ async fn main(_spawner: Spawner) {
common.free_instr(loaded3.used_memory); common.free_instr(loaded3.used_memory);
} }
{ {
let prg = pio_proc::pio_asm!(".origin 0", "nop"); let prg = pio_asm!(".origin 0", "nop");
match common.try_load_program(&prg.program) { match common.try_load_program(&prg.program) {
Ok(_) => (), Ok(_) => (),
_ => panic!("program didn't loaded when it shouldn"), _ => panic!("program didn't loaded when it shouldn"),
}; };
let prg = pio_proc::pio_asm!("nop"); let prg = pio_asm!("nop");
match common.try_load_program(&prg.program) { match common.try_load_program(&prg.program) {
Ok(_) => (), Ok(_) => (),
_ => panic!("program didn't loaded when it shouldn"), _ => panic!("program didn't loaded when it shouldn"),