#[macro_export] macro_rules! peripherals { ($($(#[$cfg:meta])? $name:ident),*$(,)?) => { pub mod peripherals { $( $(#[$cfg])? #[allow(non_camel_case_types)] pub struct $name { _private: () } $(#[$cfg])? impl embassy::util::Steal for $name { #[inline] unsafe fn steal() -> Self { Self{ _private: ()} } } $(#[$cfg])? unsafe impl $crate::Unborrow for $name { type Target = $name; #[inline] unsafe fn unborrow(self) -> $name { self } } )* } #[allow(non_snake_case)] pub struct Peripherals { $( $(#[$cfg])? pub $name: peripherals::$name, )* } impl Peripherals { ///Returns all the peripherals *once* #[inline] pub(crate) fn take() -> Self { #[no_mangle] static mut _EMBASSY_DEVICE_PERIPHERALS: bool = false; critical_section::with(|_| unsafe { if _EMBASSY_DEVICE_PERIPHERALS { panic!("init called more than once!") } _EMBASSY_DEVICE_PERIPHERALS = true; ::steal() }) } } impl embassy::util::Steal for Peripherals { #[inline] unsafe fn steal() -> Self { Self { $( $(#[$cfg])? $name: ::steal(), )* } } } }; } #[macro_export] macro_rules! unborrow { ($($name:ident),*) => { $( let mut $name = unsafe { $name.unborrow() }; )* } } #[macro_export] macro_rules! unsafe_impl_unborrow { ($type:ident) => { unsafe impl $crate::Unborrow for $type { type Target = $type; #[inline] unsafe fn unborrow(self) -> Self::Target { self } } }; }