From fc1aa617af0c20bb109d7573d8a50b159d730eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Hlusi=C4=8Dka?= Date: Wed, 31 Dec 2025 01:08:12 +0100 Subject: [PATCH] Fix lints --- firmware2/src/console.rs | 3 +- firmware2/src/logging.rs | 65 ++++-------------------- firmware2/src/main.rs | 47 ++++++++--------- firmware2/src/peripherals/st7701s/lcd.rs | 1 + 4 files changed, 33 insertions(+), 83 deletions(-) diff --git a/firmware2/src/console.rs b/firmware2/src/console.rs index eb9fe75..4fa7af4 100644 --- a/firmware2/src/console.rs +++ b/firmware2/src/console.rs @@ -1,9 +1,8 @@ -use core::fmt::write; use embedded_cli::cli::CliBuilder; use embedded_cli::Command; use esp_hal::{Async, uart::{TxError, UartRx}}; -use log::{debug, info, error}; +use log::{info, error}; use crate::logging::with_uart_tx; diff --git a/firmware2/src/logging.rs b/firmware2/src/logging.rs index 09c6cd7..c1eaf3b 100644 --- a/firmware2/src/logging.rs +++ b/firmware2/src/logging.rs @@ -1,64 +1,19 @@ -use core::alloc::Layout; -use core::cell::{OnceCell, RefCell}; +use core::cell::RefCell; use core::fmt::Write; -use core::time::Duration; -use alloc::boxed::Box; -use alloc::rc::Rc; -use alloc::vec; -use bt_hci::controller::ExternalController; use critical_section::{CriticalSection, Mutex}; -use embassy_embedded_hal::adapter::BlockingAsync; -use embassy_executor::Spawner; -use embassy_time::Timer; -use esp_alloc::{HeapRegion, MemoryCapability}; -use esp_hal::clock::CpuClock; -use esp_hal::dma::{BurstConfig, DmaDescriptor, DmaTxBuf, ExternalBurstConfig}; -use esp_hal::gpio::{Flex, Input, InputConfig, Io, Level, Output, OutputConfig, Pull}; -use esp_hal::handler; -use esp_hal::i2c::master::{I2c, I2cAddress}; -use esp_hal::interrupt::Priority; -use esp_hal::interrupt::software::SoftwareInterruptControl; -use esp_hal::lcd_cam::LcdCam; -use esp_hal::lcd_cam::lcd::dpi::Dpi; -use esp_hal::mcpwm::{McPwm, PeripheralClockConfig}; -use esp_hal::peripherals::Peripherals; -use esp_hal::psram::{FlashFreq, PsramConfig, PsramSize, SpiRamFreq, SpiTimingConfigCoreClock}; -use esp_hal::rng::TrngSource; -use esp_hal::system::Stack; -use esp_hal::time::Instant; -use esp_hal::timer::timg::TimerGroup; -use esp_hal::uart::{Uart, UartTx}; -use esp_hal::usb_serial_jtag::{UsbSerialJtag, UsbSerialJtagTx}; -use esp_hal::{Blocking, ram}; -use esp_radio::Controller; -use esp_radio::ble::controller::BleConnector; -use esp_rtos::embassy::{Executor, InterruptExecutor}; -use esp_storage::FlashStorage; -use itertools::chain; -use log::{LevelFilter, Log, error, info}; -use rmk::channel::EVENT_CHANNEL; -use rmk::config::{BehaviorConfig, PositionalConfig, RmkConfig, StorageConfig, VialConfig}; -use rmk::debounce::default_debouncer::DefaultDebouncer; -use rmk::embassy_futures::yield_now; -use rmk::input_device::Runnable; -use rmk::{join_all}; -use rmk::keyboard::Keyboard; -use rmk::storage::async_flash_wrapper; -use rmk::{initialize_keymap_and_storage, run_devices, run_rmk}; -use slint::platform::software_renderer::{Rgb565Pixel, TargetPixel}; -use slint::{ComponentHandle, PhysicalSize, WindowSize}; -use slint::platform::Platform; -use static_cell::StaticCell; +use esp_hal::uart::UartTx; +use esp_hal::Blocking; +use log::{LevelFilter, Log}; static ALT_LOGGER_UART: Mutex>>> = Mutex::new(RefCell::new(None)); -pub fn with_uart_tx(mut f: impl FnOnce(CriticalSection<'_>, &'_ mut UartTx<'static, Blocking>) -> R) -> R { +pub fn with_uart_tx(f: impl FnOnce(CriticalSection<'_>, &'_ mut UartTx<'static, Blocking>) -> R) -> R { critical_section::with(|cs| { let mut uart = ALT_LOGGER_UART.borrow(cs).borrow_mut(); - let mut uart = uart.as_mut().unwrap(); + let uart = uart.as_mut().unwrap(); - (f)(cs, &mut uart) + (f)(cs, uart) }) } @@ -99,11 +54,9 @@ macro_rules! println { }}; } -#[cfg(not(feature = "alt-log"))] -use esp_println::println; fn do_print(args: core::fmt::Arguments<'_>) { - with_uart_tx(|cs, uart| { + with_uart_tx(|_, uart| { uart.write_fmt(args).unwrap(); uart.write_str("\n").unwrap(); uart.flush().unwrap(); @@ -124,7 +77,7 @@ fn print_log_record(uart: &mut UartTx<'_, Blocking>, record: &log::Record) { uart.flush().unwrap(); } -#[cfg(feature = "alt-log")] +#[cfg(not(feature = "usb-log"))] #[panic_handler] fn panic_handler(info: &core::panic::PanicInfo) -> ! { use esp_backtrace::Backtrace; diff --git a/firmware2/src/main.rs b/firmware2/src/main.rs index f0bac2d..75f30c0 100644 --- a/firmware2/src/main.rs +++ b/firmware2/src/main.rs @@ -5,8 +5,7 @@ extern crate alloc; use core::alloc::Layout; -use core::cell::{OnceCell, RefCell}; -use core::fmt::Write; +use core::cell::RefCell; use core::time::Duration; use alloc::boxed::Box; @@ -14,36 +13,28 @@ use alloc::rc::Rc; use alloc::vec; use shadow_rs::shadow; use bt_hci::controller::ExternalController; -use critical_section::Mutex; -use embassy_embedded_hal::adapter::BlockingAsync; use embassy_executor::Spawner; -use embassy_time::Timer; use esp_alloc::{HeapRegion, MemoryCapability}; use esp_hal::clock::CpuClock; use esp_hal::dma::{BurstConfig, DmaDescriptor, DmaTxBuf, ExternalBurstConfig}; use esp_hal::gpio::{Flex, Input, InputConfig, Io, Level, Output, OutputConfig, Pull}; use esp_hal::handler; use esp_hal::i2c::master::{I2c, I2cAddress}; -use esp_hal::interrupt::Priority; use esp_hal::interrupt::software::SoftwareInterruptControl; use esp_hal::lcd_cam::LcdCam; use esp_hal::lcd_cam::lcd::dpi::Dpi; use esp_hal::mcpwm::{McPwm, PeripheralClockConfig}; -use esp_hal::peripherals::Peripherals; use esp_hal::psram::{FlashFreq, PsramConfig, PsramSize, SpiRamFreq, SpiTimingConfigCoreClock}; use esp_hal::rng::TrngSource; use esp_hal::system::Stack; use esp_hal::time::Instant; use esp_hal::timer::timg::TimerGroup; -use esp_hal::uart::Uart; -use esp_hal::usb_serial_jtag::{UsbSerialJtag, UsbSerialJtagTx}; use esp_hal::{Blocking, ram}; use esp_radio::Controller; use esp_radio::ble::controller::BleConnector; -use esp_rtos::embassy::{Executor, InterruptExecutor}; +use esp_rtos::embassy::Executor; use esp_storage::FlashStorage; -use itertools::chain; -use log::{LevelFilter, Log, debug, error, info}; +use log::{LevelFilter, error, info}; use rmk::channel::EVENT_CHANNEL; use rmk::config::{BehaviorConfig, PositionalConfig, RmkConfig, StorageConfig, VialConfig}; use rmk::debounce::default_debouncer::DefaultDebouncer; @@ -53,9 +44,8 @@ use rmk::{join_all}; use rmk::keyboard::Keyboard; use rmk::storage::async_flash_wrapper; use rmk::{initialize_keymap_and_storage, run_devices, run_rmk}; -use slint::platform::software_renderer::{Rgb565Pixel, TargetPixel}; +use slint::platform::software_renderer::Rgb565Pixel; use slint::{ComponentHandle, PhysicalSize, WindowSize}; -use slint::platform::Platform; use static_cell::StaticCell; use ui::AppWindow; use {esp_alloc as _, esp_backtrace as _}; @@ -70,6 +60,8 @@ mod peripherals; mod vial; mod ui; mod logging; + +#[cfg(feature = "alt-log")] mod console; shadow!(build); @@ -104,6 +96,8 @@ async fn main(_spawner: Spawner) { #[cfg(feature = "alt-log")] let alt_uart_rx_task = { + use esp_hal::uart::Uart; + let (uart_rx, uart_tx) = Uart::new(peripherals.UART2, Default::default()).unwrap().with_tx(peripherals.GPIO12).with_rx(peripherals.GPIO5).split(); logging::setup_alternative_logging(uart_tx, LOG_LEVEL_FILTER); info!("Logger initialized!"); @@ -151,20 +145,23 @@ async fn main(_spawner: Spawner) { esp_rtos::start( timg0.timer0, /*, software_interrupt.software_interrupt0 */ ); - // Enable the TRNG source, so `Trng` can be constructed. - let _trng_source = TrngSource::new(peripherals.RNG, peripherals.ADC1); - let mut rng = esp_hal::rng::Trng::try_new().unwrap(); - static RADIO: StaticCell> = StaticCell::new(); - let radio = RADIO.init(esp_radio::init().unwrap()); - let bluetooth = peripherals.BT; - let connector = BleConnector::new(radio, bluetooth, Default::default()).unwrap(); - let controller: ExternalController<_, 20> = ExternalController::new(connector); - let central_addr = [0x18, 0xe2, 0x21, 0x80, 0xc0, 0xc7]; + #[cfg(feature = "ble")] let mut host_resources = rmk::HostResources::new(); #[cfg(feature = "ble")] - let stack = - rmk::ble::build_ble_stack(controller, central_addr, &mut rng, &mut host_resources).await; + let stack = { + // Enable the TRNG source, so `Trng` can be constructed. + let _trng_source = TrngSource::new(peripherals.RNG, peripherals.ADC1); + let mut rng = esp_hal::rng::Trng::try_new().unwrap(); + static RADIO: StaticCell> = StaticCell::new(); + let radio = RADIO.init(esp_radio::init().unwrap()); + let bluetooth = peripherals.BT; + let connector = BleConnector::new(radio, bluetooth, Default::default()).unwrap(); + let controller: ExternalController<_, 20> = ExternalController::new(connector); + let central_addr = [0x18, 0xe2, 0x21, 0x80, 0xc0, 0xc7]; + + rmk::ble::build_ble_stack(controller, central_addr, &mut rng, &mut host_resources).await + }; // Initialize USB #[cfg(not(feature = "no-usb"))] diff --git a/firmware2/src/peripherals/st7701s/lcd.rs b/firmware2/src/peripherals/st7701s/lcd.rs index 2a4c4a2..ab9553c 100644 --- a/firmware2/src/peripherals/st7701s/lcd.rs +++ b/firmware2/src/peripherals/st7701s/lcd.rs @@ -70,6 +70,7 @@ pub async fn spi_write( cs.set_high(); } +#[expect(unused)] pub async fn spi_read( command: u8, dummy_cycle: bool,