uhid: emit per-button Usage items instead of Usage Min/Max range#235
Conversation
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one. |
|
Warning Review limit reached
Your plan includes 1 review of capacity. Refill in 10 minutes and 54 seconds. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more review capacity refills, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
📝 WalkthroughWalkthroughEmit HID Button Page usages per-button by resolving configured evdev BTN_* codes via a new mapper, assign fallback usages for unresolved buttons, and update Flydigi Vader5 device output button mappings to explicit ChangesButton Descriptor Per-Usage Resolution
Flydigi Vader5 device mapping
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/io/uhid_descriptor.zig`:
- Around line 247-269: The button_usages array is declared uninitialized and
later fully iterated, which can cause undefined reads; zero-initialize
button_usages (or explicitly fill it with 0) before the enum walk so any slots
not assigned remain 0 and the subsequent `for (button_usages[0..button_count])`
loop and `next_free` allocation see defined values; update the declaration/early
code around `var button_usages: [64]u8`, `occupied`, and the enum `inline for`
block to ensure `button_usages` is initialized before partial population.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3e63ff8e-3994-4bd5-afa5-28c814c48593
📒 Files selected for processing (1)
src/io/uhid_descriptor.zig
|
Thanks @VaisVaisov. The per-button The paddle Usage numbers are off. padctl emits a Minimal fix: map M1 to M4 to Usage 21 to 24 (these resolve to |
Emitting a contiguous Usage Minimum/Maximum range caused the kernel to assign BTN_GAMEPAD+N for the first 16 buttons and then wrap to BTN_MISC, regardless of the evdev codes declared in [output.buttons]. As a result, extra buttons (M1-M4 etc.) landed on wrong BTN_* codes and were invisible to SDL/Steam. Replace the range with one Usage (N) item per button, where N is derived from the button's configured BTN_* code via the kernel's four-group mapping (BTN_GAMEPAD→1-16, BTN_MISC→17-32, BTN_MOUSE→33-48, BTN_JOYSTICK→49-64). Codes outside those groups (e.g. BTN_TRIGGER_HAPPY) receive the lowest free Usage so the descriptor stays valid. Add btnCodeToHidUsage() to implement the reverse BTN_*→Usage mapping.
Replace BTN_TRIGGER_HAPPY* with BTN_MISC (BTN_0-BTN_8) codes. BTN_TRIGGER_HAPPY falls outside the kernel's four HID Button Page groups, so with the UHID backend it received arbitrary Usage numbers rather than stable ones derived from the evdev code. BTN_MISC (0x100-0x10F) maps to Usage 17-32, giving each button a deterministic Usage that SDL can rely on. Also enable C/Z/LM/RM by default — they are standard Vader 5 Pro buttons with known bit positions.
7a0464b to
af8c195
Compare
…slots) (#353) ## Summary - Xbox Elite Series 2 evdev spec reserves `BTN_TRIGGER_HAPPY1..4` for back paddles P1..P4. padctl masquerades Vader 5 Pro as Xbox Elite Series 2 (vid=0x045e pid=0x0b00), so the same slot reservation applies. - PR #235 (1535d8a) enabled `C`/`Z`/`LM`/`RM` in `[output.buttons]` and placed them at `HAPPY1..4`, displacing real back paddles `M1..M4` to `HAPPY5..8` which Steam/games do not recognize as paddles. User-observed regression: pressing extra face buttons (C/Z) appeared as back-paddle input; pressing real back paddles produced no input. - Move `M1..M4` to `HAPPY1..4` (preserving the M2/M3 swap per PR #323's intent so Vader M2 lands at the Steam Elite P3 slot). Push `C/Z/LM/RM/O` to `HAPPY9..13` — stable evdev codes but no longer in the paddle reserved range. - Update companion test in `src/io/uhid_descriptor.zig` whose hardcoded HAPPY values and USAGE-number offsets propagated from the TOML. - Add regression test in `src/test/validate_e2e_test.zig`: (1) positive lock M1..M4 → HAPPY1..4 with M2/M3 swap; (2) structural invariant — none of C/Z/LM/RM/O fall in HAPPY1..4 paddle range. ## Test plan - [x] `zig build test` green in canonical Docker image (1558 tests, 7 skipped) - [x] Falsifiability: setting `M1 = BTN_TRIGGER_HAPPY5` fires the positive-lock test and the uhid_descriptor companion test - [x] User local hardware verification (Flydigi Vader 5 Pro) with `evtest /dev/input/event26`: physical M1..M4 → HAPPY1..4 confirmed, physical C/Z/LM/RM → HAPPY9..12 confirmed - [x] CI: build / coverage / lean / e2e / install / pkg / systemd hardening compat / distro-check (debian-12 + fedora-41) / tsan all green Refs #235
Problem
buildFromOutputemittedUsage Minimum (1) / Usage Maximum (N)for the button collection. This causes the kernel to assign evdev codes in a fixed pattern — BTN_GAMEPAD for usages 1-16, then BTN_MISC for 17-32 — regardless of what is declared in[output.buttons]. Extra buttons like M1-M4 ended up on wrong BTN_* codes and were not visible to SDL/Steam.Fix
Replace the range with one
Usage (N)item per button, where N is derived from the button's configured BTN_* code via the kernel's reverse mapping:Codes outside these ranges (e.g. BTN_TRIGGER_HAPPY) receive the lowest free Usage number so the descriptor remains valid.
Adds
btnCodeToHidUsage()to implement the reverse BTN_* → HID Button Page Usage mapping.Tested
Verified with
evtestand Steam on Linux (CachyOS, kernel 7.0.5) using a Flydigi Vader 5 Pro. All buttons including extra paddle/misc buttons now map to the correct BTN_* codes.Summary by CodeRabbit