aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-03-21 20:57:49 +0100
committerDario Nieuwenhuis <[email protected]>2021-03-29 00:58:57 +0200
commitc0876187dd16d4a391a9b11a4eb5f91689c7d6ff (patch)
treebe3a215b0705d686386c64cd7bd9ff78b6615cd3
parentec7309962a8f427732a0c6fc7c29713923b39028 (diff)
extras: move peripherals from nrf to extras
-rw-r--r--embassy-extras/src/lib.rs1
-rw-r--r--embassy-extras/src/macros.rs45
-rw-r--r--embassy-nrf/src/peripherals.rs49
3 files changed, 47 insertions, 48 deletions
diff --git a/embassy-extras/src/lib.rs b/embassy-extras/src/lib.rs
index 536e86c61..5dafba702 100644
--- a/embassy-extras/src/lib.rs
+++ b/embassy-extras/src/lib.rs
@@ -3,6 +3,7 @@
3// This mod MUST go first, so that the others see its macros. 3// This mod MUST go first, so that the others see its macros.
4pub(crate) mod fmt; 4pub(crate) mod fmt;
5 5
6mod macros;
6pub mod peripheral; 7pub mod peripheral;
7pub mod ring_buffer; 8pub mod ring_buffer;
8pub mod usb; 9pub mod usb;
diff --git a/embassy-extras/src/macros.rs b/embassy-extras/src/macros.rs
new file mode 100644
index 000000000..151f410af
--- /dev/null
+++ b/embassy-extras/src/macros.rs
@@ -0,0 +1,45 @@
1#[macro_export]
2macro_rules! peripherals {
3 ($($(#[$cfg:meta])? $name:ident: $type:ident),*$(,)?) => {
4 $(
5 $(#[$cfg])?
6 #[allow(non_camel_case_types)]
7 pub struct $type { _private: () }
8
9 $(#[$cfg])?
10 impl embassy::util::PeripheralBorrow for $type {
11 type Target = $type;
12 unsafe fn unborrow(self) -> $type {
13 self
14 }
15 }
16
17 $(#[$cfg])?
18 impl embassy::util::PeripheralBorrow for &mut $type {
19 type Target = $type;
20 unsafe fn unborrow(self) -> $type {
21 ::core::ptr::read(self)
22 }
23 }
24 )*
25
26 pub struct Peripherals {
27 $(
28 $(#[$cfg])?
29 pub $name: $type,
30 )*
31 }
32
33 impl Peripherals {
34 pub unsafe fn steal() -> Self {
35 Self {
36 $(
37 $(#[$cfg])?
38 $name: $type { _private: () },
39 )*
40 }
41 }
42 }
43
44 };
45}
diff --git a/embassy-nrf/src/peripherals.rs b/embassy-nrf/src/peripherals.rs
index 1f449e91a..ea76c8092 100644
--- a/embassy-nrf/src/peripherals.rs
+++ b/embassy-nrf/src/peripherals.rs
@@ -1,51 +1,4 @@
1use embassy::util::PeripheralBorrow; 1embassy_extras::peripherals! {
2
3macro_rules! peripherals {
4 ($($(#[$cfg:meta])? $name:ident: $type:ident),*$(,)?) => {
5 $(
6 $(#[$cfg])?
7 #[allow(non_camel_case_types)]
8 pub struct $type { _private: () }
9
10 $(#[$cfg])?
11 impl PeripheralBorrow for $type {
12 type Target = $type;
13 unsafe fn unborrow(self) -> $type {
14 self
15 }
16 }
17
18 $(#[$cfg])?
19 impl PeripheralBorrow for &mut $type {
20 type Target = $type;
21 unsafe fn unborrow(self) -> $type {
22 ::core::ptr::read(self)
23 }
24 }
25 )*
26
27 pub struct Peripherals {
28 $(
29 $(#[$cfg])?
30 pub $name: $type,
31 )*
32 }
33
34 impl Peripherals {
35 pub unsafe fn steal() -> Self {
36 Self {
37 $(
38 $(#[$cfg])?
39 $name: $type { _private: () },
40 )*
41 }
42 }
43 }
44
45 };
46}
47
48peripherals! {
49 // RTC 2 // RTC
50 rtc0: RTC0, 3 rtc0: RTC0,
51 rtc1: RTC1, 4 rtc1: RTC1,