This module allows to create and handle USB audio class instances. For detailed information on the USB audio class, refer to these specification documents:
A typical audio class has one control interface and one streaming interface. Before you can declare a class instance, you must first properly define the audio class descriptors:
Example 1: Layout of headphone descriptors:
Example 2: Layout of microphone descriptors:
The difference between headphones and microphone descriptors is in the direction of the isochronous endpoint descriptor. Microphone has the IN direction defined (from the USB device to the host). For headphones, the isochronous endpoint direction is set to OUT (from the host to the USB device). Both of these classes have two audio streaming descriptors:
Example: Descriptors for an audio class (Headphones: 2 channels, Fs = 48KHz, Format 16bit PCM):
When all descriptors are correctly defined, you can define the audio class:
If you wish to skip an optional descriptor, use NULL:
To work with isochronous endpoints, you must use a SOF event. This means that the SOF event must be activated when calling the app_usbd_init function:
When timing is critical, it is possible to prepare for processing the SOF event directly in the interrupt - before the event queue is processed:
When the SOF event is processed, transfer may be started in any direction inside this event. The following example code shows transferring of audio data from the headphones to the buffer:
Audio class defines 3 events:
You can pass an event handler function to the class instance definition. The following is an example of a correct audio class user event handler prototype:
In this example code, the APP_USBD_AUDIO_USER_EVT_RX_DONE event is used to start the transfer of the data received from headphone output to the microphone input:
After the whole class instance is defined, you must register the new class to the USBD library: