diff --git a/embassy-cortex-m/Cargo.toml b/embassy-cortex-m/Cargo.toml new file mode 100644 index 000000000..8bd30403e --- /dev/null +++ b/embassy-cortex-m/Cargo.toml @@ -0,0 +1,47 @@ +[package] +name = "embassy-cortex-m" +version = "0.1.0" +authors = ["Dario Nieuwenhuis "] +edition = "2018" +resolver = "2" + +[package.metadata.embassy_docs] +src_base = "https://github.com/embassy-rs/embassy/blob/embassy-cortex-m-v$VERSION/embassy-cortex-m/src/" +src_base_git = "https://github.com/embassy-rs/embassy/blob/master/embassy-cortex-m/src/" +features = [] +flavors = [ + { name = "thumbv6m-none-eabi", target = "thumbv6m-none-eabi", features = [] }, + { name = "thumbv7m-none-eabi", target = "thumbv7m-none-eabi", features = [] }, + { name = "thumbv7em-none-eabi", target = "thumbv7em-none-eabi", features = [] }, + { name = "thumbv7em-none-eabihf", target = "thumbv7em-none-eabihf", features = [] }, + { name = "thumbv8m.base-none-eabi", target = "thumbv8m.base-none-eabi", features = [] }, + { name = "thumbv8m.main-none-eabi", target = "thumbv8m.main-none-eabi", features = [] }, + { name = "thumbv8m.main-none-eabihf", target = "thumbv8m.main-none-eabihf", features = [] }, +] + +[features] +default = [] + +# Define the number of NVIC priority bits. +prio-bits-0 = [] +prio-bits-1 = [] +prio-bits-2 = [] +prio-bits-3 = [] +prio-bits-4 = [] +prio-bits-5 = [] +prio-bits-6 = [] +prio-bits-7 = [] +prio-bits-8 = [] + +[dependencies] +defmt = { version = "0.3", optional = true } +log = { version = "0.4.14", optional = true } + +embassy = { version = "0.1.0", path = "../embassy"} +embassy-macros = { version = "0.1.0", path = "../embassy-macros"} +embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common"} +atomic-polyfill = "0.1.5" +critical-section = "0.2.5" +cfg-if = "1.0.0" +cortex-m = "0.7.3" + diff --git a/embassy-cortex-m/build.rs b/embassy-cortex-m/build.rs new file mode 100644 index 000000000..6fe82b44f --- /dev/null +++ b/embassy-cortex-m/build.rs @@ -0,0 +1,29 @@ +use std::env; + +fn main() { + let target = env::var("TARGET").unwrap(); + + if target.starts_with("thumbv6m-") { + println!("cargo:rustc-cfg=cortex_m"); + println!("cargo:rustc-cfg=armv6m"); + } else if target.starts_with("thumbv7m-") { + println!("cargo:rustc-cfg=cortex_m"); + println!("cargo:rustc-cfg=armv7m"); + } else if target.starts_with("thumbv7em-") { + println!("cargo:rustc-cfg=cortex_m"); + println!("cargo:rustc-cfg=armv7m"); + println!("cargo:rustc-cfg=armv7em"); // (not currently used) + } else if target.starts_with("thumbv8m.base") { + println!("cargo:rustc-cfg=cortex_m"); + println!("cargo:rustc-cfg=armv8m"); + println!("cargo:rustc-cfg=armv8m_base"); + } else if target.starts_with("thumbv8m.main") { + println!("cargo:rustc-cfg=cortex_m"); + println!("cargo:rustc-cfg=armv8m"); + println!("cargo:rustc-cfg=armv8m_main"); + } + + if target.ends_with("-eabihf") { + println!("cargo:rustc-cfg=has_fpu"); + } +} diff --git a/embassy-cortex-m/src/executor.rs b/embassy-cortex-m/src/executor.rs new file mode 100644 index 000000000..63a1519cf --- /dev/null +++ b/embassy-cortex-m/src/executor.rs @@ -0,0 +1,89 @@ +use core::marker::PhantomData; + +use crate::interrupt::{Interrupt, InterruptExt}; +use embassy::executor::{raw, SendSpawner}; + +pub use embassy::executor::Executor; + +fn pend_by_number(n: u16) { + #[derive(Clone, Copy)] + struct N(u16); + unsafe impl cortex_m::interrupt::InterruptNumber for N { + fn number(self) -> u16 { + self.0 + } + } + cortex_m::peripheral::NVIC::pend(N(n)) +} + +/// Interrupt mode executor. +/// +/// This executor runs tasks in interrupt mode. The interrupt handler is set up +/// to poll tasks, and when a task is woken the interrupt is pended from software. +/// +/// This allows running async tasks at a priority higher than thread mode. One +/// use case is to leave thread mode free for non-async tasks. Another use case is +/// to run multiple executors: one in thread mode for low priority tasks and another in +/// interrupt mode for higher priority tasks. Higher priority tasks will preempt lower +/// priority ones. +/// +/// It is even possible to run multiple interrupt mode executors at different priorities, +/// by assigning different priorities to the interrupts. For an example on how to do this, +/// See the 'multiprio' example for 'embassy-nrf'. +/// +/// To use it, you have to pick an interrupt that won't be used by the hardware. +/// Some chips reserve some interrupts for this purpose, sometimes named "software interrupts" (SWI). +/// If this is not the case, you may use an interrupt from any unused peripheral. +/// +/// It is somewhat more complex to use, it's recommended to use the thread-mode +/// [`Executor`] instead, if it works for your use case. +pub struct InterruptExecutor { + irq: I, + inner: raw::Executor, + not_send: PhantomData<*mut ()>, +} + +impl InterruptExecutor { + /// Create a new Executor. + pub fn new(irq: I) -> Self { + let ctx = irq.number() as *mut (); + Self { + irq, + inner: raw::Executor::new(|ctx| pend_by_number(ctx as u16), ctx), + not_send: PhantomData, + } + } + + /// Start the executor. + /// + /// This initializes the executor, configures and enables the interrupt, and returns. + /// The executor keeps running in the background through the interrupt. + /// + /// This returns a [`SendSpawner`] you can use to spawn tasks on it. A [`SendSpawner`] + /// is returned instead of a [`Spawner`] because the executor effectively runs in a + /// different "thread" (the interrupt), so spawning tasks on it is effectively + /// sending them. + /// + /// To obtain a [`Spawner`] for this executor, use [`Spawner::for_current_executor`] from + /// a task running in it. + /// + /// This function requires `&'static mut self`. This means you have to store the + /// Executor instance in a place where it'll live forever and grants you mutable + /// access. There's a few ways to do this: + /// + /// - a [Forever](crate::util::Forever) (safe) + /// - a `static mut` (unsafe) + /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) + pub fn start(&'static mut self) -> SendSpawner { + self.irq.disable(); + + self.irq.set_handler(|ctx| unsafe { + let executor = &*(ctx as *const raw::Executor); + executor.poll(); + }); + self.irq.set_handler_context(&self.inner as *const _ as _); + self.irq.enable(); + + self.inner.spawner().make_send() + } +} diff --git a/embassy-cortex-m/src/fmt.rs b/embassy-cortex-m/src/fmt.rs new file mode 100644 index 000000000..f8bb0a035 --- /dev/null +++ b/embassy-cortex-m/src/fmt.rs @@ -0,0 +1,228 @@ +#![macro_use] +#![allow(unused_macros)] + +#[cfg(all(feature = "defmt", feature = "log"))] +compile_error!("You may not enable both `defmt` and `log` features."); + +macro_rules! assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::assert!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::assert!($($x)*); + } + }; +} + +macro_rules! assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::assert_eq!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::assert_eq!($($x)*); + } + }; +} + +macro_rules! assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::assert_ne!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::assert_ne!($($x)*); + } + }; +} + +macro_rules! debug_assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::debug_assert!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::debug_assert!($($x)*); + } + }; +} + +macro_rules! debug_assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::debug_assert_eq!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::debug_assert_eq!($($x)*); + } + }; +} + +macro_rules! debug_assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::debug_assert_ne!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::debug_assert_ne!($($x)*); + } + }; +} + +macro_rules! todo { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::todo!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::todo!($($x)*); + } + }; +} + +macro_rules! unreachable { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::unreachable!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::unreachable!($($x)*); + } + }; +} + +macro_rules! panic { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::panic!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::panic!($($x)*); + } + }; +} + +macro_rules! trace { + ($s:literal $(, $x:expr)* $(,)?) => { + { + #[cfg(feature = "log")] + ::log::trace!($s $(, $x)*); + #[cfg(feature = "defmt")] + ::defmt::trace!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); + } + }; +} + +macro_rules! debug { + ($s:literal $(, $x:expr)* $(,)?) => { + { + #[cfg(feature = "log")] + ::log::debug!($s $(, $x)*); + #[cfg(feature = "defmt")] + ::defmt::debug!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); + } + }; +} + +macro_rules! info { + ($s:literal $(, $x:expr)* $(,)?) => { + { + #[cfg(feature = "log")] + ::log::info!($s $(, $x)*); + #[cfg(feature = "defmt")] + ::defmt::info!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); + } + }; +} + +macro_rules! warn { + ($s:literal $(, $x:expr)* $(,)?) => { + { + #[cfg(feature = "log")] + ::log::warn!($s $(, $x)*); + #[cfg(feature = "defmt")] + ::defmt::warn!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); + } + }; +} + +macro_rules! error { + ($s:literal $(, $x:expr)* $(,)?) => { + { + #[cfg(feature = "log")] + ::log::error!($s $(, $x)*); + #[cfg(feature = "defmt")] + ::defmt::error!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); + } + }; +} + +#[cfg(feature = "defmt")] +macro_rules! unwrap { + ($($x:tt)*) => { + ::defmt::unwrap!($($x)*) + }; +} + +#[cfg(not(feature = "defmt"))] +macro_rules! unwrap { + ($arg:expr) => { + match $crate::fmt::Try::into_result($arg) { + ::core::result::Result::Ok(t) => t, + ::core::result::Result::Err(e) => { + ::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e); + } + } + }; + ($arg:expr, $($msg:expr),+ $(,)? ) => { + match $crate::fmt::Try::into_result($arg) { + ::core::result::Result::Ok(t) => t, + ::core::result::Result::Err(e) => { + ::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e); + } + } + } +} + +#[cfg(feature = "defmt-timestamp-uptime")] +defmt::timestamp! {"{=u64:us}", crate::time::Instant::now().as_micros() } + +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct NoneError; + +pub trait Try { + type Ok; + type Error; + fn into_result(self) -> Result; +} + +impl Try for Option { + type Ok = T; + type Error = NoneError; + + #[inline] + fn into_result(self) -> Result { + self.ok_or(NoneError) + } +} + +impl Try for Result { + type Ok = T; + type Error = E; + + #[inline] + fn into_result(self) -> Self { + self + } +} diff --git a/embassy-hal-common/src/interrupt.rs b/embassy-cortex-m/src/interrupt.rs similarity index 59% rename from embassy-hal-common/src/interrupt.rs rename to embassy-cortex-m/src/interrupt.rs index 80b2cad5d..df2aad0ec 100644 --- a/embassy-hal-common/src/interrupt.rs +++ b/embassy-cortex-m/src/interrupt.rs @@ -1,49 +1,198 @@ +use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; use core::mem; +use core::ptr; +use cortex_m::peripheral::NVIC; +use embassy_hal_common::Unborrow; -macro_rules! prio { - ($name:ident, $mask:expr, ($($k:ident = $v:expr,)*)) => { - #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] - #[cfg_attr(feature = "defmt", derive(defmt::Format))] - #[repr(u8)] - pub enum $name { - $($k = $v),* - } +pub use embassy_macros::cortex_m_interrupt_take as take; - impl From for $name { - fn from(priority: u8) -> Self { - unsafe { mem::transmute(priority & $mask) } - } - } - - impl From<$name> for u8 { - fn from(p: $name) -> Self { - p as u8 - } - } - }; +/// Implementation detail, do not use outside embassy crates. +#[doc(hidden)] +pub struct Handler { + pub func: AtomicPtr<()>, + pub ctx: AtomicPtr<()>, } -#[rustfmt::skip] -prio!(Priority0, 0x00, ( - P0 = 0x0, -)); +impl Handler { + pub const fn new() -> Self { + Self { + func: AtomicPtr::new(ptr::null_mut()), + ctx: AtomicPtr::new(ptr::null_mut()), + } + } +} -#[rustfmt::skip] -prio!(Priority1, 0x80, ( +#[derive(Clone, Copy)] +pub(crate) struct NrWrap(pub(crate) u16); +unsafe impl cortex_m::interrupt::InterruptNumber for NrWrap { + fn number(self) -> u16 { + self.0 + } +} + +pub unsafe trait Interrupt: Unborrow { + fn number(&self) -> u16; + unsafe fn steal() -> Self; + + /// Implementation detail, do not use outside embassy crates. + #[doc(hidden)] + unsafe fn __handler(&self) -> &'static Handler; +} + +pub trait InterruptExt: Interrupt { + fn set_handler(&self, func: unsafe fn(*mut ())); + fn remove_handler(&self); + fn set_handler_context(&self, ctx: *mut ()); + fn enable(&self); + fn disable(&self); + #[cfg(not(armv6m))] + fn is_active(&self) -> bool; + fn is_enabled(&self) -> bool; + fn is_pending(&self) -> bool; + fn pend(&self); + fn unpend(&self); + fn get_priority(&self) -> Priority; + fn set_priority(&self, prio: Priority); +} + +impl InterruptExt for T { + fn set_handler(&self, func: unsafe fn(*mut ())) { + compiler_fence(Ordering::SeqCst); + let handler = unsafe { self.__handler() }; + handler.func.store(func as *mut (), Ordering::Relaxed); + compiler_fence(Ordering::SeqCst); + } + + fn remove_handler(&self) { + compiler_fence(Ordering::SeqCst); + let handler = unsafe { self.__handler() }; + handler.func.store(ptr::null_mut(), Ordering::Relaxed); + compiler_fence(Ordering::SeqCst); + } + + fn set_handler_context(&self, ctx: *mut ()) { + let handler = unsafe { self.__handler() }; + handler.ctx.store(ctx, Ordering::Relaxed); + } + + #[inline] + fn enable(&self) { + compiler_fence(Ordering::SeqCst); + unsafe { + NVIC::unmask(NrWrap(self.number())); + } + } + + #[inline] + fn disable(&self) { + NVIC::mask(NrWrap(self.number())); + compiler_fence(Ordering::SeqCst); + } + + #[inline] + #[cfg(not(armv6m))] + fn is_active(&self) -> bool { + NVIC::is_active(NrWrap(self.number())) + } + + #[inline] + fn is_enabled(&self) -> bool { + NVIC::is_enabled(NrWrap(self.number())) + } + + #[inline] + fn is_pending(&self) -> bool { + NVIC::is_pending(NrWrap(self.number())) + } + + #[inline] + fn pend(&self) { + NVIC::pend(NrWrap(self.number())) + } + + #[inline] + fn unpend(&self) { + NVIC::unpend(NrWrap(self.number())) + } + + #[inline] + fn get_priority(&self) -> Priority { + Priority::from(NVIC::get_priority(NrWrap(self.number()))) + } + + #[inline] + fn set_priority(&self, prio: Priority) { + unsafe { + let mut nvic: cortex_m::peripheral::NVIC = mem::transmute(()); + nvic.set_priority(NrWrap(self.number()), prio.into()) + } + } +} + +impl From for Priority { + fn from(priority: u8) -> Self { + unsafe { mem::transmute(priority & PRIO_MASK) } + } +} + +impl From for u8 { + fn from(p: Priority) -> Self { + p as u8 + } +} + +#[cfg(feature = "prio-bits-0")] +const PRIO_MASK: u8 = 0x00; +#[cfg(feature = "prio-bits-1")] +const PRIO_MASK: u8 = 0x80; +#[cfg(feature = "prio-bits-2")] +const PRIO_MASK: u8 = 0xc0; +#[cfg(feature = "prio-bits-3")] +const PRIO_MASK: u8 = 0xe0; +#[cfg(feature = "prio-bits-4")] +const PRIO_MASK: u8 = 0xf0; +#[cfg(feature = "prio-bits-5")] +const PRIO_MASK: u8 = 0xf8; +#[cfg(feature = "prio-bits-6")] +const PRIO_MASK: u8 = 0xfc; +#[cfg(feature = "prio-bits-7")] +const PRIO_MASK: u8 = 0xfe; +#[cfg(feature = "prio-bits-8")] +const PRIO_MASK: u8 = 0xff; + +#[cfg(feature = "prio-bits-0")] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[repr(u8)] +pub enum Priority { + P0 = 0x0, +} + +#[cfg(feature = "prio-bits-1")] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[repr(u8)] +pub enum Priority { P0 = 0x0, P1 = 0x80, -)); +} -#[rustfmt::skip] -prio!(Priority2, 0xc0, ( +#[cfg(feature = "prio-bits-2")] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[repr(u8)] +pub enum Priority { P0 = 0x0, P1 = 0x40, P2 = 0x80, P3 = 0xc0, -)); +} -#[rustfmt::skip] -prio!(Priority3, 0xe0, ( +#[cfg(feature = "prio-bits-3")] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[repr(u8)] +pub enum Priority { P0 = 0x0, P1 = 0x20, P2 = 0x40, @@ -52,10 +201,13 @@ prio!(Priority3, 0xe0, ( P5 = 0xa0, P6 = 0xc0, P7 = 0xe0, -)); +} -#[rustfmt::skip] -prio!(Priority4, 0xf0, ( +#[cfg(feature = "prio-bits-4")] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[repr(u8)] +pub enum Priority { P0 = 0x0, P1 = 0x10, P2 = 0x20, @@ -72,10 +224,13 @@ prio!(Priority4, 0xf0, ( P13 = 0xd0, P14 = 0xe0, P15 = 0xf0, -)); +} -#[rustfmt::skip] -prio!(Priority5, 0xf8, ( +#[cfg(feature = "prio-bits-5")] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[repr(u8)] +pub enum Priority { P0 = 0x0, P1 = 0x8, P2 = 0x10, @@ -108,10 +263,13 @@ prio!(Priority5, 0xf8, ( P29 = 0xe8, P30 = 0xf0, P31 = 0xf8, -)); +} -#[rustfmt::skip] -prio!(Priority6, 0xfc, ( +#[cfg(feature = "prio-bits-6")] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[repr(u8)] +pub enum Priority { P0 = 0x0, P1 = 0x4, P2 = 0x8, @@ -176,10 +334,13 @@ prio!(Priority6, 0xfc, ( P61 = 0xf4, P62 = 0xf8, P63 = 0xfc, -)); +} -#[rustfmt::skip] -prio!(Priority7, 0xfe, ( +#[cfg(feature = "prio-bits-7")] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[repr(u8)] +pub enum Priority { P0 = 0x0, P1 = 0x2, P2 = 0x4, @@ -308,10 +469,13 @@ prio!(Priority7, 0xfe, ( P125 = 0xfa, P126 = 0xfc, P127 = 0xfe, -)); +} -#[rustfmt::skip] -prio!(Priority8, 0xff, ( +#[cfg(feature = "prio-bits-8")] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[repr(u8)] +pub enum Priority { P0 = 0x0, P1 = 0x1, P2 = 0x2, @@ -568,4 +732,4 @@ prio!(Priority8, 0xff, ( P253 = 0xfd, P254 = 0xfe, P255 = 0xff, -)); +} diff --git a/embassy-cortex-m/src/lib.rs b/embassy-cortex-m/src/lib.rs new file mode 100644 index 000000000..143c56f39 --- /dev/null +++ b/embassy-cortex-m/src/lib.rs @@ -0,0 +1,8 @@ +#![no_std] + +// This mod MUST go first, so that the others see its macros. +pub(crate) mod fmt; + +pub mod executor; +pub mod interrupt; +pub mod peripheral; diff --git a/embassy-hal-common/src/peripheral.rs b/embassy-cortex-m/src/peripheral.rs similarity index 97% rename from embassy-hal-common/src/peripheral.rs rename to embassy-cortex-m/src/peripheral.rs index db2bc7888..40277691c 100644 --- a/embassy-hal-common/src/peripheral.rs +++ b/embassy-cortex-m/src/peripheral.rs @@ -1,9 +1,9 @@ use core::marker::PhantomData; use core::mem::MaybeUninit; - use cortex_m::peripheral::scb::VectActive; use cortex_m::peripheral::{NVIC, SCB}; -use embassy::interrupt::{Interrupt, InterruptExt}; + +use crate::interrupt::{Interrupt, InterruptExt, Priority}; /// A type which can be used as state with `PeripheralMutex`. /// @@ -116,7 +116,7 @@ impl<'a, S: PeripheralState> PeripheralMutex<'a, S> { } /// Gets the priority of the wrapped interrupt. - pub fn priority(&self) -> ::Priority { + pub fn priority(&self) -> Priority { self.irq.get_priority() } } diff --git a/embassy-hal-common/src/lib.rs b/embassy-hal-common/src/lib.rs index 6ee2ccd59..c8cf1c4cd 100644 --- a/embassy-hal-common/src/lib.rs +++ b/embassy-hal-common/src/lib.rs @@ -5,11 +5,11 @@ pub(crate) mod fmt; pub mod drop; -pub mod interrupt; mod macros; -pub mod peripheral; pub mod ratio; pub mod ring_buffer; +mod unborrow; +pub use unborrow::Unborrow; /// Low power blocking wait loop using WFE/SEV. pub fn low_power_wait_until(mut condition: impl FnMut() -> bool) { diff --git a/embassy-hal-common/src/macros.rs b/embassy-hal-common/src/macros.rs index 771db40f6..c054a87c4 100644 --- a/embassy-hal-common/src/macros.rs +++ b/embassy-hal-common/src/macros.rs @@ -16,7 +16,7 @@ macro_rules! peripherals { } $(#[$cfg])? - unsafe impl embassy::util::Unborrow for $name { + unsafe impl $crate::Unborrow for $name { type Target = $name; #[inline] unsafe fn unborrow(self) -> $name { @@ -80,7 +80,7 @@ macro_rules! unborrow { #[macro_export] macro_rules! unsafe_impl_unborrow { ($type:ident) => { - unsafe impl ::embassy::util::Unborrow for $type { + unsafe impl $crate::Unborrow for $type { type Target = $type; #[inline] unsafe fn unborrow(self) -> Self::Target { diff --git a/embassy/src/util/unborrow.rs b/embassy-hal-common/src/unborrow.rs similarity index 100% rename from embassy/src/util/unborrow.rs rename to embassy-hal-common/src/unborrow.rs diff --git a/embassy-lora/src/stm32wl/mod.rs b/embassy-lora/src/stm32wl/mod.rs index 7dc750cf9..b5ce278dc 100644 --- a/embassy-lora/src/stm32wl/mod.rs +++ b/embassy-lora/src/stm32wl/mod.rs @@ -2,9 +2,9 @@ use core::future::Future; use core::mem::MaybeUninit; use embassy::channel::signal::Signal; -use embassy::interrupt::InterruptExt; -use embassy::util::Unborrow; use embassy_hal_common::unborrow; +use embassy_stm32::interrupt::InterruptExt; +use embassy_stm32::Unborrow; use embassy_stm32::{ dma::NoDma, gpio::{AnyPin, Output}, diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs index 085f7889d..50f442438 100644 --- a/embassy-macros/src/lib.rs +++ b/embassy-macros/src/lib.rs @@ -22,16 +22,20 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { } #[proc_macro_attribute] -pub fn interrupt(args: TokenStream, item: TokenStream) -> TokenStream { +pub fn cortex_m_interrupt(args: TokenStream, item: TokenStream) -> TokenStream { let args = syn::parse_macro_input!(args as syn::AttributeArgs); let f = syn::parse_macro_input!(item as syn::ItemFn); - interrupt::run(args, f).unwrap_or_else(|x| x).into() + cortex_m_interrupt::run(args, f) + .unwrap_or_else(|x| x) + .into() } #[proc_macro] -pub fn interrupt_declare(item: TokenStream) -> TokenStream { +pub fn cortex_m_interrupt_declare(item: TokenStream) -> TokenStream { let name = syn::parse_macro_input!(item as syn::Ident); - interrupt_declare::run(name).unwrap_or_else(|x| x).into() + cortex_m_interrupt_declare::run(name) + .unwrap_or_else(|x| x) + .into() } /// # interrupt_take procedural macro @@ -40,7 +44,9 @@ pub fn interrupt_declare(item: TokenStream) -> TokenStream { /// We are aware that this brings bloat in the form of core::fmt, but the bloat is already included with e.g. array indexing panics. /// To get rid of this bloat, use the compiler flags `-Zbuild-std=core -Zbuild-std-features=panic_immediate_abort`. #[proc_macro] -pub fn interrupt_take(item: TokenStream) -> TokenStream { +pub fn cortex_m_interrupt_take(item: TokenStream) -> TokenStream { let name = syn::parse_macro_input!(item as syn::Ident); - interrupt_take::run(name).unwrap_or_else(|x| x).into() + cortex_m_interrupt_take::run(name) + .unwrap_or_else(|x| x) + .into() } diff --git a/embassy-macros/src/macros/interrupt.rs b/embassy-macros/src/macros/cortex_m_interrupt.rs similarity index 100% rename from embassy-macros/src/macros/interrupt.rs rename to embassy-macros/src/macros/cortex_m_interrupt.rs diff --git a/embassy-macros/src/macros/interrupt_declare.rs b/embassy-macros/src/macros/cortex_m_interrupt_declare.rs similarity index 70% rename from embassy-macros/src/macros/interrupt_declare.rs rename to embassy-macros/src/macros/cortex_m_interrupt_declare.rs index 0059936d9..eeed5d483 100644 --- a/embassy-macros/src/macros/interrupt_declare.rs +++ b/embassy-macros/src/macros/cortex_m_interrupt_declare.rs @@ -9,8 +9,7 @@ pub fn run(name: syn::Ident) -> Result { let result = quote! { #[allow(non_camel_case_types)] pub struct #name_interrupt(()); - unsafe impl ::embassy::interrupt::Interrupt for #name_interrupt { - type Priority = crate::interrupt::Priority; + unsafe impl ::embassy_cortex_m::interrupt::Interrupt for #name_interrupt { fn number(&self) -> u16 { use cortex_m::interrupt::InterruptNumber; let irq = InterruptEnum::#name; @@ -19,14 +18,14 @@ pub fn run(name: syn::Ident) -> Result { unsafe fn steal() -> Self { Self(()) } - unsafe fn __handler(&self) -> &'static ::embassy::interrupt::Handler { + unsafe fn __handler(&self) -> &'static ::embassy_cortex_m::interrupt::Handler { #[export_name = #name_handler] - static HANDLER: ::embassy::interrupt::Handler = ::embassy::interrupt::Handler::new(); + static HANDLER: ::embassy_cortex_m::interrupt::Handler = ::embassy_cortex_m::interrupt::Handler::new(); &HANDLER } } - unsafe impl ::embassy::util::Unborrow for #name_interrupt { + unsafe impl ::embassy_hal_common::Unborrow for #name_interrupt { type Target = #name_interrupt; unsafe fn unborrow(self) -> #name_interrupt { self diff --git a/embassy-macros/src/macros/interrupt_take.rs b/embassy-macros/src/macros/cortex_m_interrupt_take.rs similarity index 95% rename from embassy-macros/src/macros/interrupt_take.rs rename to embassy-macros/src/macros/cortex_m_interrupt_take.rs index 230b9c741..29dca12fd 100644 --- a/embassy-macros/src/macros/interrupt_take.rs +++ b/embassy-macros/src/macros/cortex_m_interrupt_take.rs @@ -13,7 +13,7 @@ pub fn run(name: syn::Ident) -> Result { pub unsafe extern "C" fn trampoline() { extern "C" { #[link_name = #name_handler] - static HANDLER: ::embassy::interrupt::Handler; + static HANDLER: interrupt::Handler; } let func = HANDLER.func.load(::embassy::export::atomic::Ordering::Relaxed); diff --git a/embassy-macros/src/macros/mod.rs b/embassy-macros/src/macros/mod.rs index 4350f229f..e547736fc 100644 --- a/embassy-macros/src/macros/mod.rs +++ b/embassy-macros/src/macros/mod.rs @@ -1,5 +1,5 @@ -pub mod interrupt; -pub mod interrupt_declare; -pub mod interrupt_take; +pub mod cortex_m_interrupt; +pub mod cortex_m_interrupt_declare; +pub mod cortex_m_interrupt_take; pub mod main; pub mod task; diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index bf903af6d..f1e6815a5 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml @@ -66,6 +66,7 @@ _gpio-p1 = [] [dependencies] embassy = { version = "0.1.0", path = "../embassy" } +embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]} embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["nrf"]} embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } embassy-usb = {version = "0.1.0", path = "../embassy-usb", optional=true } diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index 6972d625d..ef3ccdc93 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs @@ -13,15 +13,15 @@ //! //! Please also see [crate::uarte] to understand when [BufferedUarte] should be used. +use crate::interrupt::InterruptExt; +use crate::Unborrow; use core::cmp::min; use core::future::Future; use core::marker::PhantomData; use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; -use embassy::interrupt::InterruptExt; -use embassy::util::Unborrow; use embassy::waitqueue::WakerRegistration; -use embassy_hal_common::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; +use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; use embassy_hal_common::ring_buffer::RingBuffer; use embassy_hal_common::{low_power_wait_until, unborrow}; use futures::future::poll_fn; diff --git a/embassy-nrf/src/chips/nrf52805.rs b/embassy-nrf/src/chips/nrf52805.rs index c917dcdd0..31659859b 100644 --- a/embassy-nrf/src/chips/nrf52805.rs +++ b/embassy-nrf/src/chips/nrf52805.rs @@ -198,7 +198,7 @@ impl_saadc_input!(P0_05, ANALOGINPUT3); pub mod irqs { use crate::pac::Interrupt as InterruptEnum; - use embassy_macros::interrupt_declare as declare; + use embassy_macros::cortex_m_interrupt_declare as declare; declare!(POWER_CLOCK); declare!(RADIO); diff --git a/embassy-nrf/src/chips/nrf52810.rs b/embassy-nrf/src/chips/nrf52810.rs index 922b683f9..195be51c8 100644 --- a/embassy-nrf/src/chips/nrf52810.rs +++ b/embassy-nrf/src/chips/nrf52810.rs @@ -219,7 +219,7 @@ impl_saadc_input!(P0_31, ANALOGINPUT7); pub mod irqs { use crate::pac::Interrupt as InterruptEnum; - use embassy_macros::interrupt_declare as declare; + use embassy_macros::cortex_m_interrupt_declare as declare; declare!(POWER_CLOCK); declare!(RADIO); diff --git a/embassy-nrf/src/chips/nrf52811.rs b/embassy-nrf/src/chips/nrf52811.rs index d23ab5b39..18f054059 100644 --- a/embassy-nrf/src/chips/nrf52811.rs +++ b/embassy-nrf/src/chips/nrf52811.rs @@ -220,7 +220,7 @@ impl_saadc_input!(P0_31, ANALOGINPUT7); pub mod irqs { use crate::pac::Interrupt as InterruptEnum; - use embassy_macros::interrupt_declare as declare; + use embassy_macros::cortex_m_interrupt_declare as declare; declare!(POWER_CLOCK); declare!(RADIO); diff --git a/embassy-nrf/src/chips/nrf52820.rs b/embassy-nrf/src/chips/nrf52820.rs index e94ddbb14..b4ad4c729 100644 --- a/embassy-nrf/src/chips/nrf52820.rs +++ b/embassy-nrf/src/chips/nrf52820.rs @@ -212,7 +212,7 @@ impl_ppi_channel!(PPI_CH31, 31 => static); pub mod irqs { use crate::pac::Interrupt as InterruptEnum; - use embassy_macros::interrupt_declare as declare; + use embassy_macros::cortex_m_interrupt_declare as declare; declare!(POWER_CLOCK); declare!(RADIO); diff --git a/embassy-nrf/src/chips/nrf52832.rs b/embassy-nrf/src/chips/nrf52832.rs index fec7e10de..d578519ff 100644 --- a/embassy-nrf/src/chips/nrf52832.rs +++ b/embassy-nrf/src/chips/nrf52832.rs @@ -236,7 +236,7 @@ impl_saadc_input!(P0_31, ANALOGINPUT7); pub mod irqs { use crate::pac::Interrupt as InterruptEnum; - use embassy_macros::interrupt_declare as declare; + use embassy_macros::cortex_m_interrupt_declare as declare; declare!(POWER_CLOCK); declare!(RADIO); diff --git a/embassy-nrf/src/chips/nrf52833.rs b/embassy-nrf/src/chips/nrf52833.rs index e09c77187..92f415a51 100644 --- a/embassy-nrf/src/chips/nrf52833.rs +++ b/embassy-nrf/src/chips/nrf52833.rs @@ -279,7 +279,7 @@ impl_saadc_input!(P0_31, ANALOGINPUT7); pub mod irqs { use crate::pac::Interrupt as InterruptEnum; - use embassy_macros::interrupt_declare as declare; + use embassy_macros::cortex_m_interrupt_declare as declare; declare!(POWER_CLOCK); declare!(RADIO); diff --git a/embassy-nrf/src/chips/nrf52840.rs b/embassy-nrf/src/chips/nrf52840.rs index 2e71e04b0..e7a94b18f 100644 --- a/embassy-nrf/src/chips/nrf52840.rs +++ b/embassy-nrf/src/chips/nrf52840.rs @@ -284,7 +284,7 @@ impl_saadc_input!(P0_31, ANALOGINPUT7); pub mod irqs { use crate::pac::Interrupt as InterruptEnum; - use embassy_macros::interrupt_declare as declare; + use embassy_macros::cortex_m_interrupt_declare as declare; declare!(POWER_CLOCK); declare!(RADIO); diff --git a/embassy-nrf/src/chips/nrf5340_app.rs b/embassy-nrf/src/chips/nrf5340_app.rs index 89579b69f..13ed23cd7 100644 --- a/embassy-nrf/src/chips/nrf5340_app.rs +++ b/embassy-nrf/src/chips/nrf5340_app.rs @@ -469,7 +469,7 @@ impl_saadc_input!(P0_20, ANALOGINPUT7); pub mod irqs { use crate::pac::Interrupt as InterruptEnum; - use embassy_macros::interrupt_declare as declare; + use embassy_macros::cortex_m_interrupt_declare as declare; declare!(FPU); declare!(CACHE); diff --git a/embassy-nrf/src/chips/nrf5340_net.rs b/embassy-nrf/src/chips/nrf5340_net.rs index e2ae97a9d..a7e70cdc3 100644 --- a/embassy-nrf/src/chips/nrf5340_net.rs +++ b/embassy-nrf/src/chips/nrf5340_net.rs @@ -329,7 +329,7 @@ impl_ppi_channel!(PPI_CH31, 31 => configurable); pub mod irqs { use crate::pac::Interrupt as InterruptEnum; - use embassy_macros::interrupt_declare as declare; + use embassy_macros::cortex_m_interrupt_declare as declare; declare!(CLOCK_POWER); declare!(RADIO); diff --git a/embassy-nrf/src/chips/nrf9160.rs b/embassy-nrf/src/chips/nrf9160.rs index b8caa1264..57ff39b7b 100644 --- a/embassy-nrf/src/chips/nrf9160.rs +++ b/embassy-nrf/src/chips/nrf9160.rs @@ -347,7 +347,7 @@ impl_saadc_input!(P0_20, ANALOGINPUT7); pub mod irqs { use crate::pac::Interrupt as InterruptEnum; - use embassy_macros::interrupt_declare as declare; + use embassy_macros::cortex_m_interrupt_declare as declare; declare!(SPU); declare!(CLOCK_POWER); diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index f5212c6af..a6c846213 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs @@ -4,8 +4,8 @@ use core::convert::Infallible; use core::hint::unreachable_unchecked; use core::marker::PhantomData; +use crate::Unborrow; use cfg_if::cfg_if; -use embassy::util::Unborrow; use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; use crate::pac; diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index c0bfd9d65..051546236 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs @@ -1,8 +1,8 @@ +use crate::interrupt::{Interrupt, InterruptExt}; use core::convert::Infallible; use core::future::Future; use core::marker::PhantomData; use core::task::{Context, Poll}; -use embassy::interrupt::{Interrupt, InterruptExt}; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unsafe_impl_unborrow; use futures::future::poll_fn; diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 9c298a8b0..6eaadfc63 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs @@ -114,23 +114,23 @@ mod chip; pub use chip::EASY_DMA_SIZE; +pub mod interrupt { + pub use crate::chip::irqs::*; + pub use cortex_m::interrupt::{CriticalSection, Mutex}; + pub use embassy_cortex_m::interrupt::*; +} + +// Reexports + #[cfg(feature = "unstable-pac")] pub use chip::pac; #[cfg(not(feature = "unstable-pac"))] pub(crate) use chip::pac; -pub use embassy::util::Unborrow; -pub use embassy_hal_common::unborrow; - pub use chip::{peripherals, Peripherals}; - -pub mod interrupt { - pub use crate::chip::irqs::*; - pub use cortex_m::interrupt::{CriticalSection, Mutex}; - pub use embassy::interrupt::{declare, take, Interrupt}; - pub use embassy_hal_common::interrupt::Priority3 as Priority; -} -pub use embassy_macros::interrupt; +pub use embassy_cortex_m::executor; +pub use embassy_hal_common::{unborrow, Unborrow}; +pub use embassy_macros::cortex_m_interrupt as interrupt; pub mod config { pub enum HfclkSource { diff --git a/embassy-nrf/src/nvmc.rs b/embassy-nrf/src/nvmc.rs index 7d7b56841..108a71d5e 100644 --- a/embassy-nrf/src/nvmc.rs +++ b/embassy-nrf/src/nvmc.rs @@ -3,10 +3,10 @@ use crate::pac; use crate::peripherals::NVMC; +use crate::Unborrow; use core::marker::PhantomData; use core::ptr; use core::slice; -use embassy::util::Unborrow; use embassy_hal_common::unborrow; use embedded_storage::nor_flash::{ ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, diff --git a/embassy-nrf/src/ppi/dppi.rs b/embassy-nrf/src/ppi/dppi.rs index 1842590b4..8609ef8d4 100644 --- a/embassy-nrf/src/ppi/dppi.rs +++ b/embassy-nrf/src/ppi/dppi.rs @@ -1,6 +1,6 @@ use core::marker::PhantomData; -use embassy::util::Unborrow; +use crate::Unborrow; use embassy_hal_common::unborrow; use crate::pac; diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs index aeccb154b..faabbf7ca 100644 --- a/embassy-nrf/src/ppi/mod.rs +++ b/embassy-nrf/src/ppi/mod.rs @@ -16,9 +16,9 @@ //! use crate::peripherals; +use crate::Unborrow; use core::marker::PhantomData; use core::ptr::NonNull; -use embassy::util::Unborrow; use embassy_hal_common::unsafe_impl_unborrow; #[cfg(feature = "_dppi")] diff --git a/embassy-nrf/src/ppi/ppi.rs b/embassy-nrf/src/ppi/ppi.rs index cdbe046f8..d832d69e7 100644 --- a/embassy-nrf/src/ppi/ppi.rs +++ b/embassy-nrf/src/ppi/ppi.rs @@ -1,6 +1,6 @@ use core::marker::PhantomData; -use embassy::util::Unborrow; +use crate::Unborrow; use embassy_hal_common::unborrow; use super::{Channel, ConfigurableChannel, Event, Ppi, StaticChannel, Task}; diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs index 5ac52f172..3ed60ca05 100644 --- a/embassy-nrf/src/pwm.rs +++ b/embassy-nrf/src/pwm.rs @@ -1,8 +1,8 @@ #![macro_use] +use crate::Unborrow; use core::marker::PhantomData; use core::sync::atomic::{compiler_fence, Ordering}; -use embassy::util::Unborrow; use embassy_hal_common::unborrow; use crate::gpio::sealed::Pin as _; diff --git a/embassy-nrf/src/qdec.rs b/embassy-nrf/src/qdec.rs index c26815389..b230043b4 100644 --- a/embassy-nrf/src/qdec.rs +++ b/embassy-nrf/src/qdec.rs @@ -6,10 +6,10 @@ use crate::interrupt; use crate::pac; use crate::peripherals::QDEC; +use crate::interrupt::InterruptExt; +use crate::Unborrow; use core::marker::PhantomData; use core::task::Poll; -use embassy::interrupt::InterruptExt; -use embassy::util::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unborrow; use futures::future::poll_fn; diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index 8902879f8..adb0d8386 100644 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs @@ -1,10 +1,10 @@ #![macro_use] +use crate::interrupt::{Interrupt, InterruptExt}; +use crate::Unborrow; use core::marker::PhantomData; use core::ptr; use core::task::Poll; -use embassy::interrupt::{Interrupt, InterruptExt}; -use embassy::util::Unborrow; use embassy_hal_common::drop::DropBomb; use embassy_hal_common::unborrow; use futures::future::poll_fn; diff --git a/embassy-nrf/src/rng.rs b/embassy-nrf/src/rng.rs index 98833c52b..43cf805fd 100644 --- a/embassy-nrf/src/rng.rs +++ b/embassy-nrf/src/rng.rs @@ -4,8 +4,8 @@ use core::sync::atomic::AtomicPtr; use core::sync::atomic::Ordering; use core::task::Poll; -use embassy::interrupt::InterruptExt; -use embassy::util::Unborrow; +use crate::interrupt::InterruptExt; +use crate::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::unborrow; diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index 61bc1fbda..915115a12 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs @@ -1,10 +1,10 @@ #![macro_use] +use crate::interrupt::InterruptExt; +use crate::Unborrow; use core::marker::PhantomData; use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; -use embassy::interrupt::InterruptExt; -use embassy::util::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unborrow; use futures::future::poll_fn; diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index f97a1c0fe..7b28373df 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs @@ -1,10 +1,10 @@ #![macro_use] +use crate::interrupt::InterruptExt; +use crate::Unborrow; use core::marker::PhantomData; use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; -use embassy::interrupt::InterruptExt; -use embassy::util::Unborrow; use embassy_hal_common::unborrow; use futures::future::poll_fn; diff --git a/embassy-nrf/src/temp.rs b/embassy-nrf/src/temp.rs index f7c6e6609..e5e5f29ab 100644 --- a/embassy-nrf/src/temp.rs +++ b/embassy-nrf/src/temp.rs @@ -4,10 +4,10 @@ use crate::interrupt; use crate::pac; use crate::peripherals::TEMP; +use crate::interrupt::InterruptExt; +use crate::Unborrow; use core::marker::PhantomData; use core::task::Poll; -use embassy::interrupt::InterruptExt; -use embassy::util::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::{drop::OnDrop, unborrow}; use fixed::types::I30F2; diff --git a/embassy-nrf/src/time_driver.rs b/embassy-nrf/src/time_driver.rs index a32a7bc7c..8f1758146 100644 --- a/embassy-nrf/src/time_driver.rs +++ b/embassy-nrf/src/time_driver.rs @@ -1,10 +1,10 @@ +use crate::interrupt::{Interrupt, InterruptExt}; use core::cell::Cell; use core::sync::atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering}; use core::{mem, ptr}; use critical_section::CriticalSection; use embassy::blocking_mutex::raw::CriticalSectionRawMutex; use embassy::blocking_mutex::CriticalSectionMutex as Mutex; -use embassy::interrupt::{Interrupt, InterruptExt}; use embassy::time::driver::{AlarmHandle, Driver}; use crate::interrupt; diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs index 9173338b6..588654f96 100644 --- a/embassy-nrf/src/timer.rs +++ b/embassy-nrf/src/timer.rs @@ -3,9 +3,9 @@ use core::marker::PhantomData; use core::task::Poll; -use embassy::interrupt::Interrupt; -use embassy::interrupt::InterruptExt; -use embassy::util::Unborrow; +use crate::interrupt::Interrupt; +use crate::interrupt::InterruptExt; +use crate::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::unborrow; diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs index 510266c9a..2337ae219 100644 --- a/embassy-nrf/src/twim.rs +++ b/embassy-nrf/src/twim.rs @@ -6,14 +6,14 @@ //! //! - nRF52832: Section 33 //! - nRF52840: Section 6.31 +use crate::interrupt::{Interrupt, InterruptExt}; +use crate::Unborrow; use core::future::Future; use core::marker::PhantomData; use core::sync::atomic::{compiler_fence, Ordering::SeqCst}; use core::task::Poll; -use embassy::interrupt::{Interrupt, InterruptExt}; #[cfg(feature = "time")] use embassy::time::{Duration, Instant}; -use embassy::util::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unborrow; use futures::future::poll_fn; diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 8970b8a1e..70dbfb080 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs @@ -13,11 +13,11 @@ //! memory may be used given that buffers are passed in directly to its read and write //! methods. +use crate::interrupt::InterruptExt; +use crate::Unborrow; use core::marker::PhantomData; use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; -use embassy::interrupt::InterruptExt; -use embassy::util::Unborrow; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::unborrow; use futures::future::poll_fn; diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index 842abf162..d0223c4c9 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs @@ -1,12 +1,12 @@ #![macro_use] +use crate::interrupt::InterruptExt; +use crate::Unborrow; use core::marker::PhantomData; use core::mem::MaybeUninit; use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; use core::task::Poll; use cortex_m::peripheral::NVIC; -use embassy::interrupt::InterruptExt; -use embassy::util::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unborrow; use embassy_usb::driver::{self, EndpointError, Event, Unsupported}; diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml index f2eed64df..4896647fb 100644 --- a/embassy-rp/Cargo.toml +++ b/embassy-rp/Cargo.toml @@ -29,6 +29,7 @@ unstable-traits = ["embedded-hal-1"] [dependencies] embassy = { version = "0.1.0", path = "../embassy", features = [ "time-tick-1mhz", "nightly"] } +embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]} embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["rp"]} atomic-polyfill = "0.1.5" diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index 12b9f6aca..a2e1b3d7b 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs @@ -6,7 +6,7 @@ use crate::pac::common::{Reg, RW}; use crate::pac::SIO; use crate::peripherals; -use embassy::util::Unborrow; +use crate::Unborrow; use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; /// Represents a digital input or output level. diff --git a/embassy-rp/src/interrupt.rs b/embassy-rp/src/interrupt.rs index 109afcbc4..042882691 100644 --- a/embassy-rp/src/interrupt.rs +++ b/embassy-rp/src/interrupt.rs @@ -4,39 +4,33 @@ //! nrf_softdevice::interrupt. Intended for switching between the two at compile-time. // Re-exports -pub use embassy::interrupt::{declare, take, Interrupt}; -pub use embassy_hal_common::interrupt::Priority3 as Priority; +pub use embassy_cortex_m::interrupt::*; -mod irqs { - use super::*; - use crate::pac::Interrupt as InterruptEnum; - - declare!(TIMER_IRQ_0); - declare!(TIMER_IRQ_1); - declare!(TIMER_IRQ_2); - declare!(TIMER_IRQ_3); - declare!(PWM_IRQ_WRAP); - declare!(USBCTRL_IRQ); - declare!(XIP_IRQ); - declare!(PIO0_IRQ_0); - declare!(PIO0_IRQ_1); - declare!(PIO1_IRQ_0); - declare!(PIO1_IRQ_1); - declare!(DMA_IRQ_0); - declare!(DMA_IRQ_1); - declare!(IO_IRQ_BANK0); - declare!(IO_IRQ_QSPI); - declare!(SIO_IRQ_PROC0); - declare!(SIO_IRQ_PROC1); - declare!(CLOCKS_IRQ); - declare!(SPI0_IRQ); - declare!(SPI1_IRQ); - declare!(UART0_IRQ); - declare!(UART1_IRQ); - declare!(ADC_IRQ_FIFO); - declare!(I2C0_IRQ); - declare!(I2C1_IRQ); - declare!(RTC_IRQ); -} - -pub use irqs::*; +use crate::pac::Interrupt as InterruptEnum; +use embassy_macros::cortex_m_interrupt_declare as declare; +declare!(TIMER_IRQ_0); +declare!(TIMER_IRQ_1); +declare!(TIMER_IRQ_2); +declare!(TIMER_IRQ_3); +declare!(PWM_IRQ_WRAP); +declare!(USBCTRL_IRQ); +declare!(XIP_IRQ); +declare!(PIO0_IRQ_0); +declare!(PIO0_IRQ_1); +declare!(PIO1_IRQ_0); +declare!(PIO1_IRQ_1); +declare!(DMA_IRQ_0); +declare!(DMA_IRQ_1); +declare!(IO_IRQ_BANK0); +declare!(IO_IRQ_QSPI); +declare!(SIO_IRQ_PROC0); +declare!(SIO_IRQ_PROC1); +declare!(CLOCKS_IRQ); +declare!(SPI0_IRQ); +declare!(SPI1_IRQ); +declare!(UART0_IRQ); +declare!(UART1_IRQ); +declare!(ADC_IRQ_FIFO); +declare!(I2C0_IRQ); +declare!(I2C1_IRQ); +declare!(RTC_IRQ); diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index 5de38af08..72fe864b5 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs @@ -2,22 +2,12 @@ #![feature(generic_associated_types)] #![feature(type_alias_impl_trait)] -#[cfg(feature = "unstable-pac")] -pub use rp2040_pac2 as pac; -#[cfg(not(feature = "unstable-pac"))] -pub(crate) use rp2040_pac2 as pac; - -pub use embassy::util::Unborrow; -pub use embassy_hal_common::unborrow; - // This mod MUST go first, so that the others see its macros. pub(crate) mod fmt; -pub mod interrupt; -pub use embassy_macros::interrupt; - pub mod dma; pub mod gpio; +pub mod interrupt; pub mod spi; pub mod timer; pub mod uart; @@ -25,6 +15,17 @@ pub mod uart; mod clocks; mod reset; +// Reexports + +#[cfg(feature = "unstable-pac")] +pub use rp2040_pac2 as pac; +#[cfg(not(feature = "unstable-pac"))] +pub(crate) use rp2040_pac2 as pac; + +pub use embassy_cortex_m::executor; +pub use embassy_hal_common::{unborrow, Unborrow}; +pub use embassy_macros::cortex_m_interrupt as interrupt; + embassy_hal_common::peripherals! { PIN_0, PIN_1, diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs index 8b90ba285..726c20a83 100644 --- a/embassy-rp/src/spi.rs +++ b/embassy-rp/src/spi.rs @@ -1,6 +1,6 @@ use core::marker::PhantomData; -use embassy::util::Unborrow; +use crate::Unborrow; use embassy_hal_common::unborrow; use crate::gpio::sealed::Pin as _; diff --git a/embassy-rp/src/timer.rs b/embassy-rp/src/timer.rs index f449df000..c43e044f3 100644 --- a/embassy-rp/src/timer.rs +++ b/embassy-rp/src/timer.rs @@ -1,9 +1,9 @@ +use crate::interrupt::{Interrupt, InterruptExt}; use atomic_polyfill::{AtomicU8, Ordering}; use core::cell::Cell; use critical_section::CriticalSection; use embassy::blocking_mutex::raw::CriticalSectionRawMutex; use embassy::blocking_mutex::Mutex; -use embassy::interrupt::{Interrupt, InterruptExt}; use embassy::time::driver::{AlarmHandle, Driver}; use crate::{interrupt, pac}; diff --git a/embassy-rp/src/uart.rs b/embassy-rp/src/uart.rs index 0d85be860..1aa3c5a84 100644 --- a/embassy-rp/src/uart.rs +++ b/embassy-rp/src/uart.rs @@ -1,6 +1,6 @@ use core::marker::PhantomData; -use embassy::util::Unborrow; +use crate::Unborrow; use embassy_hal_common::unborrow; use gpio::Pin; diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 01a96a5fb..4f83e4cd5 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -34,6 +34,7 @@ flavors = [ [dependencies] embassy = { version = "0.1.0", path = "../embassy" } +embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-4"]} embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["stm32"] } embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } embassy-net = { version = "0.1.0", path = "../embassy-net", optional = true } diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 7b1376f0b..42c88a269 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -96,8 +96,9 @@ fn main() { g.extend(quote! { pub mod interrupt { use crate::pac::Interrupt as InterruptEnum; + use embassy_macros::cortex_m_interrupt_declare as declare; #( - embassy::interrupt::declare!(#irqs); + declare!(#irqs); )* } }); diff --git a/embassy-stm32/src/adc/f1.rs b/embassy-stm32/src/adc/f1.rs index 6031883ec..ecb68b1a9 100644 --- a/embassy-stm32/src/adc/f1.rs +++ b/embassy-stm32/src/adc/f1.rs @@ -1,8 +1,8 @@ use crate::adc::{AdcPin, Instance}; use crate::rcc::get_freqs; use crate::time::Hertz; +use crate::Unborrow; use core::marker::PhantomData; -use embassy::util::Unborrow; use embassy_hal_common::unborrow; use embedded_hal_02::blocking::delay::DelayUs; diff --git a/embassy-stm32/src/adc/v2.rs b/embassy-stm32/src/adc/v2.rs index ab71c0f52..cdb8dfe9e 100644 --- a/embassy-stm32/src/adc/v2.rs +++ b/embassy-stm32/src/adc/v2.rs @@ -1,7 +1,7 @@ use crate::adc::{AdcPin, Instance}; use crate::time::Hertz; +use crate::Unborrow; use core::marker::PhantomData; -use embassy::util::Unborrow; use embassy_hal_common::unborrow; use embedded_hal_02::blocking::delay::DelayUs; diff --git a/embassy-stm32/src/adc/v3.rs b/embassy-stm32/src/adc/v3.rs index 68d941604..875510b7b 100644 --- a/embassy-stm32/src/adc/v3.rs +++ b/embassy-stm32/src/adc/v3.rs @@ -1,6 +1,6 @@ use crate::adc::{AdcPin, Instance}; +use crate::Unborrow; use core::marker::PhantomData; -use embassy::util::Unborrow; use embassy_hal_common::unborrow; use embedded_hal_02::blocking::delay::DelayUs; diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs index 99326f38c..316e04e0c 100644 --- a/embassy-stm32/src/adc/v4.rs +++ b/embassy-stm32/src/adc/v4.rs @@ -1,9 +1,9 @@ use core::marker::PhantomData; use crate::time::{Hertz, U32Ext}; +use crate::Unborrow; use atomic_polyfill::AtomicU8; use atomic_polyfill::Ordering; -use embassy::util::Unborrow; use embedded_hal_02::blocking::delay::DelayUs; use pac::adc::vals::{Adcaldif, Boost, Difsel, Exten, Pcsel}; use pac::adccommon::vals::Presc; diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index c1de55393..0922d4d65 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs @@ -1,7 +1,7 @@ use core::marker::PhantomData; use core::ops::{Deref, DerefMut}; -use embassy::util::Unborrow; +use crate::Unborrow; use embassy_hal_common::unborrow; use crate::gpio::sealed::AFType; diff --git a/embassy-stm32/src/crc/v1.rs b/embassy-stm32/src/crc/v1.rs index c657192e2..1ab4530b9 100644 --- a/embassy-stm32/src/crc/v1.rs +++ b/embassy-stm32/src/crc/v1.rs @@ -3,7 +3,7 @@ use core::marker::PhantomData; use crate::pac::CRC as PAC_CRC; use crate::peripherals::CRC; use crate::rcc::sealed::RccPeripheral; -use embassy::util::Unborrow; +use crate::Unborrow; use embassy_hal_common::unborrow; pub struct Crc<'d> { diff --git a/embassy-stm32/src/crc/v2v3.rs b/embassy-stm32/src/crc/v2v3.rs index 08e40a116..b6645c67f 100644 --- a/embassy-stm32/src/crc/v2v3.rs +++ b/embassy-stm32/src/crc/v2v3.rs @@ -4,7 +4,7 @@ use crate::pac::crc::vals; use crate::pac::CRC as PAC_CRC; use crate::peripherals::CRC; use crate::rcc::sealed::RccPeripheral; -use embassy::util::Unborrow; +use crate::Unborrow; use embassy_hal_common::unborrow; pub struct Crc<'d> { diff --git a/embassy-stm32/src/dac/v2.rs b/embassy-stm32/src/dac/v2.rs index ef64f60e9..0b421cc88 100644 --- a/embassy-stm32/src/dac/v2.rs +++ b/embassy-stm32/src/dac/v2.rs @@ -1,7 +1,7 @@ use crate::dac::{DacPin, Instance}; use crate::pac::dac; +use crate::Unborrow; use core::marker::PhantomData; -use embassy::util::Unborrow; use embassy_hal_common::unborrow; #[derive(Debug, Copy, Clone, Eq, PartialEq)] diff --git a/embassy-stm32/src/dcmi.rs b/embassy-stm32/src/dcmi.rs index e70db90c0..8a28ca4b2 100644 --- a/embassy-stm32/src/dcmi.rs +++ b/embassy-stm32/src/dcmi.rs @@ -1,8 +1,8 @@ use core::marker::PhantomData; use core::task::Poll; -use embassy::interrupt::{Interrupt, InterruptExt}; -use embassy::util::Unborrow; +use crate::interrupt::{Interrupt, InterruptExt}; +use crate::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unborrow; use futures::future::poll_fn; diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs index 413285320..b17d22953 100644 --- a/embassy-stm32/src/dma/bdma.rs +++ b/embassy-stm32/src/dma/bdma.rs @@ -3,7 +3,7 @@ use core::sync::atomic::{fence, Ordering}; use core::task::Waker; -use embassy::interrupt::{Interrupt, InterruptExt}; +use crate::interrupt::{Interrupt, InterruptExt}; use embassy::waitqueue::AtomicWaker; use crate::_generated::BDMA_CHANNEL_COUNT; diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index bc796c541..04cde7b4b 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs @@ -1,7 +1,7 @@ use core::sync::atomic::{fence, Ordering}; use core::task::Waker; -use embassy::interrupt::{Interrupt, InterruptExt}; +use crate::interrupt::{Interrupt, InterruptExt}; use embassy::waitqueue::AtomicWaker; use crate::_generated::DMA_CHANNEL_COUNT; diff --git a/embassy-stm32/src/dma/gpdma.rs b/embassy-stm32/src/dma/gpdma.rs index 0cb986b32..b054f95cc 100644 --- a/embassy-stm32/src/dma/gpdma.rs +++ b/embassy-stm32/src/dma/gpdma.rs @@ -1,7 +1,7 @@ use core::sync::atomic::{fence, Ordering}; use core::task::Waker; -use embassy::interrupt::{Interrupt, InterruptExt}; +use crate::interrupt::{Interrupt, InterruptExt}; use embassy::waitqueue::AtomicWaker; use crate::_generated::GPDMA_CHANNEL_COUNT; diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index c19f7b3c7..3a9097784 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs @@ -10,13 +10,13 @@ mod gpdma; #[cfg(dmamux)] pub use dmamux::*; +use crate::Unborrow; use core::future::Future; use core::marker::PhantomData; use core::mem; use core::pin::Pin; use core::task::Waker; use core::task::{Context, Poll}; -use embassy::util::Unborrow; use embassy_hal_common::unborrow; #[cfg(feature = "unstable-pac")] diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs index 327deea2a..d2cfb17c0 100644 --- a/embassy-stm32/src/eth/v1/mod.rs +++ b/embassy-stm32/src/eth/v1/mod.rs @@ -4,9 +4,9 @@ use core::marker::PhantomData; use core::sync::atomic::{fence, Ordering}; use core::task::Waker; -use embassy::util::Unborrow; +use crate::Unborrow; use embassy::waitqueue::AtomicWaker; -use embassy_hal_common::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; +use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; use embassy_hal_common::unborrow; use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index 6a49904d1..e438a7b5e 100644 --- a/embassy-stm32/src/eth/v2/mod.rs +++ b/embassy-stm32/src/eth/v2/mod.rs @@ -2,9 +2,9 @@ use core::marker::PhantomData; use core::sync::atomic::{fence, Ordering}; use core::task::Waker; -use embassy::util::Unborrow; +use crate::Unborrow; use embassy::waitqueue::AtomicWaker; -use embassy_hal_common::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; +use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; use embassy_hal_common::unborrow; use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index d065a5557..efe54e59a 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs @@ -1,8 +1,8 @@ +use crate::Unborrow; use core::future::Future; use core::marker::PhantomData; use core::pin::Pin; use core::task::{Context, Poll}; -use embassy::util::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unsafe_impl_unborrow; @@ -366,8 +366,8 @@ macro_rules! enable_irq { /// safety: must be called only once pub(crate) unsafe fn init() { - use embassy::interrupt::Interrupt; - use embassy::interrupt::InterruptExt; + use crate::interrupt::Interrupt; + use crate::interrupt::InterruptExt; foreach_exti_irq!(enable_irq); diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs index 4be611d2e..330e51421 100644 --- a/embassy-stm32/src/flash/mod.rs +++ b/embassy-stm32/src/flash/mod.rs @@ -1,6 +1,6 @@ use crate::peripherals::FLASH; +use crate::Unborrow; use core::marker::PhantomData; -use embassy::util::Unborrow; use embassy_hal_common::unborrow; use embedded_storage::nor_flash::{ diff --git a/embassy-stm32/src/fmc/mod.rs b/embassy-stm32/src/fmc/mod.rs index 2a730f5f8..c227cfa17 100644 --- a/embassy-stm32/src/fmc/mod.rs +++ b/embassy-stm32/src/fmc/mod.rs @@ -1,5 +1,5 @@ +use crate::Unborrow; use core::marker::PhantomData; -use embassy::util::Unborrow; use embassy_hal_common::unborrow; use crate::gpio::sealed::AFType; diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index f7a5da0a8..31f22e21b 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs @@ -1,7 +1,7 @@ #![macro_use] +use crate::Unborrow; use core::convert::Infallible; use core::marker::PhantomData; -use embassy::util::Unborrow; use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; use crate::pac; diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index c2a4c2546..54f8d1935 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs @@ -1,6 +1,6 @@ #![macro_use] -use embassy::interrupt::Interrupt; +use crate::interrupt::Interrupt; #[cfg_attr(i2c_v1, path = "v1.rs")] #[cfg_attr(i2c_v2, path = "v2.rs")] diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index e0b151142..77acc3870 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs @@ -1,5 +1,5 @@ +use crate::Unborrow; use core::marker::PhantomData; -use embassy::util::Unborrow; use embassy_hal_common::unborrow; use crate::gpio::sealed::AFType; diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index f3714cbcb..4d4840a0d 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs @@ -2,9 +2,9 @@ use core::cmp; use core::marker::PhantomData; use core::task::Poll; +use crate::interrupt::InterruptExt; +use crate::Unborrow; use atomic_polyfill::{AtomicUsize, Ordering}; -use embassy::interrupt::InterruptExt; -use embassy::util::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::unborrow; diff --git a/embassy-stm32/src/interrupt.rs b/embassy-stm32/src/interrupt.rs index 714dcc4ca..9dc1f2044 100644 --- a/embassy-stm32/src/interrupt.rs +++ b/embassy-stm32/src/interrupt.rs @@ -1,6 +1,5 @@ pub use bare_metal::Mutex; pub use critical_section::CriticalSection; -pub use embassy::interrupt::{take, Interrupt}; -pub use embassy_hal_common::interrupt::Priority4 as Priority; +pub use embassy_cortex_m::interrupt::*; pub use crate::_generated::interrupt::*; diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index bb70faab1..b795352c1 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -4,14 +4,6 @@ feature(generic_associated_types, type_alias_impl_trait) )] -#[cfg(feature = "unstable-pac")] -pub use stm32_metapac as pac; -#[cfg(not(feature = "unstable-pac"))] -pub(crate) use stm32_metapac as pac; - -pub use embassy::util::Unborrow; -pub use embassy_hal_common::unborrow; - // This must go FIRST so that all the other modules see its macros. pub mod fmt; include!(concat!(env!("OUT_DIR"), "/_macros.rs")); @@ -79,8 +71,17 @@ pub(crate) mod _generated { include!(concat!(env!("OUT_DIR"), "/_generated.rs")); } + +// Reexports pub use _generated::{peripherals, Peripherals}; -pub use embassy_macros::interrupt; +pub use embassy_cortex_m::executor; +pub use embassy_hal_common::{unborrow, Unborrow}; +pub use embassy_macros::cortex_m_interrupt as interrupt; + +#[cfg(feature = "unstable-pac")] +pub use stm32_metapac as pac; +#[cfg(not(feature = "unstable-pac"))] +pub(crate) use stm32_metapac as pac; #[non_exhaustive] pub struct Config { diff --git a/embassy-stm32/src/pwm/simple_pwm.rs b/embassy-stm32/src/pwm/simple_pwm.rs index 3706cc5ba..990f5bda7 100644 --- a/embassy-stm32/src/pwm/simple_pwm.rs +++ b/embassy-stm32/src/pwm/simple_pwm.rs @@ -1,5 +1,5 @@ +use crate::Unborrow; use core::marker::PhantomData; -use embassy::util::Unborrow; use embassy_hal_common::unborrow; use super::*; diff --git a/embassy-stm32/src/rcc/h7.rs b/embassy-stm32/src/rcc/h7.rs index 6c81d3dbd..0cd89645f 100644 --- a/embassy-stm32/src/rcc/h7.rs +++ b/embassy-stm32/src/rcc/h7.rs @@ -1,6 +1,6 @@ use core::marker::PhantomData; -use embassy::util::Unborrow; +use crate::Unborrow; use embassy_hal_common::unborrow; use stm32_metapac::rcc::vals::{Mco1, Mco2}; diff --git a/embassy-stm32/src/rcc/l5.rs b/embassy-stm32/src/rcc/l5.rs index dba5ec3b7..4419f3d31 100644 --- a/embassy-stm32/src/rcc/l5.rs +++ b/embassy-stm32/src/rcc/l5.rs @@ -1,3 +1,5 @@ +use stm32_metapac::PWR; + use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw}; use crate::pac::{FLASH, RCC}; use crate::rcc::{set_freqs, Clocks}; @@ -295,6 +297,8 @@ impl Default for Config { } pub(crate) unsafe fn init(config: Config) { + PWR.cr1() + .modify(|w| w.set_vos(stm32_metapac::pwr::vals::Vos::RANGE0)); let (sys_clk, sw) = match config.mux { ClockSrc::MSI(range) => { // Enable MSI diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index 0a93951bf..e74b66237 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs @@ -1,8 +1,8 @@ #![macro_use] +use crate::Unborrow; use core::marker::PhantomData; use core::task::Poll; -use embassy::util::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unborrow; use futures::future::poll_fn; diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index f983c6759..a7290e74c 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs @@ -4,8 +4,8 @@ use core::default::Default; use core::marker::PhantomData; use core::task::Poll; -use embassy::interrupt::InterruptExt; -use embassy::util::Unborrow; +use crate::interrupt::InterruptExt; +use crate::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::unborrow; diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 23240ad82..3cdc87c70 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs @@ -1,8 +1,8 @@ #![macro_use] +use crate::Unborrow; use core::marker::PhantomData; use core::ptr; -use embassy::util::Unborrow; use embassy_hal_common::unborrow; use futures::future::join; diff --git a/embassy-stm32/src/subghz/mod.rs b/embassy-stm32/src/subghz/mod.rs index 9c8b7f7ec..6736324ce 100644 --- a/embassy-stm32/src/subghz/mod.rs +++ b/embassy-stm32/src/subghz/mod.rs @@ -77,6 +77,7 @@ pub use value_error::ValueError; use embassy_hal_common::ratio::Ratio; +use crate::Unborrow; use crate::{ dma::NoDma, pac, @@ -85,7 +86,6 @@ use crate::{ spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0}, time::Hertz, }; -use embassy::util::Unborrow; /// Passthrough for SPI errors (for now) pub type Error = crate::spi::Error; diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index d936a11a2..b63ed5bd4 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs @@ -1,3 +1,4 @@ +use crate::interrupt::InterruptExt; use atomic_polyfill::{AtomicU32, AtomicU8}; use core::cell::Cell; use core::convert::TryInto; @@ -5,7 +6,6 @@ use core::sync::atomic::{compiler_fence, Ordering}; use core::{mem, ptr}; use embassy::blocking_mutex::raw::CriticalSectionRawMutex; use embassy::blocking_mutex::Mutex; -use embassy::interrupt::InterruptExt; use embassy::time::driver::{AlarmHandle, Driver}; use embassy::time::TICKS_PER_SECOND; use stm32_metapac::timer::regs; diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index f9fefdf73..3cc6298be 100644 --- a/embassy-stm32/src/timer/mod.rs +++ b/embassy-stm32/src/timer/mod.rs @@ -1,4 +1,4 @@ -use embassy::interrupt::Interrupt; +use crate::interrupt::Interrupt; use crate::rcc::{sealed::RccPeripheral as __RccPeri, RccPeripheral}; use crate::time::Hertz; diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index 36d176b91..e2c9f7802 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs @@ -2,7 +2,7 @@ use atomic_polyfill::{compiler_fence, Ordering}; use core::future::Future; use core::task::Poll; use embassy::waitqueue::WakerRegistration; -use embassy_hal_common::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; +use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; use embassy_hal_common::ring_buffer::RingBuffer; use futures::future::poll_fn; diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 472680113..2acec874f 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -1,8 +1,8 @@ #![macro_use] +use crate::interrupt::Interrupt; +use crate::Unborrow; use core::marker::PhantomData; -use embassy::interrupt::Interrupt; -use embassy::util::Unborrow; use embassy_hal_common::unborrow; use crate::dma::NoDma; diff --git a/embassy-stm32/src/usb/mod.rs b/embassy-stm32/src/usb/mod.rs index 71b407cbd..65451917e 100644 --- a/embassy-stm32/src/usb/mod.rs +++ b/embassy-stm32/src/usb/mod.rs @@ -1,4 +1,4 @@ -use embassy::interrupt::Interrupt; +use crate::interrupt::Interrupt; use crate::rcc::RccPeripheral; diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index 113b20262..eaf24f8ae 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs @@ -1,12 +1,12 @@ #![macro_use] +use crate::interrupt::InterruptExt; +use crate::Unborrow; use atomic_polyfill::{AtomicBool, AtomicU8}; use core::marker::PhantomData; use core::sync::atomic::Ordering; use core::task::Poll; -use embassy::interrupt::InterruptExt; use embassy::time::{block_for, Duration}; -use embassy::util::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unborrow; use embassy_usb::driver::{self, EndpointAllocError, EndpointError, Event, Unsupported}; diff --git a/embassy-stm32/src/usb_otg.rs b/embassy-stm32/src/usb_otg.rs index c3cd776ca..0f732965c 100644 --- a/embassy-stm32/src/usb_otg.rs +++ b/embassy-stm32/src/usb_otg.rs @@ -1,5 +1,5 @@ +use crate::Unborrow; use core::marker::PhantomData; -use embassy::util::Unborrow; use embassy_hal_common::unborrow; use crate::gpio::sealed::AFType; diff --git a/embassy/src/executor/arch/cortex_m.rs b/embassy/src/executor/arch/cortex_m.rs index 16f290083..cf80389b6 100644 --- a/embassy/src/executor/arch/cortex_m.rs +++ b/embassy/src/executor/arch/cortex_m.rs @@ -1,8 +1,7 @@ use core::marker::PhantomData; use core::ptr; -use super::{raw, SendSpawner, Spawner}; -use crate::interrupt::{Interrupt, InterruptExt}; +use super::{raw, Spawner}; /// Thread mode executor, using WFE/SEV. /// @@ -55,86 +54,3 @@ impl Executor { } } } - -fn pend_by_number(n: u16) { - #[derive(Clone, Copy)] - struct N(u16); - unsafe impl cortex_m::interrupt::InterruptNumber for N { - fn number(self) -> u16 { - self.0 - } - } - cortex_m::peripheral::NVIC::pend(N(n)) -} - -/// Interrupt mode executor. -/// -/// This executor runs tasks in interrupt mode. The interrupt handler is set up -/// to poll tasks, and when a task is woken the interrupt is pended from software. -/// -/// This allows running async tasks at a priority higher than thread mode. One -/// use case is to leave thread mode free for non-async tasks. Another use case is -/// to run multiple executors: one in thread mode for low priority tasks and another in -/// interrupt mode for higher priority tasks. Higher priority tasks will preempt lower -/// priority ones. -/// -/// It is even possible to run multiple interrupt mode executors at different priorities, -/// by assigning different priorities to the interrupts. For an example on how to do this, -/// See the 'multiprio' example for 'embassy-nrf'. -/// -/// To use it, you have to pick an interrupt that won't be used by the hardware. -/// Some chips reserve some interrupts for this purpose, sometimes named "software interrupts" (SWI). -/// If this is not the case, you may use an interrupt from any unused peripheral. -/// -/// It is somewhat more complex to use, it's recommended to use the thread-mode -/// [`Executor`] instead, if it works for your use case. -pub struct InterruptExecutor { - irq: I, - inner: raw::Executor, - not_send: PhantomData<*mut ()>, -} - -impl InterruptExecutor { - /// Create a new Executor. - pub fn new(irq: I) -> Self { - let ctx = irq.number() as *mut (); - Self { - irq, - inner: raw::Executor::new(|ctx| pend_by_number(ctx as u16), ctx), - not_send: PhantomData, - } - } - - /// Start the executor. - /// - /// This initializes the executor, configures and enables the interrupt, and returns. - /// The executor keeps running in the background through the interrupt. - /// - /// This returns a [`SendSpawner`] you can use to spawn tasks on it. A [`SendSpawner`] - /// is returned instead of a [`Spawner`] because the executor effectively runs in a - /// different "thread" (the interrupt), so spawning tasks on it is effectively - /// sending them. - /// - /// To obtain a [`Spawner`] for this executor, use [`Spawner::for_current_executor`] from - /// a task running in it. - /// - /// This function requires `&'static mut self`. This means you have to store the - /// Executor instance in a place where it'll live forever and grants you mutable - /// access. There's a few ways to do this: - /// - /// - a [Forever](crate::util::Forever) (safe) - /// - a `static mut` (unsafe) - /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) - pub fn start(&'static mut self) -> SendSpawner { - self.irq.disable(); - - self.irq.set_handler(|ctx| unsafe { - let executor = &*(ctx as *const raw::Executor); - executor.poll(); - }); - self.irq.set_handler_context(&self.inner as *const _ as _); - self.irq.enable(); - - self.inner.spawner().make_send() - } -} diff --git a/embassy/src/interrupt.rs b/embassy/src/interrupt.rs deleted file mode 100644 index 7848ee698..000000000 --- a/embassy/src/interrupt.rs +++ /dev/null @@ -1,131 +0,0 @@ -use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; -use core::mem; -use core::ptr; -use cortex_m::peripheral::NVIC; - -pub use embassy_macros::interrupt_declare as declare; -pub use embassy_macros::interrupt_take as take; - -/// Implementation detail, do not use outside embassy crates. -#[doc(hidden)] -pub struct Handler { - pub func: AtomicPtr<()>, - pub ctx: AtomicPtr<()>, -} - -impl Handler { - pub const fn new() -> Self { - Self { - func: AtomicPtr::new(ptr::null_mut()), - ctx: AtomicPtr::new(ptr::null_mut()), - } - } -} - -#[derive(Clone, Copy)] -pub(crate) struct NrWrap(pub(crate) u16); -unsafe impl cortex_m::interrupt::InterruptNumber for NrWrap { - fn number(self) -> u16 { - self.0 - } -} - -pub unsafe trait Interrupt: crate::util::Unborrow { - type Priority: From + Into + Copy; - fn number(&self) -> u16; - unsafe fn steal() -> Self; - - /// Implementation detail, do not use outside embassy crates. - #[doc(hidden)] - unsafe fn __handler(&self) -> &'static Handler; -} - -pub trait InterruptExt: Interrupt { - fn set_handler(&self, func: unsafe fn(*mut ())); - fn remove_handler(&self); - fn set_handler_context(&self, ctx: *mut ()); - fn enable(&self); - fn disable(&self); - #[cfg(not(armv6m))] - fn is_active(&self) -> bool; - fn is_enabled(&self) -> bool; - fn is_pending(&self) -> bool; - fn pend(&self); - fn unpend(&self); - fn get_priority(&self) -> Self::Priority; - fn set_priority(&self, prio: Self::Priority); -} - -impl InterruptExt for T { - fn set_handler(&self, func: unsafe fn(*mut ())) { - compiler_fence(Ordering::SeqCst); - let handler = unsafe { self.__handler() }; - handler.func.store(func as *mut (), Ordering::Relaxed); - compiler_fence(Ordering::SeqCst); - } - - fn remove_handler(&self) { - compiler_fence(Ordering::SeqCst); - let handler = unsafe { self.__handler() }; - handler.func.store(ptr::null_mut(), Ordering::Relaxed); - compiler_fence(Ordering::SeqCst); - } - - fn set_handler_context(&self, ctx: *mut ()) { - let handler = unsafe { self.__handler() }; - handler.ctx.store(ctx, Ordering::Relaxed); - } - - #[inline] - fn enable(&self) { - compiler_fence(Ordering::SeqCst); - unsafe { - NVIC::unmask(NrWrap(self.number())); - } - } - - #[inline] - fn disable(&self) { - NVIC::mask(NrWrap(self.number())); - compiler_fence(Ordering::SeqCst); - } - - #[inline] - #[cfg(not(armv6m))] - fn is_active(&self) -> bool { - NVIC::is_active(NrWrap(self.number())) - } - - #[inline] - fn is_enabled(&self) -> bool { - NVIC::is_enabled(NrWrap(self.number())) - } - - #[inline] - fn is_pending(&self) -> bool { - NVIC::is_pending(NrWrap(self.number())) - } - - #[inline] - fn pend(&self) { - NVIC::pend(NrWrap(self.number())) - } - - #[inline] - fn unpend(&self) { - NVIC::unpend(NrWrap(self.number())) - } - - #[inline] - fn get_priority(&self) -> Self::Priority { - Self::Priority::from(NVIC::get_priority(NrWrap(self.number()))) - } - - #[inline] - fn set_priority(&self, prio: Self::Priority) { - unsafe { - let mut nvic: cortex_m::peripheral::NVIC = mem::transmute(()); - nvic.set_priority(NrWrap(self.number()), prio.into()) - } - } -} diff --git a/embassy/src/lib.rs b/embassy/src/lib.rs index 087bd357a..5cfd18db7 100644 --- a/embassy/src/lib.rs +++ b/embassy/src/lib.rs @@ -11,8 +11,6 @@ pub(crate) mod fmt; pub mod blocking_mutex; pub mod channel; pub mod executor; -#[cfg(cortex_m)] -pub mod interrupt; pub mod mutex; #[cfg(feature = "time")] pub mod time; diff --git a/embassy/src/util/mod.rs b/embassy/src/util/mod.rs index 928edf0e2..4d59147c1 100644 --- a/embassy/src/util/mod.rs +++ b/embassy/src/util/mod.rs @@ -3,11 +3,9 @@ mod forever; mod select; mod steal; -mod unborrow; mod yield_now; pub use forever::*; pub use select::*; pub use steal::*; -pub use unborrow::*; pub use yield_now::*; diff --git a/examples/nrf/src/bin/multiprio.rs b/examples/nrf/src/bin/multiprio.rs index 54f6606a9..abda18aa5 100644 --- a/examples/nrf/src/bin/multiprio.rs +++ b/examples/nrf/src/bin/multiprio.rs @@ -59,11 +59,11 @@ use cortex_m_rt::entry; use defmt::{info, unwrap}; -use embassy::executor::{Executor, InterruptExecutor}; -use embassy::interrupt::InterruptExt; use embassy::time::{Duration, Instant, Timer}; use embassy::util::Forever; +use embassy_nrf::executor::{Executor, InterruptExecutor}; use embassy_nrf::interrupt; +use embassy_nrf::interrupt::InterruptExt; use defmt_rtt as _; // global logger use panic_probe as _; diff --git a/examples/nrf/src/bin/usb_hid_keyboard.rs b/examples/nrf/src/bin/usb_hid_keyboard.rs index d855a3a57..8aa08fe3d 100644 --- a/examples/nrf/src/bin/usb_hid_keyboard.rs +++ b/examples/nrf/src/bin/usb_hid_keyboard.rs @@ -8,11 +8,11 @@ use core::sync::atomic::{AtomicBool, Ordering}; use defmt::*; use embassy::channel::Signal; use embassy::executor::Spawner; -use embassy::interrupt::InterruptExt; use embassy::time::Duration; use embassy::util::{select, select3, Either, Either3}; use embassy_nrf::gpio::{Input, Pin, Pull}; use embassy_nrf::interrupt; +use embassy_nrf::interrupt::InterruptExt; use embassy_nrf::pac; use embassy_nrf::usb::Driver; use embassy_nrf::Peripherals; diff --git a/examples/stm32f3/src/bin/multiprio.rs b/examples/stm32f3/src/bin/multiprio.rs index 02380de72..684295609 100644 --- a/examples/stm32f3/src/bin/multiprio.rs +++ b/examples/stm32f3/src/bin/multiprio.rs @@ -62,11 +62,11 @@ use defmt_rtt as _; // global logger use panic_probe as _; use cortex_m_rt::entry; -use embassy::executor::{Executor, InterruptExecutor}; -use embassy::interrupt::InterruptExt; use embassy::time::{Duration, Instant, Timer}; use embassy::util::Forever; +use embassy_stm32::executor::{Executor, InterruptExecutor}; use embassy_stm32::interrupt; +use embassy_stm32::interrupt::InterruptExt; #[embassy::task] async fn run_high() { diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs index 02380de72..684295609 100644 --- a/examples/stm32f4/src/bin/multiprio.rs +++ b/examples/stm32f4/src/bin/multiprio.rs @@ -62,11 +62,11 @@ use defmt_rtt as _; // global logger use panic_probe as _; use cortex_m_rt::entry; -use embassy::executor::{Executor, InterruptExecutor}; -use embassy::interrupt::InterruptExt; use embassy::time::{Duration, Instant, Timer}; use embassy::util::Forever; +use embassy_stm32::executor::{Executor, InterruptExecutor}; use embassy_stm32::interrupt; +use embassy_stm32::interrupt::InterruptExt; #[embassy::task] async fn run_high() { diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index 3b1b8044d..647c5a8fa 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs @@ -9,12 +9,12 @@ use panic_probe as _; use defmt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; -use embassy::util::Unborrow; use embassy_stm32::gpio::low_level::AFType; use embassy_stm32::gpio::Speed; use embassy_stm32::pwm::*; use embassy_stm32::time::{Hertz, U32Ext}; use embassy_stm32::unborrow; +use embassy_stm32::Unborrow; use embassy_stm32::{Config, Peripherals}; pub fn config() -> Config { diff --git a/examples/stm32wl/src/bin/subghz.rs b/examples/stm32wl/src/bin/subghz.rs index 562e25ac0..f5f9b6a32 100644 --- a/examples/stm32wl/src/bin/subghz.rs +++ b/examples/stm32wl/src/bin/subghz.rs @@ -10,11 +10,11 @@ use panic_probe as _; use defmt::*; use embassy::channel::signal::Signal; -use embassy::interrupt::{Interrupt, InterruptExt}; use embassy_stm32::dma::NoDma; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; use embassy_stm32::interrupt; +use embassy_stm32::interrupt::{Interrupt, InterruptExt}; use embassy_stm32::subghz::*; use embassy_stm32::Peripherals;