diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-05-12 01:57:01 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-05-17 00:57:37 +0200 |
| commit | 0310e4d458b86df31f1765104eb3aa9a6ee09bfc (patch) | |
| tree | aca167ae6e37442cafc932b3c729e37082d23b04 /embassy-extras | |
| parent | bfc7f52e6dd7b5ad12fa1f09483fa60f2732ae0c (diff) | |
Add `init` fn. Initializes hw and returns Peripherals.
Diffstat (limited to 'embassy-extras')
| -rw-r--r-- | embassy-extras/src/macros.rs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/embassy-extras/src/macros.rs b/embassy-extras/src/macros.rs index 860c0795a..fba752619 100644 --- a/embassy-extras/src/macros.rs +++ b/embassy-extras/src/macros.rs | |||
| @@ -46,18 +46,17 @@ macro_rules! peripherals { | |||
| 46 | impl Peripherals { | 46 | impl Peripherals { |
| 47 | ///Returns all the peripherals *once* | 47 | ///Returns all the peripherals *once* |
| 48 | #[inline] | 48 | #[inline] |
| 49 | pub fn take() -> Option<Self> { | 49 | pub(crate) fn take() -> Self { |
| 50 | 50 | ||
| 51 | #[no_mangle] | 51 | #[no_mangle] |
| 52 | static mut _EMBASSY_DEVICE_PERIPHERALS: bool = false; | 52 | static mut _EMBASSY_DEVICE_PERIPHERALS: bool = false; |
| 53 | 53 | ||
| 54 | critical_section::with(|_| { | 54 | critical_section::with(|_| unsafe { |
| 55 | if unsafe { _EMBASSY_DEVICE_PERIPHERALS } { | 55 | if _EMBASSY_DEVICE_PERIPHERALS { |
| 56 | None | 56 | panic!("init called more than once!") |
| 57 | } else { | ||
| 58 | unsafe { _EMBASSY_DEVICE_PERIPHERALS = true }; | ||
| 59 | Some(unsafe { <Self as embassy::util::Steal>::steal() }) | ||
| 60 | } | 57 | } |
| 58 | _EMBASSY_DEVICE_PERIPHERALS = true; | ||
| 59 | <Self as embassy::util::Steal>::steal() | ||
| 61 | }) | 60 | }) |
| 62 | } | 61 | } |
| 63 | } | 62 | } |
