aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/gpio.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-07-23 14:00:19 +0200
committerDario Nieuwenhuis <[email protected]>2022-07-23 14:00:19 +0200
commit4901c34d9c4cd326ab9bca02dd099a663da2567f (patch)
tree8225afebb595fb10c1d67148c0d19b7b732853da /embassy-nrf/src/gpio.rs
parent8a9d2f59af004902d3978a2922843833b98bcce0 (diff)
Rename Unborrowed -> PeripheralRef, Unborrow -> Peripheral
Diffstat (limited to 'embassy-nrf/src/gpio.rs')
-rw-r--r--embassy-nrf/src/gpio.rs30
1 files changed, 15 insertions, 15 deletions
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs
index f6320b8ee..ae08d859a 100644
--- a/embassy-nrf/src/gpio.rs
+++ b/embassy-nrf/src/gpio.rs
@@ -4,12 +4,12 @@ use core::convert::Infallible;
4use core::hint::unreachable_unchecked; 4use core::hint::unreachable_unchecked;
5 5
6use cfg_if::cfg_if; 6use cfg_if::cfg_if;
7use embassy_hal_common::{impl_unborrow, unborrow, Unborrowed}; 7use embassy_hal_common::{impl_peripheral, into_ref, PeripheralRef};
8 8
9use self::sealed::Pin as _; 9use self::sealed::Pin as _;
10use crate::pac::p0 as gpio; 10use crate::pac::p0 as gpio;
11use crate::pac::p0::pin_cnf::{DRIVE_A, PULL_A}; 11use crate::pac::p0::pin_cnf::{DRIVE_A, PULL_A};
12use crate::{pac, Unborrow}; 12use crate::{pac, Peripheral};
13 13
14/// A GPIO port with up to 32 pins. 14/// A GPIO port with up to 32 pins.
15#[derive(Debug, Eq, PartialEq)] 15#[derive(Debug, Eq, PartialEq)]
@@ -38,7 +38,7 @@ pub struct Input<'d, T: Pin> {
38 38
39impl<'d, T: Pin> Input<'d, T> { 39impl<'d, T: Pin> Input<'d, T> {
40 #[inline] 40 #[inline]
41 pub fn new(pin: impl Unborrow<Target = T> + 'd, pull: Pull) -> Self { 41 pub fn new(pin: impl Peripheral<P = T> + 'd, pull: Pull) -> Self {
42 let mut pin = Flex::new(pin); 42 let mut pin = Flex::new(pin);
43 pin.set_as_input(pull); 43 pin.set_as_input(pull);
44 44
@@ -118,7 +118,7 @@ pub struct Output<'d, T: Pin> {
118 118
119impl<'d, T: Pin> Output<'d, T> { 119impl<'d, T: Pin> Output<'d, T> {
120 #[inline] 120 #[inline]
121 pub fn new(pin: impl Unborrow<Target = T> + 'd, initial_output: Level, drive: OutputDrive) -> Self { 121 pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level, drive: OutputDrive) -> Self {
122 let mut pin = Flex::new(pin); 122 let mut pin = Flex::new(pin);
123 match initial_output { 123 match initial_output {
124 Level::High => pin.set_high(), 124 Level::High => pin.set_high(),
@@ -193,7 +193,7 @@ fn convert_pull(pull: Pull) -> PULL_A {
193/// set while not in output mode, so the pin's level will be 'remembered' when it is not in output 193/// set while not in output mode, so the pin's level will be 'remembered' when it is not in output
194/// mode. 194/// mode.
195pub struct Flex<'d, T: Pin> { 195pub struct Flex<'d, T: Pin> {
196 pub(crate) pin: Unborrowed<'d, T>, 196 pub(crate) pin: PeripheralRef<'d, T>,
197} 197}
198 198
199impl<'d, T: Pin> Flex<'d, T> { 199impl<'d, T: Pin> Flex<'d, T> {
@@ -202,8 +202,8 @@ impl<'d, T: Pin> Flex<'d, T> {
202 /// The pin remains disconnected. The initial output level is unspecified, but can be changed 202 /// The pin remains disconnected. The initial output level is unspecified, but can be changed
203 /// before the pin is put into output mode. 203 /// before the pin is put into output mode.
204 #[inline] 204 #[inline]
205 pub fn new(pin: impl Unborrow<Target = T> + 'd) -> Self { 205 pub fn new(pin: impl Peripheral<P = T> + 'd) -> Self {
206 unborrow!(pin); 206 into_ref!(pin);
207 // Pin will be in disconnected state. 207 // Pin will be in disconnected state.
208 Self { pin } 208 Self { pin }
209 } 209 }
@@ -374,7 +374,7 @@ pub(crate) mod sealed {
374 } 374 }
375} 375}
376 376
377pub trait Pin: Unborrow<Target = Self> + sealed::Pin + Sized + 'static { 377pub trait Pin: Peripheral<P = Self> + sealed::Pin + Sized + 'static {
378 /// Number of the pin within the port (0..31) 378 /// Number of the pin within the port (0..31)
379 #[inline] 379 #[inline]
380 fn pin(&self) -> u8 { 380 fn pin(&self) -> u8 {
@@ -417,22 +417,22 @@ impl AnyPin {
417 Self { pin_port } 417 Self { pin_port }
418 } 418 }
419 419
420 pub(crate) fn unborrow_and_degrade<'a>(pin: impl Unborrow<Target = impl Pin + 'a> + 'a) -> Unborrowed<'a, Self> { 420 pub(crate) fn into_degraded_ref<'a>(pin: impl Peripheral<P = impl Pin + 'a> + 'a) -> PeripheralRef<'a, Self> {
421 Unborrowed::new(AnyPin { 421 PeripheralRef::new(AnyPin {
422 pin_port: pin.unborrow().pin_port(), 422 pin_port: pin.into_ref().pin_port(),
423 }) 423 })
424 } 424 }
425} 425}
426 426
427macro_rules! unborrow_and_degrade { 427macro_rules! into_degraded_ref {
428 ($($name:ident),*) => { 428 ($($name:ident),*) => {
429 $( 429 $(
430 let $name = $crate::gpio::AnyPin::unborrow_and_degrade($name); 430 let $name = $crate::gpio::AnyPin::into_degraded_ref($name);
431 )* 431 )*
432 }; 432 };
433} 433}
434 434
435impl_unborrow!(AnyPin); 435impl_peripheral!(AnyPin);
436impl Pin for AnyPin {} 436impl Pin for AnyPin {}
437impl sealed::Pin for AnyPin { 437impl sealed::Pin for AnyPin {
438 #[inline] 438 #[inline]
@@ -447,7 +447,7 @@ pub(crate) trait PselBits {
447 fn psel_bits(&self) -> u32; 447 fn psel_bits(&self) -> u32;
448} 448}
449 449
450impl<'a, P: Pin> PselBits for Option<Unborrowed<'a, P>> { 450impl<'a, P: Pin> PselBits for Option<PeripheralRef<'a, P>> {
451 #[inline] 451 #[inline]
452 fn psel_bits(&self) -> u32 { 452 fn psel_bits(&self) -> u32 {
453 match self { 453 match self {