diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-03-01 00:28:00 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-03-01 00:36:30 +0100 |
| commit | a30c705fd79e8f05177eaa690beac5e8c53296c1 (patch) | |
| tree | ef7e317bcc4771acbe4f85102901edd29f66d19c | |
| parent | 255bf1aa6a68193a1521ae57a841fe4a9928a1d1 (diff) | |
nrf/spim: support all chips
| -rw-r--r-- | embassy-nrf/src/spim.rs | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index ad37f0714..3c0f6e047 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs | |||
| @@ -5,7 +5,6 @@ use core::task::Poll; | |||
| 5 | use embassy::util::WakerRegistration; | 5 | use embassy::util::WakerRegistration; |
| 6 | use futures::future::poll_fn; | 6 | use futures::future::poll_fn; |
| 7 | 7 | ||
| 8 | use crate::fmt::*; | ||
| 9 | use crate::hal::gpio::Port as GpioPort; | 8 | use crate::hal::gpio::Port as GpioPort; |
| 10 | use crate::interrupt::{self, Interrupt}; | 9 | use crate::interrupt::{self, Interrupt}; |
| 11 | use crate::util::peripheral::{PeripheralMutex, PeripheralState}; | 10 | use crate::util::peripheral::{PeripheralMutex, PeripheralState}; |
| @@ -216,12 +215,6 @@ impl<U: Instance> PeripheralState for State<U> { | |||
| 216 | 215 | ||
| 217 | mod sealed { | 216 | mod sealed { |
| 218 | pub trait Instance {} | 217 | pub trait Instance {} |
| 219 | |||
| 220 | impl Instance for crate::pac::SPIM0 {} | ||
| 221 | impl Instance for crate::pac::SPIM1 {} | ||
| 222 | impl Instance for crate::pac::SPIM2 {} | ||
| 223 | impl Instance for crate::pac::SPIM3 {} | ||
| 224 | impl<T: Instance> Instance for &mut T {} | ||
| 225 | } | 218 | } |
| 226 | 219 | ||
| 227 | pub trait Instance: sealed::Instance { | 220 | pub trait Instance: sealed::Instance { |
| @@ -229,24 +222,40 @@ pub trait Instance: sealed::Instance { | |||
| 229 | fn regs(&mut self) -> &pac::spim0::RegisterBlock; | 222 | fn regs(&mut self) -> &pac::spim0::RegisterBlock; |
| 230 | } | 223 | } |
| 231 | 224 | ||
| 225 | impl sealed::Instance for pac::SPIM0 {} | ||
| 232 | impl Instance for pac::SPIM0 { | 226 | impl Instance for pac::SPIM0 { |
| 227 | #[cfg(feature = "52810")] | ||
| 228 | type Interrupt = interrupt::SPIM0_SPIS0_SPI0; | ||
| 229 | #[cfg(not(feature = "52810"))] | ||
| 233 | type Interrupt = interrupt::SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0; | 230 | type Interrupt = interrupt::SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0; |
| 234 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { | 231 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { |
| 235 | self | 232 | self |
| 236 | } | 233 | } |
| 237 | } | 234 | } |
| 235 | |||
| 236 | #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] | ||
| 237 | impl sealed::Instance for pac::SPIM1 {} | ||
| 238 | #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] | ||
| 238 | impl Instance for pac::SPIM1 { | 239 | impl Instance for pac::SPIM1 { |
| 239 | type Interrupt = interrupt::SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1; | 240 | type Interrupt = interrupt::SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1; |
| 240 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { | 241 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { |
| 241 | self | 242 | self |
| 242 | } | 243 | } |
| 243 | } | 244 | } |
| 245 | |||
| 246 | #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] | ||
| 247 | impl sealed::Instance for pac::SPIM2 {} | ||
| 248 | #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] | ||
| 244 | impl Instance for pac::SPIM2 { | 249 | impl Instance for pac::SPIM2 { |
| 245 | type Interrupt = interrupt::SPIM2_SPIS2_SPI2; | 250 | type Interrupt = interrupt::SPIM2_SPIS2_SPI2; |
| 246 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { | 251 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { |
| 247 | self | 252 | self |
| 248 | } | 253 | } |
| 249 | } | 254 | } |
| 255 | |||
| 256 | #[cfg(any(feature = "52833", feature = "52840"))] | ||
| 257 | impl sealed::Instance for pac::SPIM3 {} | ||
| 258 | #[cfg(any(feature = "52833", feature = "52840"))] | ||
| 250 | impl Instance for pac::SPIM3 { | 259 | impl Instance for pac::SPIM3 { |
| 251 | type Interrupt = interrupt::SPIM3; | 260 | type Interrupt = interrupt::SPIM3; |
| 252 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { | 261 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { |
| @@ -254,6 +263,7 @@ impl Instance for pac::SPIM3 { | |||
| 254 | } | 263 | } |
| 255 | } | 264 | } |
| 256 | 265 | ||
| 266 | impl<T: sealed::Instance> sealed::Instance for &mut T {} | ||
| 257 | impl<T: Instance> Instance for &mut T { | 267 | impl<T: Instance> Instance for &mut T { |
| 258 | type Interrupt = T::Interrupt; | 268 | type Interrupt = T::Interrupt; |
| 259 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { | 269 | fn regs(&mut self) -> &pac::spim0::RegisterBlock { |
