Skip to content

Commit

Permalink
refactor: reformat code
Browse files Browse the repository at this point in the history
Signed-off-by: Haobo Gu <[email protected]>
  • Loading branch information
HaoboGu committed Dec 5, 2024
1 parent eab0fbb commit fc67b29
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 37 deletions.
2 changes: 1 addition & 1 deletion rmk-macro/src/behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//!
use quote::quote;
use crate::config::{OneShotConfig, TriLayerConfig};

use crate::config::{OneShotConfig, TriLayerConfig};
use crate::keyboard_config::KeyboardConfig;

fn expand_tri_layer(tri_layer: &Option<TriLayerConfig>) -> proc_macro2::TokenStream {
Expand Down
2 changes: 1 addition & 1 deletion rmk-macro/src/bind_interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use proc_macro2::TokenStream as TokenStream2;
use quote::{format_ident, quote};
use crate::config::BleConfig;
use syn::ItemMod;

use crate::config::BleConfig;
use crate::keyboard_config::KeyboardConfig;

// Expand `bind_interrupt!` stuffs
Expand Down
5 changes: 2 additions & 3 deletions rmk-macro/src/flash.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! Initialize flash boilerplate of RMK, including USB or BLE
//!
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use crate::config::StorageConfig;

use crate::{keyboard_config::KeyboardConfig, ChipSeries};
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;

pub(crate) fn expand_flash_init(keyboard_config: &KeyboardConfig) -> TokenStream2 {
if !keyboard_config.storage.enabled {
Expand Down
24 changes: 11 additions & 13 deletions rmk-macro/src/gpio_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,17 @@ pub(crate) fn convert_direct_pins_to_initializers(
for (row_idx, row_pins) in pins.into_iter().enumerate() {
let mut col_idents = vec![];
// Process each pin in the current row
let pin_initializers = row_pins
.into_iter()
.map(|p| {
let ident_name = format_ident!("{}_{}_{}", p.to_lowercase(), row_idx, col_idents.len());
col_idents.push(ident_name.clone());
if p != "_" {
// Convert pin to Some(pin) when it's not "_"
let pin = convert_gpio_str_to_input_pin(chip, p, async_matrix, low_active);
quote! { let #ident_name = Some(#pin); }
} else {
quote! { let #ident_name = None; }
}
});
let pin_initializers = row_pins.into_iter().map(|p| {
let ident_name = format_ident!("{}_{}_{}", p.to_lowercase(), row_idx, col_idents.len());
col_idents.push(ident_name.clone());
if p != "_" {
// Convert pin to Some(pin) when it's not "_"
let pin = convert_gpio_str_to_input_pin(chip, p, async_matrix, low_active);
quote! { let #ident_name = Some(#pin); }
} else {
quote! { let #ident_name = None; }
}
});
// Extend initializers with current row's pin initializations
initializers.extend(pin_initializers);
// Create array for current row
Expand Down
6 changes: 3 additions & 3 deletions rmk-macro/src/keyboard_config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use serde::Deserialize;
use std::fs;

use crate::config::{
BehaviorConfig, BleConfig, DependencyConfig, KeyboardInfo, KeyboardTomlConfig, LayoutConfig,
LightConfig, MatrixConfig, MatrixType, SplitConfig, StorageConfig,
};
use serde::Deserialize;
use std::fs;

use crate::{
default_config::{
esp32::default_esp32, nrf52810::default_nrf52810, nrf52832::default_nrf52832,
Expand Down
4 changes: 2 additions & 2 deletions rmk-macro/src/light.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Initialize light config boilerplate of RMK, including USB or BLE
//!
use quote::quote;
use crate::config::PinConfig;

use crate::{
gpio_config::convert_gpio_str_to_output_pin, keyboard_config::KeyboardConfig, ChipModel,
config::PinConfig, gpio_config::convert_gpio_str_to_output_pin,
keyboard_config::KeyboardConfig, ChipModel,
};

pub(crate) fn build_light_config(
Expand Down
2 changes: 1 addition & 1 deletion rmk-macro/src/split/central.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use core::panic;

use proc_macro2::TokenStream as TokenStream2;
use quote::{format_ident, quote};
use crate::config::{MatrixType, SerialConfig, SplitConfig};
use syn::ItemMod;

use crate::{
Expand All @@ -11,6 +10,7 @@ use crate::{
ble::expand_ble_config,
chip_init::expand_chip_init,
comm::expand_usb_init,
config::{MatrixType, SerialConfig, SplitConfig},
feature::{get_rmk_features, is_feature_enabled},
flash::expand_flash_init,
import::expand_imports,
Expand Down
4 changes: 1 addition & 3 deletions rmk-macro/src/split/peripheral.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::rc::Weak;

use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use crate::config::{MatrixType, SplitBoardConfig};
use syn::ItemMod;

use crate::{
chip_init::expand_chip_init,
config::{MatrixType, SplitBoardConfig},
feature::{get_rmk_features, is_feature_enabled},
import::expand_imports,
keyboard_config::{read_keyboard_toml_config, BoardConfig, KeyboardConfig},
Expand Down
2 changes: 1 addition & 1 deletion rmk/src/ble/esp/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub(crate) mod server;

use self::server::{BleServer, VialReaderWriter};
use crate::config::StorageConfig;
use crate::keyboard::keyboard_report_channel;
use crate::matrix::MatrixTrait;
use crate::storage::nor_flash::esp_partition::{Partition, PartitionType};
Expand All @@ -20,7 +21,6 @@ use embedded_hal::digital::OutputPin;
use embedded_storage_async::nor_flash::ReadNorFlash;
use esp_idf_svc::hal::task::block_on;
use futures::pin_mut;
use crate::config::StorageConfig;

/// Initialize and run the BLE keyboard service, with given keyboard usb config.
/// Can only be used on nrf52 series microcontrollers with `nrf-softdevice` crate.
Expand Down
2 changes: 1 addition & 1 deletion rmk/src/ble/nrf/battery_service.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::config::BleBatteryConfig;
use defmt::{error, info};
use embassy_time::Timer;
use nrf_softdevice::ble::Connection;
use crate::config::BleBatteryConfig;

use super::server::BleServer;

Expand Down
2 changes: 1 addition & 1 deletion rmk/src/ble/nrf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub(crate) mod spec;
mod vial_service;

use self::server::BleServer;
use crate::config::BleBatteryConfig;
use crate::keyboard::{keyboard_report_channel, REPORT_CHANNEL_SIZE};
use crate::matrix::MatrixTrait;
use crate::storage::StorageKeys;
Expand Down Expand Up @@ -46,7 +47,6 @@ use nrf_softdevice::{
raw, Config, Flash, Softdevice,
};
use profile::update_profile;
use crate::config::BleBatteryConfig;
use sequential_storage::{cache::NoCache, map::fetch_item};
use static_cell::StaticCell;
use vial_service::VialReaderWriter;
Expand Down
2 changes: 1 addition & 1 deletion rmk/src/ble/nrf/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::{
hid_service::{HidService, HidServiceEvent},
vial_service::{BleVialService, VialServiceEvent},
};
use crate::config::KeyboardUsbConfig;
use crate::{
ble::device_info::{DeviceInformation, PnPID, VidSource},
hid::{ConnectionType, ConnectionTypeWrapper, HidError, HidReaderWrapper, HidWriterWrapper},
Expand All @@ -17,7 +18,6 @@ use nrf_softdevice::{
},
Softdevice,
};
use crate::config::KeyboardUsbConfig;
use usbd_hid::descriptor::AsInputReport;

/// Wrapper struct for writing via BLE
Expand Down
2 changes: 1 addition & 1 deletion rmk/src/keyboard.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::config::BehaviorConfig;
use crate::{
action::{Action, KeyAction},
hid::{ConnectionType, HidWriterWrapper},
Expand All @@ -17,7 +18,6 @@ use embassy_sync::{
use embassy_time::{Instant, Timer};
use heapless::{FnvIndexMap, Vec};
use postcard::experimental::max_size::MaxSize;
use crate::config::BehaviorConfig;
use serde::{Deserialize, Serialize};
use usbd_hid::descriptor::KeyboardReport;

Expand Down
2 changes: 1 addition & 1 deletion rmk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use crate::ble::esp::initialize_esp_ble_keyboard_with_config_and_run;
#[cfg(feature = "_nrf_ble")]
use crate::ble::nrf::initialize_nrf_ble_keyboard_and_run;
use crate::config::RmkConfig;
#[cfg(not(feature = "rapid_debouncer"))]
use crate::debounce::default_bouncer::DefaultDebouncer;
#[cfg(feature = "rapid_debouncer")]
Expand Down Expand Up @@ -50,7 +51,6 @@ use keyboard::{
};
use keymap::KeyMap;
use matrix::{Matrix, MatrixTrait};
use crate::config::RmkConfig;
pub use rmk_macro as macros;
use usb::KeyboardUsbDevice;
use via::process::VialService;
Expand Down
2 changes: 1 addition & 1 deletion rmk/src/light.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::config::{LightConfig, LightPinConfig};
use crate::hid::HidReaderWrapper;
use bitfield_struct::bitfield;
use defmt::{debug, error, warn, Format};
use embassy_futures::select::select;
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, channel::Channel};
use embedded_hal::digital::{Error, OutputPin, PinState};
use crate::config::{LightConfig, LightPinConfig};

pub(crate) static LED_CHANNEL: Channel<CriticalSectionRawMutex, LedIndicator, 8> = Channel::new();

Expand Down
2 changes: 1 addition & 1 deletion rmk/src/split/central.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use embedded_hal::digital::{InputPin, OutputPin};
#[cfg(feature = "async_matrix")]
use embedded_hal_async::digital::Wait;
use heapless::Vec;
use crate::config::RmkConfig;

use crate::action::KeyAction;
#[cfg(feature = "_nrf_ble")]
use crate::ble::nrf::initialize_nrf_ble_keyboard_and_run;
use crate::config::RmkConfig;
#[cfg(not(feature = "rapid_debouncer"))]
use crate::debounce::default_bouncer::DefaultDebouncer;
#[cfg(feature = "rapid_debouncer")]
Expand Down
4 changes: 3 additions & 1 deletion rmk/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,9 @@ impl<F: AsyncNorFlash, const ROW: usize, const COL: usize, const NUM_LAYER: usiz

if config.clear_storage {
// Clear storage
let _ = sequential_storage::erase_all(&mut storage.flash, storage.storage_range.clone()).await;
let _ =
sequential_storage::erase_all(&mut storage.flash, storage.storage_range.clone())
.await;
}

// Check whether keymap and configs have been storaged in flash
Expand Down
2 changes: 1 addition & 1 deletion rmk/src/via/process.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{protocol::*, vial::process_vial};
use crate::config::VialConfig;
use crate::{
hid::{HidError, HidReaderWriterWrapper},
keyboard_macro::{MACRO_SPACE_SIZE, NUM_MACRO},
Expand All @@ -12,7 +13,6 @@ use core::cell::RefCell;
use defmt::{debug, error, info, warn};
use embassy_time::Instant;
use num_enum::{FromPrimitive, TryFromPrimitive};
use crate::config::VialConfig;

pub(crate) struct VialService<'a, const ROW: usize, const COL: usize, const NUM_LAYER: usize> {
// VialService holds a reference of keymap, for updating
Expand Down

0 comments on commit fc67b29

Please sign in to comment.