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.
BGLib.h@4:21eee6881dac, 2015-05-19 (annotated)
- Committer:
- dishbreak
- Date:
- Tue May 19 04:35:46 2015 +0000
- Revision:
- 4:21eee6881dac
- Parent:
- 3:8f43af513d87
- Child:
- 5:7c7220a316ed
Added support for timestamp callback.
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:8f43af513d87 | 52 | /** Send a Reset command to the device. */ |
dishbreak | 3:8f43af513d87 | 53 | void ble_cmd_system_reset(ble_msg_system_reset_t args); |
dishbreak | 3:8f43af513d87 | 54 | |
dishbreak | 3:8f43af513d87 | 55 | /** Set the callback for a Boot event. Invoked when the BLE112 is powered on or reset. |
dishbreak | 3:8f43af513d87 | 56 | * @param pCallback Function pointer to the desired callback. |
dishbreak | 3:8f43af513d87 | 57 | */ |
dishbreak | 3:8f43af513d87 | 58 | void set_ble_evt_system_boot(boot_callback_t pCallback); |
dishbreak | 3:8f43af513d87 | 59 | |
dishbreak | 4:21eee6881dac | 60 | /** Set a "timestamping" callback. This is invoked whenever the mbed receives data on the UART interface. |
dishbreak | 4:21eee6881dac | 61 | * @param pCallback Function pointer to the desired callback. |
dishbreak | 4:21eee6881dac | 62 | */ |
dishbreak | 4:21eee6881dac | 63 | void set_timestamp_callback(timestamp_callback_t pCallback); |
dishbreak | 4:21eee6881dac | 64 | |
dishbreak | 1:3336b2391c80 | 65 | private: |
dishbreak | 1:3336b2391c80 | 66 | void parse(); |
dishbreak | 1:3336b2391c80 | 67 | void send_bytes(uint8_t bytes[], int length); |
dishbreak | 3:8f43af513d87 | 68 | |
dishbreak | 1:3336b2391c80 | 69 | Serial mSerial; |
dishbreak | 2:3ce9a31a6a7e | 70 | |
dishbreak | 1:3336b2391c80 | 71 | hello_callback_t mHelloCallback; |
dishbreak | 2:3ce9a31a6a7e | 72 | get_info_callback_t mGetInfoCallback; |
dishbreak | 3:8f43af513d87 | 73 | boot_callback_t mBootCallback; |
dishbreak | 4:21eee6881dac | 74 | timestamp_callback_t mTimestampCallback; |
dishbreak | 1:3336b2391c80 | 75 | |
dishbreak | 1:3336b2391c80 | 76 | }; |