@@ -15,16 +15,27 @@ use crate::{
1515 typelevel:: Sealed ,
1616} ;
1717
18+ mod non_blocking;
19+
1820const PIO_INSTRUCTION_COUNT : usize = 32 ;
1921
2022impl Sealed for PIO0 { }
2123impl Sealed for PIO1 { }
2224
2325/// PIO Instance
2426pub trait PIOExt : Deref < Target = RegisterBlock > + SubsystemReset + Sized + Send + Sealed {
27+ /// RX FIFO depth
28+ const RX_FIFO_DEPTH : usize ;
29+
30+ /// TX FIFO depth
31+ const TX_FIFO_DEPTH : usize ;
32+
2533 /// Associated Pin Function.
2634 type PinFunction : Function ;
2735
36+ /// Returns a pointer to the PIO’s Register Block
37+ fn ptr ( ) -> * const RegisterBlock ;
38+
2839 /// Create a new PIO wrapper and split the state machines into individual objects.
2940 #[ allow( clippy:: type_complexity) ] // Required for symmetry with PIO::free().
3041 fn split (
@@ -77,13 +88,23 @@ pub trait PIOExt: Deref<Target = RegisterBlock> + SubsystemReset + Sized + Send
7788}
7889
7990impl PIOExt for PIO0 {
91+ const RX_FIFO_DEPTH : usize = 4 ;
92+ const TX_FIFO_DEPTH : usize = 4 ;
8093 type PinFunction = FunctionPio0 ;
94+ fn ptr ( ) -> * const RegisterBlock {
95+ PIO0 :: ptr ( )
96+ }
8197 fn id ( ) -> usize {
8298 0
8399 }
84100}
85101impl PIOExt for PIO1 {
102+ const RX_FIFO_DEPTH : usize = 4 ;
103+ const TX_FIFO_DEPTH : usize = 4 ;
86104 type PinFunction = FunctionPio1 ;
105+ fn ptr ( ) -> * const RegisterBlock {
106+ PIO1 :: ptr ( )
107+ }
87108 fn id ( ) -> usize {
88109 1
89110 }
@@ -586,9 +607,9 @@ pub struct Running;
586607#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
587608pub enum PioIRQ {
588609 #[ allow( missing_docs) ]
589- Irq0 ,
610+ Irq0 = 0 ,
590611 #[ allow( missing_docs) ]
591- Irq1 ,
612+ Irq1 = 1 ,
592613}
593614impl PioIRQ {
594615 const fn to_index ( self ) -> usize {
@@ -1392,6 +1413,32 @@ impl<SM: ValidStateMachine, RxSize: TransferSize> Rx<SM, RxSize> {
13921413 unsafe { self . block ( ) . fstat ( ) . read ( ) . rxfull ( ) . bits ( ) & ( 1 << SM :: id ( ) ) != 0 }
13931414 }
13941415
1416+ /// Reads the number of word in the fifo
1417+ pub fn fifo_level ( & self ) -> usize {
1418+ // Safety: read-only access without side-effect
1419+ let flevel = unsafe { self . block ( ) . flevel ( ) . read ( ) } ;
1420+ ( match SM :: id ( ) {
1421+ 0 => flevel. rx0 ( ) . bits ( ) ,
1422+ 1 => flevel. rx1 ( ) . bits ( ) ,
1423+ 2 => flevel. rx2 ( ) . bits ( ) ,
1424+ 3 => flevel. rx3 ( ) . bits ( ) ,
1425+ _ => unreachable ! ( ) ,
1426+ } ) as usize
1427+ }
1428+
1429+ /// Returns the FIFO depth.
1430+ pub fn fifo_depth ( & self ) -> usize {
1431+ // Safety: read-only access without side-effect
1432+ let block = unsafe { self . block ( ) } ;
1433+ let join_rx = block. sm ( SM :: id ( ) ) . sm_shiftctrl ( ) . read ( ) . fjoin_rx ( ) . bit ( ) ;
1434+ let depth = block. dbg_cfginfo ( ) . read ( ) . fifo_depth ( ) . bits ( ) as usize ;
1435+ if join_rx {
1436+ depth * 2
1437+ } else {
1438+ depth
1439+ }
1440+ }
1441+
13951442 /// Enable RX FIFO not empty interrupt.
13961443 ///
13971444 /// This interrupt is raised when the RX FIFO is not empty, i.e. one could read more data from it.
@@ -1510,7 +1557,7 @@ impl<SM: ValidStateMachine, TxSize: TransferSize> Tx<SM, TxSize> {
15101557 /// This is a value between 0 and 39. Each FIFO on each state machine on
15111558 /// each PIO has a unique value.
15121559 pub fn dreq_value ( & self ) -> u8 {
1513- if self . block as usize == 0x5020_0000usize {
1560+ if self . block == PIO0 :: ptr ( ) {
15141561 TREQ_SEL_A :: PIO0_TX0 as u8 + ( SM :: id ( ) as u8 )
15151562 } else {
15161563 TREQ_SEL_A :: PIO1_TX0 as u8 + ( SM :: id ( ) as u8 )
@@ -1600,6 +1647,32 @@ impl<SM: ValidStateMachine, TxSize: TransferSize> Tx<SM, TxSize> {
16001647 unsafe { self . block ( ) . fstat ( ) . read ( ) . txfull ( ) . bits ( ) & ( 1 << SM :: id ( ) ) != 0 }
16011648 }
16021649
1650+ /// Reads the number of word in the FIFO
1651+ pub fn fifo_level ( & self ) -> usize {
1652+ // Safety: read-only access without side-effect
1653+ let flevel = unsafe { self . block ( ) . flevel ( ) . read ( ) } ;
1654+ ( match SM :: id ( ) {
1655+ 0 => flevel. tx0 ( ) . bits ( ) ,
1656+ 1 => flevel. tx1 ( ) . bits ( ) ,
1657+ 2 => flevel. tx2 ( ) . bits ( ) ,
1658+ 3 => flevel. tx3 ( ) . bits ( ) ,
1659+ _ => unreachable ! ( ) ,
1660+ } ) as usize
1661+ }
1662+
1663+ /// Returns the FIFO depth.
1664+ pub fn fifo_depth ( & self ) -> usize {
1665+ // Safety: read-only access without side-effect
1666+ let block = unsafe { self . block ( ) } ;
1667+ let join_tx = block. sm ( SM :: id ( ) ) . sm_shiftctrl ( ) . read ( ) . fjoin_tx ( ) . bit ( ) ;
1668+ let depth = block. dbg_cfginfo ( ) . read ( ) . fifo_depth ( ) . bits ( ) as usize ;
1669+ if join_tx {
1670+ depth * 2
1671+ } else {
1672+ depth
1673+ }
1674+ }
1675+
16031676 /// Enable TX FIFO not full interrupt.
16041677 ///
16051678 /// This interrupt is raised when the TX FIFO is not full, i.e. one could push more data to it.
0 commit comments