USB Libraries Help > USB Device Libraries > USB Audio 2.0 Device Library > Library Interface > a) Functions > USB_DEVICE_AUDIO_V2_EventHandlerSet Function
MPLAB Harmony USB Stack
USB_DEVICE_AUDIO_V2_EventHandlerSet Function

This function registers a event handler for the specified Audio function driver instance. This function should be called by the application when it receives a SET CONFIGURATION event from the device layer. The application must register an event handler with the function driver in order to receive and respond to function driver specific events and control transfers. If the event handler is not registered, the device layer will stall function driver specific commands and the USB device may not function.

C
USB_DEVICE_AUDIO_V2_RESULT USB_DEVICE_AUDIO_V2_EventHandlerSet(
    USB_DEVICE_AUDIO_V2_INDEX instanceIndex, 
    USB_DEVICE_AUDIO_V2_EVENT_HANDLER eventHandler, 
    uintptr_t context
);
Preconditions

This function should be called when the function driver has been initialized as a result of a set configuration.

Parameters
Parameters 
Description 
instance 
Instance of the Audio v2.0 Function Driver. 
eventHandler 
A pointer to event handler function. 
context 
Application specific context that is returned in the event handler. 
Returns
  • USB_DEVICE_AUDIO_V2_RESULT_OK - The operation was successful
  • USB_DEVICE_AUDIO_V2_RESULT_ERROR_INSTANCE_INVALID - The specified instance does not exist.
  • USB_DEVICE_AUDIO_V2_RESULT_ERROR_PARAMETER_INVALID - The eventHandler parameter is NULL
Remarks

None.

Example
// The following code shows an example registering an event handler. The
// application specifies the context parameter as a pointer to an
// application object (appObject) that should be associated with this 
// instance of the Audio function driver.

USB_DEVICE_AUDIO_V2_RESULT result;

USB_DEVICE_AUDIO_V2_EVENT_RESPONSE APP_USBDeviceAUDIOEventHandler
(
    USB_DEVICE_AUDIO_V2_INDEX instanceIndex ,
    USB_DEVICE_AUDIO_V2_EVENT event ,
    void* pData,
    uintptr_t context
)
{
    // Event Handling comes here

    switch(event) 
    {
        ...
    }

    return(USB_DEVICE_AUDIO_V2_EVENT_RESPONSE_NONE);
}

result = USB_DEVICE_AUDIO_V2_EventHandlerSet ( USB_DEVICE_AUDIO_V2_INSTANCE_0 ,
            &APP_USBDeviceAUDIOEventHandler, (uintptr_t) &appObject);

if(USB_DEVICE_AUDIO_V2_RESULT_OK != result)
{
    // Do error handling here
}