Repository navigation
Conversation
…xbox_host, xinput, SwitchProHost) espp could emulate a Switch Pro controller (switch_pro) and an Xbox 360 controller (usb_device's X-Input function) to a host, but a board with a USB host port could read neither kind of controller: a Switch Pro controller reports nothing useful until a host runs its handshake, and Xbox controllers are not HID devices at all. - xinput (new, header-only): the X-Input wire format, moved out of usb_device so the device and host sides share it. It now also parses a controller's input report and builds the rumble and LED-ring reports a host sends. usb_device requires it; the examples that build usb_device list it. - xbox_host (new): espp::XboxHost, a USB Host Library client beside espp::UsbHost's HID driver that claims X-Input (Xbox 360, third-party X-input mode) and GIP (Xbox One / Series) interfaces, starts each controller (GIP power-on, acknowledging the Xbox button), decodes its input into gamepad_map's GamepadState and drives rumble and the player LED. gip.hpp and xbox_gamepad_state.hpp are header-only and host-tested. - switch_pro: espp::SwitchProHost, the host side of the emulator. It runs the USB handshake, reads the stick calibration from the controller's SPI flash (typical values for one it cannot read or that is implausible, as some third-party controllers store the whole range), decodes the reports into GamepadState, and drives rumble and the player lights. It is transport-light like SwitchPro (UsbHost::HidDevice is the intended pairing) and host-tested against a fake controller. - hid-rp: encode_switch_rumble(), the inverse of decode_switch_rumble(). - Examples: xbox_host/example and switch_pro/host_example (ESP32-S3, with espp::UsbHost), in the CI build matrix; docs pages and Doxygen inputs. - Until espp/xinput is on the registry, the examples that build usb_device with the component manager on carry a main/idf_component.yml that points at the in-repo copy (delete them after the release, as for lilygo-t5-47). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY
|
✅Static analysis result - no issues found! ✅ |
Contributor
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
1 open issue
What changed in this PR
Adds USB host-side support for reading real Nintendo Switch Pro controllers and wired Xbox controllers (X-Input + GIP) on ESP32 USB host ports, and factors out X-Input wire format helpers into a reusable header-only component shared by device + host.
Changes:
- Add new
xbox_hostcomponent (library + docs + example + host tests) for wired Xbox 360/X-Input and Xbox One/Series GIP controllers. - Add
SwitchProHosttoswitch_pro(library + docs + host example + host tests) to perform the Pro controller handshake/calibration and decode input. - Introduce new header-only
xinputcomponent (wire format + host tests) and extendhid-rpwithencode_switch_rumble()+ round-trip tests.
| File | Description |
|---|---|
| doc/en/hid/switch_pro_host_example.md | Adds docs page that includes the host example README. |
| doc/en/hid/switch_pro.rst | Documents SwitchProHost, links host example + API include. |
| doc/en/buses/xbox_host_example.md | Adds docs page that includes the Xbox host example README. |
| doc/en/buses/xbox_host.rst | Adds new Xbox host driver documentation + toctree + API includes. |
| doc/en/buses/index.rst | Adds xbox_host to buses doc index. |
| doc/Doxyfile | Adds new examples/inputs for SwitchProHost, XboxHost, xinput wiring headers. |
| components/xinput/test/xinput_host_test.cpp | Expands xinput host tests (parse input report + build rumble/LED reports). |
| components/xinput/test/CMakeLists.txt | Registers xinput host test target. |
| components/xinput/include/xinput.hpp | Adds host-side parsing plus host-built rumble/LED report builders. |
| components/xinput/idf_component.yml | Adds component manager manifest for xinput. |
| components/xinput/README.md | Documents xinput component usage and wire format. |
| components/xinput/CMakeLists.txt | Registers header-only component. |
| components/xbox_host/test/xbox_host_test.cpp | Adds host tests for GIP parsing/formatting and conversions to/from Gamepad/Rumble state. |
| components/xbox_host/test/CMakeLists.txt | Registers xbox_host host test target. |
| components/xbox_host/src/xbox_host.cpp | Implements XboxHost USB Host Library client, device claiming, transfers, parsing, rumble/LED output. |
| components/xbox_host/include/xbox_host.hpp | Declares XboxHost API, controller info/state callbacks, and configuration. |
| components/xbox_host/include/xbox_gamepad_state.hpp | Adds conversion helpers between xinput/gip wire states and GamepadState/RumbleState. |
| components/xbox_host/include/gip.hpp | Adds dependency-free GIP wire parsing/building helpers. |
| components/xbox_host/idf_component.yml | Adds component manager manifest for xbox_host. |
| components/xbox_host/example/sdkconfig.defaults | Sets ESP32-S3 host-console defaults for example. |
| components/xbox_host/example/main/xbox_host_example.cpp | Adds XboxHost example using UsbHost + rumble demo. |
| components/xbox_host/example/main/idf_component.yml | Adds temporary override for in-repo xinput until registry release. |
| components/xbox_host/example/main/CMakeLists.txt | Registers example main component requirements. |
| components/xbox_host/example/README.md | Documents Xbox host example setup and output. |
| components/xbox_host/example/CMakeLists.txt | Defines example project + component directories. |
| components/xbox_host/README.md | Documents XboxHost usage, rationale, and wire formats. |
| components/xbox_host/CMakeLists.txt | Registers xbox_host component and dependencies. |
| components/wdi/usb_example/CMakeLists.txt | Adds xinput to example component dirs (usb_device dependency change). |
| components/vl53l/vl53l5cx_webapp_example/CMakeLists.txt | Adds xinput to example component dirs (usb_device dependency change). |
| components/usb_device/xinput_example/CMakeLists.txt | Adds xinput to example component dirs. |
| components/usb_device/test/CMakeLists.txt | Removes xinput host test from usb_device tests (moved to xinput component). |
| components/usb_device/msc_example/CMakeLists.txt | Adds xinput to example component dirs. |
| components/usb_device/idf_component.yml | Declares new dependency on espp/xinput. |
| components/usb_device/example/CMakeLists.txt | Adds xinput to example component dirs. |
| components/usb_device/README.md | Updates docs to reference xinput component for X-Input wire definitions. |
| components/usb_device/CMakeLists.txt | Adds xinput to usb_device component requirements. |
| components/telemetry/example/CMakeLists.txt | Adds xinput to example component dirs (usb_device dependency change). |
| components/system/example/CMakeLists.txt | Adds xinput to example component dirs (usb_device dependency change). |
| components/switch_pro/test/switch_pro_host_test.cpp | Adds host tests for SwitchProHost handshake, calibration, decoding, rumble, lights. |
| components/switch_pro/test/CMakeLists.txt | Registers switch_pro host test target. |
| components/switch_pro/src/switch_pro_host.cpp | Implements SwitchProHost handshake/state decoding/rumble/lights. |
| components/switch_pro/include/switch_pro_host.hpp | Declares SwitchProHost API and documents protocol/usage. |
| components/switch_pro/idf_component.yml | Updates switch_pro manifest to include host example + gamepad_map dependency. |
| components/switch_pro/host_example/sdkconfig.defaults | Sets ESP32-S3 host-console defaults for host example. |
| components/switch_pro/host_example/main/switch_pro_host_example.cpp | Adds SwitchProHost + UsbHost integration example. |
| components/switch_pro/host_example/main/CMakeLists.txt | Registers host example main component requirements. |
| components/switch_pro/host_example/README.md | Documents Switch Pro host example setup and output. |
| components/switch_pro/host_example/CMakeLists.txt | Defines host example project + component directories. |
| components/switch_pro/example/main/idf_component.yml | Adds temporary override for in-repo xinput until registry release. |
| components/switch_pro/example/CMakeLists.txt | Adds required component dirs (including xinput) for updated deps. |
| components/switch_pro/README.md | Adds SwitchProHost documentation and requirements. |
| components/switch_pro/CMakeLists.txt | Adds gamepad_map dependency for SwitchProHost public headers. |
| components/ota/example/CMakeLists.txt | Adds xinput to example component dirs (usb_device dependency change). |
| components/odrive_native/usb_example/main/idf_component.yml | Adds temporary override for in-repo xinput until registry release. |
| components/odrive_native/usb_example/CMakeLists.txt | Adds xinput to example component dirs (usb_device dependency change). |
| components/mcp266/webapp_example/CMakeLists.txt | Adds xinput to example component dirs (usb_device dependency change). |
| components/hid-rp/test/hid_rp_rumble_host_test.cpp | Adds round-trip tests for Switch rumble encode/decode. |
| components/hid-rp/include/hid-rp-rumble.hpp | Adds encode_switch_rumble() inverse helper for host rumble packets. |
| components/gamepad_map/webapp_example/CMakeLists.txt | Adds xinput to example component dirs (usb_device dependency change). |
| components/desktop/example/CMakeLists.txt | Adds xinput to example component dirs (usb_device dependency change). |
| components/coredump/example/CMakeLists.txt | Adds xinput to example component dirs (usb_device dependency change). |
| components/canopen/can_bridge_example/main/idf_component.yml | Adds temporary override for in-repo xinput until registry release. |
| components/canopen/can_bridge_example/CMakeLists.txt | Adds xinput to example component dirs (usb_device dependency change). |
| components/bldc_haptics/example/CMakeLists.txt | Adds xinput to example component dirs (usb_device dependency change). |
| .github/workflows/upload_components.yml | Adds xbox_host and xinput to upload list. |
| .github/workflows/build.yml | Adds build matrix entries for new host examples. |
Review effort: Lite
| const int32_t range = v >= 0 ? a.above : a.below; | ||
| if (range <= 0) | ||
| return 0; | ||
| return v * GamepadState::AXIS_MAX / range; |
Copilot stopped reviewing on behalf of
finger563 due to an error
December 2, 2026 04:38
…omponents - switch_pro_host.cpp: the SPI reply's debug log writes its bytes as hex by hand; fmt's range formatter tripped MSVC's unreachable-code warning (C4702, an error under /WX) in fmt/ranges.h. An inline suppression for the 'ready' flag, which finish() sets under the lock where cppcheck does not follow it. - gip.hpp: Sequence::next() without a condition (1..255, then 1 again). - xbox_host.cpp: std::copy_if / any_of / find_if instead of raw loops. - switch_pro_host_test.cpp: swap instead of move-then-clear, count_if / transform; and, as for the WDI host tests, file-level suppressions for the vectors its fake controller's callbacks fill, which cppcheck reports as always empty. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY
This branch has not been deployed
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.

Summary
espp can emulate a Switch Pro controller (
switch_pro) and an Xbox 360 controller (usb_device's X-Input function) to a host. A board with a USB host port could read neither kind of controller, though. A Switch Pro controller reports nothing useful until a host runs its handshake, and Xbox controllers are not HID devices at all. This PR adds both, as components other projects can use.xbox_host(new)espp::XboxHost: wired Xbox controllers on a USB host port. It reads both X-Input pads (Xbox 360, and third-party controllers in X-input mode) and GIP pads (Xbox One / Series).switch_proespp::SwitchProHost: the host side of the existing emulator. It reads a real Pro controller.xinput(new, header-only)usb_deviceso the device and host sides share it.hid-rpencode_switch_rumble(), the inverse ofdecode_switch_rumble().Both drivers decode into gamepad_map's
espp::GamepadState, and both takeespp::RumbleStatefor rumble.espp::XboxHostXbox controllers present a vendor-specific interface, not a HID one: X-Input is
0xFF/0x5D/0x01and GIP is0xFF/0x47/0xD0, each with interrupt IN and OUT endpoints. SoUsbHost's HID driver never sees them.XboxHostis a second USB Host Library client next toUsbHost's HID driver. Both share the same port, and controllers already attached when it starts are picked up too. It doesn't install the library itself:espp::UsbHostdoes that, or the application's ownusb_host_install().gip.hpp, andxbox_gamepad_state.hppfor both directions of conversion.espp::SwitchProHost0x80init commands, then subcommands for:057E:2009store the whole 12-bit range, which would keep their sticks from ever reaching full deflection.SwitchPro, it is transport-light.UsbHost::HidDevice::send_output_report()matches its send hook. The handshake, calibration, decoding and rumble are host-tested against a fake controller.Packaging
usb_devicenow requiresxinput. The 16 examples that buildusb_devicelist it among their component directories.xbox_host/exampleandswitch_pro/host_example, both ESP32-S3 withespp::UsbHost. Both are in the CI build matrix.xbox_hostandxinputare inupload_components.yml.espp/xinputis on the registry, four examples carry amain/idf_component.ymlthat points at the in-repo copy, aslilygo-t5-47did before. Three of them build with the component manager on:canopen/can_bridge_example,odrive_native/usb_exampleandswitch_pro/example. The fourth is the newxbox_host/example. These files can be deleted after the release.Testing
xinput,xbox_host,switch_pro(theSwitchProHosthandshake) andhid-rp(rumble round-trip). All 41 host-test programs pass with Apple clang and with g++-16, under the CI flags (-Wall -Wextra -Werror).usb_device/xinput_exampleandcanopen/can_bridge_examplewith the component manager off;odrive_native/usb_exampleandswitch_pro/examplewith it on.045e:028e) throughXboxHost;UsbHost.🤖 Generated with Claude Code
https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY