Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce OptionalPeripherals #2213

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions embassy-hal-internal/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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),
)*
}
}
}
};
}

Expand Down
2 changes: 1 addition & 1 deletion embassy-nrf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ macro_rules! bind_interrupts {
pub use chip::pac;
#[cfg(not(feature = "unstable-pac"))]
pub(crate) use chip::pac;
pub use chip::{peripherals, Peripherals, EASY_DMA_SIZE};
pub use chip::{peripherals, OptionalPeripherals, Peripherals, EASY_DMA_SIZE};
pub use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef};

pub use crate::chip::interrupt;
Expand Down
2 changes: 1 addition & 1 deletion embassy-stm32/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ macro_rules! bind_interrupts {
}

// Reexports
pub use _generated::{peripherals, Peripherals};
pub use _generated::{peripherals, OptionalPeripherals, Peripherals};
pub use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef};
#[cfg(feature = "unstable-pac")]
pub use stm32_metapac as pac;
Expand Down
Loading