diff --git a/cyw43-pio/src/lib.rs b/cyw43-pio/src/lib.rs index 5fe7af95d..b08e68307 100644 --- a/cyw43-pio/src/lib.rs +++ b/cyw43-pio/src/lib.rs @@ -8,7 +8,7 @@ use core::slice; use cyw43::SpiBusCyw43; use embassy_rp::dma::Channel; 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::{Common, Config, Direction, Instance, Irq, PioPin, ShiftDirection, StateMachine}; use embassy_rp::{Peripheral, PeripheralRef}; use fixed::types::extra::U8; use fixed::FixedU32; @@ -161,10 +161,10 @@ where defmt::trace!("write={} read={}", write_bits, read_bits); unsafe { - instr::set_x(&mut self.sm, write_bits as u32); - instr::set_y(&mut self.sm, read_bits as u32); - instr::set_pindir(&mut self.sm, 0b1); - instr::exec_jmp(&mut self.sm, self.wrap_target); + self.sm.set_x(write_bits as u32); + self.sm.set_y(read_bits as u32); + self.sm.set_pindir(0b1); + self.sm.exec_jmp(self.wrap_target); } self.sm.set_enable(true); @@ -192,10 +192,10 @@ where defmt::trace!("cmd_read cmd = {:02x} len = {}", cmd, read.len()); unsafe { - instr::set_y(&mut self.sm, read_bits as u32); - instr::set_x(&mut self.sm, write_bits as u32); - instr::set_pindir(&mut self.sm, 0b1); - instr::exec_jmp(&mut self.sm, self.wrap_target); + self.sm.set_y(read_bits as u32); + self.sm.set_x(write_bits as u32); + self.sm.set_pindir(0b1); + self.sm.exec_jmp(self.wrap_target); } // self.cs.set_low(); diff --git a/embassy-rp/src/pio/instr.rs b/embassy-rp/src/pio/instr.rs index 9a44088c6..b15d507de 100644 --- a/embassy-rp/src/pio/instr.rs +++ b/embassy-rp/src/pio/instr.rs @@ -3,99 +3,101 @@ use pio::{InSource, InstructionOperands, JmpCondition, OutDestination, SetDestin use crate::pio::{Instance, StateMachine}; -/// Set value of scratch register X. -pub unsafe fn set_x(sm: &mut StateMachine, value: u32) { - const OUT: u16 = InstructionOperands::OUT { - destination: OutDestination::X, - bit_count: 32, +impl<'d, PIO: Instance, const SM: usize> StateMachine<'d, PIO, SM> { + /// Set value of scratch register X. + pub unsafe fn set_x(&mut self, value: u32) { + const OUT: u16 = InstructionOperands::OUT { + 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. -pub unsafe fn get_x(sm: &mut StateMachine) -> u32 { - const IN: u16 = InstructionOperands::IN { - source: InSource::X, - bit_count: 32, + /// Get value of scratch register X. + pub unsafe fn get_x(&mut self) -> u32 { + const IN: u16 = InstructionOperands::IN { + source: InSource::X, + 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. -pub unsafe fn set_y(sm: &mut StateMachine, value: u32) { - const OUT: u16 = InstructionOperands::OUT { - destination: OutDestination::Y, - bit_count: 32, + /// Set value of scratch register Y. + pub unsafe fn set_y(&mut self, value: u32) { + const OUT: u16 = InstructionOperands::OUT { + destination: OutDestination::Y, + 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. -pub unsafe fn get_y(sm: &mut StateMachine) -> u32 { - const IN: u16 = InstructionOperands::IN { - source: InSource::Y, - bit_count: 32, + /// Get value of scratch register Y. + pub unsafe fn get_y(&mut self) -> u32 { + const IN: u16 = InstructionOperands::IN { + source: InSource::Y, + 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(sm: &mut StateMachine, data: u8) { - let set: u16 = InstructionOperands::SET { - destination: SetDestination::PINDIRS, - data, + /// Set instruction for pindir destination. + pub unsafe fn set_pindir(&mut self, data: u8) { + let set: u16 = InstructionOperands::SET { + destination: SetDestination::PINDIRS, + data, + } + .encode(); + self.exec_instr(set); } - .encode(); - sm.exec_instr(set); -} -/// Set instruction for pin destination. -pub unsafe fn set_pin(sm: &mut StateMachine, data: u8) { - let set: u16 = InstructionOperands::SET { - destination: SetDestination::PINS, - data, + /// Set instruction for pin destination. + pub unsafe fn set_pin(&mut self, data: u8) { + let set: u16 = InstructionOperands::SET { + destination: SetDestination::PINS, + data, + } + .encode(); + self.exec_instr(set); } - .encode(); - sm.exec_instr(set); -} -/// Out instruction for pin destination. -pub unsafe fn set_out_pin(sm: &mut StateMachine, data: u32) { - const OUT: u16 = InstructionOperands::OUT { - destination: OutDestination::PINS, - bit_count: 32, + /// Out instruction for pin destination. + pub unsafe fn set_out_pin(&mut self, data: u32) { + const OUT: u16 = InstructionOperands::OUT { + destination: OutDestination::PINS, + 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. -pub unsafe fn set_out_pindir(sm: &mut StateMachine, data: u32) { - const OUT: u16 = InstructionOperands::OUT { - destination: OutDestination::PINDIRS, - bit_count: 32, + /// Out instruction for pindir destination. + pub unsafe fn set_out_pindir(&mut self, data: u32) { + const OUT: u16 = InstructionOperands::OUT { + destination: OutDestination::PINDIRS, + 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. -pub unsafe fn exec_jmp(sm: &mut StateMachine, to_addr: u8) { - let jmp: u16 = InstructionOperands::JMP { - address: to_addr, - condition: JmpCondition::Always, + /// Jump instruction to address. + pub unsafe fn exec_jmp(&mut self, to_addr: u8) { + let jmp: u16 = InstructionOperands::JMP { + address: to_addr, + condition: JmpCondition::Always, + } + .encode(); + self.exec_instr(jmp); } - .encode(); - sm.exec_instr(jmp); } diff --git a/embassy-rp/src/pio/mod.rs b/embassy-rp/src/pio/mod.rs index 2776f9e3c..d4c0af55e 100644 --- a/embassy-rp/src/pio/mod.rs +++ b/embassy-rp/src/pio/mod.rs @@ -18,7 +18,7 @@ use crate::interrupt::typelevel::{Binding, Handler, Interrupt}; use crate::relocate::RelocatedProgram; use crate::{pac, peripherals, RegExt}; -pub mod instr; +mod instr; /// Wakers for interrupts and FIFOs. pub struct Wakers([AtomicWaker; 12]); @@ -812,7 +812,7 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> { } if let Some(origin) = config.origin { - unsafe { instr::exec_jmp(self, origin) } + unsafe { self.exec_jmp(origin) } } }