aboutsummaryrefslogtreecommitdiffstats
path: root/src/log.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/log.rs')
-rw-r--r--src/log.rs20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/log.rs b/src/log.rs
index ddb6792..7eb15e4 100644
--- a/src/log.rs
+++ b/src/log.rs
@@ -1,10 +1,14 @@
-use core::fmt::{write, Arguments};
+use core::{
+ cell::RefCell,
+ fmt::{write, Arguments},
+};
-use gd32vf103xx_hal::{
+use stm32f1xx_hal::{
serial::Tx,
pac::USART1,
};
-use riscv::interrupt::{self, Mutex};
+
+use cortex_m::interrupt::{self, Mutex};
#[macro_export]
macro_rules! log {
@@ -21,16 +25,16 @@ macro_rules! logln {
}
}
-static mut TX: Mutex<Option<Tx<USART1>>> = Mutex::new(None);
+static TX: Mutex<RefCell<Option<Tx<USART1>>>> = Mutex::new(RefCell::new(None));
pub fn init(tx: Tx<USART1>) {
- interrupt::free(|_cs| {
- unsafe { TX.get_mut().insert(tx) };
+ interrupt::free(|cs| {
+ TX.borrow(cs).replace(Some(tx));
});
}
pub fn log_args(args: Arguments) {
- interrupt::free(|_cs| {
- unsafe { TX.get_mut().as_mut().map(|tx| write(tx, args)) };
+ interrupt::free(|cs| {
+ TX.borrow(cs).borrow_mut().as_mut().map(|tx| write(tx, args));
});
}