diff options
| -rw-r--r-- | embassy-nrf/src/spim.rs | 67 |
1 files changed, 24 insertions, 43 deletions
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index ef89afbc6..b236f5387 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs | |||
| @@ -215,59 +215,40 @@ impl<U: Instance> PeripheralState for State<U> { | |||
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | mod sealed { | 217 | mod sealed { |
| 218 | pub trait Instance {} | 218 | use super::*; |
| 219 | |||
| 220 | pub trait Instance { | ||
| 221 | fn regs(&mut self) -> &pac::spim0::RegisterBlock; | ||
| 222 | } | ||
| 219 | } | 223 | } |
| 220 | 224 | ||
| 221 | pub trait Instance: sealed::Instance { | 225 | pub trait Instance: sealed::Instance { |
| 222 | type Interrupt: Interrupt; | 226 | type Interrupt: Interrupt; |
| 223 | fn regs(&mut self) -> &pac::spim0::RegisterBlock; | ||
| 224 | } | 227 | } |
| 225 | 228 | ||
| 226 | impl sealed::Instance for pac::SPIM0 {} | 229 | macro_rules! make_impl { |
| 227 | impl Instance for pac::SPIM0 { | 230 | ($SPIMx:ident, $IRQ:ident) => { |
| 228 | #[cfg(feature = "52810")] | 231 | impl sealed::Instance for pac::$SPIMx { |
| 229 | type Interrupt = interrupt::SPIM0_SPIS0_SPI0; | 232 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { |
| 230 | #[cfg(not(feature = "52810"))] | 233 | self |
| 231 | type Interrupt = interrupt::SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0; | 234 | } |
| 232 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { | 235 | } |
| 233 | self | 236 | impl Instance for pac::$SPIMx { |
| 234 | } | 237 | type Interrupt = interrupt::$IRQ; |
| 238 | } | ||
| 239 | }; | ||
| 235 | } | 240 | } |
| 236 | 241 | ||
| 237 | #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] | 242 | #[cfg(feature = "52810")] |
| 238 | impl sealed::Instance for pac::SPIM1 {} | 243 | make_impl!(SPIM0, SPIM0_SPIS0_SPI0); |
| 239 | #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] | 244 | #[cfg(not(feature = "52810"))] |
| 240 | impl Instance for pac::SPIM1 { | 245 | make_impl!(SPIM0, SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0); |
| 241 | type Interrupt = interrupt::SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1; | ||
| 242 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { | ||
| 243 | self | ||
| 244 | } | ||
| 245 | } | ||
| 246 | 246 | ||
| 247 | #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] | 247 | #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] |
| 248 | impl sealed::Instance for pac::SPIM2 {} | 248 | make_impl!(SPIM1, SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1); |
| 249 | |||
| 249 | #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] | 250 | #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] |
| 250 | impl Instance for pac::SPIM2 { | 251 | make_impl!(SPIM2, SPIM2_SPIS2_SPI2); |
| 251 | type Interrupt = interrupt::SPIM2_SPIS2_SPI2; | ||
| 252 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { | ||
| 253 | self | ||
| 254 | } | ||
| 255 | } | ||
| 256 | 252 | ||
| 257 | #[cfg(any(feature = "52833", feature = "52840"))] | 253 | #[cfg(any(feature = "52833", feature = "52840"))] |
| 258 | impl sealed::Instance for pac::SPIM3 {} | 254 | make_impl!(SPIM3, SPIM3); |
| 259 | #[cfg(any(feature = "52833", feature = "52840"))] | ||
| 260 | impl Instance for pac::SPIM3 { | ||
| 261 | type Interrupt = interrupt::SPIM3; | ||
| 262 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { | ||
| 263 | self | ||
| 264 | } | ||
| 265 | } | ||
| 266 | |||
| 267 | impl<T: sealed::Instance> sealed::Instance for &mut T {} | ||
| 268 | impl<T: Instance> Instance for &mut T { | ||
| 269 | type Interrupt = T::Interrupt; | ||
| 270 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { | ||
| 271 | T::regs(*self) | ||
| 272 | } | ||
| 273 | } | ||
