Skip to content

Conversation

archnode
Copy link

@archnode archnode commented Aug 29, 2025

This is a first draft of adding bidirectional matrix scanning. It also implements the explicit naming of scan modes as discussed in #380, as this is needed with a third scan mode.

Copy link

github-actions bot commented Aug 29, 2025

Binary Size Report

use_config/nrf52832_ble

   text	   data	    bss	    dec	    hex	filename
 309900	   5040	  37012	 351952	  55ed0	rmk-nrf52832
Diff
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +8.5%      +4  [ = ]       0    [Unmapped]
  -0.3%      -2  [ = ]       0    .defmt
  -0.1%     -32  -0.1%     -32    .rodata
  -0.3%    -120  [ = ]       0    .debug_aranges
  -0.2%    -272  [ = ]       0    .debug_ranges
  -0.8%    -280  [ = ]       0    .debug_frame
  -0.5%    -496  [ = ]       0    .symtab
  -0.3%    -921  [ = ]       0    .debug_line
  -0.4% -1.00Ki  -0.4% -1.00Ki    .text
  -0.2% -1.12Ki  [ = ]       0    .debug_loc
  -0.1% -1.12Ki  [ = ]       0    .debug_str
  -0.6% -1.40Ki  [ = ]       0    .strtab
  -0.2% -3.40Ki  [ = ]       0    .debug_info
  -0.2% -10.1Ki  -0.3% -1.04Ki    TOTAL

use_config/nrf52840_ble

   text	   data	    bss	    dec	    hex	filename
 345428	   5040	  45604	 396072	  60b28	rmk-nrf52840
Diff
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.3%    +568  [ = ]       0    .debug_ranges
  -0.3%      -2  [ = ]       0    .defmt
 -12.0%      -6  [ = ]       0    [Unmapped]
  -0.1%     -32  -0.1%     -32    .rodata
  -0.4%    -136  [ = ]       0    .debug_aranges
  -0.0%    -252  [ = ]       0    .debug_loc
  -0.7%    -300  [ = ]       0    .debug_frame
  -0.5%    -560  [ = ]       0    .symtab
  -0.3%    -947  [ = ]       0    .debug_line
  -0.4% -1.09Ki  -0.4% -1.09Ki    .text
  -0.5% -1.35Ki  [ = ]       0    .strtab
  -0.1% -1.68Ki  [ = ]       0    .debug_str
  -0.2% -4.09Ki  [ = ]       0    .debug_info
  -0.2% -9.83Ki  -0.3% -1.12Ki    TOTAL

use_config/nrf52840_ble_split

   text	   data	    bss	    dec	    hex	filename
 417032	   6260	  42452	 465744	  71b50	central

   text	   data	    bss	    dec	    hex	filename
 263888	   5668	  27772	 297328	  48970	peripheral
Diff

Central Diff

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1%    +224  [ = ]       0    .debug_ranges
  +6.4%      +3  [ = ]       0    [Unmapped]
  -0.6%      -4  [ = ]       0    .defmt
  -0.1%     -32  -0.1%     -32    .rodata
  -0.1%     -56  [ = ]       0    .debug_aranges
  -0.3%    -152  [ = ]       0    .debug_frame
  -0.2%    -272  [ = ]       0    .symtab
  -0.2%    -929  [ = ]       0    .debug_loc
  -0.3%    -995  [ = ]       0    .debug_line
  -0.4% -1.23Ki  [ = ]       0    .strtab
  -0.4% -1.47Ki  -0.4% -1.47Ki    .text
  -0.1% -1.57Ki  [ = ]       0    .debug_str
  -0.2% -3.95Ki  [ = ]       0    .debug_info
  -0.2% -10.4Ki  -0.3% -1.50Ki    TOTAL

Peripheral Diff

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.3% +1.10Ki  [ = ]       0    .debug_loc
  +0.0%     +77  [ = ]       0    .debug_str
   +13%      +7  [ = ]       0    [Unmapped]
  -0.9%      -4  [ = ]       0    .defmt
  -0.0%      -8  [ = ]       0    .debug_ranges
  -0.1%     -32  -0.1%     -32    .rodata
  -0.2%     -72  [ = ]       0    .debug_aranges
  -0.6%    -160  [ = ]       0    .debug_frame
  -0.3%    -304  [ = ]       0    .symtab
  -0.4%    -770  [ = ]       0    .debug_line
  -0.4% -1.00Ki  -0.4% -1.00Ki    .text
  -0.6% -1.04Ki  [ = ]       0    .strtab
  -0.2% -1.68Ki  [ = ]       0    .debug_info
  -0.1% -3.85Ki  -0.4% -1.04Ki    TOTAL

use_config/pi_pico_w_ble

   text	   data	    bss	    dec	    hex	filename
 581296	      0	  56076	 637372	  9b9bc	rmk-pi-pico-w
Diff
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.4%    +752  [ = ]       0    .debug_ranges
  -0.3%      -2  [ = ]       0    .defmt
  -6.0%      -4  [ = ]       0    [Unmapped]
  -0.0%     -32  -0.0%     -32    .rodata
  -0.2%     -64  [ = ]       0    .debug_aranges
  -0.5%    -168  [ = ]       0    .debug_frame
  -0.8%    -560  [ = ]       0    .symtab
  -0.3%    -895  [ = ]       0    .debug_line
  -0.1%    -954  [ = ]       0    .debug_loc
  -0.5% -1.31Ki  -0.5% -1.31Ki    .text
  -0.6% -1.38Ki  [ = ]       0    .strtab
  -0.1% -1.74Ki  [ = ]       0    .debug_str
  -0.2% -3.89Ki  [ = ]       0    .debug_info
  -0.2% -10.2Ki  -0.2% -1.34Ki    TOTAL

use_config/pi_pico_w_ble_split

   text	   data	    bss	    dec	    hex	filename
 609992	      0	  58640	 668632	  a33d8	central

   text	   data	    bss	    dec	    hex	filename
 481936	      0	  43608	 525544	  804e8	peripheral
Diff

Central Diff

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1%    +128  [ = ]       0    .debug_ranges
  -0.3%      -2  [ = ]       0    .defmt
 -23.5%     -12  [ = ]       0    [Unmapped]
  -0.0%     -32  -0.0%     -32    .rodata
  -0.2%     -64  [ = ]       0    .debug_aranges
  -0.5%    -168  [ = ]       0    .debug_frame
  -0.5%    -400  [ = ]       0    .symtab
  -0.3% -1.08Ki  [ = ]       0    .debug_line
  -0.1% -1.11Ki  [ = ]       0    .debug_loc
  -0.5% -1.35Ki  [ = ]       0    .strtab
  -0.5% -1.52Ki  -0.5% -1.52Ki    .text
  -0.1% -1.57Ki  [ = ]       0    .debug_str
  -0.2% -3.86Ki  [ = ]       0    .debug_info
  -0.2% -11.0Ki  -0.2% -1.55Ki    TOTAL

Peripheral Diff

    FILE SIZE        VM SIZE    
 --------------  -------------- 
   +39%     +18  [ = ]       0    [Unmapped]
  +0.0%     +14  [ = ]       0    .debug_str
  -0.4%      -2  [ = ]       0    .defmt
  -0.0%     -32  [ = ]       0    .debug_ranges
  -0.0%     -32  -0.0%     -32    .rodata
  -0.2%     -48  [ = ]       0    .debug_aranges
  -0.5%    -112  [ = ]       0    .debug_frame
  -0.6%    -272  [ = ]       0    .symtab
  -0.1%    -390  [ = ]       0    .debug_loc
  -0.4%   -1012  [ = ]       0    .debug_line
  -0.6% -1.03Ki  [ = ]       0    .strtab
  -0.7% -1.33Ki  -0.7% -1.33Ki    .text
  -0.2% -1.99Ki  [ = ]       0    .debug_info
  -0.1% -6.18Ki  -0.3% -1.36Ki    TOTAL

use_config/rp2040

   text	   data	    bss	    dec	    hex	filename
 134424	      0	  13892	 148316	  2435c	rmk-rp2040
Diff
    FILE SIZE        VM SIZE    
 --------------  -------------- 
   +22%     +10  [ = ]       0    [Unmapped]
  -0.6%      -2  [ = ]       0    .defmt
  -0.2%     -32  -0.2%     -32    .rodata
  -0.5%     -64  [ = ]       0    .debug_aranges
  -1.2%    -168  [ = ]       0    .debug_frame
  -0.8%    -512  [ = ]       0    .debug_ranges
  -1.8%    -528  [ = ]       0    .symtab
  -0.8% -1.19Ki  [ = ]       0    .debug_line
  -1.5% -1.36Ki  [ = ]       0    .strtab
  -1.2% -1.45Ki  -1.2% -1.45Ki    .text
  -0.2% -1.56Ki  [ = ]       0    .debug_str
  -1.4% -3.52Ki  [ = ]       0    .debug_loc
  -0.5% -3.71Ki  [ = ]       0    .debug_info
  -0.6% -14.1Ki  -1.0% -1.48Ki    TOTAL

use_config/rp2040_split

   text	   data	    bss	    dec	    hex	filename
 146816	      0	  14880	 161696	  277a0	central

   text	   data	    bss	    dec	    hex	filename
  22320	      0	   2280	  24600	   6018	peripheral
Diff

Central Diff

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +16  [ = ]       0    .debug_ranges
  -0.6%      -2  [ = ]       0    .defmt
  -5.8%      -3  [ = ]       0    [Unmapped]
  -0.2%     -32  -0.2%     -32    .rodata
  -0.4%     -64  [ = ]       0    .debug_aranges
  -1.1%    -168  [ = ]       0    .debug_frame
  -1.4%    -464  [ = ]       0    .symtab
  -0.7% -1.17Ki  [ = ]       0    .debug_line
  -1.3% -1.34Ki  [ = ]       0    .strtab
  -1.1% -1.44Ki  -1.1% -1.44Ki    .text
  -0.2% -2.04Ki  [ = ]       0    .debug_str
  -0.8% -2.38Ki  [ = ]       0    .debug_loc
  -0.4% -3.77Ki  [ = ]       0    .debug_info
  -0.4% -12.8Ki  -0.9% -1.47Ki    TOTAL

Peripheral Diff

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +2  [ = ]       0    .strtab
  +1.6%      +1  [ = ]       0    [Unmapped]
  -0.1%     -16  [ = ]       0    .debug_aranges
  -0.0%     -72  [ = ]       0    .debug_info
  -0.1%    -351  [ = ]       0    .debug_str
  -0.0%    -436  [ = ]       0    TOTAL

use_config/stm32f1

   text	   data	    bss	    dec	    hex	filename
  86116	     24	  11836	  97976	  17eb8	rmk-stm32f1
Diff
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2%    +104  [ = ]       0    .debug_ranges
   +29%     +11  [ = ]       0    [Unmapped]
  -0.3%     -48  [ = ]       0    .debug_aranges
  -1.1%    -168  [ = ]       0    .debug_frame
  -1.2%    -320  [ = ]       0    .symtab
  -0.3%    -604  [ = ]       0    .debug_loc
  -0.7%    -864  [ = ]       0    .debug_line
  -2.0% -1.04Ki  [ = ]       0    .strtab
  -1.5% -1.23Ki  -1.5% -1.23Ki    .text
  -0.1% -1.38Ki  [ = ]       0    .debug_str
  -0.5% -3.74Ki  [ = ]       0    .debug_info
  -0.4% -9.24Ki  -1.3% -1.23Ki    TOTAL

use_config/stm32f4

   text	   data	    bss	    dec	    hex	filename
 136884	    316	  15136	 152336	  25310	rmk-stm32f4
Diff
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.6%    +448  [ = ]       0    .debug_ranges
   +48%     +21  [ = ]       0    [Unmapped]
  -0.5%      -2  [ = ]       0    .defmt
  -0.1%     -16  -0.1%     -16    .rodata
  -0.2%     -56  [ = ]       0    .debug_aranges
  -0.8%    -152  [ = ]       0    .debug_frame
  -0.8%    -288  [ = ]       0    .symtab
  -0.2%    -498  [ = ]       0    .debug_loc
  -0.7% -1.02Ki  [ = ]       0    .debug_line
  -1.1% -1.32Ki  -1.1% -1.32Ki    .text
  -1.3% -1.34Ki  [ = ]       0    .strtab
  -0.1% -1.90Ki  [ = ]       0    .debug_str
  -0.5% -4.44Ki  [ = ]       0    .debug_info
  -0.4% -10.5Ki  -0.9% -1.33Ki    TOTAL

use_config/stm32h7

   text	   data	    bss	    dec	    hex	filename
 123612	    260	  14344	 138216	  21be8	rmk-stm32h7
Diff
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +1.1%    +864  [ = ]       0    .debug_ranges
  +0.0%     +60  [ = ]       0    .debug_loc
  +6.5%      +3  [ = ]       0    [Unmapped]
  -0.1%     -16  -0.1%     -16    .rodata
  -0.2%     -72  [ = ]       0    .debug_aranges
  -1.2%    -216  [ = ]       0    .debug_frame
  -1.2%    -416  [ = ]       0    .symtab
  -0.8% -1.10Ki  [ = ]       0    .debug_line
  -1.6% -1.11Ki  [ = ]       0    .strtab
  -1.2% -1.27Ki  -1.2% -1.27Ki    .text
  -0.1% -1.38Ki  [ = ]       0    .debug_str
  -0.4% -4.08Ki  [ = ]       0    .debug_info
  -0.2% -8.75Ki  -0.9% -1.29Ki    TOTAL

@HaoboGu
Copy link
Owner

HaoboGu commented Sep 2, 2025

I think a separate BidirectionalMatrix which implements Matrix trait should be added. That's why Matrix trait exists: in this way the complex feature gate trick could be avoided and the users can still choose their matrix easily.

@archnode
Copy link
Author

archnode commented Sep 3, 2025

Thank you for taking a look. You're right - I thought I could get away with feature gates, but I also had to change the signature a bit, which makes a separate BidirectionalMatrix a much better solution.

I updated my implementation and will try to complete and test it with my prototype in the next days.

@archnode
Copy link
Author

archnode commented Sep 8, 2025

I changed the implementation a bit to simplify the pin setup and add a "scan matrix" that explicitly specifies the scanned pairs (this is also how PRK does it). I think its good to make the matrix scanning a bit more explicit, this also allows for a more flexible pin setups.

  • Currently the new matrix seems to work fine with my prototype.
  • the scan process currently is very simple and switches each pin through input / output each read. We could probably improve on this by pre-sorting matching output-pins and only conditionally switching.
  • Async matrix functionality currently missing
  • Flex pin implementation currently only for RP2040

Example configuration: https://github.com/archnode/weaver-keyboard-rmk/blob/main/src/main.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants