embedded-hal-internal: introduce OptionalPeripherals
This commit is contained in:
parent
e0727fe1f6
commit
af35f9a423
@ -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 {
|
||||
///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),
|
||||
)*
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user