aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpennae <[email protected]>2023-04-25 19:28:01 +0200
committerpennae <[email protected]>2023-05-01 12:58:57 +0200
commit4618b79b22bee36ef9485a2b0e8562121b84c54b (patch)
tree4fbfc9b3c57a91137175e2202ed83463e63f4a51
parentdb16b6ff3f94e48f50c4212c164d018741b61b42 (diff)
rp/pio: seal PioInstance, SmInstance
seems prudent to hide access to the internals.
-rw-r--r--embassy-rp/src/pio.rs61
1 files changed, 41 insertions, 20 deletions
diff --git a/embassy-rp/src/pio.rs b/embassy-rp/src/pio.rs
index 3775060f0..756f0e928 100644
--- a/embassy-rp/src/pio.rs
+++ b/embassy-rp/src/pio.rs
@@ -12,6 +12,7 @@ use crate::dma::{Channel, Transfer};
12use crate::gpio::sealed::Pin as SealedPin; 12use crate::gpio::sealed::Pin as SealedPin;
13use crate::gpio::{Drive, Pin, Pull, SlewRate}; 13use crate::gpio::{Drive, Pin, Pull, SlewRate};
14use crate::pac::dma::vals::{DataSize, TreqSel}; 14use crate::pac::dma::vals::{DataSize, TreqSel};
15use crate::pio::sealed::{PioInstance as _, SmInstance as _};
15use crate::{interrupt, pac, peripherals, RegExt}; 16use crate::{interrupt, pac, peripherals, RegExt};
16 17
17struct Wakers([AtomicWaker; 12]); 18struct Wakers([AtomicWaker; 12]);
@@ -320,14 +321,13 @@ pub struct PioStateMachineInstance<PIO: PioInstance, SM: SmInstance> {
320 sm: PhantomData<SM>, 321 sm: PhantomData<SM>,
321} 322}
322 323
323impl<PIO: PioInstance, SM: SmInstance> PioStateMachine for PioStateMachineInstance<PIO, SM> { 324impl<PIO: PioInstance, SM: SmInstance> sealed::PioStateMachine for PioStateMachineInstance<PIO, SM> {
324 type Pio = PIO; 325 type Pio = PIO;
325 type Sm = SM; 326 type Sm = SM;
326} 327}
328impl<PIO: PioInstance, SM: SmInstance> PioStateMachine for PioStateMachineInstance<PIO, SM> {}
327 329
328pub trait PioStateMachine: Sized + Unpin { 330pub trait PioStateMachine: sealed::PioStateMachine + Sized + Unpin {
329 type Pio: PioInstance;
330 type Sm: SmInstance;
331 fn pio_no(&self) -> u8 { 331 fn pio_no(&self) -> u8 {
332 let _ = self; 332 let _ = self;
333 Self::Pio::PIO_NO 333 Self::Pio::PIO_NO
@@ -1027,9 +1027,10 @@ pub struct PioCommonInstance<PIO: PioInstance> {
1027 pio: PhantomData<PIO>, 1027 pio: PhantomData<PIO>,
1028} 1028}
1029 1029
1030impl<PIO: PioInstance> PioCommon for PioCommonInstance<PIO> { 1030impl<PIO: PioInstance> sealed::PioCommon for PioCommonInstance<PIO> {
1031 type Pio = PIO; 1031 type Pio = PIO;
1032} 1032}
1033impl<PIO: PioInstance> PioCommon for PioCommonInstance<PIO> {}
1033 1034
1034fn write_instr<I>(pio_no: u8, start: usize, instrs: I, mem_user: u32) 1035fn write_instr<I>(pio_no: u8, start: usize, instrs: I, mem_user: u32)
1035where 1036where
@@ -1051,9 +1052,7 @@ where
1051 } 1052 }
1052} 1053}
1053 1054
1054pub trait PioCommon: Sized { 1055pub trait PioCommon: sealed::PioCommon + Sized {
1055 type Pio: PioInstance;
1056
1057 fn write_instr<I>(&mut self, start: usize, instrs: I) 1056 fn write_instr<I>(&mut self, start: usize, instrs: I)
1058 where 1057 where
1059 I: Iterator<Item = u16>, 1058 I: Iterator<Item = u16>,
@@ -1096,16 +1095,14 @@ pub trait PioCommon: Sized {
1096// Identifies a specific state machine inside a PIO device 1095// Identifies a specific state machine inside a PIO device
1097pub struct SmInstanceBase<const SM_NO: u8> {} 1096pub struct SmInstanceBase<const SM_NO: u8> {}
1098 1097
1099pub trait SmInstance: Unpin { 1098pub trait SmInstance: sealed::SmInstance + Unpin {}
1100 const SM_NO: u8;
1101}
1102 1099
1103impl<const SM_NO: u8> SmInstance for SmInstanceBase<SM_NO> { 1100impl<const SM_NO: u8> sealed::SmInstance for SmInstanceBase<SM_NO> {
1104 const SM_NO: u8 = SM_NO; 1101 const SM_NO: u8 = SM_NO;
1105} 1102}
1103impl<const SM_NO: u8> SmInstance for SmInstanceBase<SM_NO> {}
1106 1104
1107pub trait PioPeripheral: Sized { 1105pub trait PioPeripheral: sealed::PioPeripheral + Sized {
1108 type Pio: PioInstance;
1109 fn pio(&self) -> u8 { 1106 fn pio(&self) -> u8 {
1110 let _ = self; 1107 let _ = self;
1111 Self::Pio::PIO_NO 1108 Self::Pio::PIO_NO
@@ -1145,20 +1142,43 @@ pub trait PioPeripheral: Sized {
1145 } 1142 }
1146} 1143}
1147 1144
1145mod sealed {
1146 pub trait PioInstance {
1147 const PIO_NO: u8;
1148 }
1149
1150 pub trait PioCommon {
1151 type Pio: super::PioInstance;
1152 }
1153
1154 pub trait PioStateMachine {
1155 type Pio: super::PioInstance;
1156 type Sm: super::SmInstance;
1157 }
1158
1159 pub trait SmInstance {
1160 const SM_NO: u8;
1161 }
1162
1163 pub trait PioPeripheral {
1164 type Pio: super::PioInstance;
1165 }
1166}
1167
1148// Identifies a specific PIO device 1168// Identifies a specific PIO device
1149pub struct PioInstanceBase<const PIO_NO: u8> {} 1169pub struct PioInstanceBase<const PIO_NO: u8> {}
1150 1170
1151pub trait PioInstance: Unpin { 1171pub trait PioInstance: sealed::PioInstance + Unpin {}
1152 const PIO_NO: u8;
1153}
1154 1172
1155impl PioInstance for PioInstanceBase<0> { 1173impl sealed::PioInstance for PioInstanceBase<0> {
1156 const PIO_NO: u8 = 0; 1174 const PIO_NO: u8 = 0;
1157} 1175}
1176impl PioInstance for PioInstanceBase<0> {}
1158 1177
1159impl PioInstance for PioInstanceBase<1> { 1178impl sealed::PioInstance for PioInstanceBase<1> {
1160 const PIO_NO: u8 = 1; 1179 const PIO_NO: u8 = 1;
1161} 1180}
1181impl PioInstance for PioInstanceBase<1> {}
1162 1182
1163pub type Pio0 = PioInstanceBase<0>; 1183pub type Pio0 = PioInstanceBase<0>;
1164pub type Pio1 = PioInstanceBase<1>; 1184pub type Pio1 = PioInstanceBase<1>;
@@ -1170,9 +1190,10 @@ pub type Sm3 = SmInstanceBase<3>;
1170 1190
1171macro_rules! impl_pio_sm { 1191macro_rules! impl_pio_sm {
1172 ($name:ident, $pio:expr) => { 1192 ($name:ident, $pio:expr) => {
1173 impl PioPeripheral for peripherals::$name { 1193 impl sealed::PioPeripheral for peripherals::$name {
1174 type Pio = PioInstanceBase<$pio>; 1194 type Pio = PioInstanceBase<$pio>;
1175 } 1195 }
1196 impl PioPeripheral for peripherals::$name {}
1176 }; 1197 };
1177} 1198}
1178 1199