23 Commits

Author SHA1 Message Date
Markus Fritsche bdb0e2d99f Fix BIOS-mode 10x repeat: change-detection + real SET_IDLE / SET_PROTOCOL
Symptom: in boot protocol (BIOS / UEFI) one keypress emitted ~10
characters. _kbd_write_ep1 was rebuilding and re-arming EP1 on every
USB SOF poll; report-mode HID drivers diff consecutive reports and
collapse duplicates, but boot-mode hosts treat each IN as a fresh
press.

Changes:
- Add 9-byte lastEP1_* shadow in bank-0 RAM, plus hidProtocol /
  hidIdleRate / hidIdleCounter state.
- _kbd_write_ep1: compare freshly-built bytes against the shadow with
  CMPRS A, M. On match, only resend when the SET_IDLE counter has
  expired; otherwise NAK silently. On mismatch, copy to shadow and
  send.
- _usb_htd_hid_set_idle: actually capture wValueHi (HID 1.11 §7.2.4)
  instead of just ACKing — store as hidIdleRate, reload counter.
- New _usb_htd_hid_set_protocol: capture wValueLo (HID 1.11 §7.2.5)
  into hidProtocol; invalidate shadow so the new wire format ships
  immediately. Wire dispatch table (0x210b) to it instead of the
  default STALL handler.
- _usb_sof: tick hidIdleCounter when rate is non-zero so the resend
  fires at idle-rate cadence.
- _kbd_write_ep1 sets UE1R_C=8 in boot protocol, 9 in report. The
  9th byte (consumer/extraState0) is kept in the EP1 buffer slack
  but truncated on the wire under boot protocol.

Net effect: a held key in BIOS mode now produces one keydown plus one
keyup, matching report-mode behaviour.
2026-04-13 15:08:30 +00:00
test0r 5a1784cacd Fix FN+middle: pass through as middle-drag instead of scroll
FN+middle was scrolling same as plain middle because the FN-alt path
always converted TrackPoint to wheel/pan. Now FN+middle jumps to
normal mouse passthrough (REL_X/REL_Y + BTN_MIDDLE), giving proper
middle-drag behavior. FN without middle still does back/forward + scroll.

Verified on real hardware via evtest on higgs (Pi 5).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 20:40:35 +02:00
test0r 5786ab888b Add middle-button scroll, CapsLock LED, FN+F7-F12, HID fixes
Middle-button scroll state machine (3-state: idle/undecided/scrolling)
with 150ms timeout — short press sends middle click, hold converts
TrackPoint movement to scroll wheel events. FN+middle passes through.

Also implements:
- CapsLock LED feedback via host LED output reports (P5.3/PWM0)
- FN+F7 (LGUI+P), FN+F9 (LGUI+I), FN+F11 (LCTRL+LALT+TAB)
- HID GET_REPORT with per-interface responses
- SET/CLEAR FEATURE for DEVICE_REMOTE_WAKEUP

Tested with 23/23 simulator tests passing (test_scroll.py).
Flash space: 10,238/10,239 words used (1 word free).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 05:54:22 +00:00
Tobias Diedrich b38d56a653 Add extra FN key actions 2022-01-24 23:23:40 +01:00
Tobias Diedrich fef19b7759 Add FN-based mouse mode switch
When FN is held:
- Remap buttons to back/forward buttons
- Remap Y-axis as scroll and X-axis as pan
2022-01-23 22:40:26 +01:00
Tobias Diedrich 25354c4792 Always tickle watchdog in main loop
Otherwise during initial setup or wakeup, nothing may happen for long
enough to trigger a watchdog reset into the bootloader.
2022-01-23 16:51:51 +01:00
Tobias Diedrich a264ecbc27 Add debug function for writing I2C data to trackpoint 2022-01-23 16:41:44 +01:00
Tobias Diedrich e1c342b8e6 Add debug function for poking ram 2022-01-23 16:35:36 +01:00
Tobias Diedrich cf89637148 Add built-in default settings
These are read on startup to set defaults for:
- debug UART (now defaults to disabled)
- FN/CTRL swap
- FN key row lock (FnLk)
2022-01-23 16:29:06 +01:00
Tobias Diedrich fefede36ed Enable trackpoint HID device
Wheel is declared, but not supported yet, otherwise seems to work :)
2022-01-23 15:07:27 +01:00
Tobias Diedrich 4270a2dfa5 Check for slave clock stretching
This indeed fixes the values read back:
80000000ff  No buttons, no movement
80010000ff  Left button
80050000ff  Left+right buttons
80070000ff  All buttons
800012fdff  Force applied
80000fffff  force applied
2022-01-22 23:50:42 +01:00
Tobias Diedrich b3b5bb5c58 Add basic I2C support
Doesn't quite work yet, most likely the trackpoint interface is using
clock stretching.

Initial values read:
  ff 01 ff fd ff
Later values read:
  ff 80 ff e0 3f  (no buttons pressed)
  ff 80 ff e0 7f  (left button pressed)
  ff 80 ff e0 bf  (right button pressed)
2022-01-22 23:37:11 +01:00
Tobias Diedrich c8c8d47fa6 Add debug USB commands to read ram/flash/i2c 2022-01-22 23:36:02 +01:00
Tobias Diedrich 7c3b45ad94 Enable FnLock and FnCtrlSwap functionality
FN+ESC -> Toggle FnLock for F1-F12 row (suppresses ESC)
FN+RCTRL -> Toggle FnCtrlSwap (does not suppress RCTRL)
2022-01-16 22:21:15 +01:00
Tobias Diedrich 7b59505799 Add FN-key handling for F1-F3
Enables Mute/VolumeUp/VolumeDown
2022-01-16 21:58:00 +01:00
Tobias Diedrich 6088742e91 Additional default requests
Adds support for:
- CLEAR/SET FEATURE (ignored)
- GET_CONFIGURATION (always returns 1 since there is only a single config)
- GET_INTERFACE (always returns 0 since there are not altsettings)
2022-01-16 19:29:35 +01:00
Tobias Diedrich 9742b9f811 Basic SUSPEND/RESUME support 2022-01-16 19:28:11 +01:00
Tobias Diedrich 1f936f875b HID keyboard basics working
Matrix is getting scanned and converted into boot-style HID interface.
Most keys are basically working.
However the enabled debug UART prevents use of the following keys:
DELETE PRINTSCREEN INSERT PAGEUP PAGEDOWN
as S15 is in fixed output mode and thus can't be sensed right now.
2022-01-15 23:10:47 +01:00
Tobias Diedrich 0da158bf01 Add rudimentary key matrix scanning 2022-01-11 17:38:55 +01:00
Tobias Diedrich df120a1c1c Implement USB basics
This now manages to get detected as an HID keyboard by Linux, but does
not yet implement any keyboard scanning logic.
2022-01-10 20:56:08 +01:00
Tobias Diedrich a62584b7a8 Add tentative USB descriptors 2021-12-21 11:54:02 +01:00
Tobias Diedrich afc59d5d75 Add dispatch table helpers and test 2021-12-20 21:44:38 +01:00
Tobias Diedrich 0bf18ebf6f Initial version
Tested:
- UART debug output works at 115200 baud (pad S15)
- Jumps to bootloader on watchdog timeout
- Jumps to bootloader when Return is held while plugging in USB
- Jumps to bootloader when UTX/URX lines are shorted
- Measured max GPIO toggling speed is 3MHz
2021-12-19 16:28:26 +01:00