Repository navigation
feat(hid-rp, gamepad_map, switch_pro, usb_device): descriptor-driven rumble building blocks - #927
Merged
Merged
Conversation
…rumble building blocks
The first step of generic rumble for controller bridges: decode a host's rumble
request into one normalised state, and drive a controller's motors from its own
report descriptor rather than a known VID/PID.
- hid-rp ReportMap maps Output fields too (output_fields(), output_report_bytes()),
each with its unit and unit exponent. Inputs are unchanged: their own field
list and bit cursors, and only input report IDs set uses_report_ids().
- hid-rp-rumble.hpp (new):
- RumbleEncoder::from_report_map() finds a Physical Interface Device style
output report (DC Enable Actuators, a Magnitude per actuator, Duration,
Start Delay, Loop Count), as the Xbox Wireless controller declares over
BLE. The descriptor gives the layout. Which Magnitude drives which motor
follows the Xbox convention (Linux hid-microsoft: LT, RT, strong, weak;
enable bit i = actuator n-1-i), with set_motor() to override. An effect
plays once for its duration (clamped to the field), so callers re-send
while the rumble lasts and a lost stop is bounded.
- decode_switch_rumble[_report]() reads a Switch host's HD rumble (both
bands, the amplitude code inverted per dekuNukem's table) from output
reports 0x01 and 0x10, both [id][packet number][8 rumble bytes].
- gamepad_map: RumbleState (rumble_state.hpp), the output counterpart of
GamepadState (strong / weak / two trigger motors, 0..255), plus the
to_rumble_levels() / to_rumble_state() bridges in gamepad_state_hid_rp.hpp.
It is also in the desktop umbrella header.
- switch_pro: Config::on_rumble, called from on_hid_report() for every 0x01 /
0x10 report (replaces the 0x10 TODO).
- usb_device: xinput::decode_rumble() for the X-Input OUT endpoint (rumble
reports; LED reports are not rumble).
Tests (host, -Werror, g++ and clang):
- hid_rp_rumble_host_test: the Xbox descriptor's output fields at their
offsets, its encoder byte for byte against espp's hand-written
XboxRumbleOutputReport, a synthetic 2-motor layout (16-bit magnitudes, a
1-bit enable flag, ms durations), no encoder for the Switch Pro descriptor
(constant vendor outputs), Switch decoding (neutral, full, monotonic, the
packet-number offset);
- gamepad_map and xinput tests extended.
The existing hid-rp tests still pass. The switch_pro, xinput, gamepad_map and
hid-rp examples build for ESP32-S3 (IDF 6.1). Docs: READMEs, docs pages and
the Doxyfile entries for the new headers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
|
✅Static analysis result - no issues found! ✅ |
UsbDevice::set_suspend_callback() / set_resume_callback() forward esp_tinyusb's TINYUSB_EVENT_SUSPENDED / RESUMED, which the event callback used to drop. On suspend the device stays powered and configured, so an app can stop what the host was driving: a controller bridge stops the controller's rumble when a PC goes to sleep without sending a stop. Same pattern as the mount / unmount callbacks (run in the TinyUSB task, cb_mutex_-guarded). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
- hid-rp ReportMap::Parser: the local field list was named `fields`, which shadowed ReportMap::fields(). It is now `dest_fields`. - xinput host test: the decoded rumble no longer shadows the outer report `r`. - hid-rp rumble test: find_output() uses std::find_if instead of a raw loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
This was referenced Nov 24, 2026
Merged
finger563
added a commit
to finger563/esp-usb-ble-hid
that referenced
this pull request
Nov 25, 2026
* feat: descriptor-driven rumble on any controller that declares it Generalises the rumble forwarding from #43 (decode on the TinyUSB task, a latest-wins sender with keep-alive, handle-based writes, stop on unmount / suspend) with espp's new rumble pieces (esp-cpp/espp#927): - Which controllers rumble: an espp::hid_rp::RumbleEncoder built from the controller's OWN report map when it connects, replacing the 045E:0B13 gate. Any controller whose map declares a PID-style rumble report (DC Enable Actuators, a Magnitude per motor, Duration...) is driven: the Xbox Wireless Series / One S / Elite over BLE, and lookalikes. A map that could not be read (decoded as an Xbox controller) is not assumed to rumble like one, so nothing is written to an output report the controller did not declare. - Host side: the Switch's rumble through SwitchPro::Config::on_rumble, with HD rumble decoded by espp hid-rp using the amplitude table (replaces the local switch_rumble.hpp + its host test, which CI never ran); the PC's X-Input rumble through xinput::decode_rumble. Both become an espp::RumbleState. - main/rumble.cpp, the sender (replaces the ble.cpp output-report queue): - the newest target wins, an unchanged one is not re-sent, writes are at least 30 ms apart; - each report plays a 300 ms pulse, re-sent every 150 ms while the motors run; the stop is sent three times; - the motors stop when the controller changes or disconnects, and when the USB host unmounts or suspends (UsbDevice suspend callback from espp#927, replacing the tud_suspended() poll in the HID sender). - BLE: ble_has_output_report() / ble_write_output_report() (write without response when the characteristic takes it, otherwise an async write; only writable output characteristics are recorded). - Console: INFO carries an optional rumble_supported byte (absent from older firmware: "not reported"). The Device tab shows a Rumble row. ACTION 0x04 TEST_RUMBLE plays a 400 ms pulse (Test rumble button), with ERROR when the controller cannot rumble. - Docs: README, controllers / hosts / troubleshooting / web-console / button-mapping / architecture describe the descriptor-driven behaviour. Tests: device_config host test (rumble byte present / absent, TestRumble id) and the console node test (16 groups) pass. On hardware (T-Dongle-S3 in Xbox 360 mode, against espp#927 via a local override_path, not committed), with espp's hid_service example as the BLE gamepad logging every output report it receives: rumble_supported from its report map; Test rumble, and X-Input strong-only / weak-only / both / mixed levels arrive as the right enable bits and magnitudes (200 -> 78, 120 -> 47, 255 -> 100, 64 -> 25), 300 ms pulses re-sent every ~150 ms for the length of the hold, each stop sent 3 times. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU * build: espp 1.4.7 (descriptor-driven rumble pieces) hid-rp, switch_pro, usb_device and gamepad_map >= 1.4.7: RumbleEncoder, Switch HD rumble decode, xinput::decode_rumble, UsbDevice suspend / resume callbacks and RumbleState all landed in espp 1.4.7 (esp-cpp/espp#927). dependencies.lock regenerated from the registry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU * fix(rumble): match rumble_set_encoder's parameter name (cppcheck funcArgNamesDifferent) The declaration said `encoder`, the definition `e` (the file already has an `encoder` variable, which the parameter must not shadow): both are now `new_encoder`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The first phase of generic rumble for controller bridges, in espp. Every piece is header-only and host-tested:
The dongle (esp-usb-ble-hid) is the first user, in a follow-up. It builds on the decode → latest-wins queue → sender structure from esp-usb-ble-hid#43.
What's here
hid-rp: Output fields and a descriptor-driven rumble encoderReportMapnow maps them too (output_fields(),output_report_bytes()), andReportFieldcarries its unit and unit exponent. The input side is untouched: a separate field list and bit cursors, and only input report IDs setuses_report_ids(), whichsplit()relies on.RumbleEncoder::from_report_map()(newhid-rp-rumble.hpp) finds a Physical Interface Device style output report: DC Enable Actuators, one Magnitude per actuator, Duration, Start Delay and Loop Count. The Xbox Wireless controller declares exactly that over BLE. The descriptor gives each field's position, size, range and unit, so Duration is scaled correctly: 10 ms units for the Xbox, milliseconds when no time unit is declared.hid-microsoftdriver uses for Xbox controllers. Four actuators are left trigger, right trigger, strong, weak; enable bit i drives actuator n−1−i. Two actuators are strong, weak.set_motor()overrides the order for a device that differs.hid-rp: Switch host decodingdecode_switch_rumble()/decode_switch_rumble_report()read the two motor levels from a Switch host's HD rumble. That's both bands, with the amplitude code inverted using dekuNukem's rumble table rather than read linearly.0x01and0x10both lay out[id][packet number][8 rumble bytes]. This matchesswitch_pro's own subcommand offset of 10.gamepad_map:RumbleStaterumble_state.hppis the output counterpart ofGamepadState: strong, weak and two trigger motors, 0..255.to_rumble_levels()andto_rumble_state()bridge it to hid-rp, ingamepad_state_hid_rp.hpp.rumblecomponent later. It's also in the desktop umbrella header.switch_pro:Config::on_rumbleis called fromon_hid_report()for every0x01and0x10report, which replaces the0x10TODO.usb_device:xinput::decode_rumble()reads the X-Input OUT endpoint's rumble reports and returns nullopt for LED reports.usb_device:UsbDevice::set_suspend_callback()/set_resume_callback()forward esp_tinyusb's suspend / resume events, which were dropped. A bridge stops the controller's rumble when a PC sleeps without sending a stop.Tests
hid_rp_rumble_host_test, built with-Werrorunder g++ 16 and clang, covers:XboxRumbleOutputReport;set_motor();The gamepad_map and xinput host tests are extended, and the four existing hid-rp tests still pass. The
switch_pro,xinput_example,gamepad_mapandhid-rpexamples build for ESP32-S3 with IDF 6.1.Next
RumbleEncoderinstead of a hard-coded PID gate, plus a reusable sender (dedupe, short pulses re-sent while on, stop on disconnect / unmount / suspend, handle-based writes). The console gets "rumble supported" and a test button.🤖 Generated with Claude Code
https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU