aboutsummaryrefslogtreecommitdiffstats
path: root/src/log.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/log.rs')
-rw-r--r--src/log.rs28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/log.rs b/src/log.rs
index 7eb15e4..ccc9ebc 100644
--- a/src/log.rs
+++ b/src/log.rs
@@ -3,11 +3,6 @@ use core::{
fmt::{write, Arguments},
};
-use stm32f1xx_hal::{
- serial::Tx,
- pac::USART1,
-};
-
use cortex_m::interrupt::{self, Mutex};
#[macro_export]
@@ -25,9 +20,9 @@ macro_rules! logln {
}
}
-static TX: Mutex<RefCell<Option<Tx<USART1>>>> = Mutex::new(RefCell::new(None));
+static TX: Mutex<RefCell<Option<arch::Writer>>> = Mutex::new(RefCell::new(None));
-pub fn init(tx: Tx<USART1>) {
+pub fn init(tx: arch::Writer) {
interrupt::free(|cs| {
TX.borrow(cs).replace(Some(tx));
});
@@ -35,6 +30,23 @@ pub fn init(tx: Tx<USART1>) {
pub fn log_args(args: Arguments) {
interrupt::free(|cs| {
- TX.borrow(cs).borrow_mut().as_mut().map(|tx| write(tx, args));
+ TX.borrow(cs)
+ .borrow_mut()
+ .as_mut()
+ .map(|tx| write(tx, args));
});
}
+
+/*
+ * Because the logger needs to have a size in order to be allocated
+ * statically, we need to pull in architecture-specific details about
+ * the implementation.
+ *
+ * By putting everything in an `arch` module, we can more easily swap
+ * things out at compile time with feature flags, or a similar
+ * mechanism.
+ */
+mod arch {
+ use stm32f1xx_hal::{pac::USART1, serial::Tx};
+ pub type Writer = Tx<USART1>;
+}