1.1.4.4.3 DRV_WM8904_BufferEventHandlerSet Function

void DRV_WM8904_BufferEventHandlerSet

(

DRV_HANDLE handle,

const DRV_WM8904_BUFFER_EVENT_HANDLER eventHandler, const uintptr_t contextHandle

)

Summary

This function allows a client to identify a buffer event handling function for the driver to call back when queued buffer transfers have finished.

Description

When a client calls DRV_WM8904_BufferAddWrite function, it is provided with a handle identifying the buffer that was added to the driver's buffer queue. The driver will pass this handle back to the client by calling "eventHandler" function when the buffer transfer has completed.

The event handler should be set before the client performs any "buffer add" operations that could generate events. The event handler once set, persists until the client closes the driver or sets another event handler (which could be a "NULL" pointer to indicate no callback).

Preconditions

The DRV_WM8904_Initialize routine must have been called for the specified WM8904 driver instance.

DRV_WM8904_Open must have been called to obtain a valid opened device handle.

Parameters

ParametersDescription
handleA valid open-instance handle, returned from the driver's open routine
eventHandlerPointer to the event handler function.
contextThe value of parameter will be passed back to the client unchanged, when the eventHandler function is called. It can be used to identify any client specific data object that identifies the instance of the client module (for example, it may be a pointer to the client module's state structure).

Returns

None.

Remarks

If the client does not want to be notified when the queued buffer transfer has completed, it does not need to register a callback.

Example

MY_APP_OBJ myAppObj;

uint8_t mybuffer[MY_BUFFER_SIZE]; DRV_WM8904_BUFFER_HANDLE bufferHandle;

_// myWM8904Handle is the handle returned // by the DRV_WM8904_Open function._

_// Client registers an event handler with driver_

DRV_WM8904_BufferEventHandlerSet(myWM8904Handle,

APP_WM8904BufferEventHandler, (uintptr_t)&myAppObj);

DRV_WM8904_BufferAddWrite(myWM8904handle, &bufferHandle myBuffer, MY_BUFFER_SIZE); if(DRV_WM8904_BUFFER_HANDLE_INVALID == bufferHandle) {

_// Error handling here_

}

_// Event is received when // the buffer is processed._

void APP_WM8904BufferEventHandler(DRV_WM8904_BUFFER_EVENT event, DRV_WM8904_BUFFER_HANDLE bufferHandle, uintptr_t contextHandle)

{ _// contextHandle points to myAppObj._ switch(event) { case DRV_WM8904_BUFFER_EVENT_COMPLETE: _// This means the data was transferred._ break; case DRV_WM8904_BUFFER_EVENT_ERROR: _// Error handling here._ break; default: break; }

}

C

void DRV_WM8904_BufferEventHandlerSet(DRV_HANDLE handle, const DRV_WM8904_BUFFER_EVENT_HANDLER eventHandler, const uintptr_t contextHandle);