diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-02-12 01:04:01 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-02-12 01:07:02 +0100 |
| commit | 6de02bb23e270141885e24719dc8fbca0bb97feb (patch) | |
| tree | 01d6d2d13c3df50fff429ec06190ef27ac412e3f /embassy-nrf/src/gpio.rs | |
| parent | 5ae4e20f8654bdc129d152b5364b6864457c2e02 (diff) | |
nrf: remove OptionalPin
Diffstat (limited to 'embassy-nrf/src/gpio.rs')
| -rw-r--r-- | embassy-nrf/src/gpio.rs | 54 |
1 files changed, 5 insertions, 49 deletions
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index 3f204d564..09202e2f1 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs | |||
| @@ -287,8 +287,6 @@ pub(crate) mod sealed { | |||
| 287 | unsafe { self.block().outclr.write(|w| w.bits(1u32 << self._pin())) } | 287 | unsafe { self.block().outclr.write(|w| w.bits(1u32 << self._pin())) } |
| 288 | } | 288 | } |
| 289 | } | 289 | } |
| 290 | |||
| 291 | pub trait OptionalPin {} | ||
| 292 | } | 290 | } |
| 293 | 291 | ||
| 294 | pub trait Pin: Unborrow<Target = Self> + sealed::Pin + Sized + 'static { | 292 | pub trait Pin: Unborrow<Target = Self> + sealed::Pin + Sized + 'static { |
| @@ -346,59 +344,17 @@ impl sealed::Pin for AnyPin { | |||
| 346 | 344 | ||
| 347 | // ==================== | 345 | // ==================== |
| 348 | 346 | ||
| 349 | pub trait OptionalPin: Unborrow<Target = Self> + sealed::OptionalPin + Sized { | 347 | pub(crate) trait PselBits { |
| 350 | type Pin: Pin; | 348 | fn psel_bits(&self) -> u32; |
| 351 | fn pin(&self) -> Option<&Self::Pin>; | ||
| 352 | fn pin_mut(&mut self) -> Option<&mut Self::Pin>; | ||
| 353 | |||
| 354 | #[inline] | ||
| 355 | fn psel_bits(&self) -> u32 { | ||
| 356 | self.pin().map_or(1u32 << 31, Pin::psel_bits) | ||
| 357 | } | ||
| 358 | |||
| 359 | /// Convert from concrete pin type PX_XX to type erased `Option<AnyPin>`. | ||
| 360 | #[inline] | ||
| 361 | fn degrade_optional(mut self) -> Option<AnyPin> { | ||
| 362 | self.pin_mut() | ||
| 363 | .map(|pin| unsafe { core::ptr::read(pin) }.degrade()) | ||
| 364 | } | ||
| 365 | } | 349 | } |
| 366 | 350 | ||
| 367 | impl<T: Pin> sealed::OptionalPin for T {} | 351 | impl PselBits for Option<AnyPin> { |
| 368 | impl<T: Pin> OptionalPin for T { | ||
| 369 | type Pin = T; | ||
| 370 | |||
| 371 | #[inline] | ||
| 372 | fn pin(&self) -> Option<&T> { | ||
| 373 | Some(self) | ||
| 374 | } | ||
| 375 | |||
| 376 | #[inline] | 352 | #[inline] |
| 377 | fn pin_mut(&mut self) -> Option<&mut T> { | 353 | fn psel_bits(&self) -> u32 { |
| 378 | Some(self) | 354 | self.as_ref().map_or(1u32 << 31, Pin::psel_bits) |
| 379 | } | ||
| 380 | } | ||
| 381 | |||
| 382 | #[derive(Clone, Copy, Debug)] | ||
| 383 | pub struct NoPin; | ||
| 384 | unsafe_impl_unborrow!(NoPin); | ||
| 385 | impl sealed::OptionalPin for NoPin {} | ||
| 386 | impl OptionalPin for NoPin { | ||
| 387 | type Pin = AnyPin; | ||
| 388 | |||
| 389 | #[inline] | ||
| 390 | fn pin(&self) -> Option<&AnyPin> { | ||
| 391 | None | ||
| 392 | } | ||
| 393 | |||
| 394 | #[inline] | ||
| 395 | fn pin_mut(&mut self) -> Option<&mut AnyPin> { | ||
| 396 | None | ||
| 397 | } | 355 | } |
| 398 | } | 356 | } |
| 399 | 357 | ||
| 400 | // ==================== | ||
| 401 | |||
| 402 | pub(crate) fn deconfigure_pin(psel_bits: u32) { | 358 | pub(crate) fn deconfigure_pin(psel_bits: u32) { |
| 403 | if psel_bits & 0x8000_0000 != 0 { | 359 | if psel_bits & 0x8000_0000 != 0 { |
| 404 | return; | 360 | return; |
