From c0876187dd16d4a391a9b11a4eb5f91689c7d6ff Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sun, 21 Mar 2021 20:57:49 +0100 Subject: [PATCH] extras: move peripherals from nrf to extras --- embassy-extras/src/lib.rs | 1 + embassy-extras/src/macros.rs | 45 +++++++++++++++++++++++++++++++ embassy-nrf/src/peripherals.rs | 49 +--------------------------------- 3 files changed, 47 insertions(+), 48 deletions(-) create mode 100644 embassy-extras/src/macros.rs diff --git a/embassy-extras/src/lib.rs b/embassy-extras/src/lib.rs index 536e86c6..5dafba70 100644 --- a/embassy-extras/src/lib.rs +++ b/embassy-extras/src/lib.rs @@ -3,6 +3,7 @@ // This mod MUST go first, so that the others see its macros. pub(crate) mod fmt; +mod macros; pub mod peripheral; pub mod ring_buffer; pub mod usb; diff --git a/embassy-extras/src/macros.rs b/embassy-extras/src/macros.rs new file mode 100644 index 00000000..151f410a --- /dev/null +++ b/embassy-extras/src/macros.rs @@ -0,0 +1,45 @@ +#[macro_export] +macro_rules! peripherals { + ($($(#[$cfg:meta])? $name:ident: $type:ident),*$(,)?) => { + $( + $(#[$cfg])? + #[allow(non_camel_case_types)] + pub struct $type { _private: () } + + $(#[$cfg])? + impl embassy::util::PeripheralBorrow for $type { + type Target = $type; + unsafe fn unborrow(self) -> $type { + self + } + } + + $(#[$cfg])? + impl embassy::util::PeripheralBorrow for &mut $type { + type Target = $type; + unsafe fn unborrow(self) -> $type { + ::core::ptr::read(self) + } + } + )* + + pub struct Peripherals { + $( + $(#[$cfg])? + pub $name: $type, + )* + } + + impl Peripherals { + pub unsafe fn steal() -> Self { + Self { + $( + $(#[$cfg])? + $name: $type { _private: () }, + )* + } + } + } + + }; +} diff --git a/embassy-nrf/src/peripherals.rs b/embassy-nrf/src/peripherals.rs index 1f449e91..ea76c809 100644 --- a/embassy-nrf/src/peripherals.rs +++ b/embassy-nrf/src/peripherals.rs @@ -1,51 +1,4 @@ -use embassy::util::PeripheralBorrow; - -macro_rules! peripherals { - ($($(#[$cfg:meta])? $name:ident: $type:ident),*$(,)?) => { - $( - $(#[$cfg])? - #[allow(non_camel_case_types)] - pub struct $type { _private: () } - - $(#[$cfg])? - impl PeripheralBorrow for $type { - type Target = $type; - unsafe fn unborrow(self) -> $type { - self - } - } - - $(#[$cfg])? - impl PeripheralBorrow for &mut $type { - type Target = $type; - unsafe fn unborrow(self) -> $type { - ::core::ptr::read(self) - } - } - )* - - pub struct Peripherals { - $( - $(#[$cfg])? - pub $name: $type, - )* - } - - impl Peripherals { - pub unsafe fn steal() -> Self { - Self { - $( - $(#[$cfg])? - $name: $type { _private: () }, - )* - } - } - } - - }; -} - -peripherals! { +embassy_extras::peripherals! { // RTC rtc0: RTC0, rtc1: RTC1,