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:
Tue May 19 05:01:10 2015 +0000
Revision:
5:7c7220a316ed
Parent:
4:21eee6881dac
Child:
6:23d9a99dcde0
Updating documentation.

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 2:3ce9a31a6a7e 4 /** 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 5 *
dishbreak 2:3ce9a31a6a7e 6 * Example:
dishbreak 2:3ce9a31a6a7e 7 * @code
dishbreak 2:3ce9a31a6a7e 8 * #include "mbed.h"
dishbreak 2:3ce9a31a6a7e 9 * #include "BGLib.h"
dishbreak 2:3ce9a31a6a7e 10 *
dishbreak 2:3ce9a31a6a7e 11 * BGLib ble112(p9, p10, p7, p8);
dishbreak 2:3ce9a31a6a7e 12 *
dishbreak 2:3ce9a31a6a7e 13 * uint8_t hello_msg[] = {0x00, 0x00, 0x00, 0x01};
dishbreak 2:3ce9a31a6a7e 14 *
dishbreak 2:3ce9a31a6a7e 15 * void helloCallback() {
dishbreak 2:3ce9a31a6a7e 16 * //executed when code compiles.
dishbreak 2:3ce9a31a6a7e 17 * }
dishbreak 2:3ce9a31a6a7e 18 *
dishbreak 2:3ce9a31a6a7e 19 * int main() {
dishbreak 2:3ce9a31a6a7e 20 * ble112.set_ble_rsp_system_hello(&helloCallback);
dishbreak 2:3ce9a31a6a7e 21 * ble112.ble_cmd_system_hello();
dishbreak 2:3ce9a31a6a7e 22 * }
dishbreak 5:7c7220a316ed 23 * @endcode
dishbreak 2:3ce9a31a6a7e 24 */
dishbreak 1:3336b2391c80 25
dishbreak 5:7c7220a316ed 26 class BGLib {
dishbreak 5:7c7220a316ed 27
dishbreak 5:7c7220a316ed 28
dishbreak 1:3336b2391c80 29 public:
dishbreak 2:3ce9a31a6a7e 30 /** Create a BGLib instance
dishbreak 2:3ce9a31a6a7e 31 * @param tx Pin to use for UART transmission
dishbreak 2:3ce9a31a6a7e 32 * @param rx Pin to use for UART reception
dishbreak 2:3ce9a31a6a7e 33 * @param rts Flow control pin used for RTS.
dishbreak 2:3ce9a31a6a7e 34 * @param cts Flow control pin used for CTS.
dishbreak 2:3ce9a31a6a7e 35 */
dishbreak 1:3336b2391c80 36 BGLib(PinName tx, PinName rx, PinName rts, PinName cts);
dishbreak 1:3336b2391c80 37
dishbreak 2:3ce9a31a6a7e 38 /** Send a Hello command to the device. */
dishbreak 2:3ce9a31a6a7e 39 void ble_cmd_system_hello();
dishbreak 2:3ce9a31a6a7e 40
dishbreak 2:3ce9a31a6a7e 41 /** Set the callback for a Hello command. Invoked when a response arrives.
dishbreak 2:3ce9a31a6a7e 42 * @param pCallback Function pointer to the desired callback.
dishbreak 2:3ce9a31a6a7e 43 */
dishbreak 2:3ce9a31a6a7e 44 void set_ble_rsp_system_hello(hello_callback_t pCallback);
dishbreak 2:3ce9a31a6a7e 45
dishbreak 2:3ce9a31a6a7e 46 /** Send a Get Info command to the device. */
dishbreak 2:3ce9a31a6a7e 47 void ble_cmd_system_get_info();
dishbreak 2:3ce9a31a6a7e 48
dishbreak 2:3ce9a31a6a7e 49 /** Set the callback for a Get Info command. Invoked when a response arrives.
dishbreak 2:3ce9a31a6a7e 50 * @param pCallback Function pointer to the desired callback.
dishbreak 2:3ce9a31a6a7e 51 */
dishbreak 2:3ce9a31a6a7e 52 void set_ble_rsp_system_get_info(get_info_callback_t pCallback);
dishbreak 1:3336b2391c80 53
dishbreak 3:8f43af513d87 54 /** Send a Reset command to the device. */
dishbreak 3:8f43af513d87 55 void ble_cmd_system_reset(ble_msg_system_reset_t args);
dishbreak 3:8f43af513d87 56
dishbreak 3:8f43af513d87 57 /** Set the callback for a Boot event. Invoked when the BLE112 is powered on or reset.
dishbreak 3:8f43af513d87 58 * @param pCallback Function pointer to the desired callback.
dishbreak 3:8f43af513d87 59 */
dishbreak 3:8f43af513d87 60 void set_ble_evt_system_boot(boot_callback_t pCallback);
dishbreak 3:8f43af513d87 61
dishbreak 4:21eee6881dac 62 /** Set a "timestamping" callback. This is invoked whenever the mbed receives data on the UART interface.
dishbreak 4:21eee6881dac 63 * @param pCallback Function pointer to the desired callback.
dishbreak 4:21eee6881dac 64 */
dishbreak 4:21eee6881dac 65 void set_timestamp_callback(timestamp_callback_t pCallback);
dishbreak 4:21eee6881dac 66
dishbreak 1:3336b2391c80 67 private:
dishbreak 1:3336b2391c80 68 void parse();
dishbreak 1:3336b2391c80 69 void send_bytes(uint8_t bytes[], int length);
dishbreak 3:8f43af513d87 70
dishbreak 1:3336b2391c80 71 Serial mSerial;
dishbreak 2:3ce9a31a6a7e 72
dishbreak 1:3336b2391c80 73 hello_callback_t mHelloCallback;
dishbreak 2:3ce9a31a6a7e 74 get_info_callback_t mGetInfoCallback;
dishbreak 3:8f43af513d87 75 boot_callback_t mBootCallback;
dishbreak 4:21eee6881dac 76 timestamp_callback_t mTimestampCallback;
dishbreak 1:3336b2391c80 77
dishbreak 1:3336b2391c80 78 };