From 97ca54fa6639371e5a871bd1e87562c126d92a16 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 14 Apr 2021 19:59:52 +0200 Subject: [PATCH] Rename PeripheralBorrow to Unborrow --- embassy-extras/src/macros.rs | 8 ++++---- embassy-macros/src/lib.rs | 4 ++-- embassy-nrf/src/buffered_uarte.rs | 20 ++++++++++---------- embassy-nrf/src/gpio.rs | 6 +++--- embassy-nrf/src/ppi.rs | 4 ++-- embassy-nrf/src/qspi.rs | 18 +++++++++--------- embassy-nrf/src/saadc.rs | 15 ++++++--------- embassy-nrf/src/spim.rs | 12 ++++++------ embassy-nrf/src/uarte.rs | 14 +++++++------- embassy-rp/src/gpio.rs | 6 +++--- embassy-rp/src/uart.rs | 12 ++++++------ embassy/src/util/mod.rs | 6 +++--- 12 files changed, 61 insertions(+), 64 deletions(-) diff --git a/embassy-extras/src/macros.rs b/embassy-extras/src/macros.rs index 832e76d68..d85439358 100644 --- a/embassy-extras/src/macros.rs +++ b/embassy-extras/src/macros.rs @@ -16,7 +16,7 @@ macro_rules! peripherals { } $(#[$cfg])? - impl embassy::util::PeripheralBorrow for $name { + impl embassy::util::Unborrow for $name { type Target = $name; #[inline] unsafe fn unborrow(self) -> $name { @@ -25,7 +25,7 @@ macro_rules! peripherals { } $(#[$cfg])? - impl embassy::util::PeripheralBorrow for &mut $name { + impl embassy::util::Unborrow for &mut $name { type Target = $name; #[inline] unsafe fn unborrow(self) -> $name { @@ -89,7 +89,7 @@ macro_rules! unborrow { #[macro_export] macro_rules! impl_unborrow { ($type:ident) => { - impl ::embassy::util::PeripheralBorrow for $type { + impl ::embassy::util::Unborrow for $type { type Target = $type; #[inline] unsafe fn unborrow(self) -> Self::Target { @@ -97,7 +97,7 @@ macro_rules! impl_unborrow { } } - impl<'a> ::embassy::util::PeripheralBorrow for &'a mut $type { + impl<'a> ::embassy::util::Unborrow for &'a mut $type { type Target = $type; #[inline] unsafe fn unborrow(self) -> Self::Target { diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs index 402f0e08a..cca6c8a56 100644 --- a/embassy-macros/src/lib.rs +++ b/embassy-macros/src/lib.rs @@ -147,14 +147,14 @@ pub fn interrupt_declare(item: TokenStream) -> TokenStream { } } - impl ::embassy::util::PeripheralBorrow for #name_interrupt { + impl ::embassy::util::Unborrow for #name_interrupt { type Target = #name_interrupt; unsafe fn unborrow(self) -> #name_interrupt { self } } - impl ::embassy::util::PeripheralBorrow for &mut #name_interrupt { + impl ::embassy::util::Unborrow for &mut #name_interrupt { type Target = #name_interrupt; unsafe fn unborrow(self) -> #name_interrupt { ::core::ptr::read(self) diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index 9e67aaef6..49e8dd2b6 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs @@ -5,7 +5,7 @@ use core::sync::atomic::{compiler_fence, Ordering}; use core::task::{Context, Poll}; use embassy::interrupt::InterruptExt; use embassy::io::{AsyncBufRead, AsyncWrite, Result}; -use embassy::util::{PeripheralBorrow, WakerRegistration}; +use embassy::util::{Unborrow, WakerRegistration}; use embassy_extras::peripheral::{PeripheralMutex, PeripheralState}; use embassy_extras::ring_buffer::RingBuffer; use embassy_extras::{low_power_wait_until, unborrow}; @@ -63,15 +63,15 @@ pub struct BufferedUarte<'d, U: UarteInstance, T: TimerInstance> { impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { /// unsafe: may not leak self or futures pub unsafe fn new( - uarte: impl PeripheralBorrow + 'd, - timer: impl PeripheralBorrow + 'd, - ppi_ch1: impl PeripheralBorrow + 'd, - ppi_ch2: impl PeripheralBorrow + 'd, - irq: impl PeripheralBorrow + 'd, - rxd: impl PeripheralBorrow + 'd, - txd: impl PeripheralBorrow + 'd, - cts: impl PeripheralBorrow + 'd, - rts: impl PeripheralBorrow + 'd, + uarte: impl Unborrow + 'd, + timer: impl Unborrow + 'd, + ppi_ch1: impl Unborrow + 'd, + ppi_ch2: impl Unborrow + 'd, + irq: impl Unborrow + 'd, + rxd: impl Unborrow + 'd, + txd: impl Unborrow + 'd, + cts: impl Unborrow + 'd, + rts: impl Unborrow + 'd, config: Config, rx_buffer: &'d mut [u8], tx_buffer: &'d mut [u8], diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index 5a5f7b8da..a06ee6053 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs @@ -2,7 +2,7 @@ use core::convert::Infallible; use core::hint::unreachable_unchecked; use core::marker::PhantomData; -use embassy::util::PeripheralBorrow; +use embassy::util::Unborrow; use embassy_extras::{impl_unborrow, unborrow}; use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin}; use gpio::pin_cnf::DRIVE_A; @@ -38,7 +38,7 @@ pub struct Input<'d, T: Pin> { } impl<'d, T: Pin> Input<'d, T> { - pub fn new(pin: impl PeripheralBorrow + 'd, pull: Pull) -> Self { + pub fn new(pin: impl Unborrow + 'd, pull: Pull) -> Self { unborrow!(pin); pin.conf().write(|w| { @@ -123,7 +123,7 @@ pub struct Output<'d, T: Pin> { impl<'d, T: Pin> Output<'d, T> { pub fn new( - pin: impl PeripheralBorrow + 'd, + pin: impl Unborrow + 'd, initial_output: Level, drive: OutputDrive, ) -> Self { diff --git a/embassy-nrf/src/ppi.rs b/embassy-nrf/src/ppi.rs index 6487267da..e8bcbd603 100644 --- a/embassy-nrf/src/ppi.rs +++ b/embassy-nrf/src/ppi.rs @@ -11,7 +11,7 @@ use core::marker::PhantomData; use core::ptr::NonNull; -use embassy::util::PeripheralBorrow; +use embassy::util::Unborrow; use embassy_extras::{impl_unborrow, unborrow}; use crate::{pac, peripherals}; @@ -25,7 +25,7 @@ pub struct Ppi<'d, C: Channel> { } impl<'d, C: Channel> Ppi<'d, C> { - pub fn new(ch: impl PeripheralBorrow + 'd) -> Self { + pub fn new(ch: impl Unborrow + 'd) -> Self { unborrow!(ch); let mut this = Self { ch, diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index d682c1b8c..f683138d6 100644 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs @@ -3,7 +3,7 @@ use core::marker::PhantomData; use core::task::Poll; use embassy::interrupt::{Interrupt, InterruptExt}; use embassy::traits::flash::{Error, Flash}; -use embassy::util::{AtomicWaker, DropBomb, PeripheralBorrow}; +use embassy::util::{AtomicWaker, DropBomb, Unborrow}; use embassy_extras::unborrow; use futures::future::poll_fn; @@ -61,14 +61,14 @@ pub struct Qspi<'d, T: Instance> { impl<'d, T: Instance> Qspi<'d, T> { pub fn new( - qspi: impl PeripheralBorrow + 'd, - irq: impl PeripheralBorrow + 'd, - sck: impl PeripheralBorrow + 'd, - csn: impl PeripheralBorrow + 'd, - io0: impl PeripheralBorrow + 'd, - io1: impl PeripheralBorrow + 'd, - io2: impl PeripheralBorrow + 'd, - io3: impl PeripheralBorrow + 'd, + qspi: impl Unborrow + 'd, + irq: impl Unborrow + 'd, + sck: impl Unborrow + 'd, + csn: impl Unborrow + 'd, + io0: impl Unborrow + 'd, + io1: impl Unborrow + 'd, + io2: impl Unborrow + 'd, + io3: impl Unborrow + 'd, config: Config, ) -> Self { unborrow!(qspi, irq, sck, csn, io0, io1, io2, io3); diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index b854ce780..448d0334c 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs @@ -3,15 +3,12 @@ use core::marker::PhantomData; use core::pin::Pin; use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; -use embassy::traits; -use embassy::util::{wake_on_interrupt, PeripheralBorrow}; +use embassy::util::{wake_on_interrupt, Unborrow}; use embassy_extras::unborrow; use futures::future::poll_fn; -use traits::spi::FullDuplex; -use crate::gpio::Pin as GpioPin; -use crate::interrupt::{self, Interrupt}; -use crate::{pac, peripherals, slice_in_ram_or}; +use crate::interrupt; +use crate::{pac, peripherals}; #[cfg(feature = "9160")] use pac::{saadc_ns as saadc, SAADC_NS as SAADC}; @@ -74,9 +71,9 @@ impl Default for Config { impl<'d, T: PositivePin> OneShot<'d, T> { pub fn new( - saadc: impl PeripheralBorrow + 'd, - irq: impl PeripheralBorrow + 'd, - positive_pin: impl PeripheralBorrow + 'd, + saadc: impl Unborrow + 'd, + irq: impl Unborrow + 'd, + positive_pin: impl Unborrow + 'd, config: Config, ) -> Self { unborrow!(saadc, irq, positive_pin); diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index bbe1eedf9..d6b9ee8d8 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs @@ -4,7 +4,7 @@ use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; use embassy::interrupt::InterruptExt; use embassy::traits; -use embassy::util::{AtomicWaker, PeripheralBorrow}; +use embassy::util::{AtomicWaker, Unborrow}; use embassy_extras::unborrow; use futures::future::poll_fn; use traits::spi::FullDuplex; @@ -41,11 +41,11 @@ pub struct Config { impl<'d, T: Instance> Spim<'d, T> { pub fn new( - spim: impl PeripheralBorrow + 'd, - irq: impl PeripheralBorrow + 'd, - sck: impl PeripheralBorrow + 'd, - miso: impl PeripheralBorrow + 'd, - mosi: impl PeripheralBorrow + 'd, + spim: impl Unborrow + 'd, + irq: impl Unborrow + 'd, + sck: impl Unborrow + 'd, + miso: impl Unborrow + 'd, + mosi: impl Unborrow + 'd, config: Config, ) -> Self { unborrow!(spim, irq, sck, miso, mosi); diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 9e485907c..a02f7c347 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs @@ -6,7 +6,7 @@ use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; use embassy::interrupt::InterruptExt; use embassy::traits::uart::{Error, Read, Write}; -use embassy::util::{AtomicWaker, OnDrop, PeripheralBorrow}; +use embassy::util::{AtomicWaker, OnDrop, Unborrow}; use embassy_extras::unborrow; use futures::future::poll_fn; @@ -54,12 +54,12 @@ impl<'d, T: Instance> Uarte<'d, T> { /// or [`receive`](Uarte::receive). #[allow(unused_unsafe)] pub unsafe fn new( - uarte: impl PeripheralBorrow + 'd, - irq: impl PeripheralBorrow + 'd, - rxd: impl PeripheralBorrow + 'd, - txd: impl PeripheralBorrow + 'd, - cts: impl PeripheralBorrow + 'd, - rts: impl PeripheralBorrow + 'd, + uarte: impl Unborrow + 'd, + irq: impl Unborrow + 'd, + rxd: impl Unborrow + 'd, + txd: impl Unborrow + 'd, + cts: impl Unborrow + 'd, + rts: impl Unborrow + 'd, config: Config, ) -> Self { unborrow!(uarte, irq, rxd, txd, cts, rts); diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index 46a7b5a15..ecfad1878 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs @@ -5,7 +5,7 @@ use crate::pac::generic::{Reg, RW}; use crate::pac::SIO; use crate::peripherals; -use embassy::util::PeripheralBorrow; +use embassy::util::Unborrow; use embassy_extras::{impl_unborrow, unborrow}; use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin}; @@ -37,7 +37,7 @@ pub struct Input<'d, T: Pin> { } impl<'d, T: Pin> Input<'d, T> { - pub fn new(pin: impl PeripheralBorrow + 'd, pull: Pull) -> Self { + pub fn new(pin: impl Unborrow + 'd, pull: Pull) -> Self { unborrow!(pin); unsafe { @@ -91,7 +91,7 @@ pub struct Output<'d, T: Pin> { impl<'d, T: Pin> Output<'d, T> { // TODO opendrain - pub fn new(pin: impl PeripheralBorrow + 'd, initial_output: Level) -> Self { + pub fn new(pin: impl Unborrow + 'd, initial_output: Level) -> Self { unborrow!(pin); unsafe { diff --git a/embassy-rp/src/uart.rs b/embassy-rp/src/uart.rs index 3eb768a7d..2c8986302 100644 --- a/embassy-rp/src/uart.rs +++ b/embassy-rp/src/uart.rs @@ -1,6 +1,6 @@ use core::marker::PhantomData; -use embassy::util::PeripheralBorrow; +use embassy::util::Unborrow; use embassy_extras::unborrow; use gpio::Pin; @@ -30,11 +30,11 @@ pub struct Uart<'d, T: Instance> { impl<'d, T: Instance> Uart<'d, T> { pub fn new( - inner: impl PeripheralBorrow, - tx: impl PeripheralBorrow>, - rx: impl PeripheralBorrow>, - cts: impl PeripheralBorrow>, - rts: impl PeripheralBorrow>, + inner: impl Unborrow, + tx: impl Unborrow>, + rx: impl Unborrow>, + cts: impl Unborrow>, + rts: impl Unborrow>, config: Config, ) -> Self { unborrow!(inner, tx, rx, cts, rts); diff --git a/embassy/src/util/mod.rs b/embassy/src/util/mod.rs index 25b570cc6..cace0d190 100644 --- a/embassy/src/util/mod.rs +++ b/embassy/src/util/mod.rs @@ -1,15 +1,16 @@ //! Async utilities +mod critical_section; mod drop_bomb; mod forever; mod mutex; mod on_drop; mod portal; mod signal; -mod critical_section; #[cfg_attr(feature = "executor-agnostic", path = "waker_agnostic.rs")] mod waker; +pub use critical_section::*; pub use drop_bomb::*; pub use forever::*; pub use mutex::*; @@ -17,9 +18,8 @@ pub use on_drop::*; pub use portal::*; pub use signal::*; pub use waker::*; -pub use critical_section::*; -pub trait PeripheralBorrow { +pub trait Unborrow { type Target; unsafe fn unborrow(self) -> Self::Target; }