diff --git a/embassy-hal-internal/src/macros.rs b/embassy-hal-internal/src/macros.rs index 97df3895..306e3420 100644 --- a/embassy-hal-internal/src/macros.rs +++ b/embassy-hal-internal/src/macros.rs @@ -44,6 +44,16 @@ macro_rules! peripherals_struct { )* } + /// Struct containing all the peripheral singletons wrapped in `Option`. + #[allow(non_snake_case)] + pub struct OptionalPeripherals { + $( + #[doc = concat!(stringify!($name), " peripheral")] + $(#[$cfg])? + pub $name: Option, + )* + } + impl Peripherals { ///Returns all the peripherals *once* #[inline] @@ -84,6 +94,19 @@ macro_rules! peripherals_struct { } } } + + impl OptionalPeripherals { + /// Create an `OptionalPeripherals`, consuming a `Peripherals` + #[inline] + pub fn from(p: Peripherals) -> Self { + Self { + $( + $(#[$cfg])? + $name: Some(p.$name), + )* + } + } + } }; }