diff options
author | Brian Cully <bjc@kublai.com> | 2022-10-28 16:26:43 -0400 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2022-10-28 16:26:43 -0400 |
commit | fc890e991ed960c0f2f052f2664fc07a005f4ed3 (patch) | |
tree | b6d7d2c1c2fa158c48022ef5c66708c534784c4a /src | |
parent | 5200c3cc2c87feca2bcb973e32eaeef9808fe032 (diff) | |
download | luchie-fc890e991ed960c0f2f052f2664fc07a005f4ed3.tar.gz luchie-fc890e991ed960c0f2f052f2664fc07a005f4ed3.zip |
log: move architecture-specifics to ‘arch’ sub-module
Diffstat (limited to 'src')
-rw-r--r-- | src/log.rs | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -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>; +} |