Features for log levels

This commit is contained in:
Jakub Hlusička 2026-01-02 17:31:28 +01:00
parent 8468421817
commit bfe4839d83
4 changed files with 30 additions and 6 deletions

1
firmware2/Cargo.lock generated
View file

@ -10,6 +10,7 @@ dependencies = [
"bt-hci",
"bytemuck",
"cc",
"cfg-if",
"const-gen",
"critical-section",
"embassy-embedded-hal",

View file

@ -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"] }

View file

@ -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;

View file

@ -1,6 +1,5 @@
//! 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.
@ -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: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
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
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.