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. These must be defined as a raw uint8_t array.
Example 1: Layout of headphone descriptors in a raw array:
Example 2: Layout of microphone descriptors in a raw array:
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: Raw uint8_t 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:
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:
After the function is defined, you must register the new class to the USBD library:
Events defined by app_usbd_audio_user_event_t are passed to the user event handler. Requests defined for the audio class trigger the APP_USBD_AUDIO_USER_EVT_CLASS_REQ event. Access to the class request data is obtained by the app_usbd_audio_class_request_get function. Isochronous transfers trigger two types of events:
The library client must set up buffers for isochronous transfers:
Size of these transfer buffers must be the same as the endpoint size defined in raw descriptors. Example: After registering the headphones example presented above, the following buffer is set up:
Isochronous transfer buffer can be safely switched (or modified) only on the APP_USBD_AUDIO_USER_EVT_RX_DONE or APP_USBD_AUDIO_USER_EVT_RX_DONE events. Every isochronous transfer is synchronized with the Start of Frame event (SOF) and it is fired automatically when the transfer buffer is configured.