2021-03-21 20:57:49 +01:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! peripherals {
|
2021-03-27 03:12:58 +01:00
|
|
|
($($(#[$cfg:meta])? $name:ident),*$(,)?) => {
|
2021-03-21 21:58:59 +01:00
|
|
|
pub mod peripherals {
|
|
|
|
$(
|
|
|
|
$(#[$cfg])?
|
|
|
|
#[allow(non_camel_case_types)]
|
2021-03-27 03:12:58 +01:00
|
|
|
pub struct $name { _private: () }
|
2021-03-21 21:58:59 +01:00
|
|
|
|
2021-03-22 14:55:27 +01:00
|
|
|
$(#[$cfg])?
|
2021-03-27 03:12:58 +01:00
|
|
|
impl embassy::util::Steal for $name {
|
2021-03-21 21:58:59 +01:00
|
|
|
#[inline]
|
|
|
|
unsafe fn steal() -> Self {
|
|
|
|
Self{ _private: ()}
|
|
|
|
}
|
2021-03-21 20:57:49 +01:00
|
|
|
}
|
|
|
|
|
2021-03-21 21:58:59 +01:00
|
|
|
$(#[$cfg])?
|
2022-06-11 05:08:57 +02:00
|
|
|
unsafe impl $crate::Unborrow for $name {
|
2021-03-27 03:12:58 +01:00
|
|
|
type Target = $name;
|
2021-03-21 21:58:59 +01:00
|
|
|
#[inline]
|
2021-03-27 03:12:58 +01:00
|
|
|
unsafe fn unborrow(self) -> $name {
|
2021-03-21 21:58:59 +01:00
|
|
|
self
|
|
|
|
}
|
2021-03-21 20:57:49 +01:00
|
|
|
}
|
2021-03-21 21:58:59 +01:00
|
|
|
|
|
|
|
)*
|
|
|
|
}
|
2021-03-21 20:57:49 +01:00
|
|
|
|
2021-03-27 03:12:58 +01:00
|
|
|
#[allow(non_snake_case)]
|
2021-03-21 20:57:49 +01:00
|
|
|
pub struct Peripherals {
|
|
|
|
$(
|
|
|
|
$(#[$cfg])?
|
2021-03-27 03:12:58 +01:00
|
|
|
pub $name: peripherals::$name,
|
2021-03-21 20:57:49 +01:00
|
|
|
)*
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Peripherals {
|
2021-03-21 21:58:59 +01:00
|
|
|
///Returns all the peripherals *once*
|
|
|
|
#[inline]
|
2021-05-12 01:57:01 +02:00
|
|
|
pub(crate) fn take() -> Self {
|
2021-03-21 21:58:59 +01:00
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
static mut _EMBASSY_DEVICE_PERIPHERALS: bool = false;
|
|
|
|
|
2021-05-12 01:57:01 +02:00
|
|
|
critical_section::with(|_| unsafe {
|
|
|
|
if _EMBASSY_DEVICE_PERIPHERALS {
|
|
|
|
panic!("init called more than once!")
|
2021-03-21 21:58:59 +01:00
|
|
|
}
|
2021-05-12 01:57:01 +02:00
|
|
|
_EMBASSY_DEVICE_PERIPHERALS = true;
|
|
|
|
<Self as embassy::util::Steal>::steal()
|
2021-03-21 21:58:59 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl embassy::util::Steal for Peripherals {
|
|
|
|
#[inline]
|
|
|
|
unsafe fn steal() -> Self {
|
2021-03-21 20:57:49 +01:00
|
|
|
Self {
|
|
|
|
$(
|
|
|
|
$(#[$cfg])?
|
2021-03-27 03:12:58 +01:00
|
|
|
$name: <peripherals::$name as embassy::util::Steal>::steal(),
|
2021-03-21 20:57:49 +01:00
|
|
|
)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
2021-03-21 22:09:06 +01:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! unborrow {
|
|
|
|
($($name:ident),*) => {
|
|
|
|
$(
|
2021-03-22 02:10:59 +01:00
|
|
|
let mut $name = unsafe { $name.unborrow() };
|
2021-03-21 22:09:06 +01:00
|
|
|
)*
|
|
|
|
}
|
|
|
|
}
|
2021-03-27 03:33:32 +01:00
|
|
|
|
|
|
|
#[macro_export]
|
2021-05-19 23:21:31 +02:00
|
|
|
macro_rules! unsafe_impl_unborrow {
|
2021-03-27 03:33:32 +01:00
|
|
|
($type:ident) => {
|
2022-06-11 05:08:57 +02:00
|
|
|
unsafe impl $crate::Unborrow for $type {
|
2021-03-27 03:33:32 +01:00
|
|
|
type Target = $type;
|
|
|
|
#[inline]
|
|
|
|
unsafe fn unborrow(self) -> Self::Target {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|