diff --git a/Cargo.toml b/Cargo.toml index 26aad273..54fc6616 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,15 +16,18 @@ edition = "2018" links = "cortex-m" # prevent multiple versions of this crate to be linked together [dependencies] -bare-metal = { version = "0.2.0", features = ["const-fn"] } +bare-metal = { version = "0.2.0", features = ["const-fn"], optional = true } volatile-register = "0.2.0" bitfield = "0.13.2" -embedded-hal = "0.2.4" +embedded-hal = { version = "0.2.4", optional = true } [features] +default = ["interrupt", "delay"] cm7-r0p1 = [] inline-asm = [] linker-plugin-lto = [] +interrupt = ["bare-metal"] +delay = ["embedded-hal"] [workspace] members = ["xtask", "cortex-m-semihosting", "panic-semihosting", "panic-itm"] diff --git a/src/lib.rs b/src/lib.rs index 6a736924..cabcfc1e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,7 +77,9 @@ // to be applied to the struct). #![deny(clippy::missing_inline_in_public_items)] +#[cfg(feature = "interrupt")] extern crate bare_metal; + extern crate volatile_register; #[macro_use] @@ -88,12 +90,18 @@ mod macros; pub mod asm; #[cfg(armv8m)] pub mod cmse; + +#[cfg(feature = "delay")] pub mod delay; +#[cfg(feature = "interrupt")] pub mod interrupt; #[cfg(all(not(armv6m), not(armv8m_base)))] pub mod itm; pub mod peripheral; + +#[cfg(feature = "delay")] pub mod prelude; + pub mod register; pub use crate::peripheral::Peripherals; diff --git a/src/peripheral/mod.rs b/src/peripheral/mod.rs index 8f5678db..46a8278d 100644 --- a/src/peripheral/mod.rs +++ b/src/peripheral/mod.rs @@ -58,6 +58,7 @@ use core::marker::PhantomData; use core::ops; +#[cfg(feature = "interrupt")] use crate::interrupt; #[cfg(not(armv6m))] @@ -156,6 +157,7 @@ static mut TAKEN: bool = false; impl Peripherals { /// Returns all the core peripherals *once* #[inline] + #[cfg(feature = "interrupt")] pub fn take() -> Option { interrupt::free(|_| { if unsafe { TAKEN } { diff --git a/src/peripheral/nvic.rs b/src/peripheral/nvic.rs index f0c5457f..1de08a55 100644 --- a/src/peripheral/nvic.rs +++ b/src/peripheral/nvic.rs @@ -4,7 +4,9 @@ use volatile_register::RW; #[cfg(not(armv6m))] use volatile_register::{RO, WO}; +#[cfg(feature = "interrupt")] use crate::interrupt::InterruptNumber; +#[cfg(feature = "interrupt")] use crate::peripheral::NVIC; /// Register block @@ -74,6 +76,7 @@ pub struct RegisterBlock { pub stir: WO, } +#[cfg(feature = "interrupt")] impl NVIC { /// Request an IRQ in software /// diff --git a/src/prelude.rs b/src/prelude.rs index bc47cc02..d89c301b 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1,3 +1,4 @@ //! Prelude +#[cfg(feature = "delay")] pub use embedded_hal::prelude::*;