aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2022-10-28 16:26:43 -0400
committerBrian Cully <bjc@kublai.com>2022-10-28 16:26:43 -0400
commitfc890e991ed960c0f2f052f2664fc07a005f4ed3 (patch)
treeb6d7d2c1c2fa158c48022ef5c66708c534784c4a
parent5200c3cc2c87feca2bcb973e32eaeef9808fe032 (diff)
downloadluchie-fc890e991ed960c0f2f052f2664fc07a005f4ed3.tar.gz
luchie-fc890e991ed960c0f2f052f2664fc07a005f4ed3.zip
log: move architecture-specifics to ‘arch’ sub-module
-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>;
+}