rp/pio: drop Pio prefix from almost all names

it's only any good for PioPin because there it follows a pattern of gpio
pin alternate functions being named like that, everything else can just
as well be referred to as `pio::Thing`
This commit is contained in:
pennae 2023-05-03 17:16:35 +02:00
parent 4439031d43
commit 8ebe6e5f20
5 changed files with 103 additions and 103 deletions

View File

@ -96,18 +96,18 @@ pub(crate) unsafe fn init() {
/// Future that waits for TX-FIFO to become writable /// Future that waits for TX-FIFO to become writable
#[must_use = "futures do nothing unless you `.await` or poll them"] #[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct FifoOutFuture<'a, 'd, PIO: PioInstance, const SM: usize> { pub struct FifoOutFuture<'a, 'd, PIO: Instance, const SM: usize> {
sm_tx: &'a mut PioStateMachineTx<'d, PIO, SM>, sm_tx: &'a mut StateMachineTx<'d, PIO, SM>,
value: u32, value: u32,
} }
impl<'a, 'd, PIO: PioInstance, const SM: usize> FifoOutFuture<'a, 'd, PIO, SM> { impl<'a, 'd, PIO: Instance, const SM: usize> FifoOutFuture<'a, 'd, PIO, SM> {
pub fn new(sm: &'a mut PioStateMachineTx<'d, PIO, SM>, value: u32) -> Self { pub fn new(sm: &'a mut StateMachineTx<'d, PIO, SM>, value: u32) -> Self {
FifoOutFuture { sm_tx: sm, value } FifoOutFuture { sm_tx: sm, value }
} }
} }
impl<'a, 'd, PIO: PioInstance, const SM: usize> Future for FifoOutFuture<'a, 'd, PIO, SM> { impl<'a, 'd, PIO: Instance, const SM: usize> Future for FifoOutFuture<'a, 'd, PIO, SM> {
type Output = (); type Output = ();
fn poll(self: FuturePin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(self: FuturePin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
//debug!("Poll {},{}", PIO::PIO_NO, SM); //debug!("Poll {},{}", PIO::PIO_NO, SM);
@ -127,7 +127,7 @@ impl<'a, 'd, PIO: PioInstance, const SM: usize> Future for FifoOutFuture<'a, 'd,
} }
} }
impl<'a, 'd, PIO: PioInstance, const SM: usize> Drop for FifoOutFuture<'a, 'd, PIO, SM> { impl<'a, 'd, PIO: Instance, const SM: usize> Drop for FifoOutFuture<'a, 'd, PIO, SM> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
PIO::PIO.irqs(0).inte().write_clear(|m| { PIO::PIO.irqs(0).inte().write_clear(|m| {
@ -139,17 +139,17 @@ impl<'a, 'd, PIO: PioInstance, const SM: usize> Drop for FifoOutFuture<'a, 'd, P
/// Future that waits for RX-FIFO to become readable /// Future that waits for RX-FIFO to become readable
#[must_use = "futures do nothing unless you `.await` or poll them"] #[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct FifoInFuture<'a, 'd, PIO: PioInstance, const SM: usize> { pub struct FifoInFuture<'a, 'd, PIO: Instance, const SM: usize> {
sm_rx: &'a mut PioStateMachineRx<'d, PIO, SM>, sm_rx: &'a mut StateMachineRx<'d, PIO, SM>,
} }
impl<'a, 'd, PIO: PioInstance, const SM: usize> FifoInFuture<'a, 'd, PIO, SM> { impl<'a, 'd, PIO: Instance, const SM: usize> FifoInFuture<'a, 'd, PIO, SM> {
pub fn new(sm: &'a mut PioStateMachineRx<'d, PIO, SM>) -> Self { pub fn new(sm: &'a mut StateMachineRx<'d, PIO, SM>) -> Self {
FifoInFuture { sm_rx: sm } FifoInFuture { sm_rx: sm }
} }
} }
impl<'a, 'd, PIO: PioInstance, const SM: usize> Future for FifoInFuture<'a, 'd, PIO, SM> { impl<'a, 'd, PIO: Instance, const SM: usize> Future for FifoInFuture<'a, 'd, PIO, SM> {
type Output = u32; type Output = u32;
fn poll(mut self: FuturePin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(mut self: FuturePin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
//debug!("Poll {},{}", PIO::PIO_NO, SM); //debug!("Poll {},{}", PIO::PIO_NO, SM);
@ -168,7 +168,7 @@ impl<'a, 'd, PIO: PioInstance, const SM: usize> Future for FifoInFuture<'a, 'd,
} }
} }
impl<'a, 'd, PIO: PioInstance, const SM: usize> Drop for FifoInFuture<'a, 'd, PIO, SM> { impl<'a, 'd, PIO: Instance, const SM: usize> Drop for FifoInFuture<'a, 'd, PIO, SM> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
PIO::PIO.irqs(0).inte().write_clear(|m| { PIO::PIO.irqs(0).inte().write_clear(|m| {
@ -180,12 +180,12 @@ impl<'a, 'd, PIO: PioInstance, const SM: usize> Drop for FifoInFuture<'a, 'd, PI
/// Future that waits for IRQ /// Future that waits for IRQ
#[must_use = "futures do nothing unless you `.await` or poll them"] #[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct IrqFuture<'a, 'd, PIO: PioInstance> { pub struct IrqFuture<'a, 'd, PIO: Instance> {
pio: PhantomData<&'a PioIrq<'d, PIO, 0>>, pio: PhantomData<&'a Irq<'d, PIO, 0>>,
irq_no: u8, irq_no: u8,
} }
impl<'a, 'd, PIO: PioInstance> Future for IrqFuture<'a, 'd, PIO> { impl<'a, 'd, PIO: Instance> Future for IrqFuture<'a, 'd, PIO> {
type Output = (); type Output = ();
fn poll(self: FuturePin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(self: FuturePin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
//debug!("Poll {},{}", PIO::PIO_NO, SM); //debug!("Poll {},{}", PIO::PIO_NO, SM);
@ -215,7 +215,7 @@ impl<'a, 'd, PIO: PioInstance> Future for IrqFuture<'a, 'd, PIO> {
} }
} }
impl<'a, 'd, PIO: PioInstance> Drop for IrqFuture<'a, 'd, PIO> { impl<'a, 'd, PIO: Instance> Drop for IrqFuture<'a, 'd, PIO> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
PIO::PIO.irqs(0).inte().write_clear(|m| { PIO::PIO.irqs(0).inte().write_clear(|m| {
@ -225,12 +225,12 @@ impl<'a, 'd, PIO: PioInstance> Drop for IrqFuture<'a, 'd, PIO> {
} }
} }
pub struct Pin<'l, PIO: PioInstance> { pub struct Pin<'l, PIO: Instance> {
pin: PeripheralRef<'l, AnyPin>, pin: PeripheralRef<'l, AnyPin>,
pio: PhantomData<PIO>, pio: PhantomData<PIO>,
} }
impl<'l, PIO: PioInstance> Pin<'l, PIO> { impl<'l, PIO: Instance> Pin<'l, PIO> {
/// Set the pin's drive strength. /// Set the pin's drive strength.
#[inline] #[inline]
pub fn set_drive_strength(&mut self, strength: Drive) { pub fn set_drive_strength(&mut self, strength: Drive) {
@ -293,11 +293,11 @@ impl<'l, PIO: PioInstance> Pin<'l, PIO> {
} }
} }
pub struct PioStateMachineRx<'d, PIO: PioInstance, const SM: usize> { pub struct StateMachineRx<'d, PIO: Instance, const SM: usize> {
pio: PhantomData<&'d PIO>, pio: PhantomData<&'d PIO>,
} }
impl<'d, PIO: PioInstance, const SM: usize> PioStateMachineRx<'d, PIO, SM> { impl<'d, PIO: Instance, const SM: usize> StateMachineRx<'d, PIO, SM> {
pub fn empty(&self) -> bool { pub fn empty(&self) -> bool {
unsafe { PIO::PIO.fstat().read().rxempty() & (1u8 << SM) != 0 } unsafe { PIO::PIO.fstat().read().rxempty() & (1u8 << SM) != 0 }
} }
@ -370,11 +370,11 @@ impl<'d, PIO: PioInstance, const SM: usize> PioStateMachineRx<'d, PIO, SM> {
} }
} }
pub struct PioStateMachineTx<'d, PIO: PioInstance, const SM: usize> { pub struct StateMachineTx<'d, PIO: Instance, const SM: usize> {
pio: PhantomData<&'d PIO>, pio: PhantomData<&'d PIO>,
} }
impl<'d, PIO: PioInstance, const SM: usize> PioStateMachineTx<'d, PIO, SM> { impl<'d, PIO: Instance, const SM: usize> StateMachineTx<'d, PIO, SM> {
pub fn empty(&self) -> bool { pub fn empty(&self) -> bool {
unsafe { PIO::PIO.fstat().read().txempty() & (1u8 << SM) != 0 } unsafe { PIO::PIO.fstat().read().txempty() & (1u8 << SM) != 0 }
} }
@ -445,12 +445,12 @@ impl<'d, PIO: PioInstance, const SM: usize> PioStateMachineTx<'d, PIO, SM> {
} }
} }
pub struct PioStateMachine<'d, PIO: PioInstance, const SM: usize> { pub struct StateMachine<'d, PIO: Instance, const SM: usize> {
rx: PioStateMachineRx<'d, PIO, SM>, rx: StateMachineRx<'d, PIO, SM>,
tx: PioStateMachineTx<'d, PIO, SM>, tx: StateMachineTx<'d, PIO, SM>,
} }
impl<'d, PIO: PioInstance, const SM: usize> Drop for PioStateMachine<'d, PIO, SM> { impl<'d, PIO: Instance, const SM: usize> Drop for StateMachine<'d, PIO, SM> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
PIO::PIO.ctrl().write_clear(|w| w.set_sm_enable(1 << SM)); PIO::PIO.ctrl().write_clear(|w| w.set_sm_enable(1 << SM));
@ -459,7 +459,7 @@ impl<'d, PIO: PioInstance, const SM: usize> Drop for PioStateMachine<'d, PIO, SM
} }
} }
impl<'d, PIO: PioInstance + 'd, const SM: usize> PioStateMachine<'d, PIO, SM> { impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> {
#[inline(always)] #[inline(always)]
fn this_sm() -> crate::pac::pio::StateMachine { fn this_sm() -> crate::pac::pio::StateMachine {
PIO::PIO.sm(SM) PIO::PIO.sm(SM)
@ -771,35 +771,35 @@ impl<'d, PIO: PioInstance + 'd, const SM: usize> PioStateMachine<'d, PIO, SM> {
} }
} }
pub fn rx(&mut self) -> &mut PioStateMachineRx<'d, PIO, SM> { pub fn rx(&mut self) -> &mut StateMachineRx<'d, PIO, SM> {
&mut self.rx &mut self.rx
} }
pub fn tx(&mut self) -> &mut PioStateMachineTx<'d, PIO, SM> { pub fn tx(&mut self) -> &mut StateMachineTx<'d, PIO, SM> {
&mut self.tx &mut self.tx
} }
pub fn rx_tx(&mut self) -> (&mut PioStateMachineRx<'d, PIO, SM>, &mut PioStateMachineTx<'d, PIO, SM>) { pub fn rx_tx(&mut self) -> (&mut StateMachineRx<'d, PIO, SM>, &mut StateMachineTx<'d, PIO, SM>) {
(&mut self.rx, &mut self.tx) (&mut self.rx, &mut self.tx)
} }
} }
pub struct PioCommon<'d, PIO: PioInstance> { pub struct Common<'d, PIO: Instance> {
instructions_used: u32, instructions_used: u32,
pio: PhantomData<&'d PIO>, pio: PhantomData<&'d PIO>,
} }
impl<'d, PIO: PioInstance> Drop for PioCommon<'d, PIO> { impl<'d, PIO: Instance> Drop for Common<'d, PIO> {
fn drop(&mut self) { fn drop(&mut self) {
on_pio_drop::<PIO>(); on_pio_drop::<PIO>();
} }
} }
pub struct PioInstanceMemory<'d, PIO: PioInstance> { pub struct InstanceMemory<'d, PIO: Instance> {
used_mask: u32, used_mask: u32,
pio: PhantomData<&'d PIO>, pio: PhantomData<&'d PIO>,
} }
impl<'d, PIO: PioInstance> PioCommon<'d, PIO> { impl<'d, PIO: Instance> Common<'d, PIO> {
pub fn write_instr<I>(&mut self, start: usize, instrs: I) -> PioInstanceMemory<'d, PIO> pub fn write_instr<I>(&mut self, start: usize, instrs: I) -> InstanceMemory<'d, PIO>
where where
I: Iterator<Item = u16>, I: Iterator<Item = u16>,
{ {
@ -820,16 +820,16 @@ impl<'d, PIO: PioInstance> PioCommon<'d, PIO> {
used_mask |= mask; used_mask |= mask;
} }
self.instructions_used |= used_mask; self.instructions_used |= used_mask;
PioInstanceMemory { InstanceMemory {
used_mask, used_mask,
pio: PhantomData, pio: PhantomData,
} }
} }
/// Free instruction memory previously allocated with [`PioCommon::write_instr`]. /// Free instruction memory previously allocated with [`Common::write_instr`].
/// This is always possible but unsafe if any state machine is still using this /// This is always possible but unsafe if any state machine is still using this
/// bit of memory. /// bit of memory.
pub unsafe fn free_instr(&mut self, instrs: PioInstanceMemory<PIO>) { pub unsafe fn free_instr(&mut self, instrs: InstanceMemory<PIO>) {
self.instructions_used &= !instrs.used_mask; self.instructions_used &= !instrs.used_mask;
} }
@ -848,8 +848,8 @@ impl<'d, PIO: PioInstance> PioCommon<'d, PIO> {
} }
/// Register a pin for PIO usage. Pins will be released from the PIO block /// Register a pin for PIO usage. Pins will be released from the PIO block
/// (i.e., have their `FUNCSEL` reset to `NULL`) when the [`PioCommon`] *and* /// (i.e., have their `FUNCSEL` reset to `NULL`) when the [`Common`] *and*
/// all [`PioStateMachine`]s for this block have been dropped. **Other members /// all [`StateMachine`]s for this block have been dropped. **Other members
/// of [`Pio`] do not keep pin registrations alive.** /// of [`Pio`] do not keep pin registrations alive.**
pub fn make_pio_pin(&mut self, pin: impl Peripheral<P = impl PioPin + 'd> + 'd) -> Pin<'d, PIO> { pub fn make_pio_pin(&mut self, pin: impl Peripheral<P = impl PioPin + 'd> + 'd) -> Pin<'d, PIO> {
into_ref!(pin); into_ref!(pin);
@ -865,11 +865,11 @@ impl<'d, PIO: PioInstance> PioCommon<'d, PIO> {
} }
} }
pub struct PioIrq<'d, PIO: PioInstance, const N: usize> { pub struct Irq<'d, PIO: Instance, const N: usize> {
pio: PhantomData<&'d PIO>, pio: PhantomData<&'d PIO>,
} }
impl<'d, PIO: PioInstance, const N: usize> PioIrq<'d, PIO, N> { impl<'d, PIO: Instance, const N: usize> Irq<'d, PIO, N> {
pub fn wait<'a>(&'a mut self) -> IrqFuture<'a, 'd, PIO> { pub fn wait<'a>(&'a mut self) -> IrqFuture<'a, 'd, PIO> {
IrqFuture { IrqFuture {
pio: PhantomData, pio: PhantomData,
@ -879,11 +879,11 @@ impl<'d, PIO: PioInstance, const N: usize> PioIrq<'d, PIO, N> {
} }
#[derive(Clone)] #[derive(Clone)]
pub struct PioIrqFlags<'d, PIO: PioInstance> { pub struct IrqFlags<'d, PIO: Instance> {
pio: PhantomData<&'d PIO>, pio: PhantomData<&'d PIO>,
} }
impl<'d, PIO: PioInstance> PioIrqFlags<'d, PIO> { impl<'d, PIO: Instance> IrqFlags<'d, PIO> {
pub fn check(&self, irq_no: u8) -> bool { pub fn check(&self, irq_no: u8) -> bool {
assert!(irq_no < 8); assert!(irq_no < 8);
self.check_any(1 << irq_no) self.check_any(1 << irq_no)
@ -916,48 +916,48 @@ impl<'d, PIO: PioInstance> PioIrqFlags<'d, PIO> {
} }
} }
pub struct Pio<'d, PIO: PioInstance> { pub struct Pio<'d, PIO: Instance> {
pub common: PioCommon<'d, PIO>, pub common: Common<'d, PIO>,
pub irq_flags: PioIrqFlags<'d, PIO>, pub irq_flags: IrqFlags<'d, PIO>,
pub irq0: PioIrq<'d, PIO, 0>, pub irq0: Irq<'d, PIO, 0>,
pub irq1: PioIrq<'d, PIO, 1>, pub irq1: Irq<'d, PIO, 1>,
pub irq2: PioIrq<'d, PIO, 2>, pub irq2: Irq<'d, PIO, 2>,
pub irq3: PioIrq<'d, PIO, 3>, pub irq3: Irq<'d, PIO, 3>,
pub sm0: PioStateMachine<'d, PIO, 0>, pub sm0: StateMachine<'d, PIO, 0>,
pub sm1: PioStateMachine<'d, PIO, 1>, pub sm1: StateMachine<'d, PIO, 1>,
pub sm2: PioStateMachine<'d, PIO, 2>, pub sm2: StateMachine<'d, PIO, 2>,
pub sm3: PioStateMachine<'d, PIO, 3>, pub sm3: StateMachine<'d, PIO, 3>,
} }
impl<'d, PIO: PioInstance> Pio<'d, PIO> { impl<'d, PIO: Instance> Pio<'d, PIO> {
pub fn new(_pio: impl Peripheral<P = PIO> + 'd) -> Self { pub fn new(_pio: impl Peripheral<P = PIO> + 'd) -> Self {
PIO::state().users.store(5, Ordering::Release); PIO::state().users.store(5, Ordering::Release);
PIO::state().used_pins.store(0, Ordering::Release); PIO::state().used_pins.store(0, Ordering::Release);
Self { Self {
common: PioCommon { common: Common {
instructions_used: 0, instructions_used: 0,
pio: PhantomData, pio: PhantomData,
}, },
irq_flags: PioIrqFlags { pio: PhantomData }, irq_flags: IrqFlags { pio: PhantomData },
irq0: PioIrq { pio: PhantomData }, irq0: Irq { pio: PhantomData },
irq1: PioIrq { pio: PhantomData }, irq1: Irq { pio: PhantomData },
irq2: PioIrq { pio: PhantomData }, irq2: Irq { pio: PhantomData },
irq3: PioIrq { pio: PhantomData }, irq3: Irq { pio: PhantomData },
sm0: PioStateMachine { sm0: StateMachine {
rx: PioStateMachineRx { pio: PhantomData }, rx: StateMachineRx { pio: PhantomData },
tx: PioStateMachineTx { pio: PhantomData }, tx: StateMachineTx { pio: PhantomData },
}, },
sm1: PioStateMachine { sm1: StateMachine {
rx: PioStateMachineRx { pio: PhantomData }, rx: StateMachineRx { pio: PhantomData },
tx: PioStateMachineTx { pio: PhantomData }, tx: StateMachineTx { pio: PhantomData },
}, },
sm2: PioStateMachine { sm2: StateMachine {
rx: PioStateMachineRx { pio: PhantomData }, rx: StateMachineRx { pio: PhantomData },
tx: PioStateMachineTx { pio: PhantomData }, tx: StateMachineTx { pio: PhantomData },
}, },
sm3: PioStateMachine { sm3: StateMachine {
rx: PioStateMachineRx { pio: PhantomData }, rx: StateMachineRx { pio: PhantomData },
tx: PioStateMachineTx { pio: PhantomData }, tx: StateMachineTx { pio: PhantomData },
}, },
} }
} }
@ -974,7 +974,7 @@ pub struct State {
used_pins: AtomicU32, used_pins: AtomicU32,
} }
fn on_pio_drop<PIO: PioInstance>() { fn on_pio_drop<PIO: Instance>() {
let state = PIO::state(); let state = PIO::state();
if state.users.fetch_sub(1, Ordering::AcqRel) == 1 { if state.users.fetch_sub(1, Ordering::AcqRel) == 1 {
let used_pins = state.used_pins.load(Ordering::Relaxed); let used_pins = state.used_pins.load(Ordering::Relaxed);
@ -994,7 +994,7 @@ mod sealed {
pub trait PioPin {} pub trait PioPin {}
pub trait PioInstance { pub trait Instance {
const PIO_NO: u8; const PIO_NO: u8;
const PIO: &'static crate::pac::pio::Pio; const PIO: &'static crate::pac::pio::Pio;
const FUNCSEL: crate::pac::io::vals::Gpio0ctrlFuncsel; const FUNCSEL: crate::pac::io::vals::Gpio0ctrlFuncsel;
@ -1011,16 +1011,16 @@ mod sealed {
} }
} }
pub trait PioInstance: sealed::PioInstance + Sized + Unpin {} pub trait Instance: sealed::Instance + Sized + Unpin {}
macro_rules! impl_pio { macro_rules! impl_pio {
($name:ident, $pio:expr, $pac:ident, $funcsel:ident) => { ($name:ident, $pio:expr, $pac:ident, $funcsel:ident) => {
impl sealed::PioInstance for peripherals::$name { impl sealed::Instance for peripherals::$name {
const PIO_NO: u8 = $pio; const PIO_NO: u8 = $pio;
const PIO: &'static pac::pio::Pio = &pac::$pac; const PIO: &'static pac::pio::Pio = &pac::$pac;
const FUNCSEL: pac::io::vals::Gpio0ctrlFuncsel = pac::io::vals::Gpio0ctrlFuncsel::$funcsel; const FUNCSEL: pac::io::vals::Gpio0ctrlFuncsel = pac::io::vals::Gpio0ctrlFuncsel::$funcsel;
} }
impl PioInstance for peripherals::$name {} impl Instance for peripherals::$name {}
}; };
} }

View File

@ -1,8 +1,8 @@
use pio::{InSource, InstructionOperands, JmpCondition, OutDestination, SetDestination}; use pio::{InSource, InstructionOperands, JmpCondition, OutDestination, SetDestination};
use crate::pio::{PioInstance, PioStateMachine}; use crate::pio::{Instance, StateMachine};
pub fn set_x<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>, value: u32) { pub fn set_x<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, value: u32) {
const OUT: u16 = InstructionOperands::OUT { const OUT: u16 = InstructionOperands::OUT {
destination: OutDestination::X, destination: OutDestination::X,
bit_count: 32, bit_count: 32,
@ -12,7 +12,7 @@ pub fn set_x<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM
sm.exec_instr(OUT); sm.exec_instr(OUT);
} }
pub fn get_x<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>) -> u32 { pub fn get_x<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>) -> u32 {
const IN: u16 = InstructionOperands::IN { const IN: u16 = InstructionOperands::IN {
source: InSource::X, source: InSource::X,
bit_count: 32, bit_count: 32,
@ -22,7 +22,7 @@ pub fn get_x<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM
sm.rx().pull() sm.rx().pull()
} }
pub fn set_y<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>, value: u32) { pub fn set_y<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, value: u32) {
const OUT: u16 = InstructionOperands::OUT { const OUT: u16 = InstructionOperands::OUT {
destination: OutDestination::Y, destination: OutDestination::Y,
bit_count: 32, bit_count: 32,
@ -32,7 +32,7 @@ pub fn set_y<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM
sm.exec_instr(OUT); sm.exec_instr(OUT);
} }
pub fn get_y<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>) -> u32 { pub fn get_y<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>) -> u32 {
const IN: u16 = InstructionOperands::IN { const IN: u16 = InstructionOperands::IN {
source: InSource::Y, source: InSource::Y,
bit_count: 32, bit_count: 32,
@ -43,7 +43,7 @@ pub fn get_y<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM
sm.rx().pull() sm.rx().pull()
} }
pub fn set_pindir<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>, data: u8) { pub fn set_pindir<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u8) {
let set: u16 = InstructionOperands::SET { let set: u16 = InstructionOperands::SET {
destination: SetDestination::PINDIRS, destination: SetDestination::PINDIRS,
data, data,
@ -52,7 +52,7 @@ pub fn set_pindir<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PI
sm.exec_instr(set); sm.exec_instr(set);
} }
pub fn set_pin<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>, data: u8) { pub fn set_pin<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u8) {
let set: u16 = InstructionOperands::SET { let set: u16 = InstructionOperands::SET {
destination: SetDestination::PINS, destination: SetDestination::PINS,
data, data,
@ -61,7 +61,7 @@ pub fn set_pin<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO,
sm.exec_instr(set); sm.exec_instr(set);
} }
pub fn set_out_pin<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>, data: u32) { pub fn set_out_pin<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u32) {
const OUT: u16 = InstructionOperands::OUT { const OUT: u16 = InstructionOperands::OUT {
destination: OutDestination::PINS, destination: OutDestination::PINS,
bit_count: 32, bit_count: 32,
@ -70,7 +70,7 @@ pub fn set_out_pin<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<P
sm.tx().push(data); sm.tx().push(data);
sm.exec_instr(OUT); sm.exec_instr(OUT);
} }
pub fn set_out_pindir<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>, data: u32) { pub fn set_out_pindir<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u32) {
const OUT: u16 = InstructionOperands::OUT { const OUT: u16 = InstructionOperands::OUT {
destination: OutDestination::PINDIRS, destination: OutDestination::PINDIRS,
bit_count: 32, bit_count: 32,
@ -80,7 +80,7 @@ pub fn set_out_pindir<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachin
sm.exec_instr(OUT); sm.exec_instr(OUT);
} }
pub fn exec_jmp<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>, to_addr: u8) { pub fn exec_jmp<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, 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,

View File

@ -4,12 +4,12 @@
use defmt::info; use defmt::info;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_rp::peripherals::PIO0; use embassy_rp::peripherals::PIO0;
use embassy_rp::pio::{Pio, PioCommon, PioIrq, PioPin, PioStateMachine, ShiftDirection}; use embassy_rp::pio::{Common, Irq, Pio, PioPin, ShiftDirection, StateMachine};
use embassy_rp::pio_instr_util; use embassy_rp::pio_instr_util;
use embassy_rp::relocate::RelocatedProgram; use embassy_rp::relocate::RelocatedProgram;
use {defmt_rtt as _, panic_probe as _}; use {defmt_rtt as _, panic_probe as _};
fn setup_pio_task_sm0(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachine<PIO0, 0>, pin: impl PioPin) { fn setup_pio_task_sm0(pio: &mut Common<PIO0>, sm: &mut StateMachine<PIO0, 0>, pin: impl PioPin) {
// Setup sm0 // Setup sm0
// Send data serially to pin // Send data serially to pin
@ -37,7 +37,7 @@ fn setup_pio_task_sm0(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachine<PIO0,
} }
#[embassy_executor::task] #[embassy_executor::task]
async fn pio_task_sm0(mut sm: PioStateMachine<'static, PIO0, 0>) { async fn pio_task_sm0(mut sm: StateMachine<'static, PIO0, 0>) {
sm.set_enable(true); sm.set_enable(true);
let mut v = 0x0f0caffa; let mut v = 0x0f0caffa;
@ -48,7 +48,7 @@ async fn pio_task_sm0(mut sm: PioStateMachine<'static, PIO0, 0>) {
} }
} }
fn setup_pio_task_sm1(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachine<PIO0, 1>) { fn setup_pio_task_sm1(pio: &mut Common<PIO0>, sm: &mut StateMachine<PIO0, 1>) {
// Setupm sm1 // Setupm sm1
// Read 0b10101 repeatedly until ISR is full // Read 0b10101 repeatedly until ISR is full
@ -67,7 +67,7 @@ fn setup_pio_task_sm1(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachine<PIO0,
} }
#[embassy_executor::task] #[embassy_executor::task]
async fn pio_task_sm1(mut sm: PioStateMachine<'static, PIO0, 1>) { async fn pio_task_sm1(mut sm: StateMachine<'static, PIO0, 1>) {
sm.set_enable(true); sm.set_enable(true);
loop { loop {
let rx = sm.rx().wait_pull().await; let rx = sm.rx().wait_pull().await;
@ -75,7 +75,7 @@ async fn pio_task_sm1(mut sm: PioStateMachine<'static, PIO0, 1>) {
} }
} }
fn setup_pio_task_sm2(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachine<PIO0, 2>) { fn setup_pio_task_sm2(pio: &mut Common<PIO0>, sm: &mut StateMachine<PIO0, 2>) {
// Setup sm2 // Setup sm2
// Repeatedly trigger IRQ 3 // Repeatedly trigger IRQ 3
@ -99,7 +99,7 @@ fn setup_pio_task_sm2(pio: &mut PioCommon<PIO0>, sm: &mut PioStateMachine<PIO0,
} }
#[embassy_executor::task] #[embassy_executor::task]
async fn pio_task_sm2(mut irq: PioIrq<'static, PIO0, 3>, mut sm: PioStateMachine<'static, PIO0, 2>) { async fn pio_task_sm2(mut irq: Irq<'static, PIO0, 3>, mut sm: StateMachine<'static, PIO0, 2>) {
sm.set_enable(true); sm.set_enable(true);
loop { loop {
irq.wait().await; irq.wait().await;

View File

@ -7,7 +7,7 @@ use core::fmt::Write;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_rp::dma::{AnyChannel, Channel}; use embassy_rp::dma::{AnyChannel, Channel};
use embassy_rp::peripherals::PIO0; use embassy_rp::peripherals::PIO0;
use embassy_rp::pio::{FifoJoin, Pio, PioPin, PioStateMachine, ShiftDirection}; use embassy_rp::pio::{FifoJoin, Pio, PioPin, ShiftDirection, StateMachine};
use embassy_rp::pwm::{Config, Pwm}; use embassy_rp::pwm::{Config, Pwm};
use embassy_rp::relocate::RelocatedProgram; use embassy_rp::relocate::RelocatedProgram;
use embassy_rp::{into_ref, Peripheral, PeripheralRef}; use embassy_rp::{into_ref, Peripheral, PeripheralRef};
@ -64,7 +64,7 @@ async fn main(_spawner: Spawner) {
pub struct HD44780<'l> { pub struct HD44780<'l> {
dma: PeripheralRef<'l, AnyChannel>, dma: PeripheralRef<'l, AnyChannel>,
sm: PioStateMachine<'l, PIO0, 0>, sm: StateMachine<'l, PIO0, 0>,
buf: [u8; 40], buf: [u8; 40],
} }

View File

@ -4,18 +4,18 @@
use defmt::*; use defmt::*;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_rp::pio::{FifoJoin, Pio, PioCommon, PioInstance, PioPin, PioStateMachine, ShiftDirection}; use embassy_rp::pio::{Common, FifoJoin, Instance, Pio, PioPin, ShiftDirection, StateMachine};
use embassy_rp::pio_instr_util; use embassy_rp::pio_instr_util;
use embassy_rp::relocate::RelocatedProgram; use embassy_rp::relocate::RelocatedProgram;
use embassy_time::{Duration, Timer}; use embassy_time::{Duration, Timer};
use smart_leds::RGB8; use smart_leds::RGB8;
use {defmt_rtt as _, panic_probe as _}; use {defmt_rtt as _, panic_probe as _};
pub struct Ws2812<'d, P: PioInstance, const S: usize> { pub struct Ws2812<'d, P: Instance, const S: usize> {
sm: PioStateMachine<'d, P, S>, sm: StateMachine<'d, P, S>,
} }
impl<'d, P: PioInstance, const S: usize> Ws2812<'d, P, S> { impl<'d, P: Instance, const S: usize> Ws2812<'d, P, S> {
pub fn new(mut pio: PioCommon<'d, P>, mut sm: PioStateMachine<'d, P, S>, pin: impl PioPin) -> Self { pub fn new(mut pio: Common<'d, P>, mut sm: StateMachine<'d, P, S>, pin: impl PioPin) -> Self {
// Setup sm0 // Setup sm0
// prepare the PIO program // prepare the PIO program