From 24daa0ad29332aac7ea69ee98c09bf7bedcc43b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Hlusi=C4=8Dka?= Date: Mon, 12 Jan 2026 01:03:27 +0100 Subject: [PATCH] Fix some lints --- firmware2/build.rs | 12 ++++++++-- firmware2/src/ffi/alloc.rs | 2 +- firmware2/src/ffi/string.rs | 2 +- firmware2/src/keymap.rs | 4 +--- firmware2/src/main.rs | 45 ++++++++++++++----------------------- firmware2/src/ui/backend.rs | 2 +- firmware2/src/ui/mod.rs | 2 +- 7 files changed, 32 insertions(+), 37 deletions(-) diff --git a/firmware2/build.rs b/firmware2/build.rs index 4940899..343eb29 100644 --- a/firmware2/build.rs +++ b/firmware2/build.rs @@ -4,7 +4,7 @@ use std::io::{Read, Write}; use std::path::{Path, PathBuf}; use const_gen::*; -use indoc::formatdoc; +use indoc::{formatdoc, writedoc}; use json::JsonValue; use slint_build::{CompilerConfiguration, EmbedResourcesKind}; use xz2::read::XzEncoder; @@ -107,7 +107,15 @@ fn generate_vial_config() { writeln!(out_file, "{}", const_declarations).unwrap(); - writeln!(out_file, "#[repr(u8)] pub enum CustomKeycodes {{").unwrap(); + writedoc!( + out_file, + " + #[allow(dead_code, non_camel_case_types)] + #[repr(u8)] + pub enum CustomKeycodes {{ + " + ) + .unwrap(); // const CUSTOM_KEYCODE_FIRST: u16 = 0x840; diff --git a/firmware2/src/ffi/alloc.rs b/firmware2/src/ffi/alloc.rs index 04db8bf..278e8ab 100644 --- a/firmware2/src/ffi/alloc.rs +++ b/firmware2/src/ffi/alloc.rs @@ -18,7 +18,7 @@ pub unsafe extern "C" fn __xkbc_malloc(size: c_size_t) -> *mut c_void { #[unsafe(no_mangle)] pub unsafe extern "C" fn __xkbc_calloc(number: c_size_t, size: c_size_t) -> *mut c_void { - let total_size = number as usize * size; + let total_size = number * size; unsafe { let ptr = __xkbc_malloc(total_size) as *mut u8; diff --git a/firmware2/src/ffi/string.rs b/firmware2/src/ffi/string.rs index 12ee13e..b4f0144 100644 --- a/firmware2/src/ffi/string.rs +++ b/firmware2/src/ffi/string.rs @@ -13,7 +13,7 @@ pub unsafe extern "C" fn __xkbc_memset( c: c_int, n: c_size_t, ) -> *mut c_void { - if dest_original == null_mut() { + if dest_original.is_null() { if n > 0 { panic!("Attempted to memset a nullptr."); } else { diff --git a/firmware2/src/keymap.rs b/firmware2/src/keymap.rs index b3c038a..4922329 100644 --- a/firmware2/src/keymap.rs +++ b/firmware2/src/keymap.rs @@ -1,5 +1,4 @@ use core::alloc::Layout; -use core::convert::TryFrom; use core::fmt::Debug; use core::slice; @@ -12,7 +11,6 @@ use embassy_time::Instant; use esp_alloc::MemoryCapability; use log::{debug, info, warn}; use rmk::descriptor::KeyboardReport; -use rmk::futures::FutureExt; use rmk::hid::Report; use rmk::types::action::{Action, KeyAction}; use rmk::{a, k, layer}; @@ -167,7 +165,7 @@ pub fn create_hid_report_interceptor() -> impl Future { } } - previous_state = report.clone(); + previous_state = *report; for keycode in released_keys { debug!("Release: 0x{:02x} ({})", keycode, keycode); diff --git a/firmware2/src/main.rs b/firmware2/src/main.rs index 0ca312f..f5847ad 100644 --- a/firmware2/src/main.rs +++ b/firmware2/src/main.rs @@ -18,18 +18,15 @@ extern crate alloc; use core::alloc::Layout; use core::cell::RefCell; -use core::slice; use core::sync::atomic::{AtomicBool, Ordering}; use alloc::boxed::Box; -use alloc::string::String; use alloc::vec; -use cfg_if::cfg_if; use embassy_executor::Spawner; use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; use embassy_sync::channel::Channel; use embassy_sync::signal::Signal; -use embassy_time::{Duration, Instant}; +use embassy_time::Duration; use esp_alloc::{HeapRegion, MemoryCapability}; use esp_hal::Blocking; use esp_hal::clock::CpuClock; @@ -45,12 +42,11 @@ use esp_hal::system::Stack; use esp_hal::timer::timg::TimerGroup; use esp_rtos::embassy::Executor; use esp_storage::FlashStorage; -use log::{LevelFilter, error, info, warn}; +use log::{error, info}; use rmk::channel::{CONTROLLER_CHANNEL, ControllerSub}; use rmk::config::{BehaviorConfig, PositionalConfig, RmkConfig, StorageConfig, VialConfig}; use rmk::controller::{Controller, EventController}; use rmk::debounce::default_debouncer::DefaultDebouncer; -use rmk::descriptor::KeyboardReport; use rmk::event::ControllerEvent; use rmk::hid::Report; use rmk::input_device::Runnable; @@ -58,16 +54,12 @@ use rmk::join_all; use rmk::keyboard::Keyboard; use rmk::storage::async_flash_wrapper; use rmk::types::action::{Action, KeyAction}; -use rmk::types::keycode::{HidKeyCode, KeyCode}; use rmk::{initialize_keymap_and_storage, run_devices, run_rmk}; -use slint::ComponentHandle; use slint::platform::software_renderer::Rgb565Pixel; use static_cell::StaticCell; -use ui::AppWindow; -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::keymap::create_hid_report_interceptor; use crate::logging::LOG_LEVEL_FILTER; use crate::matrix::IoeMatrix; use crate::peripherals::st7701s::St7701s; @@ -430,25 +422,22 @@ impl Controller for UserController { type Event = ControllerEvent; async fn process_event(&mut self, event: Self::Event) { - if let ControllerEvent::Key( - keyboard_event, - KeyAction::Single(Action::User(user_key_index)), - ) = event + if let ControllerEvent::Key(keyboard_event, KeyAction::Single(Action::User(user_key_index))) = + event + && user_key_index == CustomKeycodes::FOCUS_LCD as u8 + && keyboard_event.pressed { - if user_key_index == CustomKeycodes::FOCUS_LCD as u8 && keyboard_event.pressed { - let enabled = !LCD_ENABLED.fetch_xor(true, Ordering::SeqCst); + let enabled = !LCD_ENABLED.fetch_xor(true, Ordering::SeqCst); - match enabled { - false => { - info!("Disabling LCD."); - *rmk::channel::KEYBOARD_REPORT_SENDER.write().await = - &rmk::channel::KEYBOARD_REPORT_RECEIVER; - } - true => { - info!("Enabling LCD."); - *rmk::channel::KEYBOARD_REPORT_SENDER.write().await = - &KEYBOARD_REPORT_PROXY; - } + match enabled { + false => { + info!("Disabling LCD."); + *rmk::channel::KEYBOARD_REPORT_SENDER.write().await = + &rmk::channel::KEYBOARD_REPORT_RECEIVER; + } + true => { + info!("Enabling LCD."); + *rmk::channel::KEYBOARD_REPORT_SENDER.write().await = &KEYBOARD_REPORT_PROXY; } } } diff --git a/firmware2/src/ui/backend.rs b/firmware2/src/ui/backend.rs index 0f6b4cd..d618a9a 100644 --- a/firmware2/src/ui/backend.rs +++ b/firmware2/src/ui/backend.rs @@ -2,7 +2,7 @@ use core::{cell::RefCell, time::Duration}; use alloc::rc::Rc; use esp_hal::time::Instant; -use log::{debug, info, warn}; +use log::{debug, info}; use slint::{ PhysicalSize, SharedString, WindowSize, platform::{ diff --git a/firmware2/src/ui/mod.rs b/firmware2/src/ui/mod.rs index 08abcb3..b0a1872 100644 --- a/firmware2/src/ui/mod.rs +++ b/firmware2/src/ui/mod.rs @@ -5,7 +5,7 @@ use alloc::boxed::Box; #[cfg(feature = "limit-fps")] use crate::FRAME_DURATION_MIN; use crate::{ - SIGNAL_LCD_SUBMIT, SIGNAL_UI_RENDER, keymap::KEY_MESSAGE_CHANNEL, ui::backend::SlintBackend, + SIGNAL_LCD_SUBMIT, SIGNAL_UI_RENDER, ui::backend::SlintBackend, }; pub mod backend;