aboutsummaryrefslogtreecommitdiffstats
path: root/src/log.rs
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2022-10-25 12:20:32 -0400
committerBrian Cully <bjc@kublai.com>2022-10-25 12:20:32 -0400
commit0c4eb964b015961e3c90e45ef498f6c7f89eddba (patch)
treeb0cc3b540e7123b45da044c73d1f47f98ce010ef /src/log.rs
parent0f80c612d59c855a99073e583db339fe6a42b883 (diff)
downloadluchie-0c4eb964b015961e3c90e45ef498f6c7f89eddba.tar.gz
luchie-0c4eb964b015961e3c90e45ef498f6c7f89eddba.zip
convert to gd32f303 (stm32f103) bluepill variant
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));
});
}