Building Xbox Controller Support into Keyboard

Talk about anything concerning the source code.
Post Reply
User avatar
LanceMadsen
Posts: 3
Joined: Thu Aug 07, 2014 8:36 pm

Building Xbox Controller Support into Keyboard

Post by LanceMadsen »

I recently came across GIMX and was impressed with the project. It overlaps in some ways with a project I've been working on for the past few years. My overall objective is to build a PC Gaming Keyboard with analog controls so that you can have smooth analog control using the WASD keys of the keyboard (useful for stealth games, vehicle control, and moving in more than 8 directions), but still use the mouse for aiming precision.

At this point we have it functioning as a standard gamepad under windows which works great natively in games like Battlefield 4 and Source Engine games, but most modern games assume you are using an XBOX 360 controller and so look for XInput protocol controllers. Using emulation through X360ce I can use the device in these games, but I would much rather have the device natively act just like an XBOX 360 controller. I am aware of only three commercial devices that use the XInput protocol: The Xbox 360 controller, the Xbox One controller, and the Logitech F310(F510,F710) contollers. I own an official Xbox 360 controller and the F310 and have been spending some time this past week using a USB Protocol Analyzer to capture the data being generated by these devices to get a better understanding of how to make our device behave similarly.

As this device will not be used on the Xbox console the security information handling will not be necessary. Nor will the the rumble and audio features of the xbox controller be necessary, so looking at the Logitech F310 (which does not have any of this) seems like a good place to start. I am looking for some guidance to help me understand how the data should be structured so that we can properly enumerate as a device in Windows and have games programmed for the Xbox 360 controller respond to the device appropriately.

This is the information I have collected so far about the F310 controller:

Code: Select all

XBOX 360 Controller for Windows (Logitech F310) USB Properties

Connection Status	Device connected
Current Configuration	1
Speed	Full (12 Mbit/s)
Device Address	1
Number Of Open Pipes	2
Device Descriptor Gamepad F310
Offset	Field	Size	Value	Description
0	bLength	1	12h	
1	bDescriptorType	1	01h	Device
2	bcdUSB	2	0200h	USB Spec 2.0
4	bDeviceClass	1	FFh	Vendor-Specific
5	bDeviceSubClass	1	FFh	
6	bDeviceProtocol	1	FFh	
7	bMaxPacketSize0	1	08h	8 bytes
8	idVendor	2	046Dh	Logitech, Inc.
10	idProduct	2	C21Dh	
12	bcdDevice	2	4014h	40.14
14	iManufacturer	1	01h	"Logitech"
15	iProduct	1	02h	"Gamepad F310"
16	iSerialNumber	1	03h	"C3C831E6"
17	bNumConfigurations	1	01h	
Configuration Descriptor 1 Bus Powered, 500 mA
Offset	Field	Size	Value	Description
0	bLength	1	09h	
1	bDescriptorType	1	02h	Configuration
2	wTotalLength	2	0030h	
4	bNumInterfaces	1	01h	
5	bConfigurationValue	1	01h	
6	iConfiguration	1	00h	
7	bmAttributes	1	80h	Bus Powered
	4..0: Reserved		...00000 	
	5: Remote Wakeup		..0..... 	No
	6: Self Powered		.0...... 	No, Bus Powered
	7: Reserved (set to one)
(bus-powered for 1.0)		1....... 	
8	bMaxPower	1	FAh	500 mA
Interface Descriptor 0/0 Vendor-Specific, 2 Endpoints
Offset	Field	Size	Value	Description
0	bLength	1	09h	
1	bDescriptorType	1	04h	Interface
2	bInterfaceNumber	1	00h	
3	bAlternateSetting	1	00h	
4	bNumEndpoints	1	02h	
5	bInterfaceClass	1	FFh	Vendor-Specific
6	bInterfaceSubClass	1	5Dh	
7	bInterfaceProtocol	1	01h	
8	iInterface	1	00h	
Unrecognized Class-Specific Descriptor 
Offset	Field	Size	Value	Description
0	bLength	1	10h	
1	bDescriptorType	1	21h	
2		14	10 01 01 24 81 14 03 00 
03 13 02 00 03 00 	
Endpoint Descriptor 81 1 In, Interrupt, 4 ms
Offset	Field	Size	Value	Description
0	bLength	1	07h	
1	bDescriptorType	1	05h	Endpoint
2	bEndpointAddress	1	81h	1 In
3	bmAttributes	1	03h	Interrupt
	1..0: Transfer Type		......11 	Interrupt
	7..2: Reserved		000000.. 	
4	wMaxPacketSize	2	0020h	32 bytes
6	bInterval	1	04h	4 ms
Endpoint Descriptor 02 2 Out, Interrupt, 8 ms
Offset	Field	Size	Value	Description
0	bLength	1	07h	
1	bDescriptorType	1	05h	Endpoint
2	bEndpointAddress	1	02h	2 Out
3	bmAttributes	1	03h	Interrupt
	1..0: Transfer Type		......11 	Interrupt
	7..2: Reserved		000000.. 	
4	wMaxPacketSize	2	0020h	32 bytes
6	bInterval	1	08h	8 ms


Xbox 360 Controller for Windows (F310) – PnP Properties


Description:	Xbox 360 Controller for Windows
Instance Status:	0180600Ah	DN_DRIVER_LOADED
		DN_STARTED
		DN_DISABLEABLE
		DN_REMOVABLE
		DN_NT_ENUMERATOR
		DN_NT_DRIVER
Instance ID:	USB\VID_046D&PID_C21D\C3C831E6
Hardware IDs:	USB\VID_046D&PID_C21D&REV_4014
	USB\VID_046D&PID_C21D
Compatible IDs:	USB\MS_COMP_XUSB10
	USB\Class_FF&SubClass_5D&Prot_01
	USB\Class_FF&SubClass_5D
	USB\Class_FF
Service Name:	xusb21
Setup Class:	XnaComposite
Setup Class Description:	Microsoft Common Controller For Windows Class
Setup Class GUID:	{d61ca365-5af4-4486-998b-9db4734c6ca3}
Software Key:	{d61ca365-5af4-4486-998b-9db4734c6ca3}\0001
Manufacturer:	Microsoft
Friendly Name:	
Hardware Location:	Port_#0001.Hub_#0007
PDO Name:	\Device\USBPDO-11


USB Input Device

Interface 0 HID Report Descriptor Game Pad
Item Tag (Value)	Raw Data
Usage Page (Generic Desktop)	05 01 
Usage (Game Pad)	09 05 
Collection (Application)	A1 01 
    Collection (Physical)	A1 00 
        Usage (X)	09 30 
        Usage (Y)	09 31 
        Logical Minimum (0)	15 00 
        Logical Maximum (-1)	26 FF FF 
        Physical Minimum (0)	35 00 
        Physical Maximum (-1)	46 FF FF 
        Report Count (2)	95 02 
        Report Size (16)	75 10 
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit)	81 02 
    End Collection	C0 
    Collection (Physical)	A1 00 
        Usage (Rx)	09 33 
        Usage (Ry)	09 34 
        Logical Minimum (0)	15 00 
        Logical Maximum (-1)	26 FF FF 
        Physical Minimum (0)	35 00 
        Physical Maximum (-1)	46 FF FF 
        Report Count (2)	95 02 
        Report Size (16)	75 10 
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit)	81 02 
    End Collection	C0 
    Collection (Physical)	A1 00 
        Usage (Z)	09 32 
        Logical Minimum (0)	15 00 
        Logical Maximum (-1)	26 FF FF 
        Physical Minimum (0)	35 00 
        Physical Maximum (-1)	46 FF FF 
        Report Count (1)	95 01 
        Report Size (16)	75 10 
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit)	81 02 
    End Collection	C0 
    Usage Page (Button)	05 09 
    Usage Minimum (Button 1)	19 01 
    Usage Maximum (Button 10)	29 0A 
    Report Count (10)	95 0A 
    Report Size (1)	75 01 
    Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit)	81 02 
    Usage Page (Generic Desktop)	05 01 
    Usage (Hat Switch)	09 39 
    Logical Minimum (1)	15 01 
    Logical Maximum (8)	25 08 
    Physical Minimum (0)	35 00 
    Physical Maximum (4155)	46 3B 10 
    Unit (None)	66 0E 00 
    Report Size (4)	75 04 
    Report Count (1)	95 01 
    Input (Data,Var,Abs,NWrp,Lin,Pref,Null,Bit)	81 42 
    Report Size (2)	75 02 
    Report Count (1)	95 01 
    Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit)	81 03 
    Report Size (8)	75 08 
    Report Count (2)	95 02 
    Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit)	81 03 
End Collection	C0 
	

PnP Properties

Description:	USB Input Device
Instance Status:	0180200Ah	DN_DRIVER_LOADED
		DN_STARTED
		DN_DISABLEABLE
		DN_NT_ENUMERATOR
		DN_NT_DRIVER
Instance ID:	USB\VID_046D&PID_C21D&IG_00\6&285BD627&0&00
Hardware IDs:	USB\VID_046D&PID_C21D&IG_00
Compatible IDs:	USB\Class_03&Subclass_00&Prot_00
	USB\Class_03&Subclass_00
	USB\Class_03
Service Name:	HidUsb
Setup Class:	HIDClass
Setup Class Description:	Human Interface Devices
Setup Class GUID:	{745a17a0-74d3-11d0-b6fe-00a0c90f57da}
Software Key:	{745a17a0-74d3-11d0-b6fe-00a0c90f57da}\0137
Manufacturer:	(Standard system devices)
Friendly Name:	
Hardware Location:	XBOX_360_DEVICE_00:00
PDO Name:	\Device\00000097


HID-compliant game controller

Description:	HID-compliant game controller
Instance Status:	0180200Ah	DN_DRIVER_LOADED
		DN_STARTED
		DN_DISABLEABLE
		DN_NT_ENUMERATOR
		DN_NT_DRIVER
Instance ID:	HID\VID_046D&PID_C21D&IG_00\7&25FB9FB7&0&0000
Hardware IDs:	HID\VID_046D&PID_C21D&IG_00
	HID_DEVICE_SYSTEM_GAME
	HID_DEVICE_UP:0001_U:0005
	HID_DEVICE
Compatible IDs:
Service Name:	
Setup Class:	HIDClass
Setup Class Description:	Human Interface Devices
Setup Class GUID:	{745a17a0-74d3-11d0-b6fe-00a0c90f57da}
Software Key:	{745a17a0-74d3-11d0-b6fe-00a0c90f57da}\0138
Manufacturer:	(Standard system devices)
Friendly Name:	
Hardware Location:	
PDO Name:	\Device\00000098
I have also captured USB packets from the device to help isolate the relevant changes to the bit mask. I will post them below.
User avatar
LanceMadsen
Posts: 3
Joined: Thu Aug 07, 2014 8:36 pm

Re: Building Xbox Controller Support into Keyboard

Post by LanceMadsen »

Here is an example of the captured data when pressing the "A" button on the gamepad:

Code: Select all

USB URB
USBPcap pseudoheader length: 27
IRP ID: 0xfffffa8005d5a010
IRP USBD_STATUS: USBD_STATUS_SUCCESS (0x00000000)
URB Function: URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER (0x0009)
IRP information: 0x01, Direction: PDO -> FDO
0000 000. = Reserved: 0x00
.... ...1 = Direction: PDO -> FDO (0x01)
URB bus id: 7
Device address: 1
Endpoint: 0x81, Direction: IN
1... .... = Direction: IN (1)
.000 0001 = Endpoint value: 1
URB transfer type: URB_INTERRUPT (0x01)
Packet Data Length: 20
bInterfaceClass: Unknown (0xffff)
Leftover Capture Data: 0014001000008000800080008000000000000000
When the A button is released it looks like this:

Code: Select all

USB URB
USBPcap pseudoheader length: 27
IRP ID: 0xfffffa8005feb670
IRP USBD_STATUS: USBD_STATUS_SUCCESS (0x00000000)
URB Function: URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER (0x0009)
IRP information: 0x01, Direction: PDO -> FDO
0000 000. = Reserved: 0x00
.... ...1 = Direction: PDO -> FDO (0x01)
URB bus id: 7
Device address: 1
Endpoint: 0x81, Direction: IN
1... .... = Direction: IN (1)
.000 0001 = Endpoint value: 1
URB transfer type: URB_INTERRUPT (0x01)
Packet Data Length: 20
bInterfaceClass: Unknown (0xffff)
Leftover Capture Data: 0014000000008000800080008000000000000000
I am still learning a lot, and am definitely a newbie, so forgive my lack of understanding. I am assuming if I can get the device to report to windows with similar device descriptors as the first post, and structure the data to be sent in this post I should be able to get games to think I have an xbox 360 controller connected and I have pressed the "A" button, correct?

Any feedback on things I might be misunderstanding would be appreciated.
User avatar
Matlo
Posts: 5768
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Building Xbox Controller Support into Keyboard

Post by Matlo »

LanceMadsen wrote: I am assuming if I can get the device to report to windows with similar device descriptors as the first post, and structure the data to be sent in this post I should be able to get games to think I have an xbox 360 controller connected and I have pressed the "A" button, correct?
The only way to know is to try.

I wouldn't be surprised that Microsoft restricted the Xinput driver use with a VID/PID whitelist.
GIMX creator
Post Reply