MPLAB Harmony Bluetooth Help
|
The library provides interfaces to support:
The library can be used by programs providing functionality for audio (A2DP, AVRCP and BLE), or BLE, or both.
For audio (A2DP/AVRCP/HFP), typically, there will be one simple state machine for the application and a second state machine just for the audio. After the application initializes, the audio state machine will open the BM64 Bluetooth Driver using a call to its Open function. Then, it will set up callbacks for each of two event handlers, and then open the codec driver using a call to its Open function and set up a callback from it. Then, the driver will wait until the BM64 initialization is complete, at which time the application state machine instructs the audio state machine to perform an initial buffer read from the BM64 using an AddRead call.
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; } } } break; case AUDIO_STATE_SET_BT_BUFFER_HANDLER: { DRV_BT_BufferEventHandlerSet(audioData.bt.handle, audioData.bt.bufferHandler, audioData.bt.context); DRV_BT_EventHandlerSet(audioData.bt.handle, audioData.bt.eventHandler, (uintptr_t)0); audioData.state = AUDIO_STATE_CODEC_OPEN; } break; case AUDIO_STATE_CODEC_OPEN: { audioData.codec.handle = DRV_CODEC_Open(DRV_CODEC_INDEX_0, DRV_IO_INTENT_WRITE | DRV_IO_INTENT_EXCLUSIVE); if(audioData.codec.handle != DRV_HANDLE_INVALID) { audioData.state = AUDIO_STATE_CODEC_SET_BUFFER_HANDLER; } } break; case AUDIO_STATE_CODEC_SET_BUFFER_HANDLER: { _setCodecSamplingRate(DRV_BT_AUDIO_SAMPLING_RATE); DRV_CODEC_BufferEventHandlerSet(audioData.codec.handle, audioData.codec.bufferHandler, audioData.codec.context); audioData.state = AUDIO_STATE_INIT_DONE; } break; case AUDIO_STATE_INIT_DONE: { // waits in this state until BT initialization done and app state machine // calls audioStart() to set state to AUDIO_STATE_BT_SUBMIT_INITIAL_READS break; }
After the initial buffer read has been completed, the buffer event handler for the BM64 will get a DRV_BT_BUFFER_EVENT_COMPLETE event. Once the queue has filled up, this will advance the audio state machine’s state so that it adds the buffer to the codec’s queue using its AddWrite function call. It then also makes a new call to the AddRead function to keep the queue filled.
When the buffer event handler for the codec gets a DRV_CODEC_BUFFER_EVENT_COMPLETE event, it will mark the buffer free for use again.
BLE-only applications are much simpler since they do not have to process any audio. Again typically there will be one simple state machine for the application and a second state machine just for the BLE functionality. After the application initializes, the BLE state machine will open the BM64 Bluetooth driver using a call to its Open function, then it will set up a callback for an event handler.
The application will call one of the BLE Send functions to send data to the host (smartphone). The event handler will be called whenever data has been received from the BM64, or when the connection status changes. See the BM64 demonstration application, BM64_ble_comm, for more information and example code.
Name |
Description |
This section describes the BM64 Bluetooth driver functions for initialization, maintaining task state and returning status. | |
This section describes the BM64 Bluetooth driver functions for client setup (open, close, and setting up event handlers). | |
This section describes the BM64 Bluetooth Driver data transfer function. | |
This section describes the BM64 Bluetooth Driver functions for getting and changing settings such as volume and sample rate. | |
This section describes the functions for getting and setting the sampling rate (e.g., 8000, 44100, or 48000 Hz) as a 32-bit integer. | |
This section describes the functions for getting and setting the Bluetooth device’s name and address. | |
This section describes the functions specific to Bluetooth Low Energy (BLE) operations, such as sending and receiving data, and BLE connection-related operations. |
MPLAB Harmony Bluetooth Help
|