I need some help to understand USB Game Controllers (HID devices)

hidusbxbox-onexbox360xinput

I apologize for the weird title but it is the best that I can come up with right now. So I have a project where I am building a HID device that will act as a game controller. I am thinking to emulate the controller so that it appears as an Xbox 360 controller to a Windows PC. There is a decent API called the XInput API for games so that they can utilize the 360 controller. I would like to take advantage of that.

I am currently looking into what it will take to code a microcontroller to appear as a 360 controller to the PC. I do have some questions which I am hoping someone with more expertise in the field can help me on.

1) I am looking into the HID standard. I was wondering, is there a separate subclass of the HID standard designated for game controllers that I can use that is compatible with the XInput API? Or at the very least, is there a provision for a game controller in the HID standard?

2) I found documentation on how to use the XInput API here: https://docs.microsoft.com/en-us/windows/desktop/xinput/getting-started-with-xinput

Now, I am wondering, is there any documentation out there that specifies how to make a HID device compliant to the XInput API or will I be doing some reverse engineering where I use the API to guide how I code the microcontroller?

3) Lastly, is there any documentation on the API that the PC uses to communicate with an Xbox One controller? Or is it still the XInput API? Or is it the Gamepad class (https://docs.microsoft.com/en-us/uwp/api/windows.gaming.input.gamepad)

Thank you for taking your time to read this and I look forward to your response!

Best Answer

Some info that I have on this:

Xbox 360 Controllers are using proprietary protocol to communicate with PC\console via USB and Wireless. Driver for it is implemented in XUSB22.sys that comes with Windows (was separate driver package earlier). Under the hood there are so called Krypton Packets (codename of wired controller) on USB bus and Argon Packets (wireless controller RF codename) for wireless controllers. Driver produces XInput interface and HID interface (consumed by legacy DirectInput). Under HID it lacking vibration support and LT/RT only under one axis.

Xbox One controllers are using proprietary protocol called GIP (Gaming Input Protocol) for USB and Wireless, also HID for Bluetooth (on newer controllers). Driver implementation lying in xboxgip.sys. It provides XInput interface and USB HID interface. Under HID it lacking vibration, LT/RT under one axis, LT/RT motors (so called impluse triggers) are not working. Wireless controllers are using Wifi packets on physical level with incapsulated GIP in them.

Windows.Gaming.Input - is new WinRT/UWP API that comes in addition to XInput, HID and legacy DirectInput APIs. It consumes XUSB/GIP/HID internally (via XusbGameControllerProvider, GipGameControllerProvider, HidGameControllerProvider). Its a native interface for usage of Xbox One controllers on PC since you can use impluse triggers only via this API.

You can try to reverse engineer those protocols/drivers via IDA PRO debugger, USB sniffing etc. PDB symbols are available from Microsoft Public PDB service (IDA will download them automatically): xusb.sys xboxgip.sys

Check this Linux Xbox Gamepad driver

Related Topic