Drivers Libraries Help > BM64 Bluetooth Driver Library > Using the Library > How the Library Works > Client Functions
MPLAB Harmony Bluetooth Help
Client Functions
Open and Close

For the application to start using an instance of the module, it must call the DRV_BM64_Open function which provides a driver handle to the BM64 Bluetooth driver instance.

 
Note: 
It is necessary to check the status of driver initialization before opening a driver instance. The status of the BM64 Bluetooth Driver can be known by calling DRV_BM64_Status

Example:

case AUDIO_STATE_OPEN:
{
    if (SYS_STATUS_READY == DRV_BT_Status())
    {
        // open BT module, including RX audio stream
        audioData.bt.handle = DRV_BT_Open(DRV_IO_INTENT_READ, DRV_BT_PROTOCOL_ALL);
        if(audioData.bt.handle != DRV_HANDLE_INVALID)
        {
            audioData.state = AUDIO_STATE_SET_BT_BUFFER_HANDLER;
        }
    }
}
Event Handlers

Event handlers are functions in the user’s code that are used as callbacks from the driver when something occurs that the client needs to know about. 

The function DRV_BM64_BufferEventHandlerSet is called by a client to identify a buffer-related event handling function for the driver to call back. The prototype for the callback is defined by DRV_BM64_BUFFER_EVENT_HANDLER. The callback will be called with the event DRV_BT_BUFFER_EVENT_COMPLETE. 

The function DRV_BM64_EventHandlerSet is called by a client to identify a general event handling function for the driver to call back. The prototype for the callback is defined by DRV_BM64_EVENT_HANDLER

For audio applications, the callback will be called with events such as DRV_BT_EVENT_VOLUME_CHANGED, DRV_BT_EVENT_SAMPLERATE_CHANGED, and DRV_BT_EVENT_PLAYBACK_STATUS_CHANGED. For BLE applications, the callback will be called for events such as DRV_BT_EVENT_BLESPP_MSG_RECEIVED and DRV_BT_EVENT_BLE_STATUS_CHANGED. 

Example:  

case APP_STATE_SET_BT_BUFFER_HANDLER:
{
    // note generic version of calls (DRV_BT instead of DRV_BM64) are used
    DRV_BT_BufferEventHandlerSet(appData.bt.handle, appData.bt.bufferHandler,
                                 appData.bt.context);
    DRV_BT_EventHandlerSet(appData.bt.handle, appData.bt.eventHandler, (uintptr_t)0);
    appData.state = APP_STATE_CODEC_OPEN;
}