aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/gpio.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-04-05 00:20:22 +0200
committerDario Nieuwenhuis <[email protected]>2024-04-05 00:48:46 +0200
commitab85eb4b60cd49ebcd43d2305f42327685f5e5a6 (patch)
tree3c385a5703edcd1e791ec1934d3232dc4084ab2b /embassy-nrf/src/gpio.rs
parent0e1208947e89ea60bd1b5c85e4deb79efb94d89a (diff)
nrf: remove mod sealed.
Diffstat (limited to 'embassy-nrf/src/gpio.rs')
-rw-r--r--embassy-nrf/src/gpio.rs82
1 files changed, 39 insertions, 43 deletions
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs
index f2353f21d..7b272dca0 100644
--- a/embassy-nrf/src/gpio.rs
+++ b/embassy-nrf/src/gpio.rs
@@ -7,7 +7,6 @@ use core::hint::unreachable_unchecked;
7use cfg_if::cfg_if; 7use cfg_if::cfg_if;
8use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef}; 8use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef};
9 9
10use self::sealed::Pin as _;
11#[cfg(feature = "nrf51")] 10#[cfg(feature = "nrf51")]
12use crate::pac::gpio; 11use crate::pac::gpio;
13#[cfg(feature = "nrf51")] 12#[cfg(feature = "nrf51")]
@@ -361,59 +360,56 @@ impl<'d> Drop for Flex<'d> {
361 } 360 }
362} 361}
363 362
364pub(crate) mod sealed { 363pub(crate) trait SealedPin {
365 use super::*; 364 fn pin_port(&self) -> u8;
366
367 pub trait Pin {
368 fn pin_port(&self) -> u8;
369 365
370 #[inline] 366 #[inline]
371 fn _pin(&self) -> u8 { 367 fn _pin(&self) -> u8 {
372 cfg_if! { 368 cfg_if! {
373 if #[cfg(feature = "_gpio-p1")] { 369 if #[cfg(feature = "_gpio-p1")] {
374 self.pin_port() % 32 370 self.pin_port() % 32
375 } else { 371 } else {
376 self.pin_port() 372 self.pin_port()
377 }
378 } 373 }
379 } 374 }
375 }
380 376
381 #[inline] 377 #[inline]
382 fn block(&self) -> &gpio::RegisterBlock { 378 fn block(&self) -> &gpio::RegisterBlock {
383 unsafe { 379 unsafe {
384 match self.pin_port() / 32 { 380 match self.pin_port() / 32 {
385 #[cfg(feature = "nrf51")] 381 #[cfg(feature = "nrf51")]
386 0 => &*pac::GPIO::ptr(), 382 0 => &*pac::GPIO::ptr(),
387 #[cfg(not(feature = "nrf51"))] 383 #[cfg(not(feature = "nrf51"))]
388 0 => &*pac::P0::ptr(), 384 0 => &*pac::P0::ptr(),
389 #[cfg(feature = "_gpio-p1")] 385 #[cfg(feature = "_gpio-p1")]
390 1 => &*pac::P1::ptr(), 386 1 => &*pac::P1::ptr(),
391 _ => unreachable_unchecked(), 387 _ => unreachable_unchecked(),
392 }
393 } 388 }
394 } 389 }
390 }
395 391
396 #[inline] 392 #[inline]
397 fn conf(&self) -> &gpio::PIN_CNF { 393 fn conf(&self) -> &gpio::PIN_CNF {
398 &self.block().pin_cnf[self._pin() as usize] 394 &self.block().pin_cnf[self._pin() as usize]
399 } 395 }
400 396
401 /// Set the output as high. 397 /// Set the output as high.
402 #[inline] 398 #[inline]
403 fn set_high(&self) { 399 fn set_high(&self) {
404 unsafe { self.block().outset.write(|w| w.bits(1u32 << self._pin())) } 400 unsafe { self.block().outset.write(|w| w.bits(1u32 << self._pin())) }
405 } 401 }
406 402
407 /// Set the output as low. 403 /// Set the output as low.
408 #[inline] 404 #[inline]
409 fn set_low(&self) { 405 fn set_low(&self) {
410 unsafe { self.block().outclr.write(|w| w.bits(1u32 << self._pin())) } 406 unsafe { self.block().outclr.write(|w| w.bits(1u32 << self._pin())) }
411 }
412 } 407 }
413} 408}
414 409
415/// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin]. 410/// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin].
416pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'static { 411#[allow(private_bounds)]
412pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + SealedPin + Sized + 'static {
417 /// Number of the pin within the port (0..31) 413 /// Number of the pin within the port (0..31)
418 #[inline] 414 #[inline]
419 fn pin(&self) -> u8 { 415 fn pin(&self) -> u8 {
@@ -464,7 +460,7 @@ impl AnyPin {
464 460
465impl_peripheral!(AnyPin); 461impl_peripheral!(AnyPin);
466impl Pin for AnyPin {} 462impl Pin for AnyPin {}
467impl sealed::Pin for AnyPin { 463impl SealedPin for AnyPin {
468 #[inline] 464 #[inline]
469 fn pin_port(&self) -> u8 { 465 fn pin_port(&self) -> u8 {
470 self.pin_port 466 self.pin_port
@@ -502,7 +498,7 @@ pub(crate) fn deconfigure_pin(psel_bits: u32) {
502macro_rules! impl_pin { 498macro_rules! impl_pin {
503 ($type:ident, $port_num:expr, $pin_num:expr) => { 499 ($type:ident, $port_num:expr, $pin_num:expr) => {
504 impl crate::gpio::Pin for peripherals::$type {} 500 impl crate::gpio::Pin for peripherals::$type {}
505 impl crate::gpio::sealed::Pin for peripherals::$type { 501 impl crate::gpio::SealedPin for peripherals::$type {
506 #[inline] 502 #[inline]
507 fn pin_port(&self) -> u8 { 503 fn pin_port(&self) -> u8 {
508 $port_num * 32 + $pin_num 504 $port_num * 32 + $pin_num