Skip to content

fix(keyboard): re-strike a shared HID usage so a roll types both keys - #1079

Open
snowyukitty wants to merge 2 commits into
rmk-rs:mainfrom
snowyukitty:fix/shared-usage-roll-second-keydown
Open

fix(keyboard): re-strike a shared HID usage so a roll types both keys#1079
snowyukitty wants to merge 2 commits into
rmk-rs:mainfrom
snowyukitty:fix/shared-usage-roll-second-keydown

Conversation

@snowyukitty

Copy link
Copy Markdown

Closes #809.

The defect

Two matrix positions can map to the same HID usage. On the reporter's board <
is KC_NONUS_BSLASH and > is LSFT(KC_NONUS_BSLASH) — different keys, one
usage, differing only by the shift modifier.

State tracking is already right. register_keycode gives each position its own
report slot, so held_keycodes holds NonusBackslash twice with two distinct
owners. The report is where they merge (keyboard.rs:1886):

for k in self.held_keycodes {
    let code = k as u8;
    if code != 0 && !keycodes[..n].contains(&code) {

A USB HID host emits a character on the transition of a usage from absent to
present in the keycode array. A usage that is already present and merely gains
a modifier produces nothing. So rolling < into > sends:

["NonusBackslash"]
["LShift","NonusBackslash"]
["LShift","NonusBackslash"]
[]

One make for two intended keystrokes. Roll < into > and type < again and
the host receives < <, which is the << in the report.

Why the obvious repair is not available

The deduplication is deliberate. fix(keyboard): deduplicate held keycodes in the keyboard report added it along with
hid_reports::shared_keycode_roll_keeps_second_key, whose comment states the
intent: the shared usage stays down until the last holder releases it. Before
that, releasing the first of two owners cleared a usage the second owner still
held — a dropped key.

These are two halves of one problem. Removing the deduplication brings back the
dropped key; keeping only the deduplication keeps the lost character. Both have
to hold at once.

The change

A press that gives an already-held usage an additional owner now sends one
extra report first: the ordinary report with only that usage suppressed. The
normal report follows, so the host observes a fresh absent→present transition.

Everything else stays. The suppressed report keeps every other held usage and
every held modifier — it is never an all-clear report — and the usage still
remains down until the last owner releases it.

The decision comes from counting how many report slots hold that usage on
behalf of a registered key event, immediately before and immediately after
registration. That is an observation of what registration did rather than a
prediction of what it would do, which matters in three places:

  • a real modifier never enters held_keycodes, so it can never re-strike a
    usage — holding a key and tapping Shift is one activation plus an
    independent modifier;
  • two positions bound to the same plain keycode gain an owner just as a
    SHIFTED() pair does, so they roll into two characters too;
  • a press that finds no free slot registers nothing and so gains no owner. It
    synthesises nothing and follows the existing rollover behaviour, rather than
    emitting a stroke for a key the report cannot track.

build_keyboard_report keeps its signature and behaviour for every existing
caller: it now delegates with HidKeyCode::No suppressed, which is never in a
report anyway. The extra report goes through send_report like any other. No
allocation, no feature gate, no new configuration, no change to
KeyboardReport's shape or the six-key array.

One extra report per re-strike is the intended cost. No other report count
changes.

Tests

rmk/tests/scenarios/shared_usage_restrike.toml, twelve cases, plus
shared_keycode_roll_keeps_second_key updated rather than replaced — its
subject, that the usage stays down while an owner holds it, is exactly the half
this must preserve, so only the new transition report is inserted into its
expectations and its comment now states both halves.

On this branch all five RMK_TEST_FEATURESETS rows pass:

features tests
(none) 453 passed
vial,host_lock,_no_usb,steno,passkey_entry 520 passed
rynk,_ble,split,async_matrix,storage 569 passed
dongle,_ble,storage 492 passed
dongle,vial,_ble,storage 520 passed

On unmodified main with the same test files, the rynk,_ble,split,… row
gives 561 passed, 8 failed. The eight are the ones that assert the new
transition:

shared_keycode_roll_keeps_second_key, rolled_shared_usage_types_both_keys,
reverse_roll_shifted_first, rolled_same_keycode_two_positions_types_twice,
shared_usage_survives_first_release, transition_preserves_other_held_keys,
transition_preserves_held_modifiers,
plain_keycode_restrike_preserves_an_unrelated_held_key.

The rest pass on main too, and they are what keeps the change honest rather
than just proving the symptom: each names a case where a stroke must not be
synthesised, so a rule that fired too eagerly would break them.

  • held_key_plus_tapped_real_shift_types_once and
    modifier_only_change_sends_no_transition — a modifier arriving or leaving
    while a usage is held changes the modifier byte and nothing else;
  • sequential_typing_is_unchanged — the already-correct < > < stream from
    the report is byte-identical after the change;
  • held_key_sends_no_extra_reports — one key held sends exactly one make and
    one break, so host auto-repeat is not chopped;
  • an_unregistered_seventh_press_synthesises_no_stroke — with the six-key array
    full, a seventh press mapped to a held usage registers nothing, gains no
    owner, and emits no extra report.

They do not cover every possible false positive; they cover those four classes.

cargo fmt --all -- --check on nightly and
cargo clippy … --all-targets -- -D warnings are both clean.

A limit of this validation

The transition report and the make that follows are two consecutive reports,
intended to become two interrupt transfers over USB or two notifications over
BLE HID. A link that coalesced or dropped one would hide the make again.

The scenario harness asserts the report stream, so it proves the firmware
emits both. It does not observe an actual transfer on either transport, so it
proves nothing about delivery over USB or BLE, and I have not tested that on
hardware.

Two matrix positions can map to one HID usage - `<` and its SHIFTED() twin
`>`, or the same keycode bound twice. Each press takes its own report slot,
but the report deduplicates held keycodes, so rolling from one to the other
leaves the usage continuously down. A host emits a character on a usage's
absent->present transition, so the second key produces nothing and `<><`
arrives as `<<`.

The deduplication is deliberate and stays: without it, releasing the first
of two owners clears a usage the second still holds. Both halves have to
hold at once.

So a press that re-strikes a usage another position already holds now sends
one extra report first, the ordinary report with only that usage suppressed.
Every other held usage and every held modifier stay present, and the usage
still remains down until the last owner releases it.

Detection keys on ownership rather than on the modifier set, so two
positions bound to the same plain keycode also roll into two characters,
while a real Shift tapped during a hold does not re-strike anything.
build_keyboard_report keeps its signature and behaviour for every existing
caller. One extra report per re-strike; no other report count changes.

Closes rmk-rs#809
@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown

Size Report

Example main PR Diff .text .data .bss
use_config/nrf52832_ble 391.2 KiB 391.4 KiB +0.05% ⬆️ +212 0 0
use_config/nrf52840_ble 434.5 KiB 434.4 KiB -0.02% ⬇️ -92 0 0
use_config/nrf52840_ble_split (central) 495.3 KiB 495.5 KiB +0.04% ⬆️ +204 0 0
use_config/nrf52840_ble_split (peripheral) 316.6 KiB 316.6 KiB +0.00% 0 0 0
use_config/pi_pico_w_ble 677.3 KiB 677.5 KiB +0.02% ⬆️ +168 0 0
use_config/rp2040 146.1 KiB 146.3 KiB +0.10% ⬆️ +156 0 0
use_config/rp2040_split (central) 161.0 KiB 161.2 KiB +0.13% ⬆️ +216 0 0
use_config/rp2040_split (peripheral) 27.9 KiB 27.9 KiB +0.00% 0 0 0
use_config/stm32f1 62.4 KiB 62.6 KiB +0.30% ⬆️ +184 0 +8
use_config/stm32h7 100.6 KiB 100.8 KiB +0.23% ⬆️ +236 0 +8
use_rust/nrf52832_ble 379.6 KiB 379.8 KiB +0.05% ⬆️ +216 0 0
use_rust/nrf52840_ble 428.9 KiB 429.1 KiB +0.05% ⬆️ +232 0 0
use_rust/nrf52840_ble_split (central) 493.7 KiB 493.8 KiB +0.03% ⬆️ +156 0 0
use_rust/nrf52840_ble_split (peripheral) 308.6 KiB 308.6 KiB +0.00% 0 0 0
use_rust/pi_pico_w_ble 676.7 KiB 676.8 KiB +0.01% ⬆️ +136 0 0
use_rust/rp2040 145.7 KiB 145.9 KiB +0.13% ⬆️ +208 0 0
use_rust/rp2040_split (central) 159.6 KiB 159.9 KiB +0.16% ⬆️ +268 0 0
use_rust/rp2040_split (peripheral) 28.3 KiB 28.3 KiB +0.00% 0 0 0
use_rust/stm32f1 61.7 KiB 61.9 KiB +0.31% ⬆️ +188 0 +8
use_rust/stm32h7 119.1 KiB 119.3 KiB +0.16% ⬆️ +200 0 0
use_config/nrf52832_ble — 391.2 KiB → 391.4 KiB (+0.05% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 358220	   8620	  33992	 400832	  61dc0	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 358008	   8620	  33992	 400620	  61cec	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +5.17Ki  [ = ]       0    .debug_str
  +0.1% +1.95Ki  [ = ]       0    .debug_info
  +0.0%    +329  [ = ]       0    .debug_loc
  +0.1%    +254  [ = ]       0    .debug_line
  +0.1%    +196  +0.1%    +196    .text
  +0.1%    +144  [ = ]       0    .symtab
  +0.1%    +136  [ = ]       0    .debug_ranges
  +0.2%     +84  [ = ]       0    .debug_frame
  +0.1%     +24  [ = ]       0    .debug_aranges
  +0.0%     +16  +0.0%     +16    .rodata
   +27%     +12  [ = ]       0    [Unmapped]
  -0.0%    -105  [ = ]       0    .strtab
  +0.1% +8.18Ki  +0.1%    +212    TOTAL
use_config/nrf52840_ble — 434.5 KiB → 434.4 KiB (-0.02% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 392208	   8628	  44024	 444860	  6c9bc	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 392300	   8628	  44024	 444952	  6ca18	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2% +7.44Ki  [ = ]       0    .debug_str
  +0.1% +2.15Ki  [ = ]       0    .debug_info
  +0.1%    +234  [ = ]       0    .debug_line
  +0.1%    +233  [ = ]       0    .strtab
  +0.1%    +176  [ = ]       0    .symtab
  +0.2%     +84  [ = ]       0    .debug_frame
  +0.0%     +24  [ = ]       0    .debug_aranges
  +0.0%     +16  +0.0%     +16    .rodata
 -12.5%      -7  [ = ]       0    [Unmapped]
  -0.0%     -72  [ = ]       0    .debug_ranges
  -0.0%     -90  [ = ]       0    .debug_loc
  -0.0%    -108  -0.0%    -108    .text
  +0.1% +10.1Ki  -0.0%     -92    TOTAL
use_config/nrf52840_ble_split (central) — 495.3 KiB → 495.5 KiB (+0.04% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 448608	   8668	  50120	 507396	  7be04	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 448404	   8668	  50120	 507192	  7bd38	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2% +7.65Ki  [ = ]       0    .debug_str
  +0.1% +2.17Ki  [ = ]       0    .debug_info
  +0.0%    +319  [ = ]       0    .debug_loc
  +0.1%    +276  [ = ]       0    .debug_line
  +0.0%    +203  [ = ]       0    .strtab
  +0.0%    +188  +0.0%    +188    .text
  +0.1%    +144  [ = ]       0    .symtab
  +0.1%    +136  [ = ]       0    .debug_ranges
  +0.2%     +84  [ = ]       0    .debug_frame
  +0.0%     +24  [ = ]       0    .debug_aranges
  +0.0%     +16  +0.0%     +16    .rodata
 -21.7%     -15  [ = ]       0    [Unmapped]
  +0.1% +11.2Ki  +0.0%    +204    TOTAL
use_config/nrf52840_ble_split (peripheral) — 316.6 KiB → 316.6 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 290252	   8508	  25472	 324232	  4f288	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 290252	   8508	  25472	 324232	  4f288	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +3  [ = ]       0    .debug_str
  -0.0%      -2  [ = ]       0    .strtab
  -9.0%      -7  [ = ]       0    [Unmapped]
  -0.0%     -10  [ = ]       0    .debug_loc
  -0.0%     -16  [ = ]       0    TOTAL
use_config/pi_pico_w_ble — 677.3 KiB → 677.5 KiB (+0.02% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 639684	      0	  54056	 693740	  a95ec	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 639516	      0	  54056	 693572	  a9544	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2% +7.36Ki  [ = ]       0    .debug_str
  +0.1% +1.90Ki  [ = ]       0    .debug_info
  +0.0%    +569  [ = ]       0    .debug_loc
  +0.0%    +173  [ = ]       0    .strtab
  +0.0%    +160  +0.0%    +160    .text
  +0.1%    +112  [ = ]       0    .symtab
  +0.2%     +64  [ = ]       0    .debug_frame
  +0.0%     +64  [ = ]       0    .debug_ranges
  +0.0%     +48  [ = ]       0    .debug_line
  +0.0%     +16  [ = ]       0    .debug_aranges
  +0.0%      +8  +0.0%      +8    .rodata
 -20.0%     -11  [ = ]       0    [Unmapped]
  -0.4%     -39  [ = ]       0    .debug_abbrev
  +0.1% +10.4Ki  +0.0%    +168    TOTAL
use_config/rp2040 — 146.1 KiB → 146.3 KiB (+0.10% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 135852	      0	  13932	 149784	  24918	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 135696	      0	  13932	 149628	  2487c	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.3% +5.36Ki  [ = ]       0    .debug_str
  +0.2% +2.03Ki  [ = ]       0    .debug_info
  +0.1%    +157  [ = ]       0    .debug_line
  +0.1%    +140  +0.1%    +140    .text
  +0.1%     +80  [ = ]       0    .debug_ranges
  +0.4%     +64  [ = ]       0    .debug_frame
  +0.1%     +48  [ = ]       0    .symtab
  +0.1%     +16  [ = ]       0    .debug_aranges
  +0.1%     +16  +0.1%     +16    .rodata
  +1.6%      +1  [ = ]       0    [Unmapped]
  -0.0%     -34  [ = ]       0    .strtab
  -0.0%     -67  [ = ]       0    .debug_loc
  +0.2% +7.80Ki  +0.1%    +156    TOTAL
use_config/rp2040_split (central) — 161.0 KiB → 161.2 KiB (+0.13% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 150048	      0	  14996	 165044	  284b4	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 149832	      0	  14996	 164828	  283dc	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.4% +7.39Ki  [ = ]       0    .debug_str
  +0.2% +1.97Ki  [ = ]       0    .debug_info
  +0.1%    +379  [ = ]       0    .debug_loc
  +0.1%    +278  [ = ]       0    .debug_line
  +0.2%    +200  +0.2%    +200    .text
  +0.1%    +198  [ = ]       0    .strtab
  +0.2%    +192  [ = ]       0    .debug_ranges
  +0.4%    +144  [ = ]       0    .symtab
  +0.3%     +64  [ = ]       0    .debug_frame
  +0.1%     +16  [ = ]       0    .debug_aranges
  +0.1%     +16  +0.1%     +16    .rodata
   +17%      +7  [ = ]       0    [Unmapped]
  +0.3% +10.8Ki  +0.1%    +216    TOTAL
use_config/rp2040_split (peripheral) — 27.9 KiB → 27.9 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  25632	     60	   2876	  28568	   6f98	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  25632	     60	   2876	  28568	   6f98	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +2.0%      +1  [ = ]       0    [Unmapped]
  -0.0%      -5  [ = ]       0    .debug_str
  -0.0%      -4  [ = ]       0    TOTAL
use_config/stm32f1 — 62.4 KiB → 62.6 KiB (+0.30% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  57628	     28	   6404	  64060	   fa3c	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  57444	     28	   6396	  63868	   f97c	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.8% +7.49Ki  [ = ]       0    .debug_str
  +0.4% +2.06Ki  [ = ]       0    .debug_info
  +0.3%    +430  [ = ]       0    .debug_loc
  +0.3%    +231  [ = ]       0    .debug_line
  +0.5%    +228  [ = ]       0    .strtab
  +0.3%    +184  +0.3%    +184    .text
  +0.3%    +136  [ = ]       0    .debug_ranges
  +0.7%    +128  [ = ]       0    .symtab
  +0.7%     +84  [ = ]       0    .debug_frame
  +0.4%     +24  [ = ]       0    .debug_aranges
  [ = ]       0  +0.1%      +8    .bss
   +16%      +8  [ = ]       0    [Unmapped]
  +0.6% +11.0Ki  +0.3%    +192    TOTAL
use_config/stm32h7 — 100.6 KiB → 100.8 KiB (+0.23% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  94816	    264	   8156	 103236	  19344	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  94580	    264	   8148	 102992	  19250	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.4% +7.38Ki  [ = ]       0    .debug_str
  +0.2% +1.94Ki  [ = ]       0    .debug_info
  +0.4%    +671  [ = ]       0    .debug_loc
  +0.2%    +263  [ = ]       0    .debug_line
  +0.3%    +220  +0.3%    +220    .text
  +0.1%     +94  [ = ]       0    .strtab
  +0.1%     +88  [ = ]       0    .debug_ranges
  +0.1%     +16  +0.1%     +16    .rodata
  [ = ]       0  +0.1%      +8    .bss
  +0.0%      +4  [ = ]       0    .debug_frame
  -0.0%     -16  [ = ]       0    .debug_aranges
 -30.2%     -16  [ = ]       0    [Unmapped]
  -0.3%     -80  [ = ]       0    .symtab
  +0.3% +10.5Ki  +0.2%    +244    TOTAL
use_rust/nrf52832_ble — 379.6 KiB → 379.8 KiB (+0.05% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 346368	   8620	  33936	 388924	  5ef3c	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 346152	   8620	  33936	 388708	  5ee64	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +5.22Ki  [ = ]       0    .debug_str
  +0.1% +2.00Ki  [ = ]       0    .debug_info
  +0.1%    +522  [ = ]       0    .debug_loc
  +0.1%    +213  [ = ]       0    .debug_line
  +0.1%    +200  +0.1%    +200    .text
  +0.1%    +112  [ = ]       0    .symtab
  +0.1%    +104  [ = ]       0    .debug_ranges
  +0.2%     +68  [ = ]       0    .debug_frame
  +0.0%     +16  [ = ]       0    .debug_aranges
  +0.0%     +16  +0.0%     +16    .rodata
   +23%     +14  [ = ]       0    [Unmapped]
  -0.1%    -147  [ = ]       0    .strtab
  +0.1% +8.31Ki  +0.1%    +216    TOTAL
use_rust/nrf52840_ble — 428.9 KiB → 429.1 KiB (+0.05% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 389544	   8628	  41256	 439428	  6b484	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 389312	   8628	  41256	 439196	  6b39c	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2% +7.43Ki  [ = ]       0    .debug_str
  +0.1% +2.36Ki  [ = ]       0    .debug_info
  +0.2%    +626  [ = ]       0    .debug_line
  +0.1%    +446  [ = ]       0    .debug_loc
  +0.1%    +216  +0.1%    +216    .text
  +0.1%    +200  [ = ]       0    .debug_ranges
  +0.0%    +164  [ = ]       0    .strtab
  +0.1%    +112  [ = ]       0    .symtab
  +0.1%     +68  [ = ]       0    .debug_frame
  +0.0%     +16  [ = ]       0    .debug_aranges
  +0.0%     +16  +0.0%     +16    .rodata
  -4.8%      -3  [ = ]       0    [Unmapped]
  +0.1% +11.6Ki  +0.1%    +232    TOTAL
use_rust/nrf52840_ble_split (central) — 493.7 KiB → 493.8 KiB (+0.03% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 445468	   8668	  51536	 505672	  7b748	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 445312	   8668	  51536	 505516	  7b6ac	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2% +8.30Ki  [ = ]       0    .debug_str
  +0.1% +2.08Ki  [ = ]       0    .debug_info
  +0.1%    +253  [ = ]       0    .strtab
  +0.0%    +248  [ = ]       0    .debug_loc
  +0.1%    +232  [ = ]       0    .debug_line
  +0.0%    +140  +0.0%    +140    .text
  +0.0%    +120  [ = ]       0    .debug_ranges
  +0.1%    +112  [ = ]       0    .symtab
  +0.1%     +68  [ = ]       0    .debug_frame
  +0.0%     +16  [ = ]       0    .debug_aranges
  +0.0%     +16  +0.0%     +16    .rodata
   +11%      +6  [ = ]       0    [Unmapped]
  +0.1% +11.6Ki  +0.0%    +156    TOTAL
use_rust/nrf52840_ble_split (peripheral) — 308.6 KiB → 308.6 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 282444	   8508	  25016	 315968	  4d240	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 282444	   8508	  25016	 315968	  4d240	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +574  [ = ]       0    .debug_str
  +0.0%     +29  [ = ]       0    .strtab
 -17.3%      -9  [ = ]       0    [Unmapped]
  -0.0%     -10  [ = ]       0    .debug_loc
  +0.0%    +584  [ = ]       0    TOTAL
use_rust/pi_pico_w_ble — 676.7 KiB → 676.8 KiB (+0.01% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 639336	      0	  53736	 693072	  a9350	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 639200	      0	  53736	 692936	  a92c8	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2% +7.39Ki  [ = ]       0    .debug_str
  +0.1% +2.09Ki  [ = ]       0    .debug_info
  +0.0%    +501  [ = ]       0    .debug_loc
  +0.1%    +192  [ = ]       0    .strtab
  +0.0%    +120  +0.0%    +120    .text
  +0.1%    +112  [ = ]       0    .symtab
  +0.0%     +87  [ = ]       0    .debug_line
  +0.2%     +64  [ = ]       0    .debug_frame
  +0.0%     +64  [ = ]       0    .debug_ranges
   +51%     +25  [ = ]       0    [Unmapped]
  +0.0%     +16  [ = ]       0    .debug_aranges
  +0.0%     +16  +0.0%     +16    .rodata
  -0.4%     -39  [ = ]       0    .debug_abbrev
  +0.1% +10.6Ki  +0.0%    +136    TOTAL
use_rust/rp2040 — 145.7 KiB → 145.9 KiB (+0.13% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 135624	      0	  13764	 149388	  2478c	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 135416	      0	  13764	 149180	  246bc	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.3% +5.43Ki  [ = ]       0    .debug_str
  +0.2% +2.01Ki  [ = ]       0    .debug_info
  +0.2%    +663  [ = ]       0    .debug_loc
  +0.2%    +192  +0.2%    +192    .text
  +0.1%    +173  [ = ]       0    .debug_line
  +0.4%    +144  [ = ]       0    .symtab
  +0.1%     +96  [ = ]       0    .debug_ranges
  +0.4%     +64  [ = ]       0    .debug_frame
  +0.1%     +16  [ = ]       0    .debug_aranges
  +0.1%     +16  +0.1%     +16    .rodata
  -0.0%      -8  [ = ]       0    .strtab
 -25.5%     -14  [ = ]       0    [Unmapped]
  +0.2% +8.75Ki  +0.1%    +208    TOTAL
use_rust/rp2040_split (central) — 159.6 KiB → 159.9 KiB (+0.16% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 148988	      0	  14740	 163728	  27f90	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 148720	      0	  14740	 163460	  27e84	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.4% +7.46Ki  [ = ]       0    .debug_str
  +0.2% +2.02Ki  [ = ]       0    .debug_info
  +0.2%    +404  [ = ]       0    .debug_line
  +0.2%    +252  +0.2%    +252    .text
  +0.2%    +192  [ = ]       0    .debug_ranges
  +0.1%    +181  [ = ]       0    .strtab
  +0.3%     +64  [ = ]       0    .debug_frame
  +0.1%     +48  [ = ]       0    .symtab
  +0.1%     +16  [ = ]       0    .debug_aranges
  +0.1%     +16  +0.1%     +16    .rodata
 -21.5%     -14  [ = ]       0    [Unmapped]
  -0.1%    -396  [ = ]       0    .debug_loc
  +0.2% +10.2Ki  +0.2%    +268    TOTAL
use_rust/rp2040_split (peripheral) — 28.3 KiB → 28.3 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  25740	     60	   3140	  28940	   710c	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  25740	     60	   3140	  28940	   710c	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +8.1%      +3  [ = ]       0    [Unmapped]
  -0.0%      -1  [ = ]       0    .strtab
  -0.0%      -6  [ = ]       0    .debug_str
  -0.0%      -4  [ = ]       0    TOTAL
use_rust/stm32f1 — 61.7 KiB → 61.9 KiB (+0.31% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  56992	     28	   6324	  63344	   f770	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  56804	     28	   6316	  63148	   f6ac	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.8% +7.49Ki  [ = ]       0    .debug_str
  +0.4% +2.05Ki  [ = ]       0    .debug_info
  +0.3%    +384  [ = ]       0    .debug_loc
  +0.3%    +281  [ = ]       0    .debug_line
  +0.5%    +228  [ = ]       0    .strtab
  +0.5%    +200  [ = ]       0    .debug_ranges
  +0.3%    +188  +0.3%    +188    .text
  +0.7%    +128  [ = ]       0    .symtab
  +0.7%     +84  [ = ]       0    .debug_frame
  +0.5%     +24  [ = ]       0    .debug_aranges
  [ = ]       0  +0.1%      +8    .bss
  +8.2%      +4  [ = ]       0    [Unmapped]
  +0.6% +11.0Ki  +0.3%    +196    TOTAL
use_rust/stm32h7 — 119.1 KiB → 119.3 KiB (+0.16% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 107780	    320	  14052	 122152	  1dd28	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 107580	    320	  14052	 121952	  1dc60	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.3% +7.32Ki  [ = ]       0    .debug_str
  +0.2% +2.05Ki  [ = ]       0    .debug_info
  +0.1%    +304  [ = ]       0    .debug_loc
  +0.2%    +219  [ = ]       0    .strtab
  +0.2%    +200  +0.2%    +200    .text
  +0.1%    +136  [ = ]       0    .debug_line
  +0.2%    +136  [ = ]       0    .debug_ranges
  +0.4%    +128  [ = ]       0    .symtab
  +0.4%     +84  [ = ]       0    .debug_frame
  +0.1%     +24  [ = ]       0    .debug_aranges
 -18.5%     -10  [ = ]       0    [Unmapped]
  +0.2% +10.6Ki  +0.2%    +200    TOTAL

@HaoboGu

HaoboGu commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Please simplify and clean the code. The current code is low-quality

`build_keyboard_report` takes the suppressed usage as a parameter instead of
delegating to a second builder, and `send_keyboard_report_with_resolved_modifiers`
calls the suppressing send instead of repeating the send-and-yield pair. Two
added helpers rather than four.

Comments are cut back to the density of the surrounding file, here and in the
scenario header, which was longer than any of its neighbours.

No behaviour change: same condition, same report stream, and the same test
counts on every RMK_TEST_FEATURESETS row.
@snowyukitty

Copy link
Copy Markdown
Author

Simplified, thanks.

  • build_keyboard_report now takes the suppressed usage as a parameter itself, so the second builder that used to sit behind it is gone, and send_keyboard_report_with_resolved_modifiers calls the suppressing send instead of repeating the send-and-yield pair. Two new functions instead of three, and no delegation layer.
  • The comment blocks in keyboard.rs and in the scenario header are shortened.

Against the base this branch was cut from, keyboard.rs now adds 29 lines and removes 5; before it added 57 and removed 1.

Behaviour is unchanged, and the test counts on every RMK_TEST_FEATURESETS row are the same as before (453 / 520 / 569 / 492 / 520). cargo clippy -- -D warnings and cargo +nightly fmt --check are clean.

If you had a different shape in mind — no new function at all, or the ownership count folded into register_key — say which and I'll redo it.

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.

Missed keystrokes when alternating MODIFIER(KC) and KC in quick succession

2 participants