diff --git a/firmware2/.cargo/config.toml b/firmware2/.cargo/config.toml index dd86e83..fb541c7 100644 --- a/firmware2/.cargo/config.toml +++ b/firmware2/.cargo/config.toml @@ -12,7 +12,7 @@ rustflags = [ [env] -ESP_LOG = "info" +ESP_LOG = "warn" # This is overkill, but we can afford it. SLINT_FONT_SIZES = "8,11,10,12,13,14,15,16,18,20,22,24,32" diff --git a/firmware2/Cargo.toml b/firmware2/Cargo.toml index 3522ec4..b46c2d4 100644 --- a/firmware2/Cargo.toml +++ b/firmware2/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/haobogu/rmk" edition = "2024" [features] -default = ["usb-log", "limit-fps", "warn"] +default = ["usb-log", "limit-fps"] # Make RMK not to use USB no-usb = ["rmk/_no_usb"] # Let RMK use BLE @@ -26,12 +26,6 @@ rtt-log = ["dep:rtt-target", "dep:panic-rtt-target"] # which causes the LCD to glitch. To prevent the main core from spending all its # execution time on just driving the LCD, it will be limited. limit-fps = [] -# Log levels (lower takes precedence) TODO: Use env vars -error = [] -warn = [] -info = [] -debug = [] -trace = [] # Development profiles develop = ["limit-fps", "alt-log"] develop-usb = ["limit-fps", "usb-log", "no-usb", "ble"] diff --git a/firmware2/src/logging.rs b/firmware2/src/logging.rs index 4c754d9..d0525bc 100644 --- a/firmware2/src/logging.rs +++ b/firmware2/src/logging.rs @@ -4,7 +4,27 @@ use core::fmt::Write; use critical_section::{CriticalSection, Mutex}; use esp_hal::Blocking; use esp_hal::uart::UartTx; -use log::Log; +use log::{LevelFilter, Log}; + +pub const LOG_LEVEL_FILTER: LevelFilter = { + if let Some(string) = option_env!("ESP_LOG") { + if string.eq_ignore_ascii_case("ERROR") { + LevelFilter::Error + } else if string.eq_ignore_ascii_case("WARN") { + LevelFilter::Warn + } else if string.eq_ignore_ascii_case("INFO") { + LevelFilter::Info + } else if string.eq_ignore_ascii_case("DEBUG") { + LevelFilter::Debug + } else if string.eq_ignore_ascii_case("TRACE") { + LevelFilter::Trace + } else { + panic!("Unknown `ESP_LOG` value. Only `ERROR`, `WARN`, `INFO`, `DEBUG`, `TRACE`, or `OFF` may be used."); + } + } else { + LevelFilter::Off + } +}; static ALT_LOGGER_UART: Mutex>>> = Mutex::new(RefCell::new(None)); diff --git a/firmware2/src/main.rs b/firmware2/src/main.rs index a265444..0ca312f 100644 --- a/firmware2/src/main.rs +++ b/firmware2/src/main.rs @@ -68,6 +68,7 @@ use xkbcommon::xkb::{self, FeedResult, KeyDirection, Keysym, Status}; use {esp_alloc as _, esp_backtrace as _}; use crate::keymap::{KEY_MESSAGE_CHANNEL, create_hid_report_interceptor}; +use crate::logging::LOG_LEVEL_FILTER; use crate::matrix::IoeMatrix; use crate::peripherals::st7701s::St7701s; use crate::ui::backend::{FramebufferPtr, SlintBackend}; @@ -90,22 +91,6 @@ mod console; // For more information see: esp_bootloader_esp_idf::esp_app_desc!(); -cfg_if! { - if #[cfg(feature = "trace")] { - const LOG_LEVEL_FILTER: LevelFilter = LevelFilter::Trace; - } else if #[cfg(feature = "debug")] { - const LOG_LEVEL_FILTER: LevelFilter = LevelFilter::Debug; - } else if #[cfg(feature = "info")] { - const LOG_LEVEL_FILTER: LevelFilter = LevelFilter::Info; - } else if #[cfg(feature = "warn")] { - const LOG_LEVEL_FILTER: LevelFilter = LevelFilter::Warn; - } else if #[cfg(feature = "error")] { - const LOG_LEVEL_FILTER: LevelFilter = LevelFilter::Error; - } else { - const LOG_LEVEL_FILTER: LevelFilter = LevelFilter::Off; - } -} - // const FRAME_DURATION_MIN: Duration = Duration::from_millis(40); // 25 FPS const FRAME_DURATION_MIN: Duration = Duration::from_millis(100); // 10 FPS @@ -556,7 +541,7 @@ async fn run_lcd(mut st7701s: St7701s<'static, Blocking>, framebuffer: &'static #[cfg(not(feature = "limit-fps"))] while !transfer.is_done() { // Timer::after_millis(1).await; - yield_now().await; + rmk::embassy_futures::yield_now().await; } let result;