From fc890e991ed960c0f2f052f2664fc07a005f4ed3 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Fri, 28 Oct 2022 16:26:43 -0400 Subject: =?UTF-8?q?log:=20move=20architecture-specifics=20to=20=E2=80=98ar?= =?UTF-8?q?ch=E2=80=99=20sub-module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/log.rs | 28 ++++++++++++++++++++-------- 1 file 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>>> = Mutex::new(RefCell::new(None)); +static TX: Mutex>> = Mutex::new(RefCell::new(None)); -pub fn init(tx: Tx) { +pub fn init(tx: arch::Writer) { interrupt::free(|cs| { TX.borrow(cs).replace(Some(tx)); }); @@ -35,6 +30,23 @@ pub fn init(tx: Tx) { 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; +} -- cgit v1.2.3