Skip to content

wireless: fix raw HID over the 2.4 GHz receiver - #549

Open
brbla wants to merge 1 commit into
Keychron:2025q3from
brbla:fix-wireless-raw-hid
Open

brbla wants to merge 1 commit into
Keychron:2025q3from
brbla:fix-wireless-raw-hid

Conversation

@brbla

@brbla brbla commented Nov 30, 2026

Copy link
Copy Markdown

Description

Raw HID (VIA / Keychron Launcher protocol) through the 2.4 GHz receiver (Keychron Link, 3434:d030) gets no answer from the keyboard. The receiver exposes the raw HID interface (usage page 0xFF60) and lkbt51.c turns the forwarded requests into EVT_RAW_HID events, but wireless_event_task() cannot handle them:

  • the guard tests WILRESS_RAW_ENABLE (typo) instead of WIRELESS_RAW_ENABLE
  • the VIA branch calls via_raw_hid_receive(), which does not exist anywhere in the tree, and the non-VIA branch calls kc_raw_hid_rx(), which wireless.c does not declare. With only the typo fixed, the firmware fails to build (implicit declaration) as soon as WIRELESS_RAW_ENABLE is defined.

The handler now calls raw_hid_receive(src, data, length) in both cases, the same entry point USB uses (tmk_core/protocol/chibios/usb_main.c). With VIA that is the VIA handler in quantum/via.c; without VIA it is defined in keychron_raw_hid.c and forwards to kc_raw_hid_rx().

WIRELESS_RAW_ENABLE stays opt-in (nothing defines it), so existing builds are not affected. A keyboard turns it on with OPT_DEFS += -DWIRELESS_RAW_ENABLE in its rules.mk.

The reply goes back through kc_raw_hid_send(RAW_HID_SRC_WIRELESS, …) (directly, or via via_raw_hid_send() for commands the VIA handler answers) → wireless_transport.send_raw_hid while the receiver is connected. In VIA builds kc_raw_hid_rx() already adds the VID/PID to the protocol version reply for a non-USB source, so the rest of the path appears intended for this.

Testing

  • 2025q3 + this PR builds for keychron/k10_he/ansi:keychron (VIA) and keychron/k10_he/ansi:default (no VIA), each without and with WIRELESS_RAW_ENABLE. With it, wireless.o references raw_hid_receive in both keymaps, and wireless.c compiles without warnings. The non-VIA variant was only built, not run.
  • On a K10 HE ANSI with a Keychron Link I ran the keychron (VIA) keymap with 2025q3 + this fix (an earlier revision whose VIA branch is identical) + WIRELESS_RAW_ENABLE + my fork's own features: lighting extras, an extra command id, init/task/key-handling hooks and its own EEPROM area. They change other parts of keychron_raw_hid.c, the RGB code and one LED-shutdown check in wireless/indicator.c, but not wireless_event_task() or the raw HID transport (lkbt51.c, transport.c).
    • A full read through the receiver (keymap, macros, VIA lighting, per-key RGB, mixed regions, indicators, all HE profiles via 0xA9 0x12, calibration, misc settings) matches the same read over USB made just before flashing, except for calibration values the firmware keeps refining (two reads over USB differ in the same way). The full read took about 3 s.
    • Writes through the receiver, each one read back and then restored: keycode, VIA lighting, the macro buffer (multi-packet, full 32-byte reports), HE travel per key, a DKS key (27-byte request), a gamepad key and SOCD. The gamepad curve and the wireless LPM timeouts were rewritten with their current values.
    • On a later build of my fork, 0xA9 0x30 realtime travel through the receiver reported pressed keys down to the full 4.08 mm. That build also answers 0x02 0x03 from the analog matrix for any source (see Notes).
    • In the same run on the later build (keys pressed and text typed through the receiver while polling), 25 of at least 7,515 requests got no reply (at most about 0.33 %; 20 of them my fork's own command, 3 × 0x02 0x03 and 2 × 0xA9 0x30); the host can simply resend them. The text typed meanwhile arrived complete (checked by eye, not by script). I did not look into this further and this PR does not change it.
  • Over Bluetooth the host sees no raw HID (0xFF60) interface, so this applies to the 2.4 GHz receiver only.

Notes (not changed by this PR)

  • On analog-matrix boards, 0x02 0x03 (switch matrix state) from the receiver is answered by the generic VIA handler with the digital matrix, because kc_raw_hid_rx() sends only USB requests to send_analog_matrix(). Keys in DKS or gamepad mode are therefore missing from the key tester over the receiver.
  • lkbt51.c uses one static raw_hid_data buffer for every queued EVT_RAW_HID, so two requests queued back to back would overwrite each other.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

  • none filed

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

🤖 Generated with Claude Code

The EVT_RAW_HID handler could never be compiled in:
- the guard tested WILRESS_RAW_ENABLE (typo) instead of
  WIRELESS_RAW_ENABLE
- the VIA branch called via_raw_hid_receive(), which does not exist,
  and the non-VIA branch called kc_raw_hid_rx(), which wireless.c
  does not declare

Call raw_hid_receive(src, data, length) in both cases, the same entry
point USB uses (tmk_core/protocol/chibios/usb_main.c). Without VIA it
is defined in keychron_raw_hid.c and forwards to kc_raw_hid_rx().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant