diff options
Diffstat (limited to 'embassy-hal-internal/src/macros.rs')
| -rw-r--r-- | embassy-hal-internal/src/macros.rs | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/embassy-hal-internal/src/macros.rs b/embassy-hal-internal/src/macros.rs index 07cd89487..cd2bc3cab 100644 --- a/embassy-hal-internal/src/macros.rs +++ b/embassy-hal-internal/src/macros.rs | |||
| @@ -18,8 +18,8 @@ macro_rules! peripherals_definition { | |||
| 18 | /// | 18 | /// |
| 19 | /// You must ensure that you're only using one instance of this type at a time. | 19 | /// You must ensure that you're only using one instance of this type at a time. |
| 20 | #[inline] | 20 | #[inline] |
| 21 | pub unsafe fn steal() -> Self { | 21 | pub unsafe fn steal() -> $crate::Peri<'static, Self> { |
| 22 | Self{ _private: ()} | 22 | $crate::Peri::new_unchecked(Self{ _private: ()}) |
| 23 | } | 23 | } |
| 24 | } | 24 | } |
| 25 | 25 | ||
| @@ -42,7 +42,7 @@ macro_rules! peripherals_struct { | |||
| 42 | $( | 42 | $( |
| 43 | #[doc = concat!(stringify!($name), " peripheral")] | 43 | #[doc = concat!(stringify!($name), " peripheral")] |
| 44 | $(#[$cfg])? | 44 | $(#[$cfg])? |
| 45 | pub $name: peripherals::$name, | 45 | pub $name: $crate::Peri<'static, peripherals::$name>, |
| 46 | )* | 46 | )* |
| 47 | } | 47 | } |
| 48 | 48 | ||
| @@ -108,28 +108,26 @@ macro_rules! peripherals { | |||
| 108 | }; | 108 | }; |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | /// Convenience converting into reference. | ||
| 112 | #[macro_export] | ||
| 113 | macro_rules! into_ref { | ||
| 114 | ($($name:ident),*) => { | ||
| 115 | $( | ||
| 116 | let mut $name = $name.into_ref(); | ||
| 117 | )* | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | /// Implement the peripheral trait. | 111 | /// Implement the peripheral trait. |
| 122 | #[macro_export] | 112 | #[macro_export] |
| 123 | macro_rules! impl_peripheral { | 113 | macro_rules! impl_peripheral { |
| 124 | ($type:ident) => { | 114 | ($type:ident<$($T:ident $(: $bound:tt $(+ $others:tt )*)?),*>) => { |
| 125 | impl $crate::Peripheral for $type { | 115 | impl<$($T: $($bound $(+$others)*)?),*> Copy for $type <$($T),*> {} |
| 126 | type P = $type; | 116 | impl<$($T: $($bound $(+$others)*)?),*> Clone for $type <$($T),*> { |
| 117 | fn clone(&self) -> Self { | ||
| 118 | *self | ||
| 119 | } | ||
| 120 | } | ||
| 121 | impl<$($T: $($bound $(+$others)*)?),*> PeripheralType for $type <$($T),*> {} | ||
| 122 | }; | ||
| 127 | 123 | ||
| 128 | #[inline] | 124 | ($type:ident) => { |
| 129 | unsafe fn clone_unchecked(&self) -> Self::P { | 125 | impl Copy for $type {} |
| 130 | #[allow(clippy::needless_update)] | 126 | impl Clone for $type { |
| 131 | $type { ..*self } | 127 | fn clone(&self) -> Self { |
| 128 | *self | ||
| 132 | } | 129 | } |
| 133 | } | 130 | } |
| 131 | impl $crate::PeripheralType for $type {} | ||
| 134 | }; | 132 | }; |
| 135 | } | 133 | } |
