From ac336b7a263c6c729647c99c9afc8290c22d3db6 Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 12 Mar 2020 00:50:24 +0100 Subject: [PATCH] main: split into mod init_log --- src/init_log.rs | 19 +++++++++++++++++++ src/main.rs | 21 ++------------------- 2 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 src/init_log.rs diff --git a/src/init_log.rs b/src/init_log.rs new file mode 100644 index 0000000..fc736df --- /dev/null +++ b/src/init_log.rs @@ -0,0 +1,19 @@ +#[cfg(not(feature = "semihosting"))] +pub fn init_log() {} + +#[cfg(feature = "semihosting")] +pub fn init_log() { + use log::LevelFilter; + use cortex_m_log::log::{Logger, init}; + use cortex_m_log::printer::semihosting::{InterruptOk, hio::HStdout}; + static mut LOGGER: Option>> = None; + let logger = Logger { + inner: InterruptOk::<_>::stdout().expect("semihosting stdout"), + level: LevelFilter::Info, + }; + let logger = unsafe { + LOGGER.get_or_insert(logger) + }; + + init(logger).expect("set logger"); +} diff --git a/src/main.rs b/src/main.rs index 6b9124f..7f3869d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,8 @@ use smoltcp::{ wire::EthernetAddress, }; +mod init_log; +use init_log::init_log; mod pins; use pins::Pins; mod ad7172; @@ -46,25 +48,6 @@ const WATCHDOG_INTERVAL: u32 = 10_000; #[cfg(not(feature = "generate-hwaddr"))] const NET_HWADDR: [u8; 6] = [0x02, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; -#[cfg(not(feature = "semihosting"))] -fn init_log() {} - -#[cfg(feature = "semihosting")] -fn init_log() { - use log::LevelFilter; - use cortex_m_log::log::{Logger, init}; - use cortex_m_log::printer::semihosting::{InterruptOk, hio::HStdout}; - static mut LOGGER: Option>> = None; - let logger = Logger { - inner: InterruptOk::<_>::stdout().expect("semihosting stdout"), - level: LevelFilter::Info, - }; - let logger = unsafe { - LOGGER.get_or_insert(logger) - }; - - init(logger).expect("set logger"); -} /// Initialization and main loop #[entry]