From 14831ac9b9399079e7d4ed9da3c59c1cd6caf2b3 Mon Sep 17 00:00:00 2001 From: Joe Finney Date: Fri, 11 Dec 2015 04:57:06 +0000 Subject: [PATCH] Updates to BLE 2.1.11 / ble-nrf51822 2.2.3 Minor amends: - bleDisconnectionCallback signature change - bleSetAdvertisingInterval now takes milliseconds as a parameter - event based invocation of DFU bootloader --- inc/MicroBit.h | 2 +- source/MicroBit.cpp | 5 ++- source/MicroBitSuperMain.cpp | 2 +- source/ble-services/MicroBitDFUService.cpp | 37 +++++++++++++++++++++- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/inc/MicroBit.h b/inc/MicroBit.h index 417b300..86d2d12 100644 --- a/inc/MicroBit.h +++ b/inc/MicroBit.h @@ -302,7 +302,7 @@ extern MicroBit uBit; // BLE callback when an active GATT session with another device is terminated. // Used to reset state and restart advertising ourselves. // -void bleDisconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason); +void bleDisconnectionCallback(const Gap::DisconnectionCallbackParams_t *reason); // Entry point for application programs. Called after the super-main function // has initialized the device and runtime environment. diff --git a/source/MicroBit.cpp b/source/MicroBit.cpp index 2f5467c..2550e37 100644 --- a/source/MicroBit.cpp +++ b/source/MicroBit.cpp @@ -31,9 +31,8 @@ microbit_reset() /** * Callback when a BLE GATT disconnect occurs. */ -void bleDisconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) +void bleDisconnectionCallback(const Gap::DisconnectionCallbackParams_t *reason) { - (void) handle; /* -Wunused-param */ (void) reason; /* -Wunused-param */ uBit.ble->startAdvertising(); @@ -167,7 +166,7 @@ void MicroBit::init() ble->accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble->accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)MICROBIT_BLE_DEVICE_NAME, sizeof(MICROBIT_BLE_DEVICE_NAME)); ble->setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); - ble->setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(200)); + ble->setAdvertisingInterval(200); ble->startAdvertising(); #endif diff --git a/source/MicroBitSuperMain.cpp b/source/MicroBitSuperMain.cpp index ed1a790..9b62a81 100644 --- a/source/MicroBitSuperMain.cpp +++ b/source/MicroBitSuperMain.cpp @@ -60,7 +60,7 @@ int main() uBit.ble->accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); uBit.ble->accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)MICROBIT_BLE_DEVICE_NAME, sizeof(MICROBIT_BLE_DEVICE_NAME)); uBit.ble->setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); - uBit.ble->setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(200)); + uBit.ble->setAdvertisingInterval(200); uBit.ble->startAdvertising(); } diff --git a/source/ble-services/MicroBitDFUService.cpp b/source/ble-services/MicroBitDFUService.cpp index 96277fa..f6915be 100644 --- a/source/ble-services/MicroBitDFUService.cpp +++ b/source/ble-services/MicroBitDFUService.cpp @@ -17,6 +17,31 @@ #include "MicroBit.h" #include "ble/UUID.h" +#if !defined(__arm) +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#endif + +/* + * The underlying Nordic libraries that support BLE do not compile cleanly with the stringent GCC settings we employ + * If we're compiling under GCC, then we suppress any warnings generated from this code (but not the rest of the DAL) + * The ARM cc compiler is more tolerant. We don't test __GNUC__ here to detect GCC as ARMCC also typically sets this + * as a compatability option, but does not support the options used... + */ +extern "C" { +#include "dfu_app_handler.h" +} + +/* + * Return to our predefined compiler settings. + */ +#if !defined(__arm) +#pragma GCC diagnostic pop +#endif + + + /** * Constructor. * Create a representation of a MicroBit device. @@ -121,7 +146,17 @@ void MicroBitDFUService::onDataWritten(const GattWriteCallbackParams *params) #if CONFIG_ENABLED(MICROBIT_DBG) uBit.serial.printf(" ACTIVATING BOOTLOADER.\n"); #endif - bootloader_start(); + + + // Call bootloader_start implicitly trough a event handler call + // it is a work around for bootloader_start not being public in sdk 8.1 + ble_dfu_t p_dfu; + ble_dfu_evt_t p_evt; + + p_dfu.conn_handle = params->connHandle; + p_evt.ble_dfu_evt_type = BLE_DFU_START; + + dfu_app_on_dfu_evt(&p_dfu, &p_evt); } break;