embedded-hal-internal: introduce OptionalPeripherals

This commit is contained in:
Kaspar Schleiser 2023-11-22 13:55:34 +01:00
parent e0727fe1f6
commit af35f9a423

View File

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