#[macro_export]
macro_rules! access_global {
($NAME_GLOBAL:ident, $name_local:ident, $cs:expr) => {
let mut part1 = $NAME_GLOBAL.borrow($cs).borrow_mut();
let $name_local = part1.as_mut().unwrap();
};
}
#[macro_export]
macro_rules! access_globals {
([$(($NAME_GLOBAL:ident, $name_local:ident)),* $(,)?], $cs:expr) => {
$(
let mut part = $NAME_GLOBAL.borrow($cs).borrow_mut();
let $name_local = part.as_mut().unwrap();
)*
};
}
#[macro_export]
macro_rules! make_globals {
($(($NAME:ident, $type:ty)),+ $(,)?) => {
$(
static $NAME: ::critical_section::Mutex<core::cell::RefCell<Option<$type>>> = ::critical_section::Mutex::new(core::cell::RefCell::new(None));
)+
};
}
#[macro_export]
macro_rules! make_simple_globals {
($(($NAME:ident, $type:ty, $val:expr)),+ $(,)?) => {
$(
static $NAME: ::critical_section::Mutex<core::cell::Cell<$type>> = ::critical_section::Mutex::new(core::cell::Cell::new($val));
)+
};
}
#[macro_export]
macro_rules! init_globals {
($(($NAME:ident, $val:expr)),* $(,)?) => {
::critical_section::with(|cs| {
$(
$NAME.borrow(cs).replace(Some($val));
)*
});
};
}
#[macro_export]
macro_rules! setup_nvic {
(
[ $( ($int:ident, $prio:expr) ),* $(,)? ],
$cp:ident
) => {
unsafe {
$(
cortex_m::peripheral::NVIC::unmask(pac::Interrupt::$int);
)*
$(
$cp.NVIC.set_priority(pac::Interrupt::$int, $prio);
)*
}
};
}
#[macro_export]
macro_rules! parse_le {
($bytes:expr, $t:ty, $range:expr) => {{ <$t>::from_le_bytes($bytes[$range].try_into().unwrap()) }};
}
#[macro_export]
macro_rules! parse_be {
($bytes:expr, $t:ty, $range:expr) => {{ <$t>::from_be_bytes($bytes[$range].try_into().unwrap()) }};
}
#[macro_export]
macro_rules! copy_le {
($dest:expr, $src:expr, $range:expr) => {{ $dest[$range].copy_from_slice(&$src.to_le_bytes()) }};
}
#[macro_export]
macro_rules! copy_be {
($dest:expr, $src:expr, $range:expr) => {{ $dest[$range].copy_from_slice(&$src.to_be_bytes()) }};
}