Skip to content

Commit

Permalink
refactor: format code
Browse files Browse the repository at this point in the history
Signed-off-by: Haobo Gu <[email protected]>
  • Loading branch information
HaoboGu committed Jan 3, 2025
1 parent 017ab7d commit f667479
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 44 deletions.
6 changes: 2 additions & 4 deletions rmk/src/ble/esp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) async fn initialize_esp_ble_keyboard_with_config_and_run<
>(
mut matrix: M,
default_keymap: &mut [[[KeyAction; COL]; ROW]; NUM_LAYER],

keyboard_config: RmkConfig<'static, Out>,
) -> ! {
let f = Partition::new(PartitionType::Custom, Some(c"rmk"));
Expand All @@ -60,9 +60,7 @@ pub(crate) async fn initialize_esp_ble_keyboard_with_config_and_run<
)
.await;

let keymap = RefCell::new(
KeyMap::new_from_storage(default_keymap, Some(&mut storage)).await,
);
let keymap = RefCell::new(KeyMap::new_from_storage(default_keymap, Some(&mut storage)).await);

let keyboard_report_sender = KEYBOARD_REPORT_CHANNEL.sender();
let keyboard_report_receiver = KEYBOARD_REPORT_CHANNEL.receiver();
Expand Down
6 changes: 2 additions & 4 deletions rmk/src/ble/nrf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pub(crate) async fn initialize_nrf_ble_keyboard_and_run<
mut matrix: M,
#[cfg(not(feature = "_no_usb"))] usb_driver: D,
default_keymap: &mut [[[KeyAction; COL]; ROW]; NUM_LAYER],

mut keyboard_config: RmkConfig<'static, Out>,
ble_addr: Option<[u8; 6]>,
spawner: Spawner,
Expand All @@ -251,9 +251,7 @@ pub(crate) async fn initialize_nrf_ble_keyboard_and_run<
// Flash and keymap configuration
let flash = Flash::take(sd);
let mut storage = Storage::new(flash, default_keymap, keyboard_config.storage_config).await;
let keymap = RefCell::new(
KeyMap::new_from_storage(default_keymap, Some(&mut storage)).await,
);
let keymap = RefCell::new(KeyMap::new_from_storage(default_keymap, Some(&mut storage)).await);

let mut buf: [u8; 128] = [0; 128];

Expand Down
10 changes: 2 additions & 8 deletions rmk/src/direct_pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ pub async fn run_rmk_direct_pin<
run_rmk_direct_pin_with_async_flash::<_, _, ROW, COL, SIZE, NUM_LAYER>(
direct_pins,
default_keymap,

keyboard_config,
low_active,
#[cfg(not(feature = "_esp_ble"))]
Expand All @@ -94,7 +93,6 @@ pub async fn run_rmk_direct_pin<
direct_pins,
usb_driver,
default_keymap,

keyboard_config,
low_active,
#[cfg(not(feature = "_esp_ble"))]
Expand All @@ -109,7 +107,6 @@ pub async fn run_rmk_direct_pin<
direct_pins,
async_flash,
default_keymap,

keyboard_config,
low_active,
#[cfg(not(feature = "_esp_ble"))]
Expand All @@ -125,7 +122,6 @@ pub async fn run_rmk_direct_pin<
usb_driver,
async_flash,
default_keymap,

keyboard_config,
low_active,
#[cfg(not(feature = "_esp_ble"))]
Expand Down Expand Up @@ -163,7 +159,7 @@ pub async fn run_rmk_direct_pin_with_async_flash<
#[cfg(not(feature = "_no_usb"))] usb_driver: D,
#[cfg(not(feature = "_no_external_storage"))] flash: F,
default_keymap: &mut [[[KeyAction; COL]; ROW]; NUM_LAYER],

keyboard_config: RmkConfig<'static, Out>,
low_active: bool,
#[cfg(not(feature = "_esp_ble"))] spawner: Spawner,
Expand All @@ -184,15 +180,14 @@ pub async fn run_rmk_direct_pin_with_async_flash<
#[cfg(not(feature = "_no_usb"))]
usb_driver,
default_keymap,

keyboard_config,
None,
spawner,
)
.await;

#[cfg(feature = "_esp_ble")]
initialize_esp_ble_keyboard_with_config_and_run(matrix, default_keymap, keyboard_config).await;
initialize_esp_ble_keyboard_with_config_and_run(matrix, default_keymap, keyboard_config).await;

#[cfg(all(
not(feature = "_no_usb"),
Expand All @@ -204,7 +199,6 @@ pub async fn run_rmk_direct_pin_with_async_flash<
#[cfg(not(feature = "_no_external_storage"))]
flash,
default_keymap,

keyboard_config,
)
.await;
Expand Down
4 changes: 1 addition & 3 deletions rmk/src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ pub(crate) struct KeyMap<'a, const ROW: usize, const COL: usize, const NUM_LAYER
impl<'a, const ROW: usize, const COL: usize, const NUM_LAYER: usize>
KeyMap<'a, ROW, COL, NUM_LAYER>
{
pub(crate) async fn new(
action_map: &'a mut [[[KeyAction; COL]; ROW]; NUM_LAYER],
) -> Self {
pub(crate) async fn new(action_map: &'a mut [[[KeyAction; COL]; ROW]; NUM_LAYER]) -> Self {
KeyMap {
layers: action_map,
layer_state: [false; NUM_LAYER],
Expand Down
17 changes: 6 additions & 11 deletions rmk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub async fn run_rmk<
#[cfg(not(feature = "_no_usb"))] usb_driver: D,
#[cfg(not(feature = "_no_external_storage"))] flash: F,
default_keymap: &mut [[[KeyAction; COL]; ROW]; NUM_LAYER],

keyboard_config: RmkConfig<'static, Out>,
#[cfg(not(feature = "_esp_ble"))] spawner: Spawner,
) -> ! {
Expand All @@ -133,7 +133,6 @@ pub async fn run_rmk<
#[cfg(not(feature = "_no_external_storage"))]
async_flash,
default_keymap,

keyboard_config,
#[cfg(not(feature = "_esp_ble"))]
spawner,
Expand Down Expand Up @@ -171,7 +170,7 @@ pub async fn run_rmk_with_async_flash<
#[cfg(not(feature = "_no_usb"))] usb_driver: D,
#[cfg(not(feature = "_no_external_storage"))] flash: F,
default_keymap: &mut [[[KeyAction; COL]; ROW]; NUM_LAYER],

keyboard_config: RmkConfig<'static, Out>,
#[cfg(not(feature = "_esp_ble"))] spawner: Spawner,
) -> ! {
Expand All @@ -198,15 +197,14 @@ pub async fn run_rmk_with_async_flash<
#[cfg(not(feature = "_no_usb"))]
usb_driver,
default_keymap,

keyboard_config,
None,
spawner,
)
.await;

#[cfg(feature = "_esp_ble")]
initialize_esp_ble_keyboard_with_config_and_run(matrix, default_keymap, keyboard_config).await;
initialize_esp_ble_keyboard_with_config_and_run(matrix, default_keymap, keyboard_config).await;

#[cfg(all(
not(feature = "_no_usb"),
Expand All @@ -218,7 +216,6 @@ pub async fn run_rmk_with_async_flash<
#[cfg(not(feature = "_no_external_storage"))]
flash,
default_keymap,

keyboard_config,
)
.await;
Expand All @@ -241,21 +238,19 @@ pub(crate) async fn initialize_usb_keyboard_and_run<
usb_driver: D,
#[cfg(any(feature = "_nrf_ble", not(feature = "_no_external_storage")))] flash: F,
default_keymap: &mut [[[KeyAction; COL]; ROW]; NUM_LAYER],

keyboard_config: RmkConfig<'static, Out>,
) -> ! {
// Initialize storage and keymap
// For USB keyboard, the "external" storage means the storage initialized by the user.
#[cfg(any(feature = "_nrf_ble", not(feature = "_no_external_storage")))]
let (mut storage, keymap) = {
let mut s = Storage::new(flash, default_keymap, keyboard_config.storage_config).await;
let keymap =
RefCell::new(KeyMap::new_from_storage(default_keymap, Some(&mut s)).await);
let keymap = RefCell::new(KeyMap::new_from_storage(default_keymap, Some(&mut s)).await);
(s, keymap)
};
#[cfg(all(not(feature = "_nrf_ble"), feature = "_no_external_storage"))]
let keymap =
RefCell::new(KeyMap::<ROW, COL, NUM_LAYER>::new(default_keymap).await);
let keymap = RefCell::new(KeyMap::<ROW, COL, NUM_LAYER>::new(default_keymap).await);

let keyboard_report_sender = KEYBOARD_REPORT_CHANNEL.sender();
let keyboard_report_receiver = KEYBOARD_REPORT_CHANNEL.receiver();
Expand Down
11 changes: 3 additions & 8 deletions rmk/src/split/central.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub async fn run_rmk_split_central<
#[cfg(not(feature = "_no_usb"))] usb_driver: D,
#[cfg(not(feature = "_no_external_storage"))] flash: F,
default_keymap: &mut [[[KeyAction; TOTAL_COL]; TOTAL_ROW]; NUM_LAYER],

keyboard_config: RmkConfig<'static, Out>,
#[cfg(feature = "_nrf_ble")] central_addr: [u8; 6],
#[cfg(not(feature = "_esp_ble"))] spawner: Spawner,
Expand Down Expand Up @@ -108,7 +108,6 @@ pub async fn run_rmk_split_central<
matrix,
usb_driver,
default_keymap,

keyboard_config,
Some(central_addr),
spawner,
Expand All @@ -121,7 +120,6 @@ pub async fn run_rmk_split_central<
usb_driver,
flash,
default_keymap,

keyboard_config,
)
.await;
Expand Down Expand Up @@ -162,7 +160,7 @@ pub async fn run_rmk_split_central_direct_pin<
#[cfg(not(feature = "_no_usb"))] usb_driver: D,
#[cfg(not(feature = "_no_external_storage"))] flash: F,
default_keymap: &mut [[[KeyAction; TOTAL_COL]; TOTAL_ROW]; NUM_LAYER],

keyboard_config: RmkConfig<'static, Out>,
low_active: bool,
#[cfg(feature = "_nrf_ble")] central_addr: [u8; 6],
Expand Down Expand Up @@ -191,7 +189,6 @@ pub async fn run_rmk_split_central_direct_pin<
matrix,
usb_driver,
default_keymap,

keyboard_config,
Some(central_addr),
spawner,
Expand All @@ -204,7 +201,6 @@ pub async fn run_rmk_split_central_direct_pin<
usb_driver,
flash,
default_keymap,

keyboard_config,
)
.await;
Expand Down Expand Up @@ -256,7 +252,7 @@ pub(crate) async fn initialize_usb_split_central_and_run<
#[cfg(not(feature = "_no_usb"))] usb_driver: D,
#[cfg(any(feature = "_nrf_ble", not(feature = "_no_external_storage")))] flash: F,
default_keymap: &mut [[[KeyAction; TOTAL_COL]; TOTAL_ROW]; NUM_LAYER],

keyboard_config: RmkConfig<'static, Out>,
) -> ! {
// Initialize storage and keymap
Expand All @@ -267,7 +263,6 @@ pub(crate) async fn initialize_usb_split_central_and_run<
let keymap = RefCell::new(
KeyMap::<TOTAL_ROW, TOTAL_COL, NUM_LAYER>::new_from_storage(
default_keymap,

Some(&mut s),
)
.await,
Expand Down
15 changes: 9 additions & 6 deletions rmk/src/via/vial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use byteorder::{ByteOrder, LittleEndian};
use defmt::{debug, info};
use num_enum::FromPrimitive;

use crate::{
keymap::KeyMap,
usb::descriptor::ViaReport,
};
use crate::{keymap::KeyMap, usb::descriptor::ViaReport};

#[derive(Debug, Copy, Clone, defmt::Format, PartialEq, Eq, PartialOrd, Ord, FromPrimitive)]
#[repr(u8)]
Expand Down Expand Up @@ -94,7 +91,10 @@ pub(crate) fn process_vial<'a, const ROW: usize, const COL: usize, const NUM_LAY
VialCommand::GetEncoder => {
let layer = report.output_data[2];
let index = report.output_data[3];
debug!("Received Vial - GetEncoder, encoder idx: {} at layer: {}", index, layer);
debug!(
"Received Vial - GetEncoder, encoder idx: {} at layer: {}",
index, layer
);
// Get encoder value
// if let Some(encoders) = &keymap.borrow().encoders {
// if let Some(encoder_layer) = encoders.get(layer as usize) {
Expand All @@ -115,7 +115,10 @@ pub(crate) fn process_vial<'a, const ROW: usize, const COL: usize, const NUM_LAY
let layer = report.output_data[2];
let index = report.output_data[3];
let clockwise = report.output_data[4];
debug!("Received Vial - SetEncoder, encoder idx: {} clockwise: {} at layer: {}", index, clockwise, layer);
debug!(
"Received Vial - SetEncoder, encoder idx: {} clockwise: {} at layer: {}",
index, clockwise, layer
);
// if let Some(&mut mut encoders) = keymap.borrow_mut().encoders {
// if let Some(&mut mut encoder_layer) = encoders.get_mut(layer as usize) {
// if let Some(&mut mut encoder) = encoder_layer.get_mut(index as usize) {
Expand Down

0 comments on commit f667479

Please sign in to comment.