@@ -15,6 +15,8 @@ use crate::{
15
15
typelevel:: Sealed ,
16
16
} ;
17
17
18
+ mod non_blocking;
19
+
18
20
const PIO_INSTRUCTION_COUNT : usize = 32 ;
19
21
20
22
impl Sealed for PIO0 { }
@@ -23,9 +25,18 @@ impl Sealed for PIO2 {}
23
25
24
26
/// PIO Instance
25
27
pub 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
+
26
34
/// Associated Pin Function.
27
35
type PinFunction : Function ;
28
36
37
+ /// Returns a pointer to the PIO’s Register Block
38
+ fn ptr ( ) -> * const RegisterBlock ;
39
+
29
40
/// Create a new PIO wrapper and split the state machines into individual objects.
30
41
#[ allow( clippy:: type_complexity) ] // Required for symmetry with PIO::free().
31
42
fn split (
@@ -78,13 +89,23 @@ pub trait PIOExt: Deref<Target = RegisterBlock> + SubsystemReset + Sized + Send
78
89
}
79
90
80
91
impl PIOExt for PIO0 {
92
+ const RX_FIFO_DEPTH : usize = 4 ;
93
+ const TX_FIFO_DEPTH : usize = 4 ;
81
94
type PinFunction = FunctionPio0 ;
95
+ fn ptr ( ) -> * const RegisterBlock {
96
+ PIO0 :: ptr ( )
97
+ }
82
98
fn id ( ) -> usize {
83
99
0
84
100
}
85
101
}
86
102
impl PIOExt for PIO1 {
103
+ const RX_FIFO_DEPTH : usize = 4 ;
104
+ const TX_FIFO_DEPTH : usize = 4 ;
87
105
type PinFunction = FunctionPio1 ;
106
+ fn ptr ( ) -> * const RegisterBlock {
107
+ PIO1 :: ptr ( )
108
+ }
88
109
fn id ( ) -> usize {
89
110
1
90
111
}
@@ -601,9 +622,9 @@ pub struct Running;
601
622
#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
602
623
pub enum PioIRQ {
603
624
#[ allow( missing_docs) ]
604
- Irq0 ,
625
+ Irq0 = 0 ,
605
626
#[ allow( missing_docs) ]
606
- Irq1 ,
627
+ Irq1 = 1 ,
607
628
}
608
629
impl PioIRQ {
609
630
const fn to_index ( self ) -> usize {
@@ -1408,6 +1429,32 @@ impl<SM: ValidStateMachine, RxSize: TransferSize> Rx<SM, RxSize> {
1408
1429
unsafe { self . block ( ) . fstat ( ) . read ( ) . rxfull ( ) . bits ( ) & ( 1 << SM :: id ( ) ) != 0 }
1409
1430
}
1410
1431
1432
+ /// Reads the number of word in the fifo
1433
+ pub fn fifo_level ( & self ) -> usize {
1434
+ // Safety: read-only access without side-effect
1435
+ let flevel = unsafe { self . block ( ) . flevel ( ) . read ( ) } ;
1436
+ ( match SM :: id ( ) {
1437
+ 0 => flevel. rx0 ( ) . bits ( ) ,
1438
+ 1 => flevel. rx1 ( ) . bits ( ) ,
1439
+ 2 => flevel. rx2 ( ) . bits ( ) ,
1440
+ 3 => flevel. rx3 ( ) . bits ( ) ,
1441
+ _ => unreachable ! ( ) ,
1442
+ } ) as usize
1443
+ }
1444
+
1445
+ /// Returns the FIFO depth.
1446
+ pub fn fifo_depth ( & self ) -> usize {
1447
+ // Safety: read-only access without side-effect
1448
+ let block = unsafe { self . block ( ) } ;
1449
+ let join_rx = block. sm ( SM :: id ( ) ) . sm_shiftctrl ( ) . read ( ) . fjoin_rx ( ) . bit ( ) ;
1450
+ let depth = block. dbg_cfginfo ( ) . read ( ) . fifo_depth ( ) . bits ( ) as usize ;
1451
+ if join_rx {
1452
+ depth * 2
1453
+ } else {
1454
+ depth
1455
+ }
1456
+ }
1457
+
1411
1458
/// Enable RX FIFO not empty interrupt.
1412
1459
///
1413
1460
/// This interrupt is raised when the RX FIFO is not empty, i.e. one could read more data from it.
@@ -1526,7 +1573,7 @@ impl<SM: ValidStateMachine, TxSize: TransferSize> Tx<SM, TxSize> {
1526
1573
/// This is a value between 0 and 39. Each FIFO on each state machine on
1527
1574
/// each PIO has a unique value.
1528
1575
pub fn dreq_value ( & self ) -> u8 {
1529
- if self . block as usize == 0x5020_0000usize {
1576
+ if self . block == PIO0 :: ptr ( ) {
1530
1577
TREQ_SEL_A :: PIO0_TX0 as u8 + ( SM :: id ( ) as u8 )
1531
1578
} else if self . block as usize == 0x5030_0000usize {
1532
1579
TREQ_SEL_A :: PIO1_TX0 as u8 + ( SM :: id ( ) as u8 )
@@ -1619,6 +1666,32 @@ impl<SM: ValidStateMachine, TxSize: TransferSize> Tx<SM, TxSize> {
1619
1666
unsafe { self . block ( ) . fstat ( ) . read ( ) . txfull ( ) . bits ( ) & ( 1 << SM :: id ( ) ) != 0 }
1620
1667
}
1621
1668
1669
+ /// Reads the number of word in the FIFO
1670
+ pub fn fifo_level ( & self ) -> usize {
1671
+ // Safety: read-only access without side-effect
1672
+ let flevel = unsafe { self . block ( ) . flevel ( ) . read ( ) } ;
1673
+ ( match SM :: id ( ) {
1674
+ 0 => flevel. tx0 ( ) . bits ( ) ,
1675
+ 1 => flevel. tx1 ( ) . bits ( ) ,
1676
+ 2 => flevel. tx2 ( ) . bits ( ) ,
1677
+ 3 => flevel. tx3 ( ) . bits ( ) ,
1678
+ _ => unreachable ! ( ) ,
1679
+ } ) as usize
1680
+ }
1681
+
1682
+ /// Returns the FIFO depth.
1683
+ pub fn fifo_depth ( & self ) -> usize {
1684
+ // Safety: read-only access without side-effect
1685
+ let block = unsafe { self . block ( ) } ;
1686
+ let join_tx = block. sm ( SM :: id ( ) ) . sm_shiftctrl ( ) . read ( ) . fjoin_tx ( ) . bit ( ) ;
1687
+ let depth = block. dbg_cfginfo ( ) . read ( ) . fifo_depth ( ) . bits ( ) as usize ;
1688
+ if join_tx {
1689
+ depth * 2
1690
+ } else {
1691
+ depth
1692
+ }
1693
+ }
1694
+
1622
1695
/// Enable TX FIFO not full interrupt.
1623
1696
///
1624
1697
/// This interrupt is raised when the TX FIFO is not full, i.e. one could push more data to it.
0 commit comments