Repository: HaoboGu/rmk (language: rust)

Issue:
the debouncer of split direct pins
the debouncer for the split direct pin matrix seems wrong.
when i'm trying to build a non-square matrix, the debouncer panic

https://github.com/HaoboGu/rmk/blob/a212bbba6d328d6fa311bd77a9b90768ec7764b9/rmk/src/split/central.rs#L74-L82

> INFO  debouncing idx: 0 0
└─ rmk::split::central::{impl#3}::scan::{async_fn#0} @ /home/drin/workspace/practoy/rmk/rmk/src/split/central.rs:613
INFO  debouncing idx: 1 0
└─ rmk::split::central::{impl#3}::scan::{async_fn#0} @ /home/drin/workspace/practoy/rmk/rmk/src/split/central.rs:613
INFO  debouncing idx: 2 0
└─ rmk::split::central::{impl#3}::scan::{async_fn#0} @ /home/drin/workspace/practoy/rmk/rmk/src/split/central.rs:613
INFO  debouncing idx: 3 0
└─ rmk::split::central::{impl#3}::scan::{async_fn#0} @ /home/drin/workspace/practoy/rmk/rmk/src/split/central.rs:613
INFO  debouncing idx: 4 0
└─ rmk::split::central::{impl#3}::scan::{async_fn#0} @ /home/drin/workspace/practoy/rmk/rmk/src/split/central.rs:613
ERROR panicked at /home/drin/workspace/practoy/rmk/rmk/src/debounce/default_bouncer.rs:61:54:
index out of bounds: the len is 4 but the index is 4

everything is ok if i swap the col and row in the definition of debouncer.

and i notice that in the `direct_pin.rs`, there is only the definition about col2row.

https://github.com/HaoboGu/rmk/blob/a212bbba6d328d6fa311bd77a9b90768ec7764b9/rmk/src/direct_pin.rs#L169-L172

i'm curious about which one is correct.
the row and col in different places are a bit confusing.
the in and out pins of direct pin matrix are a bit confusing as well. 

@DivineGod  


Discussion / hints:
I checked the split-direct pin example, worked well with non-square matrix. Could you post your `keyboard.toml` here?
thanks for your quick reply.
my keyboard.toml is https://0x0.st/XhMw.toml
should i add the feature col2row in dependencies item in Cargo.toml explicitly

> should i add the feature col2row in dependencies item in Cargo.toml explicitly

If you don't have `default-features = false`, you don't need to add it explicitly. 
I can repro it. I'll fix it soon

Fix patch:
diff --git a/rmk/CHANGELOG.md b/rmk/CHANGELOG.md
index c6508ff4..8f13c763 100644
--- a/rmk/CHANGELOG.md
+++ b/rmk/CHANGELOG.md
@@ -9,8 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Fixed
 
-- Fixed invalid BLE state after reconnection on Windows
-- Fixed ghosting key on macOS
+- Fix invalid BLE state after reconnection on Windows
+- Fix ghosting key on macOS
+- Fix direct pin debouncer size error
 
 ### Added
 
diff --git a/rmk/src/direct_pin.rs b/rmk/src/direct_pin.rs
index f621eb77..de949c31 100644
--- a/rmk/src/direct_pin.rs
+++ b/rmk/src/direct_pin.rs
@@ -62,8 +62,7 @@ pub async fn run_rmk_direct_pin<
     const SIZE: usize,
     const NUM_LAYER: usize,
 >(
-    #[cfg(feature = "col2row")] direct_pins: [[Option<In>; COL]; ROW],
-    #[cfg(not(feature = "col2row"))] direct_pins: [[Option<In>; ROW]; COL],
+    direct_pins: [[Option<In>; COL]; ROW],
     #[cfg(not(feature = "_no_usb"))] usb_driver: D,
     #[cfg(not(feature = "_no_external_storage"))] flash: F,
     default_keymap: &mut [[[KeyAction; COL]; ROW]; NUM_LAYER],
@@ -156,8 +155,7 @@ pub async fn run_rmk_direct_pin_with_async_flash<
     const SIZE: usize,
     const NUM_LAYER: usize,
 >(
-    #[cfg(feature = "col2row")] direct_pins: [[Option<In>; COL]; ROW],
-    #[cfg(not(feature = "col2row"))] direct_pins: [[Option<In>; ROW]; COL],
+    direct_pins: [[Option<In>; COL]; ROW],
     #[cfg(not(feature = "_no_usb"))] usb_driver: D,
     #[cfg(not(feature = "_no_external_storage"))] flash: F,
     default_keymap: &mut [[[KeyAction; COL]; ROW]; NUM_LAYER],
@@ -165,17 +163,14 @@ pub async fn run_rmk_direct_pin_with_async_flash<
     low_active: bool,
     #[cfg(not(feature = "_esp_ble"))] spawner: Spawner,
 ) -> ! {
-    // Create the debouncer, use COL2ROW by default
+    // Create the debouncer
     #[cfg(feature = "rapid_debouncer")]
     let debouncer = RapidDebouncer::<COL, ROW>::new();
     #[cfg(not(feature = "rapid_debouncer"))]
     let debouncer = DefaultDebouncer::<COL, ROW>::new();
 
     // Keyboard matrix
-    #[cfg(feature = "col2row")]
     let matrix = DirectPinMatrix::<_, _, ROW, COL, SIZE>::new(direct_pins, debouncer, low_active);
-    #[cfg(not(feature = "col2row"))]
-    let matrix = DirectPinMatrix::<_, _, COL, ROW, SIZE>::new(direct_pins, debouncer, low_active);
 
     // Dispatch according to chip and communication type
     #[cfg(feature = "_nrf_ble")]
diff --git a/rmk/src/split/central.rs b/rmk/src/split/central.rs
index 412fc0b9..a67c6ab3 100644
--- a/rmk/src/split/central.rs
+++ b/rmk/src/split/central.rs
@@ -156,8 +156,7 @@ pub async fn run_rmk_split_central_direct_pin<
     const NUM_LAYER: usize,
     const SIZE: usize,
 >(
-    #[cfg(feature = "col2row")] direct_pins: [[Option<In>; CENTRAL_COL]; CENTRAL_ROW],
-    #[cfg(not(feature = "col2row"))] direct_pins: [[Option<In>; CENTRAL_ROW]; CENTRAL_COL],
+    direct_pins: [[Option<In>; CENTRAL_COL]; CENTRAL_ROW],
     #[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],
@@ -166,35 +165,21 @@ pub async fn run_rmk_split_central_direct_pin<
     #[cfg(feature = "_nrf_ble")] central_addr: [u8; 6],
     #[cfg(not(feature = "_esp_ble"))] spawner: Spawner,
 ) -> ! {
+    info!("Debouncer");
     // Create the debouncer, use COL2ROW by default
-    #[cfg(all(feature = "col2row", feature = "rapid_debouncer"))]
-    let debouncer: RapidDebouncer<CENTRAL_ROW, CENTRAL_COL> = RapidDebouncer::new();
-    #[cfg(all(not(feature = "col2row"), feature = "rapid_debouncer"))]
+    #[cfg(feature = "rapid_debouncer")]
     let debouncer: RapidDebouncer<CENTRAL_COL, CENTRAL_ROW> = RapidDebouncer::new();
-    #[cfg(all(feature = "col2row", not(feature = "rapid_debouncer")))]
-    let debouncer: DefaultDebouncer<CENTRAL_ROW, CENTRAL_COL> = DefaultDebouncer::new();
-    #[cfg(all(not(feature = "col2row"), not(feature = "rapid_debouncer")))]
+    #[cfg(not(feature = "rapid_debouncer"))]
     let debouncer: DefaultDebouncer<CENTRAL_COL, CENTRAL_ROW> = DefaultDebouncer::new();
 
     // Keyboard matrix, use COL2ROW by default
-    #[cfg(feature = "col2row")]
     let matrix = CentralDirectPinMatrix::<
-        In,
         _,
-        CENTRAL_ROW_OFFSET,
-        CENTRAL_COL_OFFSET,
-        CENTRAL_ROW,
-        CENTRAL_COL,
-        SIZE,
-    >::new(direct_pins, debouncer, low_active);
-    #[cfg(not(feature = "col2row"))]
-    let matrix = CentralDirectPinMatrix::<
-        In,
         _,
         CENTRAL_ROW_OFFSET,
         CENTRAL_COL_OFFSET,
-        CENTRAL_COL,
         CENTRAL_ROW,
+        CENTRAL_COL,
         SIZE,
     >::new(direct_pins, debouncer, low_active);
 
diff --git a/rmk/src/split/peripheral.rs b/rmk/src/split/peripheral.rs
index f6ff5e94..443d97af 100644
--- a/rmk/src/split/peripheral.rs
+++ b/rmk/src/split/peripheral.rs
@@ -107,8 +107,7 @@ pub async fn run_rmk_split_peripheral_direct_pin<
     const COL: usize,
     const SIZE: usize,
 >(
-    #[cfg(feature = "col2row")] direct_pins: [[Option<In>; COL]; ROW],
-    #[cfg(not(feature = "col2row"))] direct_pins: [[Option<In>; ROW]; COL],
+    direct_pins: [[Option<In>; COL]; ROW],
     #[cfg(feature = "_nrf_ble")] central_addr: [u8; 6],
     #[cfg(feature = "_nrf_ble")] peripheral_addr: [u8; 6],
     low_active: bool,
@@ -116,20 +115,13 @@ pub async fn run_rmk_split_peripheral_direct_pin<
     #[cfg(feature = "_nrf_ble")] spawner: Spawner,
 ) {
     // Create the debouncer, use COL2ROW by default
-    #[cfg(all(feature = "col2row", feature = "rapid_debouncer"))]
-    let debouncer = RapidDebouncer::<COL, ROW>::new();
-    #[cfg(all(feature = "col2row", not(feature = "rapid_debouncer")))]
-    let debouncer = DefaultDebouncer::<COL, ROW>::new();
-    #[cfg(all(not(feature = "col2row"), feature = "rapid_debouncer"))]
+    #[cfg(feature = "rapid_debouncer")]
     let debouncer = RapidDebouncer::<COL, ROW>::new();
-    #[cfg(all(not(feature = "col2row"), not(feature = "rapid_debouncer")))]
+    #[cfg(not(feature = "rapid_debouncer"))]
     let debouncer = DefaultDebouncer::<COL, ROW>::new();
 
     // Keyboard matrix
-    #[cfg(feature = "col2row")]
     let matrix = DirectPinMatrix::<_, _, ROW, COL, SIZE>::new(direct_pins, debouncer, low_active);
-    #[cfg(not(feature = "col2row"))]
-    let matrix = DirectPinMatrix::<_, _, COL, ROW, SIZE>::new(direct_pins, debouncer, low_active);
 
     #[cfg(not(feature = "_nrf_ble"))]
     initialize_serial_split_peripheral_and_run::<_, S, ROW, COL>(matrix, serial).await;


Test patch: