Windows Composite device (usb audio class and custom bulk interface) via libusb? - usb

So we're looking to make a device for an internal test fixture that is a composite USB device with a standard audio class interface and a custom bulk interface. It's primary target is Windows10.
We'd like to use libusb for the custom bulk interface and the built in usbaudio.sys for the audio interface.
Is this possible to manage? I've read it wasn't possible 6 years ago, but things may have progressed so I'm asking again.

Related

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

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://learn.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://learn.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!
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

USB MSC with STM32Cube

I'm using STM32Cube to generate simple USB MSC project. I'm using STM32F417VG.
So I'm selecting USB_OTG_FS - Device_only and USB_DEVICE - Class For FS IP - Mass Storage Class.
Then I'm generating source code, compile it and download to board, put it's USB cable to PC and nothing happens.
What am I doing wrong?
The STM32Cube application helps you get started on developing an application, but does not do the work for you. The generated code will include all the libraries necessary and initialize the hardware so that all the functions you selected are available and ready to go, and then begin an empty infinite loop. It will not show any outward behavior or respond to any external stimulus.
You will need to add some of your own code for the microcontroller to actually do anything.
If you are unsure what you need to do to make the USB functions work, take a look at the example projects that come with STM32Cube and the documentation comments in the library files it included in your project.
However, even a "simple" USB project can be relatively complex, and an unresponsive microcontroller can be mystifying. You may want to get your bearings with very simple GPIO-type projects. Making an LED blink is a microcontroller's "Hello World".

Is it possible to communicate with smartcard from QML?

I want to know if it's possible for QML (because it's used in a lot of mobile OSes) to interact with a nfc smartcard i.e. credit card, transit pass, passport etc. or with C++ code also used in developing QML apps.
There is Qt NFC API, but it's only supported on BlackBerry devices. However, QML can be easily extended using C++, so if you can do it in C++, you can basically do it in QML. All you have to do is create appropriate bindings, which is not that hard.

How can I debug a USB HID device that does not come with a driver?

I have a single button USB controller, but it did not come with any drivers (simply a Windows program that communicates with it directly for its intended purpose).
USB Fidget
Vendor ID: 0x1d34
Product ID: 0x0001
Product name: DL100A Dream Cheeky Generic Controller
So, I would like to be able to read whether or not the button is being pressed. My main development environment is Mac, but I'd like the solution to run on Windows too. So ideally a cross platform solution would be best.
I can find pieces of code for other devices by the same manufacturer but there are differences in Product ID so the code does not work and I lack understanding to change anything other than the vendor/product.
As far as I understand it I need to poll the USB device with a feature request packet?
Is there some software I can use to "watch" the USB device so I can see what is actually happening when I press the button? If not, how would I go about writing some myself?
basically on MacOs very huge amount of usb devices work through IOUserClient. This standart class provide to user mode programs ability to control device without kernel mode driver (by using usermode part of IOKit framework). To sniff for usb packets you can use USB Prober, start from this article http://developer.apple.com/library/mac/#qa/qa1370/_index.html
On windows standart way - standart USB driver + standart HID driver, no need in specific vendor driver if they not develop some additional functionality over standart. You can use any of commercial or freeware tools to sniff usb packets - like this one http://www.hhdsoftware.com/usb-monitor
I don't know of any cross platform way to handle it. This is the presentation I point people to for how to create a driver app for a random piece of HID hardware:
https://developer.apple.com/videos/wwdc/2011/?id=207
For testing / accessing HID devices, i.e.
Get Feature Report (matt's original question)
Sending Feature Reports
Sending Output Reports
Receiving Input reports
I'd suggest the "HIDAPI Test Tool" / "testgui" included in the great cross-platform HID library from signal11/hidapi.
On Windows you require an additional 3rd party package to compile the testgui application, but it was pretty easy and the GUI tool was more straightforward that other code examples and tools I saw. (I could cross-check if I am maybe allowed to publish a VS2008 compiled version of this.)
Another free option for sending output reports and receiving input reports, is our own "Docklight" tool (in evaluation mode, unlimited time, just no storing), see Docklight Scripting HID USB.

Making my own application for my USB MIDI device

I want to try and make my own application for my Novation Nocturn, which is a USB DJ controller surface. The application software interacts with it to send out MIDI messages to software like Traktor, Ableton and Cubase.
I'm aware of libusb, but that's as far as I've got. I've successfully installed it to interact with my device but stopped there.
I'm after some suitable reading material basically. USB specs, MIDI specs and such. If I'm honest the full USB 2.0 spec looks like it holds loads of stuff I don't need.
Just looking for something interesting to do now that I've finished my degree (Computer Science). My current programming knowledge is C++ and mainly C#.
Could do with some direction on how to get stuck into this task.
edit:
Update to include some info from the Device Manager on the Nocturn.
Hardware IDs:
USB\VID_1235&PID_000A&REV_0009
USB\VID_1235&PID_000A
Compatible IDs:
USB\Class_FF&SubClass_00&Prot_00
USB\Class_FF&SubClass_00
USB\Class_FF
Device Class:
MEDIA
USB MIDI is probably one abstraction layer lower than you want to deal with. I'd suggest finding a good MIDI framework and interacting with the device via MIDI instead.
For C++, Juce is probably the way to go, as you didn't mention a target platform or any other specific requirements.
If you want to go the .NET route, the easiest way to get started is with the C# MIDI Toolkit code:
http://www.codeproject.com/KB/audio-video/MIDIToolkit.aspx
In there, you'll find all the basics for opening an device, reading input, and writing output. Alternatively, NAudio has some MIDI classes, but they are somewhat incomplete.
As you develop, you'll want a reference for the MIDI spec handy.
A tool that you will find invaluable is MIDI-OX. In fact, I suggest that before you start coding, you fire up MIDI-OX and use it to sniff the messages coming from the Novation. It will give you a good idea of what the Novation sends. You can use it in conjunction with MIDI Yoke (a configurable virtual MIDI port) to insert itself between the Novation, and Ableton Live (or whatever software you normally use with your Novation) so you can see all of the messages in normal use.
Done... Kidding, but I've started on this in Python - I personally want linux support. I am teaching myself python, but I only dabble in programming.
You can see basic functionality at https://github.com/dewert/nocturn-linux-midi. The guy who reverse engineered it (i.e. the leap I wouldn't have been able to make myself) doesn't seem to be doing any more with it. His code is at https://github.com/timoahummel/nocturn-game
I am using PyPortMIDI and PyUSB, both of which I believe are wrappers for the C equivalents. I think this is all ok on Windows, but haven't tried.
What is currently on my github is crap, but it is proof-of-concept. I'm working on doing it properly now, with threading and proper configuration options.
The driver for the Nocturn makes it appear to system as a MIDI device, even though it isn't a USB MIDI device at the hardware level. The Automap software works entirely at the MIDI level, receiving MIDI instructions and sending different instructions in response - it is separate from the driver and not neccesary.
Alternatively, look at https://github.com/timoahummel/nocturn-game for an example of talking to it directly over USB from Python. You can probably port this to another language with libusb bindings.
Old thread, but I've just recently started looking into this.
I had a look at the Python application that dewert has written. Interestingly, it turns out that the data that the Nocturn emits is in fact MIDI, although it doesn't register itself as a USB MIDI device.
But looking at the actual data coming from the device, it actually emits control change messages (0xB0 controller value) for everything. Also the control commands that are sent to it are also control change messages, albeit only the data bytes, as the Nocturn seems to support MIDI running status (i.e. when sending multiple control change messages, it is not necessary to repeat the data byte).
Indeed, the looking at the magical initialization data it is actually just a bunch of control changes: it starts with 0xb0 and from there on the data comes in twos. For instance the last two bytes in the init string are 0x7f 0x00 which simply turn off the LED for the rightmost forward button. (There is something subtle happening as a result of the initialization being sent though, as the Nocturn sometimes emits some messages which appear to be some form of timeout events, and that behavior changes depending on whether the initialization string has been sent or not.)
Using MIDI-like messages makes sense, as Novation would be well aware of the MIDI protocol, so it would be easiest for them to use it for the communication even if the device is not strictly a MIDI device.
Note though that the incrementors just send the values 1 or 127, i.e. +1 or -1 step, so even with some trivial mapping software it's not really useful as it is. (Actually, if turned quickly, one can get 3 or 125 for instance, with the 125 corresponding to -3.) The only controller which sends a continuous value is the slider, which emits an 8 bit value when moved.
I suppose you'll want to know about USB classes in general and USB MIDI class in particular. The latter is the best what you can hope for in case you don't posess documentation for some proprietary protocol (whether it's used there instead).