aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/gpio.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-10-28 03:07:06 +0200
committerDario Nieuwenhuis <[email protected]>2021-10-28 03:36:25 +0200
commit663141b4e456bbfacaaff8decdba6840c76a136b (patch)
tree8d151a795b008ab0791a6faa5dbd36e5b83522b5 /embassy-nrf/src/gpio.rs
parentc995a97f2032d329c2955c79054b7e466b0b423b (diff)
nrf: add initial nrf5340 support
Diffstat (limited to 'embassy-nrf/src/gpio.rs')
-rw-r--r--embassy-nrf/src/gpio.rs23
1 files changed, 11 insertions, 12 deletions
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs
index 7896945fb..91b2e585a 100644
--- a/embassy-nrf/src/gpio.rs
+++ b/embassy-nrf/src/gpio.rs
@@ -4,6 +4,7 @@ use core::convert::Infallible;
4use core::hint::unreachable_unchecked; 4use core::hint::unreachable_unchecked;
5use core::marker::PhantomData; 5use core::marker::PhantomData;
6 6
7use cfg_if::cfg_if;
7use embassy::util::Unborrow; 8use embassy::util::Unborrow;
8use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; 9use embassy_hal_common::{unborrow, unsafe_impl_unborrow};
9use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin}; 10use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin};
@@ -20,8 +21,8 @@ pub enum Port {
20 /// Port 0, available on nRF9160 and all nRF52 and nRF51 MCUs. 21 /// Port 0, available on nRF9160 and all nRF52 and nRF51 MCUs.
21 Port0, 22 Port0,
22 23
23 /// Port 1, only available on some nRF52 MCUs. 24 /// Port 1, only available on some MCUs.
24 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))] 25 #[cfg(feature = "_gpio-p1")]
25 Port1, 26 Port1,
26} 27}
27 28
@@ -284,14 +285,12 @@ pub(crate) mod sealed {
284 285
285 #[inline] 286 #[inline]
286 fn _pin(&self) -> u8 { 287 fn _pin(&self) -> u8 {
287 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))] 288 cfg_if! {
288 { 289 if #[cfg(feature = "_gpio-p1")] {
289 self.pin_port() % 32 290 self.pin_port() % 32
290 } 291 } else {
291 292 self.pin_port()
292 #[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))] 293 }
293 {
294 self.pin_port()
295 } 294 }
296 } 295 }
297 296
@@ -300,7 +299,7 @@ pub(crate) mod sealed {
300 unsafe { 299 unsafe {
301 match self.pin_port() / 32 { 300 match self.pin_port() / 32 {
302 0 => &*pac::P0::ptr(), 301 0 => &*pac::P0::ptr(),
303 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))] 302 #[cfg(feature = "_gpio-p1")]
304 1 => &*pac::P1::ptr(), 303 1 => &*pac::P1::ptr(),
305 _ => unreachable_unchecked(), 304 _ => unreachable_unchecked(),
306 } 305 }
@@ -344,7 +343,7 @@ pub trait Pin: Unborrow<Target = Self> + sealed::Pin + Sized + 'static {
344 fn port(&self) -> Port { 343 fn port(&self) -> Port {
345 match self.pin_port() / 32 { 344 match self.pin_port() / 32 {
346 0 => Port::Port0, 345 0 => Port::Port0,
347 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))] 346 #[cfg(feature = "_gpio-p1")]
348 1 => Port::Port1, 347 1 => Port::Port1,
349 _ => unsafe { unreachable_unchecked() }, 348 _ => unsafe { unreachable_unchecked() },
350 } 349 }