Skip to content
Snippets Groups Projects
Commit 9bab4175 authored by Jorge Aparicio's avatar Jorge Aparicio
Browse files

s/all/take/g s/_all/steal/g

parent c6ed9ef4
No related branches found
No related tags found
No related merge requests found
...@@ -62,23 +62,25 @@ pub struct Peripherals { ...@@ -62,23 +62,25 @@ pub struct Peripherals {
pub TPIU: TPIU, pub TPIU: TPIU,
} }
// NOTE `no_mangle` is used here to prevent linking different minor versions of this crate as that
// would let you `take` the core peripherals more than once (one per minor version)
#[no_mangle] #[no_mangle]
static mut CORE_PERIPHERALS: bool = false; static mut CORE_PERIPHERALS: bool = false;
impl Peripherals { impl Peripherals {
/// Returns all the core peripherals *once* /// Returns all the core peripherals *once*
pub fn all() -> Option<Self> { pub fn take() -> Option<Self> {
interrupt::free(|_| { interrupt::free(|_| {
if unsafe { CORE_PERIPHERALS } { if unsafe { CORE_PERIPHERALS } {
None None
} else { } else {
Some(unsafe { Peripherals::_all() }) Some(unsafe { Peripherals::steal() })
} }
}) })
} }
#[doc(hidden)] #[doc(hidden)]
pub unsafe fn _all() -> Self { pub unsafe fn steal() -> Self {
debug_assert!(!CORE_PERIPHERALS); debug_assert!(!CORE_PERIPHERALS);
CORE_PERIPHERALS = true; CORE_PERIPHERALS = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment