diff --git a/embassy-hal-common/src/macros.rs b/embassy-hal-common/src/macros.rs index 7aa19790..d8e2a06e 100644 --- a/embassy-hal-common/src/macros.rs +++ b/embassy-hal-common/src/macros.rs @@ -21,7 +21,7 @@ macro_rules! peripherals { } $(#[$cfg])? - $crate::unsafe_impl_unborrow!($name); + $crate::impl_unborrow!($name); )* } @@ -80,7 +80,7 @@ macro_rules! unborrow { } #[macro_export] -macro_rules! unsafe_impl_unborrow { +macro_rules! impl_unborrow { ($type:ident) => { impl $crate::Unborrow for $type { type Target = $type; diff --git a/embassy-macros/src/macros/cortex_m_interrupt_declare.rs b/embassy-macros/src/macros/cortex_m_interrupt_declare.rs index 7eaaf609..13150634 100644 --- a/embassy-macros/src/macros/cortex_m_interrupt_declare.rs +++ b/embassy-macros/src/macros/cortex_m_interrupt_declare.rs @@ -25,7 +25,7 @@ pub fn run(name: syn::Ident) -> Result { } } - ::embassy_hal_common::unsafe_impl_unborrow!(#name_interrupt); + ::embassy_hal_common::impl_unborrow!(#name_interrupt); }; Ok(result) } diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index 53ca15d3..f6320b8e 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs @@ -4,7 +4,7 @@ use core::convert::Infallible; use core::hint::unreachable_unchecked; use cfg_if::cfg_if; -use embassy_hal_common::{unborrow, unsafe_impl_unborrow, Unborrowed}; +use embassy_hal_common::{impl_unborrow, unborrow, Unborrowed}; use self::sealed::Pin as _; use crate::pac::p0 as gpio; @@ -432,7 +432,7 @@ macro_rules! unborrow_and_degrade { }; } -unsafe_impl_unborrow!(AnyPin); +impl_unborrow!(AnyPin); impl Pin for AnyPin {} impl sealed::Pin for AnyPin { #[inline] diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index d4e1cb35..d59c2e34 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs @@ -4,7 +4,7 @@ use core::marker::PhantomData; use core::task::{Context, Poll}; use embassy::waitqueue::AtomicWaker; -use embassy_hal_common::unsafe_impl_unborrow; +use embassy_hal_common::impl_unborrow; use futures::future::poll_fn; use crate::gpio::sealed::Pin as _; @@ -414,7 +414,7 @@ pub trait Channel: sealed::Channel + Sized { pub struct AnyChannel { number: u8, } -unsafe_impl_unborrow!(AnyChannel); +impl_unborrow!(AnyChannel); impl sealed::Channel for AnyChannel {} impl Channel for AnyChannel { fn number(&self) -> usize { diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs index fd5bb5f7..fd1d0cf8 100644 --- a/embassy-nrf/src/ppi/mod.rs +++ b/embassy-nrf/src/ppi/mod.rs @@ -17,7 +17,7 @@ use core::ptr::NonNull; -use embassy_hal_common::{unsafe_impl_unborrow, Unborrowed}; +use embassy_hal_common::{impl_unborrow, Unborrowed}; use crate::{peripherals, Unborrow}; @@ -117,7 +117,7 @@ pub trait Group: sealed::Group + Sized { pub struct AnyStaticChannel { pub(crate) number: u8, } -unsafe_impl_unborrow!(AnyStaticChannel); +impl_unborrow!(AnyStaticChannel); impl sealed::Channel for AnyStaticChannel {} impl Channel for AnyStaticChannel { fn number(&self) -> usize { @@ -135,7 +135,7 @@ impl StaticChannel for AnyStaticChannel { pub struct AnyConfigurableChannel { pub(crate) number: u8, } -unsafe_impl_unborrow!(AnyConfigurableChannel); +impl_unborrow!(AnyConfigurableChannel); impl sealed::Channel for AnyConfigurableChannel {} impl Channel for AnyConfigurableChannel { fn number(&self) -> usize { @@ -187,7 +187,7 @@ macro_rules! impl_ppi_channel { pub struct AnyGroup { number: u8, } -unsafe_impl_unborrow!(AnyGroup); +impl_unborrow!(AnyGroup); impl sealed::Group for AnyGroup {} impl Group for AnyGroup { fn number(&self) -> usize { diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index d7d59b62..9c7207c8 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs @@ -5,7 +5,7 @@ use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; use embassy::waitqueue::AtomicWaker; -use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; +use embassy_hal_common::{impl_unborrow, unborrow}; use futures::future::poll_fn; use pac::{saadc, SAADC}; use saadc::ch::config::{GAIN_A, REFSEL_A, RESP_A, TACQ_A}; @@ -77,7 +77,7 @@ pub struct ChannelConfig<'d> { /// internal voltage. pub struct VddInput; -unsafe_impl_unborrow!(VddInput); +impl_unborrow!(VddInput); impl sealed::Input for VddInput { #[cfg(not(feature = "_nrf9160"))] @@ -97,7 +97,7 @@ impl Input for VddInput {} pub struct VddhDiv5Input; #[cfg(any(feature = "_nrf5340-app", feature = "nrf52833", feature = "nrf52840"))] -unsafe_impl_unborrow!(VddhDiv5Input); +impl_unborrow!(VddhDiv5Input); #[cfg(any(feature = "_nrf5340-app", feature = "nrf52833", feature = "nrf52840"))] impl sealed::Input for VddhDiv5Input { @@ -113,12 +113,7 @@ pub struct AnyInput { channel: InputChannel, } -unsafe impl Unborrow for AnyInput { - type Target = AnyInput; - unsafe fn unborrow(self) -> Self::Target { - self - } -} +impl_unborrow!(AnyInput); impl sealed::Input for AnyInput { fn channel(&self) -> InputChannel { diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index 94d0f25c..08a731f4 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs @@ -5,7 +5,7 @@ use core::task::{Context, Poll}; use embassy::waitqueue::AtomicWaker; use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; -use embassy_hal_common::{unborrow, unsafe_impl_unborrow, Unborrowed}; +use embassy_hal_common::{impl_unborrow, unborrow, Unborrowed}; use crate::pac::common::{Reg, RW}; use crate::pac::SIO; @@ -676,7 +676,7 @@ macro_rules! unborrow_and_degrade { }; } -unsafe_impl_unborrow!(AnyPin); +impl_unborrow!(AnyPin); impl Pin for AnyPin {} impl sealed::Pin for AnyPin { diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index 87ac38ba..02d6ca0f 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs @@ -13,10 +13,10 @@ use core::mem; use core::pin::Pin; use core::task::{Context, Poll, Waker}; -#[cfg(dmamux)] -pub use dmamux::*; -use embassy_hal_common::unborrow; +use embassy_hal_common::{impl_unborrow, unborrow}; +#[cfg(dmamux)] +pub use self::dmamux::*; use crate::Unborrow; #[cfg(feature = "unstable-pac")] @@ -294,13 +294,7 @@ pub trait Channel: sealed::Channel + Unborrow + 'static {} pub struct NoDma; -unsafe impl Unborrow for NoDma { - type Target = NoDma; - - unsafe fn unborrow(self) -> Self::Target { - self - } -} +impl_unborrow!(NoDma); // safety: must be called only once at startup pub(crate) unsafe fn init() { diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index 94e0e941..5076de2e 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs @@ -4,7 +4,7 @@ use core::pin::Pin; use core::task::{Context, Poll}; use embassy::waitqueue::AtomicWaker; -use embassy_hal_common::unsafe_impl_unborrow; +use embassy_hal_common::impl_unborrow; use crate::gpio::{AnyPin, Input, Pin as GpioPin}; use crate::pac::exti::regs::Lines; @@ -320,7 +320,7 @@ pub trait Channel: sealed::Channel + Sized { pub struct AnyChannel { number: u8, } -unsafe_impl_unborrow!(AnyChannel); +impl_unborrow!(AnyChannel); impl sealed::Channel for AnyChannel {} impl Channel for AnyChannel { fn number(&self) -> usize { diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index 1059ebf8..3bdaccce 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs @@ -2,7 +2,7 @@ use core::convert::Infallible; use core::marker::PhantomData; -use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; +use embassy_hal_common::{impl_unborrow, unborrow}; use crate::pac::gpio::{self, vals}; use crate::{pac, peripherals, Unborrow}; @@ -673,7 +673,7 @@ impl AnyPin { } } -unsafe_impl_unborrow!(AnyPin); +impl_unborrow!(AnyPin); impl Pin for AnyPin { #[cfg(feature = "exti")] type ExtiChannel = crate::exti::AnyChannel;