Add init fn. Initializes hw and returns Peripherals.

This commit is contained in:
Dario Nieuwenhuis
2021-05-12 01:57:01 +02:00
parent bfc7f52e6d
commit 0310e4d458
24 changed files with 217 additions and 258 deletions

View File

@ -46,18 +46,17 @@ macro_rules! peripherals {
impl Peripherals {
///Returns all the peripherals *once*
#[inline]
pub fn take() -> Option<Self> {
pub(crate) fn take() -> Self {
#[no_mangle]
static mut _EMBASSY_DEVICE_PERIPHERALS: bool = false;
critical_section::with(|_| {
if unsafe { _EMBASSY_DEVICE_PERIPHERALS } {
None
} else {
unsafe { _EMBASSY_DEVICE_PERIPHERALS = true };
Some(unsafe { <Self as embassy::util::Steal>::steal() })
critical_section::with(|_| unsafe {
if _EMBASSY_DEVICE_PERIPHERALS {
panic!("init called more than once!")
}
_EMBASSY_DEVICE_PERIPHERALS = true;
<Self as embassy::util::Steal>::steal()
})
}
}