Skip to content

Switch Pro and wired Xbox controllers on the USB-A port (espp 1.5.0 SwitchProHost / XboxHost) - #54

Open
finger563 wants to merge 1 commit into
mainfrom
feat/usb-pro-xbox-controllers
Open

finger563 wants to merge 1 commit into
mainfrom
feat/usb-pro-xbox-controllers

Conversation

@finger563

Copy link
Copy Markdown
Contributor

Summary

Switch Pro controllers and wired Xbox controllers now work on the USB-A port, using espp 1.5.0's new host components (esp-cpp/espp#966):

  • Switch Pro: espp::SwitchProHost from switch_pro. Until a host runs its handshake, a Switch Pro controller reports nothing useful.
  • Xbox: espp::XboxHost from xbox_host. Xbox controllers are not HID devices at all.

Changes

Switch Pro (057E:2009), in usb_hid.cpp:

  • It gets an espp::SwitchProHost instead of the HID decoder.
  • Its OUTPUT reports go out through UsbHost::HidDevice::send_output_report().
  • A 20 ms timer runs only while a controller is mid-handshake.
  • Its player lights show.

Xbox: espp::XboxHost runs beside the HID driver as a second USB Host Library client. It handles:

  • Xbox 360 controllers, and controllers in X-input mode (e.g. 8BitDo);
  • Xbox One / Series controllers (GIP).

Same mapping as the HID pads: both feed the existing gamepad path:

  • buttons by position;
  • the left stick past 40% doubles as the d-pad;
  • capture, home, or select+start opens the pause menu.

USB task priority: the USB host's tasks, and XboxHost's, now run at priority 21. That is above the games' main and video tasks (20), like the BSP's touch task.

  • At 5, a busy core (Jedi Knight) starved the dispatch task.
  • A controller that reports at a fixed rate (the Switch Pro) then overflowed its queue, and its input stopped.
  • The tasks only wake for USB events.

Header rename: include/gamepad_state.hpp is now emu_gamepad_state.hpp. The old name clashed with gamepad_map's gamepad_state.hpp, which the new components bring in.

idf_component.yml:

  • espp/switch_pro and espp/xbox_host >=1.5.0.
  • espp/usb_device >=1.5.0: its xinput.hpp moved to espp/xinput, so an older usb_device brings a second, clashing copy. The component manager picked usb_device 1.4.9 right after the release, and the build failed.

README: documents the new controllers.

Testing

On the Tab5, built against the registry's espp 1.5.0:

Earlier, the same code against a local espp checkout:

Controller Path Result
Switch Pro (a controller presenting 057E:2009 with a full-range factory calibration) SwitchProHost input, typical-values calibration fallback, Jedi Knight play with no dropped reports after the priority change
8BitDo in X-input mode (045e:028e) XboxHost works
PS5 DualSense, Backbone, 8BitDo in D-input mode HID, as before unaffected

Not tested on hardware: a genuine Xbox One / Series (GIP) pad. The GIP wire format is covered by espp's host tests.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY

…witchProHost / XboxHost)

A Switch Pro controller reports nothing useful until a host runs its
handshake, and Xbox controllers are not HID devices at all, so neither
worked on the USB-A port. espp 1.5.0 has the host side of both (esp-cpp/espp#966).

- usb_hid.cpp: a Switch Pro controller (057E:2009) gets an espp::SwitchProHost
  instead of the HID decoder: its OUTPUT reports go out with
  UsbHost::HidDevice::send_output_report(), a 20 ms timer runs only while one
  is mid-handshake, and its player lights show. An espp::XboxHost beside the
  HID driver takes wired Xbox 360 / X-input mode controllers and Xbox One /
  Series (GIP). Both feed the same gamepad path as the HID pads (positions,
  sticks past 40% as the d-pad, capture / home or select+start for the
  pause menu).
- The USB host's tasks (and XboxHost's) at priority 21, above the games'
  main and video tasks (20), like the BSP's touch task: at 5, a busy core
  (Jedi Knight) starved the dispatch task, a controller that reports at a
  fixed rate (the Switch Pro) overflowed its queue, and its input stopped.
- include/gamepad_state.hpp -> emu_gamepad_state.hpp: the name clashed with
  gamepad_map's gamepad_state.hpp, which the new components bring.
- idf_component.yml: espp/switch_pro and espp/xbox_host >= 1.5.0, and
  espp/usb_device >= 1.5.0 (its xinput.hpp moved to espp/xinput; an older
  usb_device brings a second, clashing copy).
- README: the controllers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY
Copilot AI balanced review requested due to automatic review settings December 3, 2026 05:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical timer lifecycle races can stall Switch Pro handshakes or cause null/dangling-pointer access during concurrent connections and teardown.

3 open issues
What changed in this PR

Adds Switch Pro and wired Xbox support on the USB-A port, feeding both into the existing gamepad input path.

Changes:

  • Adds controller-specific hosts, Switch Pro handshake timing, and higher USB task priorities.
  • Updates espp dependencies and renames the emulator’s gamepad header to avoid a collision.
  • Documents supported controllers and controls.
File Description
README.md Documents Switch Pro and wired Xbox support.
components/​tab5-emu/​src/​usb_hid.cpp Integrates controller hosts, input mapping, and lifecycle handling.
components/​tab5-emu/​include/​touch_controls.hpp Uses the renamed gamepad header.
components/​tab5-emu/​include/​tab5-emu.hpp Uses the renamed gamepad header.
components/​tab5-emu/​include/​emu_gamepad_state.hpp Provides emulator input types under a collision-free filename.
components/​tab5-emu/​idf_component.yml Adds host dependencies and requires compatible USB-device support.
components/​tab5-emu/​CMakeLists.txt Registers the new controller components.

Review effort: Balanced

p->update();
handshaking |= !p->running();
}
return !handshaking;
}
// runs only while a Switch Pro controller is mid-handshake (started when one
// connects, stops itself once every one is running)
hid->switch_pro_ticker = std::make_unique<espp::Timer>(espp::Timer::AdvancedConfig{
}
logger_.info("stopping the USB host");
std::error_code ec;
hid->switch_pro_ticker.reset();

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants