diff --git a/changelog.md b/changelog.md index 6a283a68..02d3acbb 100644 --- a/changelog.md +++ b/changelog.md @@ -2,19 +2,27 @@ ## 0.6.5 +### Core + - Fix setName() issue -- Add Low Level format sketch for filesystem: `libraries/nffs/examples/EraseNffs` - Add SRAM usage when compiling - Reduce Stack size from 3KB to 2KB, and functions dbgStackUsed(), dbgStackTotal() for dynamic stack usage -- Updated for latest Bluefruit LE Connect version with RGBW support - Fix #48 SPI & I2C warnings - Change board define from ARDUINO_FEATHER52 to ARDUINO_NRF52_FEATHER (ARDUINO_FEATHER52 still exists for backward comaptiable) - Change pin in hwpwm and hid_camerashutter sketches - Update nffs code to mynewt v1.0.0 -- Add Realtrace support using Segger Sysview +- Add Event recording support using Segger Sysview + +### BLE + +- Updated for latest Bluefruit LE Connect version with RGBW support - Implement Gatt readCharByUuid() - Implement Gap getPeerName() +### New Examples + +- Add Low Level format sketch for filesystem: `libraries/nffs/examples/EraseNffs` + ## 0.6.0 ### Core diff --git a/libraries/Bluefruit52Lib/src/BLECentral.cpp b/libraries/Bluefruit52Lib/src/BLECentral.cpp index ce47fdec..4bfab045 100644 --- a/libraries/Bluefruit52Lib/src/BLECentral.cpp +++ b/libraries/Bluefruit52Lib/src/BLECentral.cpp @@ -183,14 +183,33 @@ bool BLECentral::connect(const ble_gap_evt_adv_report_t* adv_report, uint16_t mi return connect(&adv_report->peer_addr, min_conn_interval, max_conn_interval); } -bool BLECentral::connected(void) +/** + * Check if connected to a specific peripheral + * @param conn_handle + * @return + */ +bool BLECentral::connected(uint16_t conn_handle) { - return (_conn_hdl != BLE_CONN_HANDLE_INVALID); + return Bluefruit.Gap.connected(conn_handle); } -uint16_t BLECentral::connHandle (void) +/** + * Check if connected to ANY peripherals + * @param conn_handle + * @return + */ +bool BLECentral::connected(void) { - return _conn_hdl; + for (uint8_t conn=0; connevt.common_evt.conn_handle; + gap_peer_t* peer = &_peers[conn_handle]; + switch(evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: - { + peer->connected = true; + peer->addr = evt->evt.gap_evt.params.connected.peer_addr; + // Init transmission buffer for notification uint8_t txbuf_max; (void) sd_ble_tx_packet_count_get(conn_handle, &txbuf_max); - _txpacket_sem[conn_handle] = xSemaphoreCreateCounting(txbuf_max, txbuf_max); - } + peer->txpacket_sem = xSemaphoreCreateCounting(txbuf_max, txbuf_max); break; case BLE_GAP_EVT_DISCONNECTED: - vSemaphoreDelete( _txpacket_sem[conn_handle] ); - _txpacket_sem[conn_handle] = NULL; + peer->connected = false; + + vSemaphoreDelete( peer->txpacket_sem ); + peer->txpacket_sem = NULL; break; case BLE_EVT_TX_COMPLETE: - if ( _txpacket_sem[conn_handle] ) + if ( peer->txpacket_sem ) { for(uint8_t i=0; ievt.common_evt.params.tx_complete.count; i++) { - xSemaphoreGive(_txpacket_sem[conn_handle]); + xSemaphoreGive(peer->txpacket_sem); } } break; diff --git a/libraries/Bluefruit52Lib/src/BLEGap.h b/libraries/Bluefruit52Lib/src/BLEGap.h index 5ceb8626..d76bb471 100644 --- a/libraries/Bluefruit52Lib/src/BLEGap.h +++ b/libraries/Bluefruit52Lib/src/BLEGap.h @@ -47,12 +47,17 @@ class BLEGap public: BLEGap(void); - bool getTxPacket(void); - bool getTxPacket(uint16_t conn_handle); + bool connected(uint16_t conn_handle); + + uint8_t getPeerAddr(uint16_t conn_handle, uint8_t addr[6]); + ble_gap_addr_t getPeerAddr(uint16_t conn_handle); uint16_t getPeerName(char* buf, uint16_t bufsize); uint16_t getPeerName(uint16_t conn_handle, char* buf, uint16_t bufsize); + bool getTxPacket(void); + bool getTxPacket(uint16_t conn_handle); + /*------------------------------------------------------------------*/ /* INTERNAL USAGE ONLY * Although declare as public, it is meant to be invoked by internal @@ -62,7 +67,15 @@ class BLEGap private: // Array of TX Packet semaphore, indexed by connection handle - SemaphoreHandle_t _txpacket_sem[BLE_GAP_MAX_CONN]; + // Peer info where conn_handle serves as index + typedef struct { + bool connected; + ble_gap_addr_t addr; + + SemaphoreHandle_t txpacket_sem; + } gap_peer_t; + + gap_peer_t _peers[BLE_GAP_MAX_CONN]; }; #endif /* BLEGAP_H_ */ diff --git a/libraries/Bluefruit52Lib/src/bluefruit.cpp b/libraries/Bluefruit52Lib/src/bluefruit.cpp index cbcc424b..7dc383c9 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.cpp +++ b/libraries/Bluefruit52Lib/src/bluefruit.cpp @@ -339,9 +339,14 @@ uint16_t AdafruitBluefruit::connInterval(void) return _conn_interval; } -ble_gap_addr_t AdafruitBluefruit::peerAddr(void) +ble_gap_addr_t AdafruitBluefruit::getPeerAddr(void) { - return _peer_addr; + return Gap.getPeerAddr(_conn_hdl); +} + +uint8_t AdafruitBluefruit::getPeerAddr(uint8_t addr[6]) +{ + return Gap.getPeerAddr(_conn_hdl, addr); } COMMENT_OUT ( @@ -488,7 +493,6 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt) _conn_hdl = evt->evt.gap_evt.conn_handle; _conn_interval = para->conn_params.min_conn_interval; - _peer_addr = para->peer_addr; // Connection interval set by Central is out of preferred range // Try to negotiate with Central using our preferred values @@ -520,7 +524,6 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt) _conn_hdl = BLE_CONN_HANDLE_INVALID; _bonded = false; - varclr(&_peer_addr); if ( _discconnect_cb ) _discconnect_cb(evt->evt.gap_evt.params.disconnected.reason); diff --git a/libraries/Bluefruit52Lib/src/bluefruit.h b/libraries/Bluefruit52Lib/src/bluefruit.h index 10e57d58..b6029931 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.h +++ b/libraries/Bluefruit52Lib/src/bluefruit.h @@ -130,7 +130,8 @@ class AdafruitBluefruit bool requestPairing (void); void clearBonds (void); - ble_gap_addr_t peerAddr(void); + ble_gap_addr_t getPeerAddr(void); + uint8_t getPeerAddr(uint8_t addr[6]); /*------------------------------------------------------------------*/ /* Callbacks @@ -178,8 +179,6 @@ public: // TODO temporary for bledfu to load bonding data private: ble_gap_sec_params_t _sec_param; - ble_gap_addr_t _peer_addr; - COMMENT_OUT( uint8_t _auth_type; char _pin[BLE_GAP_PASSKEY_LEN]; diff --git a/libraries/Bluefruit52Lib/src/services/BLEDfu.cpp b/libraries/Bluefruit52Lib/src/services/BLEDfu.cpp index a3935e4e..47310b08 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEDfu.cpp +++ b/libraries/Bluefruit52Lib/src/services/BLEDfu.cpp @@ -131,7 +131,7 @@ static void bledfu_control_wr_authorize_cb(BLECharacteristic& chr, ble_gatts_evt if ( !Bluefruit.connPaired() ) { - peer_data->addr = Bluefruit.peerAddr(); + peer_data->addr = Bluefruit.getPeerAddr(); }else { peer_data->addr = Bluefruit._bond_data.peer_id.id_addr_info;