none
Composite Device With Multiple Pre-installed Drivers (XInput) RRS feed

  • Question

  • Hi,

    I'm working on a composite device. I'm using a Teensy++ 2 board, but that shouldn't affect the question.

    I've managed to create a HID composite that consists of Mouse + Keyboard + DirectInput joystick. When that is plugged in, all works well. The drivers are detected automatically, and it "just works".

    Separately (without all the HID), I've managed to get the device recognized as an XInput controller. When connected, it automatically installs the XBox 360 Controller for Windows driver (xusb22.sys), and it "just works".

    Now I'm looking into how to put both of them together in a composite device, so Windows recognizes that it needs to install HID drivers for the HID interfaces, and XBox 360 Controller for Windows drivers for all 4 of the XInput interfaces.

    I've read through the driver and INF docs, but not all of the information has settled in yet. I have a feeling that I need to create an INF file, that would indicate that Windows should install the controller driver for the controller interfaces, but I'm not sure if that is the correct way to investigate.

    Can someone please guide me the right direction, or point out why this might not be possible?

    Best case I hope for is that I won't need to program a driver, but if that is not possible, I'm willing to do it. I would just like to know when to focus my time on.

    Thanks!


    Wednesday, January 8, 2020 8:15 AM

Answers

  • You had misunderstood the problem... As long as you are using a controller and some other interfaces together, it can cause problems, so even with the Xbox interface it can happen. It don't mean that you will have them for sure and the problems are only related to DirectInput anyway. Maybe you don't have problems now but maybe you have them later on. Like if you would toggle the XInput support, the chances that this will lead to the problem are very high. Like the controls can be displayed wrong for your device or for other devices if present, games which are using the DirectInput API can have problems and weird behaviour or you can see more entries that connected controller.

    Dealing with a Xbox controller on Win is a shame because Win apply a slot to them but you can't change or reorder them, in addition most games only accept the input from the controller from slot 1. To deal with that you need to unplug all Xbox controller, make a reboot and then plug them in in the order you want.

    No, you don't need to supply a driver at all. You just need to tell Win which driver should be used. To understand that you should read "Microsoft OS Descriptors for USB Devices". Be carefull, Win will only ask for the OS descriptors at the first time. So you need to change the revision number for the USB device describtor or you need to delete the flag in the Registry. This is all described in the documentaion.

    In short for the version 1.0, you need to tell Win that your device supports the OS describtor by having a specific string at a specific index for the USB string descriptor. Than Win will send specific requests to the device for askting about different OS specific describtors, one is the extended compatID describtor and this can be used for telling Win which driver should be applied to which interface.

    • Edited by Rocky 4 Friday, January 10, 2020 11:08 AM
    • Marked as answer by Algis Laureckis Tuesday, February 4, 2020 1:06 PM
    Friday, January 10, 2020 10:52 AM

All replies

  • Is your HID composite device 3 interfaces, each with a top-level collection, or is it one interface with three top-level collecgions?

    In any case, it doesn't really matter,  If the hid was interfaces 0, 1, and 2, and the XInput controller has interfaces 0, 1, 2, and 3, then just combine both together and renumber the XInput to 3, 4, 5, and 6.  Windows treats each interface of a composite device as a totally separate piece of hardware.  Adding the XInput interface won't change the handling of the HID interfaces, and vice versa.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Wednesday, January 8, 2020 10:12 PM
  • Thanks, I'll give it a go. But I'm not sure if Windows will recognize the XInput interfaces and install the right drivers for it. Currently from my testing it seems it will do that only if Vendor ID and Product ID are what Microsoft has defined, and I can't specify them as part of the XInput interface collection.
    Thursday, January 9, 2020 6:41 AM
  • - A Xbox 360 controller has multiple interfaces and the purpose is defined by the vendor defined describtor for the interfaces.

    - A Xbox 360 controller has a native XInput interface and a DirectInput interface (created from the driver) due to backwards compatibility.

    - Win assign driver by comparing the vendor and product ID. If your IDs don't match the ID for a driver you can tell Win to use a specific driver for your device. This can be done by using the combatID describtor from the OS 1.0 describtor documentation. For a Xbox 360 clone you need to use "XUSB10" (Xbox 360 driver which is shown as a wired controller) or "XUSB20" (Xbox 360 driver which is shown as a wireless controller).

    - For the XInput controller part you only need to clone the first interface at index 0 (Win should use the interface number -1 for this because it's special or so), because this handles the controls. The other interfaces are used for audio (in & out), the security chip and other things, so you don't really need to care about them.

    - You can mix the interfaces like you want, but as far as I know the interface for the Xbox controller must be the first interface of your composite device. 

    - You should not have any problems with the mouse, keyboard or DirectInput joystick at all because these are generic as long as you had used the values which are defined by the USB-IF for that devices.

    But it can be that you will have problems with application (even Win itself) which are using DirectInput. The reason is that Win will create a DirectInput entry for the DirectInput joystick and for the Xbox 360 controller, but also a few dummy entires between them for the other interfaces if you are unlucky. So it can create four entries where only two of them are actually controller / joysticks. The main problem is that this order isn't fixed and can changed depending of unknown reasons, leading in having more than two joystick IDs assigned to them if the order is changed. So than an interface which isn't a joystick can have a joystick ID assigned to it and this can make trouble. In short a joystick should only have joystick interfaces. So mixing a joystick with a mouse or a keyboard can cause problems. Having a device with a DirectInput joystick, a gamepad and a Xbox controller (if only the first interface is used) should be ok. Unfortuantly I don't found any workaroud besides a custom driver to deal with that problem.

    I guess because of this problem, the Xbox One driver creates a subdevice with a different product ID for the chatpad accessory so that only one joystick ID and one entry is assigned to the DirectInput joysticks. I don't know how the Xbox 360 driver hanldes that because I don't have a chatpad for it.

    • Edited by Rocky 4 Thursday, January 9, 2020 7:17 PM
    Thursday, January 9, 2020 3:05 PM
  • Thanks for the detailed explanation!

    Currently I have a mouse + KB + DirectInput implementation that works without problems (taken from example code), but if I need to toss DirectInput in order to have XInput to work, that is a sacrifice I am willing to make.

    As for "using the combatID describtor" - do I understand correctly, that I would need to supply a driver INF file (without an actual driver), for this?


    Friday, January 10, 2020 6:20 AM
  • You had misunderstood the problem... As long as you are using a controller and some other interfaces together, it can cause problems, so even with the Xbox interface it can happen. It don't mean that you will have them for sure and the problems are only related to DirectInput anyway. Maybe you don't have problems now but maybe you have them later on. Like if you would toggle the XInput support, the chances that this will lead to the problem are very high. Like the controls can be displayed wrong for your device or for other devices if present, games which are using the DirectInput API can have problems and weird behaviour or you can see more entries that connected controller.

    Dealing with a Xbox controller on Win is a shame because Win apply a slot to them but you can't change or reorder them, in addition most games only accept the input from the controller from slot 1. To deal with that you need to unplug all Xbox controller, make a reboot and then plug them in in the order you want.

    No, you don't need to supply a driver at all. You just need to tell Win which driver should be used. To understand that you should read "Microsoft OS Descriptors for USB Devices". Be carefull, Win will only ask for the OS descriptors at the first time. So you need to change the revision number for the USB device describtor or you need to delete the flag in the Registry. This is all described in the documentaion.

    In short for the version 1.0, you need to tell Win that your device supports the OS describtor by having a specific string at a specific index for the USB string descriptor. Than Win will send specific requests to the device for askting about different OS specific describtors, one is the extended compatID describtor and this can be used for telling Win which driver should be applied to which interface.

    • Edited by Rocky 4 Friday, January 10, 2020 11:08 AM
    • Marked as answer by Algis Laureckis Tuesday, February 4, 2020 1:06 PM
    Friday, January 10, 2020 10:52 AM
  • Understood, thank you very much. This helps a lot.

    Will post here when I get to a result.

    Friday, January 10, 2020 11:27 AM
  • Just wanted to update that everything worked out as described by Rocky 4.

    We were able to get a device working as both mouse, keyboard, DirectInput, raw HID and XInput device at the same time (customizable by the user), without any manual driver installation (thanks to Microsoft OS Descriptors for USB Devices).

    Just took a lot of fidling to get the descriptors right, and the XInput first interface had to be first.

    Thanks for all the help!

    Tuesday, February 4, 2020 1:10 PM