use core::{ cell::RefCell, fmt::{write, Arguments}, }; use stm32f1xx_hal::{ serial::Tx, pac::USART1, }; use cortex_m::interrupt::{self, Mutex}; #[macro_export] macro_rules! log { ($($args:tt)+) => { $crate::log::log_args(core::format_args!($($args)+)) } } #[macro_export] macro_rules! logln { () => ({ kprint!("\r\n") }); ($fmt: literal $(, $($arg: tt)+)?) => { log!(concat!($fmt, "\n") $(, $($arg)+)?) } } static TX: Mutex>>> = Mutex::new(RefCell::new(None)); pub fn init(tx: Tx) { interrupt::free(|cs| { TX.borrow(cs).replace(Some(tx)); }); } pub fn log_args(args: Arguments) { interrupt::free(|cs| { TX.borrow(cs).borrow_mut().as_mut().map(|tx| write(tx, args)); }); }