From cec30aebad590e2017c56a1bea251ec3fcf1782a Mon Sep 17 00:00:00 2001 From: hyranno Date: Wed, 1 Jan 2025 20:48:24 +0900 Subject: [PATCH 1/2] change: open modules for matrix --- rmk/src/debounce/mod.rs | 4 ++-- rmk/src/keyboard.rs | 10 +++++----- rmk/src/lib.rs | 6 +++--- rmk/src/matrix.rs | 20 ++++++++++---------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/rmk/src/debounce/mod.rs b/rmk/src/debounce/mod.rs index 87925db5..ebbcbaae 100644 --- a/rmk/src/debounce/mod.rs +++ b/rmk/src/debounce/mod.rs @@ -6,7 +6,7 @@ pub mod fast_debouncer; /// Default DEBOUNCE_THRESHOLD in ms. static DEBOUNCE_THRESHOLD: u16 = 10; -pub(crate) trait DebouncerTrait { +pub trait DebouncerTrait { fn new() -> Self; /// The `in_idx` `out_idx` can be used as two normal dimensions. @@ -20,7 +20,7 @@ pub(crate) trait DebouncerTrait { } /// Debounce state -pub(crate) enum DebounceState { +pub enum DebounceState { Debounced, InProgress, Ignored, diff --git a/rmk/src/keyboard.rs b/rmk/src/keyboard.rs index ef59811d..6ab0b25f 100644 --- a/rmk/src/keyboard.rs +++ b/rmk/src/keyboard.rs @@ -23,15 +23,15 @@ use serde::{Deserialize, Serialize}; use usbd_hid::descriptor::KeyboardReport; #[derive(Serialize, Deserialize, Clone, Copy, Debug, Format, MaxSize)] -pub(crate) struct KeyEvent { - pub(crate) row: u8, - pub(crate) col: u8, - pub(crate) pressed: bool, +pub struct KeyEvent { + pub row: u8, + pub col: u8, + pub pressed: bool, } pub(crate) const EVENT_CHANNEL_SIZE: usize = 32; pub(crate) const REPORT_CHANNEL_SIZE: usize = 32; -pub(crate) static key_event_channel: Channel< +pub static key_event_channel: Channel< CriticalSectionRawMutex, KeyEvent, EVENT_CHANNEL_SIZE, diff --git a/rmk/src/lib.rs b/rmk/src/lib.rs index 05ef8fec..ac93ff0b 100644 --- a/rmk/src/lib.rs +++ b/rmk/src/lib.rs @@ -61,17 +61,17 @@ pub mod action; #[cfg(feature = "_ble")] pub mod ble; pub mod config; -mod debounce; +pub mod debounce; pub mod direct_pin; mod flash; mod hid; -mod keyboard; +pub mod keyboard; mod keyboard_macro; pub mod keycode; mod keymap; mod layout_macro; mod light; -mod matrix; +pub mod matrix; #[cfg(feature = "split")] pub mod split; mod storage; diff --git a/rmk/src/matrix.rs b/rmk/src/matrix.rs index fa08719a..54c02c9f 100644 --- a/rmk/src/matrix.rs +++ b/rmk/src/matrix.rs @@ -13,7 +13,7 @@ use {embassy_futures::select::select_slice, embedded_hal_async::digital::Wait, h /// /// The keyboard matrix is a 2D matrix of keys, the matrix does the scanning and saves the result to each key's `KeyState`. /// The `KeyState` at position (row, col) can be read by `get_key_state` and updated by `update_key_state`. -pub(crate) trait MatrixTrait { +pub trait MatrixTrait { // Matrix size const ROW: usize; const COL: usize; @@ -60,11 +60,11 @@ pub(crate) trait MatrixTrait { /// KeyState represents the state of a key. #[derive(Copy, Clone, Debug, Format)] -pub(crate) struct KeyState { +pub struct KeyState { // True if the key is pressed - pub(crate) pressed: bool, + pub pressed: bool, // True if the key's state is just changed - // pub(crate) changed: bool, + // pub changed: bool, } impl Default for KeyState { @@ -74,25 +74,25 @@ impl Default for KeyState { } impl KeyState { - pub(crate) fn new() -> Self { + pub fn new() -> Self { KeyState { pressed: false } } - pub(crate) fn toggle_pressed(&mut self) { + pub fn toggle_pressed(&mut self) { self.pressed = !self.pressed; } - pub(crate) fn is_releasing(&self) -> bool { + pub fn is_releasing(&self) -> bool { !self.pressed } - pub(crate) fn is_pressing(&self) -> bool { + pub fn is_pressing(&self) -> bool { self.pressed } } /// Matrix is the physical pcb layout of the keyboard matrix. -pub(crate) struct Matrix< +pub struct Matrix< #[cfg(feature = "async_matrix")] In: Wait + InputPin, #[cfg(not(feature = "async_matrix"))] In: InputPin, Out: OutputPin, @@ -122,7 +122,7 @@ impl< > Matrix { /// Create a matrix from input and output pins. - pub(crate) fn new( + pub fn new( input_pins: [In; INPUT_PIN_NUM], output_pins: [Out; OUTPUT_PIN_NUM], debouncer: D, From 6b956fcf2b6730103741567f8ee8c9be65b5d99e Mon Sep 17 00:00:00 2001 From: hyranno Date: Thu, 2 Jan 2025 11:11:06 +0900 Subject: [PATCH 2/2] change: open modules public for run_rmk_ --- rmk/src/ble/esp/mod.rs | 2 +- rmk/src/ble/nrf/mod.rs | 2 +- rmk/src/debounce/default_bouncer.rs | 2 +- rmk/src/debounce/fast_debouncer.rs | 2 +- rmk/src/lib.rs | 2 +- rmk/src/split/central.rs | 2 +- rmk/src/split/mod.rs | 4 ++-- rmk/src/split/nrf/peripheral.rs | 2 +- rmk/src/split/serial/mod.rs | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/rmk/src/ble/esp/mod.rs b/rmk/src/ble/esp/mod.rs index 95f71d62..7edce121 100644 --- a/rmk/src/ble/esp/mod.rs +++ b/rmk/src/ble/esp/mod.rs @@ -35,7 +35,7 @@ use futures::pin_mut; /// * `output_pins` - output gpio pins /// * `keyboard_config` - other configurations of the keyboard, check [RmkConfig] struct for details /// * `spawner` - embassy task spawner, used to spawn nrf_softdevice background task -pub(crate) async fn initialize_esp_ble_keyboard_with_config_and_run< +pub async fn initialize_esp_ble_keyboard_with_config_and_run< M: MatrixTrait, Out: OutputPin, const ROW: usize, diff --git a/rmk/src/ble/nrf/mod.rs b/rmk/src/ble/nrf/mod.rs index 63a379da..9345fc4a 100644 --- a/rmk/src/ble/nrf/mod.rs +++ b/rmk/src/ble/nrf/mod.rs @@ -215,7 +215,7 @@ pub(crate) fn nrf_ble_config(keyboard_name: &str) -> Config { /// * `keyboard_config` - other configurations of the keyboard, check [RmkConfig] struct for details /// * `spawner` - embassy task spawner, used to spawn nrf_softdevice background task /// * `saadc` - nRF's [saadc](https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fsaadc.html) instance for battery level detection, if you don't need it, pass `None` -pub(crate) async fn initialize_nrf_ble_keyboard_and_run< +pub async fn initialize_nrf_ble_keyboard_and_run< M: MatrixTrait, Out: OutputPin, #[cfg(not(feature = "_no_usb"))] D: Driver<'static>, diff --git a/rmk/src/debounce/default_bouncer.rs b/rmk/src/debounce/default_bouncer.rs index 54c61378..444c9525 100644 --- a/rmk/src/debounce/default_bouncer.rs +++ b/rmk/src/debounce/default_bouncer.rs @@ -28,7 +28,7 @@ impl DebounceCounter { } /// Default per-key debouncer. The debouncing algorithm is same as ZMK's [default debouncer](https://github.com/zmkfirmware/zmk/blob/19613128b901723f7b78c136792d72e6ca7cf4fc/app/module/lib/zmk_debounce/debounce.c) -pub(crate) struct DefaultDebouncer { +pub struct DefaultDebouncer { last_ms: u32, counters: [[DebounceCounter; INPUT_PIN_NUM]; OUTPUT_PIN_NUM], } diff --git a/rmk/src/debounce/fast_debouncer.rs b/rmk/src/debounce/fast_debouncer.rs index 2dfb33c3..1c0040b6 100644 --- a/rmk/src/debounce/fast_debouncer.rs +++ b/rmk/src/debounce/fast_debouncer.rs @@ -6,7 +6,7 @@ use super::{DebounceState, DebouncerTrait, DEBOUNCE_THRESHOLD}; /// Fast per-key debouncer. /// The debouncing algorithm is similar as QMK's [asym eager defer pk debouncer](https://github.com/qmk/qmk_firmware/blob/2fd56317763e8b3b73f0db7488ef42a70f5b946e/quantum/debounce/asym_eager_defer_pk.c) -pub(crate) struct RapidDebouncer { +pub struct RapidDebouncer { last_ms: Instant, debouncing: [[bool; INPUT_PIN_NUM]; OUTPUT_PIN_NUM], } diff --git a/rmk/src/lib.rs b/rmk/src/lib.rs index ac93ff0b..40191fcf 100644 --- a/rmk/src/lib.rs +++ b/rmk/src/lib.rs @@ -223,7 +223,7 @@ pub async fn run_rmk_with_async_flash< defmt::panic!("The run_rmk should never return"); } -pub(crate) async fn initialize_usb_keyboard_and_run< +pub async fn initialize_usb_keyboard_and_run< Out: OutputPin, D: Driver<'static>, M: MatrixTrait, diff --git a/rmk/src/split/central.rs b/rmk/src/split/central.rs index bea8718d..e9f99652 100644 --- a/rmk/src/split/central.rs +++ b/rmk/src/split/central.rs @@ -236,7 +236,7 @@ pub async fn run_peripheral_monitor< } /// Split central is connected to host via usb -pub(crate) async fn initialize_usb_split_central_and_run< +pub async fn initialize_usb_split_central_and_run< M: MatrixTrait, Out: OutputPin, D: Driver<'static>, diff --git a/rmk/src/split/mod.rs b/rmk/src/split/mod.rs index 0396807a..722b3506 100644 --- a/rmk/src/split/mod.rs +++ b/rmk/src/split/mod.rs @@ -7,10 +7,10 @@ pub mod central; /// Common abstraction layer of split driver pub(crate) mod driver; #[cfg(feature = "_nrf_ble")] -pub(crate) mod nrf; +pub mod nrf; pub mod peripheral; #[cfg(not(feature = "_nrf_ble"))] -pub(crate) mod serial; +pub mod serial; /// Maximum size of a split message pub const SPLIT_MESSAGE_MAX_SIZE: usize = SplitMessage::POSTCARD_MAX_SIZE + 4; diff --git a/rmk/src/split/nrf/peripheral.rs b/rmk/src/split/nrf/peripheral.rs index def9368c..e7918645 100644 --- a/rmk/src/split/nrf/peripheral.rs +++ b/rmk/src/split/nrf/peripheral.rs @@ -85,7 +85,7 @@ impl<'a> SplitWriter for BleSplitPeripheralDriver<'a> { /// * `input_pins` - input gpio pins /// * `output_pins` - output gpio pins /// * `spawner` - embassy task spawner, used to spawn nrf_softdevice background task -pub(crate) async fn initialize_nrf_ble_split_peripheral_and_run< +pub async fn initialize_nrf_ble_split_peripheral_and_run< M: MatrixTrait, const ROW: usize, const COL: usize, diff --git a/rmk/src/split/serial/mod.rs b/rmk/src/split/serial/mod.rs index 66503bf4..0fe69381 100644 --- a/rmk/src/split/serial/mod.rs +++ b/rmk/src/split/serial/mod.rs @@ -90,7 +90,7 @@ impl SplitWriter for SerialSplitDriver { /// * `input_pins` - input gpio pins /// * `output_pins` - output gpio pins /// * `serial` - serial port to send key events to central board -pub(crate) async fn initialize_serial_split_peripheral_and_run< +pub async fn initialize_serial_split_peripheral_and_run< M: MatrixTrait, S: Write + Read, const ROW: usize,