Merge #875
875: Misc cleanups r=Dirbaio a=Dirbaio bors r+ Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
This commit is contained in:
commit
96f6767167
@ -8,9 +8,14 @@ macro_rules! peripherals {
|
|||||||
pub struct $name { _private: () }
|
pub struct $name { _private: () }
|
||||||
|
|
||||||
$(#[$cfg])?
|
$(#[$cfg])?
|
||||||
impl embassy::util::Steal for $name {
|
impl $name {
|
||||||
|
/// Unsafely create an instance of this peripheral out of thin air.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// You must ensure that you're only using one instance of this type at a time.
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn steal() -> Self {
|
pub unsafe fn steal() -> Self {
|
||||||
Self{ _private: ()}
|
Self{ _private: ()}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -23,7 +28,6 @@ macro_rules! peripherals {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,23 +52,27 @@ macro_rules! peripherals {
|
|||||||
panic!("init called more than once!")
|
panic!("init called more than once!")
|
||||||
}
|
}
|
||||||
_EMBASSY_DEVICE_PERIPHERALS = true;
|
_EMBASSY_DEVICE_PERIPHERALS = true;
|
||||||
<Self as embassy::util::Steal>::steal()
|
Self::steal()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl embassy::util::Steal for Peripherals {
|
impl Peripherals {
|
||||||
|
/// Unsafely create an instance of this peripheral out of thin air.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// You must ensure that you're only using one instance of this type at a time.
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn steal() -> Self {
|
pub unsafe fn steal() -> Self {
|
||||||
Self {
|
Self {
|
||||||
$(
|
$(
|
||||||
$(#[$cfg])?
|
$(#[$cfg])?
|
||||||
$name: <peripherals::$name as embassy::util::Steal>::steal(),
|
$name: peripherals::$name::steal(),
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,42 +97,3 @@ macro_rules! unsafe_impl_unborrow {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! std_peripherals {
|
|
||||||
($($(#[$cfg:meta])? $name:ident),*$(,)?) => {
|
|
||||||
#[doc = r"All the peripherals"]
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
pub struct Peripherals {
|
|
||||||
$(
|
|
||||||
$(#[$cfg])?
|
|
||||||
pub $name: pac::$name,
|
|
||||||
)+
|
|
||||||
}
|
|
||||||
|
|
||||||
static mut GLOBAL_CLOCKS: Option<Clocks> = None;
|
|
||||||
|
|
||||||
impl Peripherals {
|
|
||||||
pub fn take() -> Option<(Peripherals, Clocks)> {
|
|
||||||
match unsafe {GLOBAL_CLOCKS.take()} {
|
|
||||||
Some(clocks) => {
|
|
||||||
let dp = unsafe { pac::Peripherals::steal() };
|
|
||||||
let peripherals = Peripherals {
|
|
||||||
$(
|
|
||||||
$(#[$cfg])?
|
|
||||||
$name: dp.$name,
|
|
||||||
)+
|
|
||||||
};
|
|
||||||
|
|
||||||
Some((peripherals, clocks))
|
|
||||||
},
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn set_peripherals(clocks: Clocks) {
|
|
||||||
GLOBAL_CLOCKS.replace(clocks);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
@ -2,10 +2,8 @@
|
|||||||
|
|
||||||
mod forever;
|
mod forever;
|
||||||
mod select;
|
mod select;
|
||||||
mod steal;
|
|
||||||
mod yield_now;
|
mod yield_now;
|
||||||
|
|
||||||
pub use forever::*;
|
pub use forever::*;
|
||||||
pub use select::*;
|
pub use select::*;
|
||||||
pub use steal::*;
|
|
||||||
pub use yield_now::*;
|
pub use yield_now::*;
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
/// A type that can retrieved unsafely from anywhere.
|
|
||||||
pub trait Steal {
|
|
||||||
/// Retrieve and instance of this type.
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
///
|
|
||||||
/// It is the responsibility of the application to ensure that the
|
|
||||||
/// usage of the returned instance is not in conflict with other uses
|
|
||||||
/// of this instance.
|
|
||||||
///
|
|
||||||
/// The implementation may panic if the instance is already in use.
|
|
||||||
unsafe fn steal() -> Self;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user