embassy-hal-internal: introduce OptionalPeripherals

This commit is contained in:
Kaspar Schleiser 2023-11-22 13:55:34 +01:00
parent f5f776f815
commit 14294b5a9a

View File

@ -46,6 +46,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<peripherals::$name>,
)*
}
impl Peripherals {
///Returns all the peripherals *once*
#[inline]
@ -86,6 +96,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),
)*
}
}
}
};
}