aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-03-18 20:56:10 +0100
committerDario Nieuwenhuis <[email protected]>2021-03-18 21:59:35 +0100
commit456e04c79fb5070fadffa6e80832e78aec7c2e59 (patch)
treea0d544b5563bc938e0446d61e84529030b7360b3
parentc33c9b9aec99913ee04c7e43bf4753e9288d017f (diff)
Simplify spim macros
-rw-r--r--embassy-nrf/src/spim.rs67
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
217mod sealed { 217mod 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
221pub trait Instance: sealed::Instance { 225pub trait Instance: sealed::Instance {
222 type Interrupt: Interrupt; 226 type Interrupt: Interrupt;
223 fn regs(&mut self) -> &pac::spim0::RegisterBlock;
224} 227}
225 228
226impl sealed::Instance for pac::SPIM0 {} 229macro_rules! make_impl {
227impl 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")]
238impl sealed::Instance for pac::SPIM1 {} 243make_impl!(SPIM0, SPIM0_SPIS0_SPI0);
239#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] 244#[cfg(not(feature = "52810"))]
240impl Instance for pac::SPIM1 { 245make_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"))]
248impl sealed::Instance for pac::SPIM2 {} 248make_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"))]
250impl Instance for pac::SPIM2 { 251make_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"))]
258impl sealed::Instance for pac::SPIM3 {} 254make_impl!(SPIM3, SPIM3);
259#[cfg(any(feature = "52833", feature = "52840"))]
260impl Instance for pac::SPIM3 {
261 type Interrupt = interrupt::SPIM3;
262 fn regs(&mut self) -> &pac::spim0::RegisterBlock {
263 self
264 }
265}
266
267impl<T: sealed::Instance> sealed::Instance for &mut T {}
268impl<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}