@@ -15,6 +15,8 @@ use crate::{
1515 typelevel:: Sealed ,
1616} ;
1717
18+ mod non_blocking;
19+
1820const PIO_INSTRUCTION_COUNT : usize = 32 ;
1921
2022impl Sealed for PIO0 { }
@@ -23,9 +25,18 @@ impl Sealed for PIO2 {}
2325
2426/// PIO Instance
2527pub trait PIOExt : Deref < Target = RegisterBlock > + SubsystemReset + Sized + Send + Sealed {
28+ /// RX FIFO depth
29+ const RX_FIFO_DEPTH : usize ;
30+
31+ /// TX FIFO depth
32+ const TX_FIFO_DEPTH : usize ;
33+
2634 /// Associated Pin Function.
2735 type PinFunction : Function ;
2836
37+ /// Returns a pointer to the PIO’s Register Block
38+ fn ptr ( ) -> * const RegisterBlock ;
39+
2940 /// Create a new PIO wrapper and split the state machines into individual objects.
3041 #[ allow( clippy:: type_complexity) ] // Required for symmetry with PIO::free().
3142 fn split (
@@ -78,18 +89,30 @@ pub trait PIOExt: Deref<Target = RegisterBlock> + SubsystemReset + Sized + Send
7889}
7990
8091impl PIOExt for PIO0 {
92+ const RX_FIFO_DEPTH : usize = 4 ;
93+ const TX_FIFO_DEPTH : usize = 4 ;
8194 type PinFunction = FunctionPio0 ;
95+ fn ptr ( ) -> * const RegisterBlock {
96+ PIO0 :: ptr ( )
97+ }
8298 fn id ( ) -> usize {
8399 0
84100 }
85101}
86102impl PIOExt for PIO1 {
103+ const RX_FIFO_DEPTH : usize = 4 ;
104+ const TX_FIFO_DEPTH : usize = 4 ;
87105 type PinFunction = FunctionPio1 ;
106+ fn ptr ( ) -> * const RegisterBlock {
107+ PIO1 :: ptr ( )
108+ }
88109 fn id ( ) -> usize {
89110 1
90111 }
91112}
92113impl PIOExt for PIO2 {
114+ const RX_FIFO_DEPTH : usize = 4 ;
115+ const TX_FIFO_DEPTH : usize = 4 ;
93116 type PinFunction = FunctionPio2 ;
94117 fn id ( ) -> usize {
95118 2
@@ -601,9 +624,9 @@ pub struct Running;
601624#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
602625pub enum PioIRQ {
603626 #[ allow( missing_docs) ]
604- Irq0 ,
627+ Irq0 = 0 ,
605628 #[ allow( missing_docs) ]
606- Irq1 ,
629+ Irq1 = 1 ,
607630}
608631impl PioIRQ {
609632 const fn to_index ( self ) -> usize {
@@ -1408,6 +1431,32 @@ impl<SM: ValidStateMachine, RxSize: TransferSize> Rx<SM, RxSize> {
14081431 unsafe { self . block ( ) . fstat ( ) . read ( ) . rxfull ( ) . bits ( ) & ( 1 << SM :: id ( ) ) != 0 }
14091432 }
14101433
1434+ /// Reads the number of word in the fifo
1435+ pub fn fifo_level ( & self ) -> usize {
1436+ // Safety: read-only access without side-effect
1437+ let flevel = unsafe { self . block ( ) . flevel ( ) . read ( ) } ;
1438+ ( match SM :: id ( ) {
1439+ 0 => flevel. rx0 ( ) . bits ( ) ,
1440+ 1 => flevel. rx1 ( ) . bits ( ) ,
1441+ 2 => flevel. rx2 ( ) . bits ( ) ,
1442+ 3 => flevel. rx3 ( ) . bits ( ) ,
1443+ _ => unreachable ! ( ) ,
1444+ } ) as usize
1445+ }
1446+
1447+ /// Returns the FIFO depth.
1448+ pub fn fifo_depth ( & self ) -> usize {
1449+ // Safety: read-only access without side-effect
1450+ let block = unsafe { self . block ( ) } ;
1451+ let join_rx = block. sm ( SM :: id ( ) ) . sm_shiftctrl ( ) . read ( ) . fjoin_rx ( ) . bit ( ) ;
1452+ let depth = block. dbg_cfginfo ( ) . read ( ) . fifo_depth ( ) . bits ( ) as usize ;
1453+ if join_rx {
1454+ depth * 2
1455+ } else {
1456+ depth
1457+ }
1458+ }
1459+
14111460 /// Enable RX FIFO not empty interrupt.
14121461 ///
14131462 /// This interrupt is raised when the RX FIFO is not empty, i.e. one could read more data from it.
@@ -1526,7 +1575,7 @@ impl<SM: ValidStateMachine, TxSize: TransferSize> Tx<SM, TxSize> {
15261575 /// This is a value between 0 and 39. Each FIFO on each state machine on
15271576 /// each PIO has a unique value.
15281577 pub fn dreq_value ( & self ) -> u8 {
1529- if self . block as usize == 0x5020_0000usize {
1578+ if self . block == PIO0 :: ptr ( ) {
15301579 TREQ_SEL_A :: PIO0_TX0 as u8 + ( SM :: id ( ) as u8 )
15311580 } else if self . block as usize == 0x5030_0000usize {
15321581 TREQ_SEL_A :: PIO1_TX0 as u8 + ( SM :: id ( ) as u8 )
@@ -1619,6 +1668,32 @@ impl<SM: ValidStateMachine, TxSize: TransferSize> Tx<SM, TxSize> {
16191668 unsafe { self . block ( ) . fstat ( ) . read ( ) . txfull ( ) . bits ( ) & ( 1 << SM :: id ( ) ) != 0 }
16201669 }
16211670
1671+ /// Reads the number of word in the FIFO
1672+ pub fn fifo_level ( & self ) -> usize {
1673+ // Safety: read-only access without side-effect
1674+ let flevel = unsafe { self . block ( ) . flevel ( ) . read ( ) } ;
1675+ ( match SM :: id ( ) {
1676+ 0 => flevel. tx0 ( ) . bits ( ) ,
1677+ 1 => flevel. tx1 ( ) . bits ( ) ,
1678+ 2 => flevel. tx2 ( ) . bits ( ) ,
1679+ 3 => flevel. tx3 ( ) . bits ( ) ,
1680+ _ => unreachable ! ( ) ,
1681+ } ) as usize
1682+ }
1683+
1684+ /// Returns the FIFO depth.
1685+ pub fn fifo_depth ( & self ) -> usize {
1686+ // Safety: read-only access without side-effect
1687+ let block = unsafe { self . block ( ) } ;
1688+ let join_tx = block. sm ( SM :: id ( ) ) . sm_shiftctrl ( ) . read ( ) . fjoin_tx ( ) . bit ( ) ;
1689+ let depth = block. dbg_cfginfo ( ) . read ( ) . fifo_depth ( ) . bits ( ) as usize ;
1690+ if join_tx {
1691+ depth * 2
1692+ } else {
1693+ depth
1694+ }
1695+ }
1696+
16221697 /// Enable TX FIFO not full interrupt.
16231698 ///
16241699 /// This interrupt is raised when the TX FIFO is not full, i.e. one could push more data to it.
0 commit comments