From ea58ef0c8e76c620bffbf29d198147e8fc37631d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Hlusi=C4=8Dka?= Date: Fri, 13 Feb 2026 03:00:46 +0100 Subject: [PATCH] Fix clippy lints --- firmware/acid-firmware/build.rs | 2 +- firmware/acid-firmware/src/config.rs | 26 +---------------- firmware/acid-firmware/src/db/mod.rs | 2 +- firmware/acid-firmware/src/ffi/crypto.rs | 4 +-- firmware/acid-firmware/src/ffi/inout/dir.rs | 2 +- firmware/acid-firmware/src/ffi/time.rs | 1 + firmware/acid-firmware/src/logging.rs | 10 ++----- firmware/acid-firmware/src/main.rs | 13 +++------ firmware/acid-firmware/src/proxy.rs | 31 ++++++++------------- firmware/acid-firmware/src/ui/backend.rs | 1 - firmware/acid-firmware/src/ui/mod.rs | 17 ++++++----- firmware/acid-firmware/src/ui/storage.rs | 4 +-- 12 files changed, 35 insertions(+), 78 deletions(-) diff --git a/firmware/acid-firmware/build.rs b/firmware/acid-firmware/build.rs index 3b1378e..3111f6a 100644 --- a/firmware/acid-firmware/build.rs +++ b/firmware/acid-firmware/build.rs @@ -210,7 +210,7 @@ fn generate_vial_config() { writedoc!( out_file, " - #[allow(dead_code, non_camel_case_types)] + #[allow(dead_code, non_camel_case_types, clippy::upper_case_acronyms)] #[repr(u8)] pub enum CustomKeycodes {{ " diff --git a/firmware/acid-firmware/src/config.rs b/firmware/acid-firmware/src/config.rs index 579d29a..311cd03 100644 --- a/firmware/acid-firmware/src/config.rs +++ b/firmware/acid-firmware/src/config.rs @@ -1,35 +1,11 @@ -use core::alloc::Layout; -use core::fmt::Debug; -use core::ops::Index; -use core::slice; -use alloc::alloc::Allocator; -use alloc::boxed::Box; -use alloc::collections::btree_map::{BTreeMap, Entry}; -use alloc::string::String; -use alloc::sync::Arc; -use alloc::vec::Vec; -use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; -use embassy_sync::channel::Channel; -use embassy_time::Instant; -use esp_alloc::{EspHeap, MemoryCapability}; -use itertools::Itertools; -use log::{debug, error, info, warn}; use rmk::config::{BehaviorConfig, ForksConfig, PositionalConfig}; -use rmk::descriptor::KeyboardReport; use rmk::fork::{Fork, StateBits}; -use rmk::futures::FutureExt; -use rmk::hid::Report; use rmk::types::action::{Action, KeyAction}; use rmk::types::modifier::ModifierCombination; -use rmk::{a, heapless, join_all, k, layer}; -use slint::platform::Key; -use static_cell::StaticCell; -use xkbcommon::xkb::{self, FeedResult, KeyDirection, Keysym, ModIndex, ModMask, Status}; +use rmk::{a, heapless, k, layer}; -use crate::util::{DurationExt, get_file_name}; use crate::vial::CustomKeycodes; -use crate::{KEYBOARD_REPORT_PROXY, PSRAM_ALLOCATOR}; pub const NUM_LAYER: usize = 8; pub const MATRIX_ROWS: usize = 5; diff --git a/firmware/acid-firmware/src/db/mod.rs b/firmware/acid-firmware/src/db/mod.rs index 4872b3f..e11b98f 100644 --- a/firmware/acid-firmware/src/db/mod.rs +++ b/firmware/acid-firmware/src/db/mod.rs @@ -230,7 +230,7 @@ impl DbKey { pub struct DbPathSpectreUsers; -impl<'a> IntoIterator for DbPathSpectreUsers { +impl IntoIterator for DbPathSpectreUsers { type Item = DbPathSegment<'static>; type IntoIter = core::array::IntoIter, 2>; diff --git a/firmware/acid-firmware/src/ffi/crypto.rs b/firmware/acid-firmware/src/ffi/crypto.rs index 5c4452c..7b4de2e 100644 --- a/firmware/acid-firmware/src/ffi/crypto.rs +++ b/firmware/acid-firmware/src/ffi/crypto.rs @@ -4,9 +4,7 @@ use core::{ }; use critical_section::Mutex; -use data_encoding_macro::hexlower; use embassy_sync::blocking_mutex::{self, raw::CriticalSectionRawMutex}; -use esp_sync::RawMutex; use hmac::digest::{FixedOutput, KeyInit, Update}; use password_hash::Key; use sha2::{ @@ -89,6 +87,7 @@ unsafe extern "C" fn __spre_crypto_generichash_blake2b_salt_personal( todo!() } +#[allow(non_camel_case_types)] #[repr(C)] struct crypto_hash_sha256_state { state: [u32; 8], @@ -96,6 +95,7 @@ struct crypto_hash_sha256_state { buf: [u8; 64], } +#[allow(non_camel_case_types, unused)] struct crypto_auth_hmacsha256_state { ictx: crypto_hash_sha256_state, octx: crypto_hash_sha256_state, diff --git a/firmware/acid-firmware/src/ffi/inout/dir.rs b/firmware/acid-firmware/src/ffi/inout/dir.rs index 16e2a97..8a854d6 100644 --- a/firmware/acid-firmware/src/ffi/inout/dir.rs +++ b/firmware/acid-firmware/src/ffi/inout/dir.rs @@ -2,7 +2,7 @@ use core::ffi::{c_char, c_int}; -#[allow(non_camel_case_types)] +#[allow(non_camel_case_types, clippy::upper_case_acronyms)] pub enum DIR {} #[allow(non_camel_case_types)] diff --git a/firmware/acid-firmware/src/ffi/time.rs b/firmware/acid-firmware/src/ffi/time.rs index b3c3cef..9799343 100644 --- a/firmware/acid-firmware/src/ffi/time.rs +++ b/firmware/acid-firmware/src/ffi/time.rs @@ -1,6 +1,7 @@ use embassy_time::Instant; // TODO: Is this right? +#[allow(non_camel_case_types)] pub type time_t = i64; #[unsafe(no_mangle)] diff --git a/firmware/acid-firmware/src/logging.rs b/firmware/acid-firmware/src/logging.rs index bd34dec..eb77df9 100644 --- a/firmware/acid-firmware/src/logging.rs +++ b/firmware/acid-firmware/src/logging.rs @@ -1,12 +1,6 @@ -use core::fmt::Write; -use core::{cell::RefCell, fmt::Arguments}; +use core::fmt::Arguments; -use critical_section::{CriticalSection, Mutex}; -use esp_hal::Blocking; -use esp_hal::clock::CpuClock; -use esp_hal::psram::{FlashFreq, PsramConfig, PsramSize, SpiRamFreq, SpiTimingConfigCoreClock}; -use esp_hal::uart::UartTx; -use log::{LevelFilter, Log}; +use log::LevelFilter; pub const LOG_LEVEL_FILTER: LevelFilter = { if let Some(string) = option_env!("ESP_LOG") { diff --git a/firmware/acid-firmware/src/main.rs b/firmware/acid-firmware/src/main.rs index 04ca73e..f64de94 100644 --- a/firmware/acid-firmware/src/main.rs +++ b/firmware/acid-firmware/src/main.rs @@ -61,27 +61,23 @@ use itertools::Itertools; use log::{error, info, warn}; use rmk::channel::{CONTROLLER_CHANNEL, ControllerSub}; use rmk::config::{ - BehaviorConfig, DeviceConfig, ForksConfig, PositionalConfig, RmkConfig, StorageConfig, + DeviceConfig, RmkConfig, StorageConfig, VialConfig, }; use rmk::controller::{Controller, EventController}; use rmk::debounce::default_debouncer::DefaultDebouncer; use rmk::event::ControllerEvent; -use rmk::fork::{Fork, StateBits}; use rmk::hid::Report; use rmk::input_device::Runnable; use rmk::keyboard::Keyboard; use rmk::storage::async_flash_wrapper; use rmk::types::action::{Action, KeyAction}; -use rmk::types::keycode::KeyCode; -use rmk::types::modifier::ModifierCombination; -use rmk::{heapless, join_all}; +use rmk::join_all; use rmk::{initialize_keymap_and_storage, run_devices, run_rmk}; use slint::platform::software_renderer::Rgb565Pixel; use static_cell::StaticCell; use {esp_alloc as _, esp_backtrace as _}; -use crate::logging::LOG_LEVEL_FILTER; use crate::matrix::IoeMatrix; use crate::peripherals::st7701s::St7701s; use crate::proxy::create_hid_report_interceptor; @@ -392,12 +388,12 @@ async fn main(_spawner: Spawner) { start_addr: 0, num_sectors: { assert!( - flash_part_info_rmk.len() as u32 % FlashStorage::SECTOR_SIZE == 0, + flash_part_info_rmk.len() % FlashStorage::SECTOR_SIZE == 0, "The size of the RMK partition must be a multiple of {} bytes. Current size: {}", FlashStorage::SECTOR_SIZE, flash_part_info_rmk.len() ); - (flash_part_info_rmk.len() as u32 / FlashStorage::SECTOR_SIZE) as u8 + (flash_part_info_rmk.len() / FlashStorage::SECTOR_SIZE) as u8 }, ..Default::default() }; @@ -425,7 +421,6 @@ async fn main(_spawner: Spawner) { device_config, vial_config, storage_config, - ..Default::default() }; // Initialze keyboard stuffs diff --git a/firmware/acid-firmware/src/proxy.rs b/firmware/acid-firmware/src/proxy.rs index 61393d6..f3eaa03 100644 --- a/firmware/acid-firmware/src/proxy.rs +++ b/firmware/acid-firmware/src/proxy.rs @@ -1,6 +1,5 @@ use core::alloc::Layout; use core::fmt::Debug; -use core::ops::Index; use core::slice; use alloc::alloc::Allocator; @@ -13,20 +12,14 @@ use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; use embassy_sync::channel::Channel; use embassy_time::Instant; use esp_alloc::{EspHeap, MemoryCapability}; -use itertools::Itertools; use log::{debug, error, info, warn}; use rmk::descriptor::KeyboardReport; -use rmk::futures::FutureExt; use rmk::hid::Report; -use rmk::types::action::{Action, KeyAction}; -use rmk::{a, heapless, join_all, k, layer}; +use rmk::{heapless, join_all}; use slint::platform::Key; -use static_cell::StaticCell; -use xkbcommon::xkb::{self, FeedResult, KeyDirection, Keysym, ModIndex, ModMask, Status}; +use xkbcommon::xkb::{self, FeedResult, KeyDirection, Keysym, ModMask, Status}; -use crate::config::{MATRIX_COLS, MATRIX_ROWS}; use crate::util::{DurationExt, get_file_name}; -use crate::vial::CustomKeycodes; use crate::{KEYBOARD_REPORT_PROXY, PSRAM_ALLOCATOR}; pub static KEY_MESSAGE_CHANNEL: Channel = Channel::new(); @@ -199,15 +192,15 @@ async fn send_strings_to_host( let mut index = 0; while remaining_mask != 0 { - if remaining_mask & 1 != 0 { - if let Some(mod_descriptor) = modifier_xkb_index_to_descriptor[index] { - if let Some(hid_flag) = mod_descriptor.hid_flag { - modifier |= hid_flag; - } + if remaining_mask & 1 != 0 + && let Some(mod_descriptor) = modifier_xkb_index_to_descriptor[index] + { + if let Some(hid_flag) = mod_descriptor.hid_flag { + modifier |= hid_flag; + } - if let Some(keycode) = mod_descriptor.keycode { - let _ = keycodes_vec.push(keycode); - } + if let Some(keycode) = mod_descriptor.keycode { + let _ = keycodes_vec.push(keycode); } } @@ -432,7 +425,7 @@ pub struct HidKeycodeWithMods { pub fn string_to_hid_keycodes( keymap: &xkb::Keymap, - compose_table: &xkb::compose::Table, + _compose_table: &xkb::compose::Table, string: &str, ) -> Result, char> { #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] @@ -582,7 +575,7 @@ pub const fn xkb_to_hid_keycode(xkb_keycode: xkb::Keycode) -> Option { let mut hid: u8 = 0; loop { - xkb_to_hid[hid_to_xkb_keycode_inner(hid as u8) as usize] = hid; + xkb_to_hid[hid_to_xkb_keycode_inner(hid) as usize] = hid; let overflow; (hid, overflow) = hid.overflowing_add(1); if overflow { diff --git a/firmware/acid-firmware/src/ui/backend.rs b/firmware/acid-firmware/src/ui/backend.rs index 434d118..80e0f93 100644 --- a/firmware/acid-firmware/src/ui/backend.rs +++ b/firmware/acid-firmware/src/ui/backend.rs @@ -10,7 +10,6 @@ use alloc::{ use critical_section::Mutex; use esp_hal::time::Instant; use log::{debug, info}; -use rmk::futures::sink::drain; use slint::{ EventLoopError, PhysicalSize, SharedString, WindowSize, platform::{ diff --git a/firmware/acid-firmware/src/ui/mod.rs b/firmware/acid-firmware/src/ui/mod.rs index 64b52ea..a6f9392 100644 --- a/firmware/acid-firmware/src/ui/mod.rs +++ b/firmware/acid-firmware/src/ui/mod.rs @@ -1,6 +1,6 @@ // #![cfg_attr(not(feature = "simulator"), no_main)] -use core::{cell::RefCell, ffi::CStr, ops::DerefMut, pin::Pin}; +use core::{cell::RefCell, ffi::CStr, pin::Pin}; use alloc::{ borrow::Cow, @@ -17,14 +17,13 @@ use hex::FromHexError; use i_slint_core::model::{ModelChangeListener, ModelChangeListenerContainer}; use log::{error, info, warn}; use password_hash::Key; -use rmk::futures::{FutureExt, TryFutureExt}; use slint::{ Model, ModelExt, ModelNotify, ModelRc, ModelTracker, SharedString, StandardListViewItem, VecModel, }; use spectre_api_sys::{ SpectreAlgorithm, SpectreCounter, SpectreKeyID, SpectreKeyPurpose, SpectreResultType, - SpectreSiteKey, SpectreUserKey, + SpectreUserKey, }; #[cfg(feature = "limit-fps")] @@ -453,7 +452,7 @@ impl AppViewTrait for StateLogin { if user.key_id != user_key.keyID.bytes { State::process_callback_message( - &state_rc, + state_rc, CallbackMessage::Login(CallbackMessageLogin::LoginResult { username: user.username, result: LoginResult::Failure, @@ -494,7 +493,7 @@ impl AppViewTrait for StateLogin { let mut key_segments = key.segments(); let value = &buffer[..value_len]; let site_config = - postcard::from_bytes::(&value).unwrap(); + postcard::from_bytes::(value).unwrap(); let site = SpectreSite { config: site_config, username: key_segments.nth(2).unwrap().as_ref().into(), @@ -683,10 +682,10 @@ impl AppViewTrait for StateUserEdit { let mut existing_index = None; for index in 0..state.users.users.row_count() { - if let Some(current_user) = state.users.users.row_data(index) { - if current_user.username == user.username { - existing_index = Some(index); - } + if let Some(current_user) = state.users.users.row_data(index) + && current_user.username == user.username + { + existing_index = Some(index); } } diff --git a/firmware/acid-firmware/src/ui/storage.rs b/firmware/acid-firmware/src/ui/storage.rs index 062cdaa..c0580d6 100644 --- a/firmware/acid-firmware/src/ui/storage.rs +++ b/firmware/acid-firmware/src/ui/storage.rs @@ -1,10 +1,10 @@ use core::fmt::{Debug, Formatter}; -use alloc::{rc::Rc, string::String, vec::Vec}; +use alloc::rc::Rc; use chrono::NaiveDateTime; use password_hash::Key; use serde::{Deserialize, Serialize}; -use slint::{Model, ModelRc, SharedString, VecModel}; +use slint::{Model, SharedString, VecModel}; use spectre_api_sys::{SpectreAlgorithm, SpectreCounter, SpectreResultType}; #[derive(Deserialize, Serialize, Default)]