Repository navigation
feat(usb_device): X-Input beside a WebUSB vendor interface, recognized as an Xbox 360 controller - #893
Conversation
…zed as an Xbox controller A PC only bound the X-Input function when it was the device's only function: the device then took the Xbox 360 controller's own identity and 0xFF device class. Combined with anything else it kept the composite identity and nothing told Windows that one interface was an Xbox controller, so a controller with a configuration console on a WebUSB interface could not be both. include/ms_os_20.hpp builds the Microsoft OS 2.0 descriptor set from a list of functions, one subset per interface Windows must bind a driver to without an INF: the WebUSB vendor interface gets WINUSB plus the DeviceInterfaceGUIDs registry property, as before; an X-Input interface gets the XUSB10 compatible ID, which Windows' own Xbox 360 driver matches (USB\MS_COMP_XUSB10, the route the virtual-controller drivers take). The device code builds its set from the enabled functions instead of a fixed 0xB2-byte blob; the WinUSB-only set is byte-for-byte what it served until now, which the host test pins along with the two-function sets. The application gives a composite controller Microsoft's vendor ID (Linux's xpad binds the interface class under it) and a product ID Windows' Xbox driver INF does not list by hardware ID, since that match takes the whole device and hides the vendor interface; the header says so. X-Input alone is unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
…s in CI xinput_example gains a sdkconfig.composite variant (XINPUT_EXAMPLE_COMPOSITE with XINPUT_EXAMPLE_COMPOSITE_PID) that adds a WebUSB vendor interface beside the controller; the default stays X-Input only. The component README and the example's explain how a PC recognizes the controller in each configuration. usb_device_tests.yml runs the component's two host tests (the X-Input one never ran in CI). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
|
✅Static analysis result - no issues found! ✅ |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
What changed in this PR
Adds support for serving a Microsoft OS 2.0 descriptor set that can bind both WinUSB (for a WebUSB vendor interface) and the Xbox 360 X-Input driver (via XUSB10) on composite devices, plus CI coverage for the component’s host-buildable tests.
Changes:
- Introduces a dependency-free MS OS 2.0 descriptor-set builder and a host unit test validating structure/bytes.
- Updates
UsbDeviceto build the MS OS 2.0 descriptor dynamically based on enabled interfaces (vendor + optional X-Input). - Adds an
xinput_examplecomposite sdkconfig/Kconfig path and a GitHub Actions workflow to run host tests in CI.
| File | Description |
|---|---|
| components/usb_device/include/ms_os_20.hpp | New MS OS 2.0 descriptor-set builder for per-interface driver binding without INF |
| components/usb_device/src/usb_device.cpp | Replaces fixed MS OS 2.0 blob with builder output (WinUSB + optional XUSB10) |
| components/usb_device/test/ms_os_20_host_test.cpp | New host unit test for descriptor-set builder correctness and edge cases |
| .github/workflows/usb_device_tests.yml | New CI workflow running usb_device host tests |
| components/usb_device/xinput_example/main/Kconfig.projbuild | Adds composite configuration options (enable vendor interface + custom PID) |
| components/usb_device/xinput_example/sdkconfig.composite | New sdkconfig defaults enabling composite variant + TinyUSB vendor count |
| components/usb_device/xinput_example/main/xinput_example.cpp | Example logic for composite VID/PID + vendor function + updated log output |
| components/usb_device/xinput_example/README.md | Documents composite build variant and host driver-binding rationale |
| components/usb_device/include/usb_device.hpp | Expands documentation on identity/binding rules across configurations |
| components/usb_device/README.md | Updates component docs describing X-Input binding alone vs composite with WebUSB |
Review effort: Lite
…includes Review: the set's size was narrowed to the BOS capability's uint16_t without a check (a few hundred bytes today; fail initialization with a clear error if it ever exceeds the field), the builder was called through the implicit vector -> span conversion (now an explicit span), and the host test includes <span> / <vector> itself instead of through ms_os_20.hpp. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
…usy means Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
3 resolved since last review
Review effort: Lite
| // set header | ||
| u16(static_cast<uint16_t>(kSetHeaderLen)); | ||
| u16(kSetHeaderDescriptor); | ||
| u32(kWindowsVersion); | ||
| u16(static_cast<uint16_t>(total)); | ||
| // configuration subset header: configuration 0, reserved, subset length | ||
| u16(static_cast<uint16_t>(kConfigurationSubsetHeaderLen)); | ||
| u16(kSubsetHeaderConfiguration); | ||
| out.push_back(0x00); | ||
| out.push_back(0x00); | ||
| u16(static_cast<uint16_t>(total - kSetHeaderLen)); |
There was a problem hiding this comment.
descriptor_set() now refuses a set longer than kMaxSetLength (0xFFFF, the format's 16-bit length fields) and returns an empty vector; the per-subset lengths are at most 160 bytes by construction. The device treats an empty set as an initialization error with the computed size in the log. Host test added: an over-long list is refused, one just under the limit builds with consistent lengths.
🤖 Generated with Claude Code
| impl_->ms_os_20_desc = | ||
| espp::ms_os_20::descriptor_set(std::span<const espp::ms_os_20::Function>{ms_functions}); |
There was a problem hiding this comment.
Built from data()/size() now. (The range constructor is C++20, and espp builds as C++23 throughout, but this form needs neither.)
🤖 Generated with Claude Code
| std::vector<uint8_t> out; | ||
| const size_t total = descriptor_set_length(functions); | ||
| out.reserve(total); |
There was a problem hiding this comment.
Added: descriptor_set() asserts that out.size() == descriptor_set_length(functions) before returning.
🤖 Generated with Claude Code
Review: the builder narrowed the set and subset lengths to uint16_t without a check. descriptor_set() now returns an empty vector when the set would exceed kMaxSetLength (0xFFFF; thousands of functions, a caller error), and asserts that the bytes it emitted match descriptor_set_length(). The device treats an empty set as an initialization error. The span is built from data()/size(). Host test: an over-long list is refused, one just under the limit builds with consistent lengths. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
… the console A "USB controller" setting (device-config key 0x0A, NVS usb_ctl; Switch Pro by default) picks what the dongle is to the USB host at the next boot: the Switch Pro Controller as before, or a wired Xbox 360 controller for Windows, Linux, Steam and Android (native X-Input: analog triggers, the Guide button). The dongle stays a composite device in both modes, so the console keeps working. usb.cpp builds either the HID (Switch Pro) function or espp's X-Input function beside the vendor console. Xbox mode presents Microsoft's vendor ID with the dongle's own product ID (CONFIG_DONGLE_USB_XBOX_PID, 0x0E60): the retail identity would make Windows' Xbox driver take the whole device and hide the console; with its own product ID Windows splits the composite device and binds the X-Input interface through the XUSB10 compatible ID espp advertises (esp-cpp/espp#893), and Linux's xpad binds the interface class under the Microsoft vendor ID. Rumble from the host is ignored. main.cpp maps the settings-adjusted GamepadInputs to an X-Input state and pushes it on change; the Switch-only L+R registration window never opens in Xbox mode. INFO gains the running mode as an optional trailer byte, so the console's Device tab shows it and whether a change awaits a reboot. The console lists both identities as permitted dongles (device filter, auto-connect, plug-in), adds the select to Settings with a reboot note, and the README documents the mode and its platform limits. Depends on the espp release that carries esp-cpp/espp#893; the espp/usb_device floor is bumped to it before merge. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
Every espp floor moves to 1.4.2, the release that carries esp-cpp/espp#893, and the lock resolves all 32 espp components to it. No local override is needed any more. Verified on the T-Dongle-S3 (built from the registry, OTA): the MS OS 2.0 set read back from the device carries WINUSB + XUSB10, the neutral X-Input report queued at mount is taken when the host reads it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
… the console (#33) * feat: Xbox 360 (X-Input) as a second USB controller type, chosen from the console A "USB controller" setting (device-config key 0x0A, NVS usb_ctl; Switch Pro by default) picks what the dongle is to the USB host at the next boot: the Switch Pro Controller as before, or a wired Xbox 360 controller for Windows, Linux, Steam and Android (native X-Input: analog triggers, the Guide button). The dongle stays a composite device in both modes, so the console keeps working. usb.cpp builds either the HID (Switch Pro) function or espp's X-Input function beside the vendor console. Xbox mode presents Microsoft's vendor ID with the dongle's own product ID (CONFIG_DONGLE_USB_XBOX_PID, 0x0E60): the retail identity would make Windows' Xbox driver take the whole device and hide the console; with its own product ID Windows splits the composite device and binds the X-Input interface through the XUSB10 compatible ID espp advertises (esp-cpp/espp#893), and Linux's xpad binds the interface class under the Microsoft vendor ID. Rumble from the host is ignored. main.cpp maps the settings-adjusted GamepadInputs to an X-Input state and pushes it on change; the Switch-only L+R registration window never opens in Xbox mode. INFO gains the running mode as an optional trailer byte, so the console's Device tab shows it and whether a change awaits a reboot. The console lists both identities as permitted dongles (device filter, auto-connect, plug-in), adds the select to Settings with a reboot note, and the README documents the mode and its platform limits. Depends on the espp release that carries esp-cpp/espp#893; the espp/usb_device floor is bumped to it before merge. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU * web: the ready message names both USB identities Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU * docs: reboot before an OTA when a USB controller change is waiting Seen on hardware: with the Xbox 360 setting saved but not yet applied, the freshly flashed image booted straight into Xbox mode, and the espp-ota command-line tool, waiting for the identity it had flashed, reported the dongle missing and left the image unconfirmed (mark-valid fixed it). Say so next to the setting; the console handles either identity. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU * fix(usb): start_usb() parameter named the same in declaration and definition cppcheck (CI's static analysis): funcArgNamesDifferent. The definition says `which` because usb.cpp keeps the running mode in a file-scope `personality`. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU * feat(gui): the screen's USB-side icon follows the controller type Xbox 360 mode shows the Xbox icon where the Switch icon was (the design's xbox image was already compiled in); Switch Pro mode is unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU * feat(gui): the big icons show their link state Each side of the screen is a big icon (the controller on the BLE side, the host on the USB side) with a small link badge under it. The design recolored the controller icon solid white while the host icon kept its own colors, so the Xbox logo looked "on" (green) on the USB side from boot and never on the BLE side. Both big icons are now a white silhouette while their link is down and show their own colors once it is up; the badges toggle as before. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU * web: X-Input has no handshake; say whether the host reads the reports In Xbox 360 mode the Device tab showed "waiting for host handshake", the Pro Controller wording, whenever the host was not reading the X-Input interface (on a Mac, which has no X-Input driver, the first report stays queued and the firmware's ready flag is false). Say what it is: the host is or is not reading X-Input reports, with the report count, and name the usual reason. README says the same next to the setting. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU * fix(usb): X-Input state is kept and retried until the host takes it Review: a report the endpoint could not take was dropped, so a release, or the neutral state after a BLE disconnect, could leave the host with pressed buttons until the next input change. usb_push_xinput() now only records the latest state; the sender task submits it and retries every tick until the endpoint accepts it, and after a (re)mount the state is sent again so the new host starts from the truth. Xbox mode without the vendor interface (not the default build): X-Input alone with the retail identity, the CDC log console left out in that mode; without the vendor interface there is no MS OS 2.0 descriptor to carry the XUSB10 compatible ID, and a composite device with neither binds nothing on Windows. usb_hid_ready() in Xbox mode reports a stall only after a report has been in flight for 250 ms (a working host polls every 4 ms), not the gap between a submit and the host's next poll. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU * web: reconnect to a dongle that came back under its other USB identity Review: after a controller-type change the reboot re-enumerates the dongle as the other identity (Switch Pro <-> Xbox 360) and the recovery only looked for the one it lost. The reconnect attempts now look for the dongle's serial under every dongle identity, an arrival under the other identity with the same serial is opened at once, and when the dongle does not show up while a controller-type change was pending the log says that the new identity may need to be authorized through Connect dongle. The X-Input USB line says "ready, no report sent yet" before the first report. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU * fix(usb): X-Input sender never spins; a remount keeps the resend pending Review round 3: - a pending X-Input state no longer bypasses the sender's 8 ms wait: a push wakes it once (kick), after that a report the endpoint cannot take is retried on the tick, so a host that never reads cannot make the priority-10 task spin - the mount callback increments the state generation instead of rewinding the sent one, so an acknowledgment of a report submitted before the remount cannot clear the resend - web: a dongle arriving under its other identity during a recovery wakes the reconnect supervisor (with the identity it lost) instead of being opened behind its back, so its cancellation and discard semantics hold Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU * build: espp >= 1.4.2 (composite X-Input: the XUSB10 compatible ID) Every espp floor moves to 1.4.2, the release that carries esp-cpp/espp#893, and the lock resolves all 32 espp components to it. No local override is needed any more. Verified on the T-Dongle-S3 (built from the registry, OTA): the MS OS 2.0 set read back from the device carries WINUSB + XUSB10, the neutral X-Input report queued at mount is taken when the host reads it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>


Summary
X-Input beside a WebUSB vendor interface, recognized as an Xbox 360 controller. Until now a PC only bound the X-Input function when it was the device's only function (the device then took the Xbox 360 controller's own identity and 0xFF device class); combined with anything else it kept the composite identity and nothing told Windows that one interface was an Xbox controller. A device that is a controller and has a configuration console on a WebUSB interface needs both.
include/ms_os_20.hpp: a dependency-free builder for the Microsoft OS 2.0 descriptor set, one function subset per interface Windows must bind a driver to without an INF. The WebUSB vendor interface getsWINUSBplus theDeviceInterfaceGUIDsregistry property (as before); an X-Input interface gets theXUSB10compatible ID, which Windows' own Xbox 360 driver matches (USB\MS_COMP_XUSB10, the same route the virtual-controller drivers take). Host-tested (test/ms_os_20_host_test.cpp: the WinUSB-only set is byte-for-byte the 0xB2-byte set TinyUSB's example ships and the device served until now, plus the two-function sets in both orders, truncation, and the empty set). The device code builds its set from the enabled functions instead of a fixed 0xB2-byte blob.Config::vidto Microsoft's0x045E(Linux's xpad binds the interface class under it) andConfig::pidto a product ID Windows' Xbox driver INF does not list by hardware ID (the retail controllers' are), since a hardware-ID match takes the whole device and hides the vendor interface. X-Input beside other functions without the WebUSB one still gets no MS OS 2.0 descriptor, so Windows does not bind it.xinput_examplegains asdkconfig.compositevariant (XINPUT_EXAMPLE_COMPOSITE, withXINPUT_EXAMPLE_COMPOSITE_PID) that adds the WebUSB vendor interface; the default stays X-Input only.usb_device_tests.yml: the component's two host tests now run in CI (the X-Input one never did).First consumer: the esp-usb-ble-hid dongle, which will offer Xbox 360 emulation as a console setting beside its Switch Pro one while keeping the console interface in both modes.
Verified on hardware with the dongle: Windows binds its Xbox 360 driver through the compatible ID on this composite device and the controller works. Linux not yet checked. The X-Input-only path is unchanged (same descriptor bytes, same identity).
Test plan
ms_os_20_host_testandxinput_host_testpassxinput_examplebuilds for esp32s3, X-Input only (default) and composite (sdkconfig.composite)XUSB10compatible ID and sees a working controller; the 206-byte MS OS 2.0 set read back from the device matches the builder's output (WinUSB + GUID for the vendor interface, XUSB10 for the X-Input one)xpadbinds🤖 Generated with Claude Code
https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU