From bfe4839d83f20aed2388edadb447803c4b5a09a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Hlusi=C4=8Dka?= Date: Fri, 2 Jan 2026 17:31:28 +0100 Subject: [PATCH] Features for log levels --- firmware2/Cargo.lock | 1 + firmware2/Cargo.toml | 9 ++++++++- firmware2/build.rs | 2 +- firmware2/src/main.rs | 24 ++++++++++++++++++++---- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/firmware2/Cargo.lock b/firmware2/Cargo.lock index 30eabe1..6c8fa87 100644 --- a/firmware2/Cargo.lock +++ b/firmware2/Cargo.lock @@ -10,6 +10,7 @@ dependencies = [ "bt-hci", "bytemuck", "cc", + "cfg-if", "const-gen", "critical-section", "embassy-embedded-hal", diff --git a/firmware2/Cargo.toml b/firmware2/Cargo.toml index 2e3d2b2..8197c5b 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"] +default = ["usb-log", "limit-fps", "warn"] develop = ["limit-fps", "alt-log"] no-usb = ["rmk/_no_usb"] ble = ["rmk/esp32s3_ble"] @@ -19,6 +19,12 @@ alt-log = [] # Standard logging implementation over USB. usb-log = ["esp-backtrace/panic-handler"] limit-fps = [] +# Log levels (lower takes precedence) +error = [] +warn = [] +info = [] +debug = [] +trace = [] [dependencies] rmk = { version = "0.8.2", default-features = false, features = [ @@ -53,6 +59,7 @@ itertools = { version = "0.14.0", default-features = false } bytemuck = "1.24.0" slint = { version = "1.14.1", default-features = false, features = ["compat-1-2", "libm", "log", "unsafe-single-threaded", "renderer-software"]} critical-section = "1.2.0" +cfg-if = "1.0.4" # Crates for serial UART CLI embedded-cli = { version = "0.2.1", default-features = false, features = ["help", "macros"] } diff --git a/firmware2/build.rs b/firmware2/build.rs index aab1796..9c0d80f 100644 --- a/firmware2/build.rs +++ b/firmware2/build.rs @@ -1,7 +1,7 @@ use std::fs::{File, OpenOptions}; use std::io::{Read, Write}; use std::path::Path; -use std::{env, fs}; +use std::env; use const_gen::*; use json::JsonValue; diff --git a/firmware2/src/main.rs b/firmware2/src/main.rs index 56dabd7..a54c522 100644 --- a/firmware2/src/main.rs +++ b/firmware2/src/main.rs @@ -1,12 +1,11 @@ //! TODO: //! * GUI event dispatch. -//! * Avoid accessing PSRAM on second core (park it?) while flash is being written to (by vial). //! * Async interrupt handling of keyboard input. Reduces LCD glitching. //! * Attempt to reduce the size of the framebuffer to 240x960 by changing the front/back porch of //! the LCD driver. Reduces LCD glitching. //! * Bounce buffers to get rid of glitching completely. -//! https://esp32.com/viewtopic.php?t=28230 -//! https://esp32.com/viewtopic.php?f=12&t=26793&start=20#p95677 +//! https://esp32.com/viewtopic.php?t=28230 +//! https://esp32.com/viewtopic.php?f=12&t=26793&start=20#p95677 #![no_std] #![no_main] #![feature(macro_metavar_expr)] @@ -19,6 +18,7 @@ use core::cell::RefCell; use alloc::boxed::Box; use alloc::vec; use bt_hci::controller::ExternalController; +use cfg_if::cfg_if; use embassy_executor::Spawner; use embassy_sync::blocking_mutex::raw::{CriticalSectionRawMutex}; use embassy_sync::channel::Channel; @@ -83,7 +83,22 @@ mod console; // For more information see: esp_bootloader_esp_idf::esp_app_desc!(); -const LOG_LEVEL_FILTER: LevelFilter = LevelFilter::Info; +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 static PSRAM_ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty(); @@ -350,6 +365,7 @@ async fn main(_spawner: Spawner) { let mut user_controller = UserController::new(); + // TODO: Probably want to select! instead and re-try. join_all![ // We currently send the framebuffer data using the main core, which does not seem to slow // down the rest of the tasks too much.