Partial implementation of BlueGiga's BGAPI for use with the BLE112/3 modules over UART.

Hi there! I recently started using BLE112 modules with the mbed LPC1768 MCU, and I realized there was no implementation of BlueGiga's BGAPI available for mbed. This library implements only a few commands, but if you're looking to get started, this is a good place to look.

This was developed against BGAPI v1.3.2. I make no guarantees as to how well it will work with newer revisions of the software.

Committer:
dishbreak
Date:
Mon May 18 01:16:52 2015 +0000
Revision:
2:3ce9a31a6a7e
Parent:
1:3336b2391c80
Child:
3:8f43af513d87
Added support for Get Info command.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dishbreak 1:3336b2391c80 1 #include "mbed.h"
dishbreak 2:3ce9a31a6a7e 2 #include "callbacks.h"
dishbreak 1:3336b2391c80 3
dishbreak 1:3336b2391c80 4
dishbreak 1:3336b2391c80 5 class BGLib {
dishbreak 2:3ce9a31a6a7e 6 /** A class which can communicate with a BlueGiga BLE112(3) over a UART Connection. Note that all communication is asynchronous. Your class will have to supply callbacks for each command it intends to use.
dishbreak 2:3ce9a31a6a7e 7 *
dishbreak 2:3ce9a31a6a7e 8 * Example:
dishbreak 2:3ce9a31a6a7e 9 * @code
dishbreak 2:3ce9a31a6a7e 10 * #include "mbed.h"
dishbreak 2:3ce9a31a6a7e 11 * #include "BGLib.h"
dishbreak 2:3ce9a31a6a7e 12 *
dishbreak 2:3ce9a31a6a7e 13 * BGLib ble112(p9, p10, p7, p8);
dishbreak 2:3ce9a31a6a7e 14 *
dishbreak 2:3ce9a31a6a7e 15 * uint8_t hello_msg[] = {0x00, 0x00, 0x00, 0x01};
dishbreak 2:3ce9a31a6a7e 16 *
dishbreak 2:3ce9a31a6a7e 17 * void helloCallback() {
dishbreak 2:3ce9a31a6a7e 18 * //executed when code compiles.
dishbreak 2:3ce9a31a6a7e 19 * }
dishbreak 2:3ce9a31a6a7e 20 *
dishbreak 2:3ce9a31a6a7e 21 * int main() {
dishbreak 2:3ce9a31a6a7e 22 * ble112.set_ble_rsp_system_hello(&helloCallback);
dishbreak 2:3ce9a31a6a7e 23 * ble112.ble_cmd_system_hello();
dishbreak 2:3ce9a31a6a7e 24 * }
dishbreak 2:3ce9a31a6a7e 25 */
dishbreak 1:3336b2391c80 26
dishbreak 1:3336b2391c80 27 public:
dishbreak 2:3ce9a31a6a7e 28 /** Create a BGLib instance
dishbreak 2:3ce9a31a6a7e 29 * @param tx Pin to use for UART transmission
dishbreak 2:3ce9a31a6a7e 30 * @param rx Pin to use for UART reception
dishbreak 2:3ce9a31a6a7e 31 * @param rts Flow control pin used for RTS.
dishbreak 2:3ce9a31a6a7e 32 * @param cts Flow control pin used for CTS.
dishbreak 2:3ce9a31a6a7e 33 */
dishbreak 1:3336b2391c80 34 BGLib(PinName tx, PinName rx, PinName rts, PinName cts);
dishbreak 1:3336b2391c80 35
dishbreak 2:3ce9a31a6a7e 36 /** Send a Hello command to the device. */
dishbreak 2:3ce9a31a6a7e 37 void ble_cmd_system_hello();
dishbreak 2:3ce9a31a6a7e 38
dishbreak 2:3ce9a31a6a7e 39 /** Set the callback for a Hello command. Invoked when a response arrives.
dishbreak 2:3ce9a31a6a7e 40 * @param pCallback Function pointer to the desired callback.
dishbreak 2:3ce9a31a6a7e 41 */
dishbreak 2:3ce9a31a6a7e 42 void set_ble_rsp_system_hello(hello_callback_t pCallback);
dishbreak 2:3ce9a31a6a7e 43
dishbreak 2:3ce9a31a6a7e 44 /** Send a Get Info command to the device. */
dishbreak 2:3ce9a31a6a7e 45 void ble_cmd_system_get_info();
dishbreak 2:3ce9a31a6a7e 46
dishbreak 2:3ce9a31a6a7e 47 /** Set the callback for a Get Info command. Invoked when a response arrives.
dishbreak 2:3ce9a31a6a7e 48 * @param pCallback Function pointer to the desired callback.
dishbreak 2:3ce9a31a6a7e 49 */
dishbreak 2:3ce9a31a6a7e 50 void set_ble_rsp_system_get_info(get_info_callback_t pCallback);
dishbreak 1:3336b2391c80 51
dishbreak 1:3336b2391c80 52 private:
dishbreak 1:3336b2391c80 53 void parse();
dishbreak 1:3336b2391c80 54 void send_bytes(uint8_t bytes[], int length);
dishbreak 1:3336b2391c80 55 Serial mSerial;
dishbreak 2:3ce9a31a6a7e 56
dishbreak 1:3336b2391c80 57 hello_callback_t mHelloCallback;
dishbreak 2:3ce9a31a6a7e 58 get_info_callback_t mGetInfoCallback;
dishbreak 1:3336b2391c80 59
dishbreak 1:3336b2391c80 60 };