Files added to implement Audio Class functions:
usb-audio-v2_0.h
usb-device-audio-v2_0.h
APIs provided:
- USB_DEVICE_AUDIO_V2_Write
- USB_DEVICE_AUDIO_V2_Read
- USB_DEVICE_AUDIO_V2_TransferCancel
- USB_DEVICE_AUDIO_V2_EventHandlerSet
USB_DEVICE_AUDIO_V2_Write
Description | Parameters | Returns |
---|---|---|
USB_DEVICE_AUDIO_V2_Write initiates a write by requesting data to be placed in the specified endpoint. The write will be completed when the host requests the data. |
instance, transfer handle, interface num, data, size |
Status of the transfer request |
Parameters:
instance - USB Device Audio Function Driver instance.
transfer handle - Pointer to a USB_DEVICE_AUDIO_V2_TRANSFER_HANDLE type of
variable. This variable will contain the transfer
handle, in case the write request was successful.
interface num - The USB Audio streaming interface number on which the
write request is to be placed.
data - Pointer to the data buffer, contains the data to be written.
(For PIC32MZ devices, this buffer should be located in
the coherent memory and should be aligned a 4 byte boundary.
size - Size of the data buffer.
Example of writing to an Audio V2.0 Interface
USB_DEVICE_AUDIO_V2_RESULT result;
USB_DEVICE_AUDIO_V2_INDEX instanceIndex;
USB_DEVICE_AUDIO_V2_TRANSFER_HANDLE transferHandle;
unit8_t interfaceNumber;
instanceIndex = 0; // specify the Audio Function driver instance number.
interfaceNumber = 1; // specify the Audio Streaming interface number.
result = USB_DEVICE_AUDIO_V2_Write( instanceIndex,
transferHandle,
interfaceNumber,
&txBuffer , 127);
if( result != USB_DEVICE_RESULT_OK)
{
//Handle error.
}
USB_DEVICE_AUDIO_V2_Read
Description | Parameters | Returns |
---|---|---|
USB_DEVICE_AUDIO_V2_read requests the contents of an audio device interface be read into a receive buffer. |
instance, transfer handle, interface num, data, size |
Status of the transfer request |
Parameters:
instance - USB Device Audio Function Driver instance.
transfer handle - Pointer to a USB_DEVICE_AUDIO_V2_TRANSFER_HANDLE type of
variable. This variable will contain the transfer
handle, in case the write request was successful.
interface num - The USB Audio streaming interface number on which the
write request is to be placed.
data - Pointer to the data buffer, contains the data to be written.
(For PIC32MZ devices, this buffer should be located in
the coherent memory and should be aligned a 4-byte boundary.
size - Size of the data buffer.
Example of reading from an Audio V2.0 Interface
USB_DEVICE_AUDIO_V2_RESULT result;
USB_DEVICE_AUDIO_V2_INDEX instanceIndex;
USB_DEVICE_AUDIO_V2_TRANSFER_HANDLE transferHandle;
unit8_t interfaceNumber;
instanceIndex = 0; // specify the Audio Function driver instance number.
interfaceNumber = 1; // specify the Audio Streaming interface number.
result = USB_DEVICE_AUDIO_V2_Read( instanceIndex,
transferHandle,
interfaceNumber,
&rxBuffer , 64);
if( result != USB_DEVICE_RESULT_OK)
{
//Handle error.
}
USB_DEVICE_AUDIO_V2_TransferCancel
Description | Parameters | Returns |
---|---|---|
USB_DEVICE_AUDIO_V2_TransferCancel terminates a scheduled but incomplete transfer to or from an audio interface. |
instance, transfer handle, |
Status of the transfer request |
Parameters:
instance - USB Device Audio Function Driver instance.
transfer handle - Pointer to a USB_DEVICE_AUDIO_V2_TRANSFER_HANDLE type of
variable. This variable will contain the transfer
handle, in case the write request was successful.
Example of cancelling a pending Audio V2.0 Transfer
USB_DEVICE_AUDIO_V2_RESULT result;
USB_DEVICE_AUDIO_V2_INDEX instanceIndex;
USB_DEVICE_AUDIO_V2_TRANSFER_HANDLE transferHandle;
result = USB_DEVICE_AUDIO_V2_TransferCancel( instanceIndex,
transferHandle );
if( result != USB_DEVICE_RESULT_OK)
{
//Handle error.
}
USB_DEVICE_AUDIO_V2_EventHandlerSet
Description | Parameters | Returns |
---|---|---|
USB_DEVICE_AUDIO_V2_EventHandlerSet registers a user written function as the event handler for AUDIO 2.0 events. |
instance, event handler, context |
Status of the transfer request |
Parameters:
instance - USB Device Audio Function Driver instance.
event handler - Pointer to a user-written function, to handle the
events which occur during the typical USB AUDIO transactions.
context - The application parameter, uintptr_t is to be passed to the event handler
where the write request is to be placed.
Example of writing to an Audio V2.0 Interface
USB_DEVICE_AUDIO_V2_RESULT result;
unit8_t interfaceNumber;
result = USB_DEVICE_AUDIO_V2_EventHandlerSet ( USB_DEVICE_AUDIO_V2_INSTANCE_0 ,
&APP_USBDeviceAUDIOEventHandler, 0 );
if( result != USB_DEVICE_RESULT_OK)
{
//Handle error.
}