-
Notifications
You must be signed in to change notification settings - Fork 11
Composite Devices and Interface Associations
Composite devices are devices supporting multiple USB device classes. As an example, a loudspeaker might implement both the audio class and the HID class (used for keyboards) as it also includes volume buttons. Or a webcam with a built-in microphone will implement both the video and audio class. For both devices, each implemented class will use a separate USB interface and thus separate USB endpoints for communication.
If a composite device is plugged in, it will likely appear as multiple devices in the operating system, e.g. both as an audio and a video device.
Some devices use multiple USB interfaces, but the interfaces should be treated as a single device. An example is a virtual serial port using the USB CDC standard. It requires two interfaces: the CDC data interface for sending and receiving the serial data as well as the CDC communication interface for notifying the host about communication errors (parity error etc.) and changes to input signals (DCD, DSR etc.). To ensure that it appears as a single device, the configuration description contains an interface association descriptor (IAD) declaring that the two interfaces are associated (belong together).
A single USB device can be a composite device and use interface associations at the same time. An example are the STM Nucleo development boards. The integrated ST-Link debug adapter provides three functions: the ST-Link debugging protocol, a mass storage device for uploading firmware and a virtual serial port for serial communication with the microcontroller. The virtual serial port consists of two interfaces, the other functions of a single interface each, for a total of 4 interfaces. An interface association descriptor ensures that the two CDC interfaces are combined. So when the board is plugged in, three devices (or functions) will appear in the operating system.
The below illustration depicts the 4 interfaces, the IAD and the 3 resulting functions:
These concepts are mainly relevant for the Windows implementation of this library. If a device has multiple functions, the Windows API will present the USB device as a parent device and the functions as child devices. In order to communicate with a specific interface, the child device the interface belongs to needs to be opened, and the resulting handle must be used to open the interface.
If a device implements a single function, there are no child devices. Instead, the parent device is opened and its handle is used to open the interface(s).
This complexity does not exist on Linux and macOS.