mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-25 16:23:10 +00:00
embassy-hal-internal: introduce OptionalPeripherals
This commit is contained in:
parent
f5f776f815
commit
14294b5a9a
@ -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),
|
||||
)*
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user