aboutsummaryrefslogtreecommitdiff
path: root/embassy-hal-common
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-07-22 16:06:45 +0200
committerDario Nieuwenhuis <[email protected]>2022-07-22 16:32:19 +0200
commitffbd9363f2a52fd27c81bbfbbe8e0e605a1ece86 (patch)
treef894f84ddebbac50ad4eb853e4686d76b242d6e1 /embassy-hal-common
parenta77ff721977e6071feb7000059d7e6185965949f (diff)
Change steal() from trait to inherent fns.
Diffstat (limited to 'embassy-hal-common')
-rw-r--r--embassy-hal-common/src/macros.rs24
1 files changed, 16 insertions, 8 deletions
diff --git a/embassy-hal-common/src/macros.rs b/embassy-hal-common/src/macros.rs
index 51e4a5eea..ffa5e4fb6 100644
--- a/embassy-hal-common/src/macros.rs
+++ b/embassy-hal-common/src/macros.rs
@@ -8,9 +8,14 @@ macro_rules! peripherals {
8 pub struct $name { _private: () } 8 pub struct $name { _private: () }
9 9
10 $(#[$cfg])? 10 $(#[$cfg])?
11 impl embassy::util::Steal for $name { 11 impl $name {
12 /// Unsafely create an instance of this peripheral out of thin air.
13 ///
14 /// # Safety
15 ///
16 /// You must ensure that you're only using one instance of this type at a time.
12 #[inline] 17 #[inline]
13 unsafe fn steal() -> Self { 18 pub unsafe fn steal() -> Self {
14 Self{ _private: ()} 19 Self{ _private: ()}
15 } 20 }
16 } 21 }
@@ -23,7 +28,6 @@ macro_rules! peripherals {
23 self 28 self
24 } 29 }
25 } 30 }
26
27 )* 31 )*
28 } 32 }
29 33
@@ -48,23 +52,27 @@ macro_rules! peripherals {
48 panic!("init called more than once!") 52 panic!("init called more than once!")
49 } 53 }
50 _EMBASSY_DEVICE_PERIPHERALS = true; 54 _EMBASSY_DEVICE_PERIPHERALS = true;
51 <Self as embassy::util::Steal>::steal() 55 Self::steal()
52 }) 56 })
53 } 57 }
54 } 58 }
55 59
56 impl embassy::util::Steal for Peripherals { 60 impl Peripherals {
61 /// Unsafely create an instance of this peripheral out of thin air.
62 ///
63 /// # Safety
64 ///
65 /// You must ensure that you're only using one instance of this type at a time.
57 #[inline] 66 #[inline]
58 unsafe fn steal() -> Self { 67 pub unsafe fn steal() -> Self {
59 Self { 68 Self {
60 $( 69 $(
61 $(#[$cfg])? 70 $(#[$cfg])?
62 $name: <peripherals::$name as embassy::util::Steal>::steal(), 71 $name: peripherals::$name::steal(),
63 )* 72 )*
64 } 73 }
65 } 74 }
66 } 75 }
67
68 }; 76 };
69} 77}
70 78