diff --git a/changelog.md b/changelog.md index 79a7f994..9b6b4b94 100644 --- a/changelog.md +++ b/changelog.md @@ -2,8 +2,10 @@ ## 0.9.0 -- Feather nRF52840 support +- Added nRF52840-based board support (pca10056 and feather nRF52840 express) - Upgrade bootloader to v6.1.0 ( single bank only ) +- Upgrade BSP code to match SD v6 + - Bluefruit.Scanner.start() must be called (often in callback) to resume scanning after received an report. - Upgrade freeRTOS from v8 to v10.0.1 - Upgrade Segger SysView to 2.52d - Added nrfx to core @@ -34,7 +36,7 @@ ## 0.8.4 - Fix #160: hardware PWM issue that cause Servo freq is 640 hz instead of 50hz -- Fix #134: hardcoded pulse limits with Servo +- Fix #134: hardcoded pulse limits with Servo - Fix upload issue with windows when username has spaces - Support serialEvent() diff --git a/cores/nRF5/usb/USBSerial.cpp b/cores/nRF5/usb/USBSerial.cpp index 7ec37077..f8086e47 100644 --- a/cores/nRF5/usb/USBSerial.cpp +++ b/cores/nRF5/usb/USBSerial.cpp @@ -98,18 +98,21 @@ size_t USBSerial::write(uint8_t ch) size_t USBSerial::write(const uint8_t *buffer, size_t size) { - while ( size ) + size_t remain = size; + while ( remain && tud_cdc_connected() ) { - size_t wrcount = tud_cdc_write(buffer, size); - size -= wrcount; + size_t wrcount = tud_cdc_write(buffer, remain); + remain -= wrcount; buffer += wrcount; // Write FIFO is full, flush and re-try - if ( size ) + if ( remain ) { tud_cdc_write_flush(); } } + + return size - remain; } #endif // NRF52840_XXAA diff --git a/libraries/Bluefruit52Lib/examples/Central/central_scan/central_scan.ino b/libraries/Bluefruit52Lib/examples/Central/central_scan/central_scan.ino index 137060c0..7905431d 100644 --- a/libraries/Bluefruit52Lib/examples/Central/central_scan/central_scan.ino +++ b/libraries/Bluefruit52Lib/examples/Central/central_scan/central_scan.ino @@ -51,7 +51,7 @@ void scan_callback(ble_gap_evt_adv_report_t* report) Serial.print(report->rssi); Serial.print(" "); - Serial.printBuffer(report->data, report->dlen, '-'); + Serial.printBuffer(report->data.p_data, report->data.len, '-'); Serial.println(); // Check if advertising contain BleUart service @@ -61,13 +61,13 @@ void scan_callback(ble_gap_evt_adv_report_t* report) } Serial.println(); + + // For Softdevice v6: after received a report, scanner will be paused + // We need to call Scanner start() to resume scanning + Bluefruit.Scanner.start(); } void loop() { - // Toggle both LEDs every 1 second - digitalToggle(LED_RED); - - delay(1000); + // nothing to do } - diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/clearbonds/clearbonds.ino b/libraries/Bluefruit52Lib/examples/Peripheral/clearbonds/clearbonds.ino index 43f9c702..d6770d44 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/clearbonds/clearbonds.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/clearbonds/clearbonds.ino @@ -17,7 +17,6 @@ */ #include -#include #include void setup() diff --git a/libraries/Bluefruit52Lib/src/BLEScanner.cpp b/libraries/Bluefruit52Lib/src/BLEScanner.cpp index bdb11a58..18d482f6 100644 --- a/libraries/Bluefruit52Lib/src/BLEScanner.cpp +++ b/libraries/Bluefruit52Lib/src/BLEScanner.cpp @@ -36,8 +36,6 @@ #include "bluefruit.h" -static uint8_t _scan_data[BLE_GAP_SCAN_BUFFER_MAX]; - BLEScanner::BLEScanner(void) { _report_data.p_data = _scan_data; @@ -57,7 +55,7 @@ BLEScanner::BLEScanner(void) _rx_cb = NULL; _stop_cb = NULL; - _param = (ble_gap_scan_params_t) { + _param = ((ble_gap_scan_params_t) { // TODO Extended Adv on secondary channels .extended = 0, .report_incomplete_evts = 0, @@ -70,7 +68,7 @@ BLEScanner::BLEScanner(void) .window = BLE_SCAN_WINDOW_DFLT, .timeout = 0, // no timeout, in 10 ms units .channel_mask = { 0, 0, 0, 0, 0 } - }; + }); } void BLEScanner::useActiveScan(bool enable) @@ -117,11 +115,23 @@ ble_gap_scan_params_t* BLEScanner::getParams(void) bool BLEScanner::start(uint16_t timeout) { - _param.timeout = timeout; - VERIFY_STATUS( sd_ble_gap_scan_start(&_param, &_report_data), false ); + _report_data.p_data = _scan_data; + _report_data.len = BLE_GAP_SCAN_BUFFER_MAX; - Bluefruit._startConnLed(); // start blinking - _runnning = true; + if (_runnning) + { + // resume scanning after received an report + VERIFY_STATUS( sd_ble_gap_scan_start(NULL, &_report_data), false ); + }else + { + // start a new scan + _param.timeout = timeout; + + VERIFY_STATUS( sd_ble_gap_scan_start(&_param, &_report_data), false ); + + Bluefruit._startConnLed(); // start blinking + _runnning = true; + } return true; } @@ -393,6 +403,7 @@ void BLEScanner::_eventHandler(ble_evt_t* evt) case BLE_GAP_EVT_TIMEOUT: if (evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_SCAN) { + _runnning = false; if (_stop_cb) ada_callback(NULL, _stop_cb); } break; diff --git a/libraries/Bluefruit52Lib/src/BLEScanner.h b/libraries/Bluefruit52Lib/src/BLEScanner.h index 3b278a97..82de7072 100644 --- a/libraries/Bluefruit52Lib/src/BLEScanner.h +++ b/libraries/Bluefruit52Lib/src/BLEScanner.h @@ -96,6 +96,7 @@ public: void _eventHandler(ble_evt_t* evt); private: + uint8_t _scan_data[BLE_GAP_SCAN_BUFFER_MAX]; ble_data_t _report_data; bool _runnning;