@@ -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,19 +89,34 @@ 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 ;
117+ fn ptr ( ) -> * const RegisterBlock {
118+ PIO1 :: ptr ( )
119+ }
94120 fn id ( ) -> usize {
95121 2
96122 }
@@ -601,9 +627,9 @@ pub struct Running;
601627#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
602628pub enum PioIRQ {
603629 #[ allow( missing_docs) ]
604- Irq0 ,
630+ Irq0 = 0 ,
605631 #[ allow( missing_docs) ]
606- Irq1 ,
632+ Irq1 = 1 ,
607633}
608634impl PioIRQ {
609635 const fn to_index ( self ) -> usize {
@@ -1408,6 +1434,32 @@ impl<SM: ValidStateMachine, RxSize: TransferSize> Rx<SM, RxSize> {
14081434 unsafe { self . block ( ) . fstat ( ) . read ( ) . rxfull ( ) . bits ( ) & ( 1 << SM :: id ( ) ) != 0 }
14091435 }
14101436
1437+ /// Reads the number of word in the fifo
1438+ pub fn fifo_level ( & self ) -> usize {
1439+ // Safety: read-only access without side-effect
1440+ let flevel = unsafe { self . block ( ) . flevel ( ) . read ( ) } ;
1441+ ( match SM :: id ( ) {
1442+ 0 => flevel. rx0 ( ) . bits ( ) ,
1443+ 1 => flevel. rx1 ( ) . bits ( ) ,
1444+ 2 => flevel. rx2 ( ) . bits ( ) ,
1445+ 3 => flevel. rx3 ( ) . bits ( ) ,
1446+ _ => unreachable ! ( ) ,
1447+ } ) as usize
1448+ }
1449+
1450+ /// Returns the FIFO depth.
1451+ pub fn fifo_depth ( & self ) -> usize {
1452+ // Safety: read-only access without side-effect
1453+ let block = unsafe { self . block ( ) } ;
1454+ let join_rx = block. sm ( SM :: id ( ) ) . sm_shiftctrl ( ) . read ( ) . fjoin_rx ( ) . bit ( ) ;
1455+ let depth = block. dbg_cfginfo ( ) . read ( ) . fifo_depth ( ) . bits ( ) as usize ;
1456+ if join_rx {
1457+ depth * 2
1458+ } else {
1459+ depth
1460+ }
1461+ }
1462+
14111463 /// Enable RX FIFO not empty interrupt.
14121464 ///
14131465 /// This interrupt is raised when the RX FIFO is not empty, i.e. one could read more data from it.
@@ -1526,7 +1578,7 @@ impl<SM: ValidStateMachine, TxSize: TransferSize> Tx<SM, TxSize> {
15261578 /// This is a value between 0 and 39. Each FIFO on each state machine on
15271579 /// each PIO has a unique value.
15281580 pub fn dreq_value ( & self ) -> u8 {
1529- if self . block as usize == 0x5020_0000usize {
1581+ if self . block == PIO0 :: ptr ( ) {
15301582 TREQ_SEL_A :: PIO0_TX0 as u8 + ( SM :: id ( ) as u8 )
15311583 } else if self . block as usize == 0x5030_0000usize {
15321584 TREQ_SEL_A :: PIO1_TX0 as u8 + ( SM :: id ( ) as u8 )
@@ -1619,6 +1671,32 @@ impl<SM: ValidStateMachine, TxSize: TransferSize> Tx<SM, TxSize> {
16191671 unsafe { self . block ( ) . fstat ( ) . read ( ) . txfull ( ) . bits ( ) & ( 1 << SM :: id ( ) ) != 0 }
16201672 }
16211673
1674+ /// Reads the number of word in the FIFO
1675+ pub fn fifo_level ( & self ) -> usize {
1676+ // Safety: read-only access without side-effect
1677+ let flevel = unsafe { self . block ( ) . flevel ( ) . read ( ) } ;
1678+ ( match SM :: id ( ) {
1679+ 0 => flevel. tx0 ( ) . bits ( ) ,
1680+ 1 => flevel. tx1 ( ) . bits ( ) ,
1681+ 2 => flevel. tx2 ( ) . bits ( ) ,
1682+ 3 => flevel. tx3 ( ) . bits ( ) ,
1683+ _ => unreachable ! ( ) ,
1684+ } ) as usize
1685+ }
1686+
1687+ /// Returns the FIFO depth.
1688+ pub fn fifo_depth ( & self ) -> usize {
1689+ // Safety: read-only access without side-effect
1690+ let block = unsafe { self . block ( ) } ;
1691+ let join_tx = block. sm ( SM :: id ( ) ) . sm_shiftctrl ( ) . read ( ) . fjoin_tx ( ) . bit ( ) ;
1692+ let depth = block. dbg_cfginfo ( ) . read ( ) . fifo_depth ( ) . bits ( ) as usize ;
1693+ if join_tx {
1694+ depth * 2
1695+ } else {
1696+ depth
1697+ }
1698+ }
1699+
16221700 /// Enable TX FIFO not full interrupt.
16231701 ///
16241702 /// This interrupt is raised when the TX FIFO is not full, i.e. one could push more data to it.
0 commit comments