From cf0a84c59761260ca47c503a78d876a2515eb5c8 Mon Sep 17 00:00:00 2001 From: Univa <41708691+Univa@users.noreply.github.com> Date: Tue, 12 Mar 2024 22:25:51 -0400 Subject: [PATCH] export raw mutex type from mcu module --- rumcake/src/backlight/mod.rs | 11 +++++------ rumcake/src/bluetooth/mod.rs | 9 ++++----- rumcake/src/display/mod.rs | 6 +++--- rumcake/src/drivers/nrf_ble.rs | 25 +++++++++---------------- rumcake/src/hw/mcu/nrf.rs | 4 +++- rumcake/src/hw/mcu/stm32.rs | 3 +++ rumcake/src/hw/mod.rs | 10 +++++----- rumcake/src/keyboard.rs | 25 ++++++++++--------------- rumcake/src/lib.rs | 15 ++++++++------- rumcake/src/split/central.rs | 5 ++--- rumcake/src/storage.rs | 8 ++++---- rumcake/src/underglow/mod.rs | 12 +++++------- rumcake/src/usb.rs | 9 ++++----- rumcake/src/via/handlers.rs | 4 ++-- rumcake/src/via/mod.rs | 19 +++++++++---------- rumcake/src/via/protocol_12/mod.rs | 8 ++++---- rumcake/src/vial/mod.rs | 16 +++++++--------- rumcake/src/vial/protocol/via.rs | 7 +++---- 18 files changed, 90 insertions(+), 106 deletions(-) diff --git a/rumcake/src/backlight/mod.rs b/rumcake/src/backlight/mod.rs index de5112d..ee5b28b 100644 --- a/rumcake/src/backlight/mod.rs +++ b/rumcake/src/backlight/mod.rs @@ -278,12 +278,12 @@ macro_rules! backlight_module { use crate::keyboard::MATRIX_EVENTS; use crate::{LEDEffect, State}; use embassy_futures::select; - use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::channel::Channel; use embassy_time::{Duration, Ticker}; pub mod animations; + use crate::hw::mcu::RawMutex; use animations::{BacklightAnimator, BacklightCommand, BacklightConfig}; /// Channel for sending backlight commands. @@ -291,7 +291,7 @@ macro_rules! backlight_module { /// Channel messages should be consumed by the [`backlight_task`], so user-level /// level code should **not** attempt to receive messages from the channel, otherwise /// commands may not be processed appropriately. You should only send to this channel. - pub static BACKLIGHT_COMMAND_CHANNEL: Channel = + pub static BACKLIGHT_COMMAND_CHANNEL: Channel = Channel::new(); /// State that contains the current configuration for the backlight animator. @@ -312,20 +312,19 @@ macro_rules! storage_module { use defmt::{info, warn, Debug2Format}; use embassy_futures::select; use embassy_futures::select::Either; - use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::signal::Signal; use embassy_time::Duration; use embassy_time::Timer; + use crate::hw::mcu::RawMutex; use crate::storage::{FlashStorage, StorageDevice}; use super::BacklightConfig; use super::BACKLIGHT_CONFIG_STATE; - pub(super) static BACKLIGHT_CONFIG_STATE_LISTENER: Signal = - Signal::new(); + pub(super) static BACKLIGHT_CONFIG_STATE_LISTENER: Signal = Signal::new(); - pub(super) static BACKLIGHT_SAVE_SIGNAL: Signal = Signal::new(); + pub(super) static BACKLIGHT_SAVE_SIGNAL: Signal = Signal::new(); }; } diff --git a/rumcake/src/bluetooth/mod.rs b/rumcake/src/bluetooth/mod.rs index dd39f98..e9c3109 100644 --- a/rumcake/src/bluetooth/mod.rs +++ b/rumcake/src/bluetooth/mod.rs @@ -6,10 +6,10 @@ #[cfg(any(all(feature = "nrf", feature = "bluetooth"), doc))] pub mod nrf_ble; -use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::channel::Channel; use embassy_sync::signal::Signal; +use crate::hw::mcu::RawMutex; use crate::keyboard::{Keyboard, KeyboardLayout}; use crate::State; @@ -54,11 +54,10 @@ pub enum BluetoothCommand { /// nRF5x-based keyboards), so user-level code should **not** attempt to receive messages from the /// channel, otherwise commands may not be processed appropriately. You should only send to this /// channel. -pub static BLUETOOTH_COMMAND_CHANNEL: Channel = - Channel::new(); +pub static BLUETOOTH_COMMAND_CHANNEL: Channel = Channel::new(); pub(crate) static BLUETOOTH_CONNECTED_STATE: State = State::new(false, &[&crate::hw::BLUETOOTH_CONNECTED_STATE_LISTENER]); -pub(crate) static CURRENT_OUTPUT_STATE_LISTENER: Signal = Signal::new(); -pub(crate) static BATTERY_LEVEL_LISTENER: Signal = Signal::new(); +pub(crate) static CURRENT_OUTPUT_STATE_LISTENER: Signal = Signal::new(); +pub(crate) static BATTERY_LEVEL_LISTENER: Signal = Signal::new(); diff --git a/rumcake/src/display/mod.rs b/rumcake/src/display/mod.rs index 0d204cf..f8b9f1a 100644 --- a/rumcake/src/display/mod.rs +++ b/rumcake/src/display/mod.rs @@ -5,16 +5,16 @@ //! [`drivers::DisplayDriver`]). use embassy_futures::select::{select, select_array, Either}; -use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::signal::Signal; use embassy_time::{Duration, Ticker, Timer}; pub mod drivers; use self::drivers::DisplayDriver; +use crate::hw::mcu::RawMutex; -pub(crate) static OUTPUT_MODE_STATE_LISTENER: Signal = Signal::new(); -pub(crate) static BATTERY_LEVEL_LISTENER: Signal = Signal::new(); +pub(crate) static OUTPUT_MODE_STATE_LISTENER: Signal = Signal::new(); +pub(crate) static BATTERY_LEVEL_LISTENER: Signal = Signal::new(); /// A trait that keyboards must implement to use a display. pub trait DisplayDevice { diff --git a/rumcake/src/drivers/nrf_ble.rs b/rumcake/src/drivers/nrf_ble.rs index 059ca89..39a79c2 100644 --- a/rumcake/src/drivers/nrf_ble.rs +++ b/rumcake/src/drivers/nrf_ble.rs @@ -15,7 +15,6 @@ pub mod central { use defmt::{assert, debug, error, info, warn, Debug2Format}; use embassy_futures::select::{select, select_slice, Either}; - use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::channel::Channel; use embassy_sync::mutex::Mutex; use embassy_sync::pubsub::{PubSubChannel, Publisher}; @@ -25,6 +24,7 @@ pub mod central { use nrf_softdevice::ble::{central, Address, AddressType}; use nrf_softdevice::{RawError, Softdevice}; + use crate::hw::mcu::RawMutex; use crate::split::drivers::{CentralDeviceDriver, CentralDeviceError}; use crate::split::{ MessageToCentral, MessageToPeripheral, MESSAGE_TO_CENTRAL_BUFFER_SIZE, @@ -32,21 +32,16 @@ pub mod central { }; pub struct NRFBLECentralDriver<'a> { - publisher: Publisher<'a, ThreadModeRawMutex, MessageToPeripheral, 4, 4, 1>, + publisher: Publisher<'a, RawMutex, MessageToPeripheral, 4, 4, 1>, } - pub static BLE_MESSAGES_FROM_PERIPHERALS: Channel = + pub static BLE_MESSAGES_FROM_PERIPHERALS: Channel = Channel::new(); - pub static BLE_MESSAGES_TO_PERIPHERALS: PubSubChannel< - ThreadModeRawMutex, - MessageToPeripheral, - 4, - 4, - 1, - > = PubSubChannel::new(); + pub static BLE_MESSAGES_TO_PERIPHERALS: PubSubChannel = + PubSubChannel::new(); - pub static BLUETOOTH_CONNECTION_MUTEX: Mutex = Mutex::new(()); + pub static BLUETOOTH_CONNECTION_MUTEX: Mutex = Mutex::new(()); /// Create an instance of the nRF bluetooth central device driver. pub fn setup_driver() -> NRFBLECentralDriver<'static> { @@ -229,14 +224,13 @@ pub mod central { pub mod peripheral { use defmt::{debug, error, info, warn, Debug2Format}; use embassy_futures::select::{select, Either}; - use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::channel::Channel; use nrf_softdevice::ble::gatt_server::{run, set_sys_attrs}; use nrf_softdevice::ble::peripheral::{advertise_connectable, ConnectableAdvertisement}; use nrf_softdevice::ble::{Address, AddressType}; use nrf_softdevice::Softdevice; - use crate::hw::mcu::BLUETOOTH_ADVERTISING_MUTEX; + use crate::hw::mcu::{RawMutex, BLUETOOTH_ADVERTISING_MUTEX}; use crate::split::drivers::{PeripheralDeviceDriver, PeripheralDeviceError}; use crate::split::{ MessageToCentral, MessageToPeripheral, MESSAGE_TO_CENTRAL_BUFFER_SIZE, @@ -245,10 +239,9 @@ pub mod peripheral { pub struct NRFBLEPeripheralDriver {} - pub static BLE_MESSAGES_TO_CENTRAL: Channel = - Channel::new(); + pub static BLE_MESSAGES_TO_CENTRAL: Channel = Channel::new(); - pub static BLE_MESSAGES_FROM_CENTRAL: Channel = + pub static BLE_MESSAGES_FROM_CENTRAL: Channel = Channel::new(); /// Create an instance of the nRF bluetooth central device driver. diff --git a/rumcake/src/hw/mcu/nrf.rs b/rumcake/src/hw/mcu/nrf.rs index d36b311..cc4661d 100644 --- a/rumcake/src/hw/mcu/nrf.rs +++ b/rumcake/src/hw/mcu/nrf.rs @@ -29,6 +29,8 @@ pub use nrf_softdevice; #[cfg(feature = "nrf52840")] pub const SYSCLK: u32 = 48_000_000; +pub type RawMutex = ThreadModeRawMutex; + pub fn jump_to_bootloader() { // TODO } @@ -196,7 +198,7 @@ pub async fn adc_task() { /// A mutex that is locked when the softdevice is advertising. This is mainly to prevent /// [`nrf_softdevice::ble::peripheral::ADV_PORTAL`] from being opened by more than one task at the /// same time. -pub static BLUETOOTH_ADVERTISING_MUTEX: Mutex = Mutex::new(()); +pub static BLUETOOTH_ADVERTISING_MUTEX: Mutex = Mutex::new(()); #[cfg(feature = "nrf-ble")] /// A basic trait that all nRF5x-based devices that use bluetooth features must implement. diff --git a/rumcake/src/hw/mcu/stm32.rs b/rumcake/src/hw/mcu/stm32.rs index 89c0f5a..c7ce833 100644 --- a/rumcake/src/hw/mcu/stm32.rs +++ b/rumcake/src/hw/mcu/stm32.rs @@ -9,6 +9,7 @@ use embassy_stm32::flash::{Blocking, Flash as HALFlash}; use embassy_stm32::peripherals::{FLASH, PA11, PA12, USB}; use embassy_stm32::rcc::{APBPrescaler, Hse, Pll, PllMul, PllPreDiv, PllSource, Sysclk, HSI_FREQ}; use embassy_stm32::usb::Driver; +use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use static_cell::StaticCell; pub use rumcake_macros::{input_pin, output_pin, setup_buffered_uart, setup_i2c}; @@ -21,6 +22,8 @@ pub const SYSCLK: u32 = 48_000_000; #[cfg(feature = "stm32f303cb")] pub const SYSCLK: u32 = 72_000_000; +pub type RawMutex = ThreadModeRawMutex; + /// A function that allows you to jump to the bootloader, usually for re-flashing the firmware. pub fn jump_to_bootloader() { #[cfg(feature = "stm32f072cb")] diff --git a/rumcake/src/hw/mod.rs b/rumcake/src/hw/mod.rs index 058ecdd..db614ae 100644 --- a/rumcake/src/hw/mod.rs +++ b/rumcake/src/hw/mod.rs @@ -12,9 +12,10 @@ pub mod mcu; use crate::State; use embassy_futures::select; -use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::signal::Signal; +use mcu::RawMutex; + /// State that contains the current battery level. `rumcake` may or may not use this /// static internally, depending on what MCU is being used. The contents of this state /// is usually set by a task in the [`mcu`] module. For example, on nRF5x-based MCUs, @@ -75,10 +76,9 @@ pub static CURRENT_OUTPUT_STATE: State> = State::new( ], ); -pub(crate) static OUTPUT_MODE_STATE_LISTENER: Signal = Signal::new(); -pub(crate) static USB_RUNNING_STATE_LISTENER: Signal = Signal::new(); -pub(crate) static BLUETOOTH_CONNECTED_STATE_LISTENER: Signal = - Signal::new(); +pub(crate) static OUTPUT_MODE_STATE_LISTENER: Signal = Signal::new(); +pub(crate) static USB_RUNNING_STATE_LISTENER: Signal = Signal::new(); +pub(crate) static BLUETOOTH_CONNECTED_STATE_LISTENER: Signal = Signal::new(); #[rumcake_macros::task] pub async fn output_switcher() { diff --git a/rumcake/src/keyboard.rs b/rumcake/src/keyboard.rs index 1396efc..cc3a4b9 100644 --- a/rumcake/src/keyboard.rs +++ b/rumcake/src/keyboard.rs @@ -5,9 +5,9 @@ use core::convert::Infallible; use defmt::{debug, info, warn, Debug2Format}; +use embassy_sync::channel::Channel; use embassy_sync::mutex::{Mutex, MutexGuard}; use embassy_sync::pubsub::{PubSubBehavior, PubSubChannel}; -use embassy_sync::{blocking_mutex::raw::ThreadModeRawMutex, channel::Channel}; use embassy_time::{Duration, Ticker, Timer}; use embedded_hal::digital::v2::{InputPin, OutputPin}; use heapless::Vec; @@ -22,6 +22,7 @@ use usbd_human_interface_device::{ #[cfg(feature = "media-keycodes")] pub use usbd_human_interface_device::page::Consumer; +use crate::hw::mcu::RawMutex; use crate::hw::CURRENT_OUTPUT_STATE; pub use rumcake_macros::{build_layout, build_matrix, remap_matrix}; @@ -87,7 +88,7 @@ pub trait KeyboardLayout { /// A mutex-guaraded [`keyberon::layout::Layout`]. This also stores the original layout, so that it /// can be reset to it's initial state if modifications are made to it. pub struct Layout { - layout: once_cell::sync::OnceCell>>, + layout: once_cell::sync::OnceCell>>, } impl Layout { @@ -102,7 +103,7 @@ impl Layout { .get_or_init(|| Mutex::new(KeyberonLayout::new(layers))); } - pub async fn lock(&self) -> MutexGuard> { + pub async fn lock(&self) -> MutexGuard> { self.layout.get().unwrap().lock().await } } @@ -206,7 +207,7 @@ pub enum Keycode { /// /// The coordinates received will be remapped according to the implementation of /// [`KeyboardMatrix::remap_to_layout`]. -pub(crate) static POLLED_EVENTS_CHANNEL: Channel = Channel::new(); +pub(crate) static POLLED_EVENTS_CHANNEL: Channel = Channel::new(); #[rumcake_macros::task] pub async fn matrix_poll( @@ -258,29 +259,23 @@ pub async fn matrix_poll( /// There can be a maximum of 4 subscribers, and the number of subscribers actually used /// depend on what features you have enabled. With underglow and backlight enabled, 2 subscriber /// slots will be used. -pub static MATRIX_EVENTS: PubSubChannel = PubSubChannel::new(); +pub static MATRIX_EVENTS: PubSubChannel = PubSubChannel::new(); /// Channel for sending NKRO HID keyboard reports. /// /// Channel messages should be consumed by the bluetooth task or USB task, so user-level code /// should **not** attempt to receive messages from the channel, otherwise commands may not be /// processed appropriately. You should only send to this channel. -pub static KEYBOARD_REPORT_HID_SEND_CHANNEL: Channel< - ThreadModeRawMutex, - NKROBootKeyboardReport, - 1, -> = Channel::new(); +pub static KEYBOARD_REPORT_HID_SEND_CHANNEL: Channel = + Channel::new(); /// Channel for sending consumer HID reports. /// /// Channel messages should be consumed by the bluetooth task or USB task, so user-level code /// should **not** attempt to receive messages from the channel, otherwise commands may not be /// processed appropriately. You should only send to this channel. -pub static CONSUMER_REPORT_HID_SEND_CHANNEL: Channel< - ThreadModeRawMutex, - MultipleConsumerReport, - 1, -> = Channel::new(); +pub static CONSUMER_REPORT_HID_SEND_CHANNEL: Channel = + Channel::new(); #[rumcake_macros::task] pub async fn layout_collect(_k: K) diff --git a/rumcake/src/lib.rs b/rumcake/src/lib.rs index e7f1295..19a0655 100644 --- a/rumcake/src/lib.rs +++ b/rumcake/src/lib.rs @@ -5,10 +5,11 @@ #![warn(missing_docs)] #![doc = include_str!("../../README.md")] -use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::mutex::{Mutex, MutexGuard}; use embassy_sync::signal::Signal; +use crate::hw::mcu::RawMutex; + pub(crate) trait StaticArray { const LEN: usize; } @@ -30,13 +31,13 @@ trait Cycle { /// Data structure that allows you to notify listeners about any changes to the data being managed. /// This can be useful when you want a task to react to changes to certain data. pub struct State<'a, T: Clone + PartialEq> { - data: Mutex, - listeners: &'a [&'a Signal], + data: Mutex, + listeners: &'a [&'a Signal], } impl<'a, T: Clone + PartialEq> State<'a, T> { /// Create some new state, with the specified listeners. - pub const fn new(data: T, listeners: &'a [&'a Signal]) -> State<'a, T> { + pub const fn new(data: T, listeners: &'a [&'a Signal]) -> State<'a, T> { Self { data: Mutex::new(data), listeners, @@ -69,7 +70,7 @@ impl<'a, T: Clone + PartialEq> State<'a, T> { async fn update_inner( &self, - updater: impl FnOnce(&mut MutexGuard<'_, ThreadModeRawMutex, T>) -> R, + updater: impl FnOnce(&mut MutexGuard<'_, RawMutex, T>) -> R, ) -> (bool, R) { let mut data = self.data.lock().await; let old = data.clone(); @@ -80,7 +81,7 @@ impl<'a, T: Clone + PartialEq> State<'a, T> { /// Update state using a function, and notify listeners pub async fn update( &self, - updater: impl FnOnce(&mut MutexGuard<'_, ThreadModeRawMutex, T>) -> R, + updater: impl FnOnce(&mut MutexGuard<'_, RawMutex, T>) -> R, ) -> R { let (changed, update_result) = self.update_inner(updater).await; @@ -94,7 +95,7 @@ impl<'a, T: Clone + PartialEq> State<'a, T> { /// Update state using a function without notifying listeners pub async fn quiet_update( &self, - updater: impl FnOnce(&mut MutexGuard<'_, ThreadModeRawMutex, T>) -> R, + updater: impl FnOnce(&mut MutexGuard<'_, RawMutex, T>) -> R, ) -> R { let (_changed, update_result) = self.update_inner(updater).await; update_result diff --git a/rumcake/src/split/central.rs b/rumcake/src/split/central.rs index de5c200..ff80fa8 100644 --- a/rumcake/src/split/central.rs +++ b/rumcake/src/split/central.rs @@ -9,9 +9,9 @@ use defmt::{error, Debug2Format}; use embassy_futures::select::{select, Either}; -use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::channel::Channel; +use crate::hw::mcu::RawMutex; use crate::keyboard::POLLED_EVENTS_CHANNEL; use crate::split::MessageToCentral; @@ -23,8 +23,7 @@ use super::MessageToPeripheral; /// Channel messages should be consumed by the central task, so user-level code should /// **not** attempt to receive messages from the channel, otherwise commands may not be processed /// appropriately. You should only send to this channel. -pub static MESSAGE_TO_PERIPHERALS: Channel = - Channel::new(); +pub static MESSAGE_TO_PERIPHERALS: Channel = Channel::new(); #[rumcake_macros::task] pub async fn central_task(mut driver: impl CentralDeviceDriver) { diff --git a/rumcake/src/storage.rs b/rumcake/src/storage.rs index f5e5473..fe608a5 100644 --- a/rumcake/src/storage.rs +++ b/rumcake/src/storage.rs @@ -14,7 +14,6 @@ use core::hash::{Hash, Hasher, SipHasher}; use defmt::{assert, debug}; use defmt::{error, info, warn, Debug2Format}; -use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::mutex::{Mutex, MutexGuard}; use embedded_storage::nor_flash::ReadNorFlash; use embedded_storage_async::nor_flash::{ @@ -27,6 +26,8 @@ use serde::Serialize; use tickv::success_codes::SuccessCode; use tickv::{AsyncTicKV, ErrorCode, FlashController, MAIN_KEY}; +use crate::hw::mcu::RawMutex; + fn get_hashed_key(key: &[u8]) -> u64 { let mut hasher = SipHasher::new(); key.hash(&mut hasher); @@ -75,8 +76,7 @@ pub struct StorageService<'a, F: FlashStorage> where [(); F::ERASE_SIZE]:, { - database: - OnceCell, { F::ERASE_SIZE }>>>, + database: OnceCell, { F::ERASE_SIZE }>>>, } impl<'a, F: FlashStorage> StorageService<'a, F> @@ -93,7 +93,7 @@ where async fn get_database( &self, - ) -> MutexGuard, { F::ERASE_SIZE }>> { + ) -> MutexGuard, { F::ERASE_SIZE }>> { let mutex = self .database .get() diff --git a/rumcake/src/underglow/mod.rs b/rumcake/src/underglow/mod.rs index adc4c49..cea5ce0 100644 --- a/rumcake/src/underglow/mod.rs +++ b/rumcake/src/underglow/mod.rs @@ -4,10 +4,10 @@ //! corresponding to a driver that implements [`drivers::UnderglowDriver`]. use embassy_futures::select::{select, Either}; -use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::channel::Channel; use embassy_time::{Duration, Ticker}; +use crate::hw::mcu::RawMutex; use crate::keyboard::MATRIX_EVENTS; use crate::{LEDEffect, State}; @@ -44,8 +44,7 @@ pub trait UnderglowDevice { /// Channel messages should be consumed by the [`underglow_task`], so user-level /// level code should **not** attempt to receive messages from the channel, otherwise /// commands may not be processed appropriately. You should only send to this channel. -pub static UNDERGLOW_COMMAND_CHANNEL: Channel = - Channel::new(); +pub static UNDERGLOW_COMMAND_CHANNEL: Channel = Channel::new(); /// State that contains the current configuration for the underglow animator. pub static UNDERGLOW_CONFIG_STATE: State = State::new( @@ -169,20 +168,19 @@ pub mod storage { use defmt::{info, warn, Debug2Format}; use embassy_futures::select; use embassy_futures::select::Either; - use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::signal::Signal; use embassy_time::Duration; use embassy_time::Timer; + use crate::hw::mcu::RawMutex; use crate::storage::{FlashStorage, StorageDevice}; use super::UnderglowConfig; use super::UNDERGLOW_CONFIG_STATE; - pub(super) static UNDERGLOW_CONFIG_STATE_LISTENER: Signal = - Signal::new(); + pub(super) static UNDERGLOW_CONFIG_STATE_LISTENER: Signal = Signal::new(); - pub(super) static UNDERGLOW_SAVE_SIGNAL: Signal = Signal::new(); + pub(super) static UNDERGLOW_SAVE_SIGNAL: Signal = Signal::new(); #[rumcake_macros::task] pub async fn underglow_storage_task( diff --git a/rumcake/src/usb.rs b/rumcake/src/usb.rs index 9b85611..ab29f97 100644 --- a/rumcake/src/usb.rs +++ b/rumcake/src/usb.rs @@ -4,7 +4,6 @@ use defmt::{error, info, Debug2Format}; use embassy_futures::select::{self, select}; -use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::signal::Signal; use embassy_usb::class::hid::{ Config, HidReader, HidReaderWriter, HidWriter, ReportId, RequestHandler, State as UsbState, @@ -21,6 +20,7 @@ use usbd_human_interface_device::device::keyboard::{ NKROBootKeyboardReport, NKRO_BOOT_KEYBOARD_REPORT_DESCRIPTOR, }; +use crate::hw::mcu::RawMutex; use crate::hw::{HIDOutput, CURRENT_OUTPUT_STATE}; use crate::keyboard::{ Keyboard, KeyboardLayout, CONSUMER_REPORT_HID_SEND_CHANNEL, KEYBOARD_REPORT_HID_SEND_CHANNEL, @@ -126,7 +126,7 @@ macro_rules! usb_task_inner { }; } -pub(crate) static KB_CURRENT_OUTPUT_STATE_LISTENER: Signal = Signal::new(); +pub(crate) static KB_CURRENT_OUTPUT_STATE_LISTENER: Signal = Signal::new(); #[rumcake_macros::task] pub async fn usb_hid_kb_write_task( @@ -145,8 +145,7 @@ pub async fn usb_hid_kb_write_task( ) } -pub(crate) static CONSUMER_CURRENT_OUTPUT_STATE_LISTENER: Signal = - Signal::new(); +pub(crate) static CONSUMER_CURRENT_OUTPUT_STATE_LISTENER: Signal = Signal::new(); #[rumcake_macros::task] pub async fn usb_hid_consumer_write_task( @@ -224,7 +223,7 @@ pub async fn usb_hid_via_read_task(hid: HidReader<'static, impl Driver<'static>, } #[cfg(feature = "via")] -pub(crate) static VIA_CURRENT_OUTPUT_STATE_LISTENER: Signal = Signal::new(); +pub(crate) static VIA_CURRENT_OUTPUT_STATE_LISTENER: Signal = Signal::new(); #[cfg(feature = "via")] #[rumcake_macros::task] diff --git a/rumcake/src/via/handlers.rs b/rumcake/src/via/handlers.rs index 8e936e9..f5d46b9 100644 --- a/rumcake/src/via/handlers.rs +++ b/rumcake/src/via/handlers.rs @@ -1,9 +1,9 @@ use defmt::warn; -use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::signal::Signal; use keyberon::action::Action; use keyberon::key_code::KeyCode; +use crate::hw::mcu::RawMutex; use crate::keyboard::Keycode; use super::ViaKeyboard; @@ -77,7 +77,7 @@ pub async fn eeprom_reset() { super::storage::reset_data().await; } -pub(super) static BOOTLOADER_JUMP_SIGNAL: Signal = Signal::new(); +pub(super) static BOOTLOADER_JUMP_SIGNAL: Signal = Signal::new(); pub fn bootloader_jump() { BOOTLOADER_JUMP_SIGNAL.signal(()); diff --git a/rumcake/src/via/mod.rs b/rumcake/src/via/mod.rs index 7ec2d9c..de46e4b 100644 --- a/rumcake/src/via/mod.rs +++ b/rumcake/src/via/mod.rs @@ -7,10 +7,11 @@ use crate::keyboard::{Keyboard, KeyboardLayout}; use defmt::assert; use embassy_futures::join; -use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::channel::Channel; use embassy_sync::mutex::Mutex; +use crate::hw::mcu::RawMutex; + pub(crate) mod handlers; pub(crate) mod protocol_12; @@ -152,11 +153,10 @@ pub(crate) const VIA_REPORT_DESCRIPTOR: &[u8] = &[ /// Channel used to receive reports from the Via app to be processed. Reports that are sent to this /// channel will be processed by the Via task, and call the appropriate command handler, depending /// on the report contents. -pub static VIA_REPORT_HID_RECEIVE_CHANNEL: Channel = - Channel::new(); +pub static VIA_REPORT_HID_RECEIVE_CHANNEL: Channel = Channel::new(); /// Channel used to send Via reports back to the Via host. -pub static VIA_REPORT_HID_SEND_CHANNEL: Channel = Channel::new(); +pub static VIA_REPORT_HID_SEND_CHANNEL: Channel = Channel::new(); #[rumcake_macros::task] pub async fn via_process_task(_k: K) @@ -186,8 +186,7 @@ where ); } - let via_state: Mutex> = - Mutex::new(Default::default()); + let via_state: Mutex> = Mutex::new(Default::default()); let report_fut = async { loop { @@ -210,10 +209,10 @@ where #[cfg(feature = "storage")] pub mod storage { use defmt::warn; - use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::channel::Channel; use embassy_sync::signal::Signal; + use crate::hw::mcu::RawMutex; use crate::storage::{FlashStorage, StorageDevice, StorageKey}; use super::ViaKeyboard; @@ -265,10 +264,10 @@ pub mod storage { OPERATION_COMPLETE.wait().await; } - static OPERATION_CHANNEL: Channel = Channel::new(); - static OPERATION_COMPLETE: Signal = Signal::new(); + static OPERATION_CHANNEL: Channel = Channel::new(); + static OPERATION_COMPLETE: Signal = Signal::new(); - pub(super) static VIA_LAYOUT_OPTIONS: Signal = Signal::new(); + pub(super) static VIA_LAYOUT_OPTIONS: Signal = Signal::new(); #[rumcake_macros::task] pub async fn via_storage_task( diff --git a/rumcake/src/via/protocol_12/mod.rs b/rumcake/src/via/protocol_12/mod.rs index 8ae7675..c0d2e6b 100644 --- a/rumcake/src/via/protocol_12/mod.rs +++ b/rumcake/src/via/protocol_12/mod.rs @@ -3,10 +3,11 @@ use crate::keyboard::MATRIX_EVENTS; use crate::via::handlers::*; use defmt::{info, warn, Debug2Format}; use embassy_futures::select; -use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::mutex::Mutex; use num_derive::FromPrimitive; +use crate::hw::mcu::RawMutex; + pub(crate) mod keycodes; pub(crate) const VIA_PROTOCOL_VERSION: u16 = 0x000C; @@ -569,9 +570,8 @@ pub(crate) async fn process_via_command( } } -pub(crate) async fn background_task( - via_state: &Mutex>, -) where +pub(crate) async fn background_task(via_state: &Mutex>) +where [(); (K::LAYOUT_COLS + u8::BITS as usize - 1) / u8::BITS as usize * K::LAYOUT_ROWS]:, { // Update the layout_state. Used for SwitchMatrixState diff --git a/rumcake/src/vial/mod.rs b/rumcake/src/vial/mod.rs index 1077966..e33e2a0 100644 --- a/rumcake/src/vial/mod.rs +++ b/rumcake/src/vial/mod.rs @@ -5,11 +5,11 @@ use crate::backlight::{BacklightMatrixDevice, EmptyBacklightMatrix}; use defmt::assert; use embassy_futures::join; -use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::channel::Channel; use embassy_sync::mutex::Mutex; use smart_leds::RGB8; +use crate::hw::mcu::RawMutex; use crate::via::{ViaKeyboard, VIA_REPORT_HID_RECEIVE_CHANNEL, VIA_REPORT_HID_SEND_CHANNEL}; mod handlers; @@ -60,8 +60,7 @@ pub trait VialKeyboard: ViaKeyboard { /// Channel used to update the frame buffer for the /// [`crate::backlight::rgb_backlight_matrix::animations::BacklightEffect::DirectSet`] effect. -pub(crate) static VIAL_DIRECT_SET_CHANNEL: Channel = - Channel::new(); +pub(crate) static VIAL_DIRECT_SET_CHANNEL: Channel = Channel::new(); #[rumcake_macros::task] pub async fn vial_process_task(_k: K) @@ -94,9 +93,8 @@ where ); } - let vial_state: Mutex = Mutex::new(Default::default()); - let via_state: Mutex> = - Mutex::new(Default::default()); + let vial_state: Mutex = Mutex::new(Default::default()); + let via_state: Mutex> = Mutex::new(Default::default()); if K::VIAL_INSECURE { vial_state.lock().await.unlocked = true; @@ -128,10 +126,10 @@ where #[cfg(feature = "storage")] pub mod storage { - use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::channel::Channel; use embassy_sync::signal::Signal; + use crate::hw::mcu::RawMutex; use crate::storage::{FlashStorage, StorageDevice, StorageKey}; use super::VialKeyboard; @@ -178,8 +176,8 @@ pub mod storage { OPERATION_COMPLETE.wait().await } - static OPERATION_COMPLETE: Signal = Signal::new(); - static OPERATION_CHANNEL: Channel = Channel::new(); + static OPERATION_COMPLETE: Signal = Signal::new(); + static OPERATION_CHANNEL: Channel = Channel::new(); #[rumcake_macros::task] pub async fn vial_storage_task( diff --git a/rumcake/src/vial/protocol/via.rs b/rumcake/src/vial/protocol/via.rs index f9143bb..4b575f6 100644 --- a/rumcake/src/vial/protocol/via.rs +++ b/rumcake/src/vial/protocol/via.rs @@ -7,11 +7,11 @@ use crate::vial::handlers::*; use crate::vial::protocol::{lighting, VIALRGB_PROTOCOL_VERSION}; use crate::vial::VialKeyboard; use defmt::{info, warn, Debug2Format}; -use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; use embassy_sync::mutex::Mutex; use num_derive::FromPrimitive; use super::VialState; +use crate::hw::mcu::RawMutex; use crate::via::protocol::keycodes; // We just use the keycode conversions from the new via protocol pub(crate) const VIA_PROTOCOL_VERSION: u16 = 0x0009; @@ -451,9 +451,8 @@ pub(crate) async fn process_via_command( } } -pub(crate) async fn background_task( - via_state: &Mutex>, -) where +pub(crate) async fn background_task(via_state: &Mutex>) +where [(); (K::LAYOUT_COLS + u8::BITS as usize - 1) / u8::BITS as usize * K::LAYOUT_ROWS]:, { // Update the layout_state. Used for SwitchMatrixState