From 7ff2838929b7052de21c1aa7434cd90e46a61bcc Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 15 Jan 2025 11:15:10 +0100 Subject: [PATCH 1/7] codestyle unification --- src/local/BLELocalDevice.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 5792353f..aa4dee78 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -182,10 +182,10 @@ int BLELocalDevice::begin() // } // Serial.println(); - // // save this + // // save this // uint8_t zeros[16]; // for(int k=0; k<16; k++) zeros[15-k] = 0; - + // // HCI.leAddResolvingAddress((*BADDR_Type)[i],(*BADDRs)[i],(*IRKs)[i], zeros); // delete[] (*BADDRs)[i]; @@ -197,7 +197,7 @@ int BLELocalDevice::begin() // delete BADDRs; // delete[] (*IRKs); // delete IRKs; - + // memcheck = new uint8_t[1]; // Serial.print("nIRK location: 0x"); // Serial.println((int)memcheck,HEX); @@ -310,7 +310,7 @@ bool BLELocalDevice::setManufacturerData(const uint16_t companyId, const uint8_t bool BLELocalDevice::setLocalName(const char *localName) { - return _scanResponseData.setLocalName(localName); + return _scanResponseData.setLocalName(localName); } void BLELocalDevice::setAdvertisingData(BLEAdvertisingData& advertisingData) @@ -355,7 +355,7 @@ int BLELocalDevice::advertise() { _advertisingData.updateData(); _scanResponseData.updateData(); - return GAP.advertise( _advertisingData.data(), _advertisingData.dataLength(), + return GAP.advertise( _advertisingData.data(), _advertisingData.dataLength(), _scanResponseData.data(), _scanResponseData.dataLength()); } From b5426284395dfcdd830ad5426709767f58e224d9 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 15 Jan 2025 14:57:06 +0100 Subject: [PATCH 2/7] HCI Uart changing supported devices nina based devices will be supported through nina spi transport changing the macro from exclusion to explicit inclusion --- src/utility/HCIUartTransport.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/utility/HCIUartTransport.cpp b/src/utility/HCIUartTransport.cpp index 191811a7..7abc1538 100644 --- a/src/utility/HCIUartTransport.cpp +++ b/src/utility/HCIUartTransport.cpp @@ -17,15 +17,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) && !defined(ARDUINO_SILABS) && !defined(ARDUINO_UNOR4_WIFI) || defined(TARGET_NANO_RP2040_CONNECT) //|| defined(CORE_CM4) +#if defined(ARDUINO_PORTENTA_C33) #include "HCIUartTransport.h" -#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_AVR_UNO_WIFI_REV2) -#define SerialHCI Serial2 -#elif defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_NANO_RP2040_CONNECT) -// SerialHCI is already defined in the variant -#elif defined(ARDUINO_PORTENTA_H7_M4) +#if defined(ARDUINO_PORTENTA_H7_M4) // SerialHCI is already defined in the variant #elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) #define SerialHCI Serial2 From 8a7a2a1d27e83b595910824e2f64d429e77e3be0 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 15 Jan 2025 14:58:21 +0100 Subject: [PATCH 3/7] removing mbed devices from uart transport Since automatically excluded from previous exclusion preprocessor if --- src/utility/HCIUartTransport.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/utility/HCIUartTransport.cpp b/src/utility/HCIUartTransport.cpp index 7abc1538..606c8148 100644 --- a/src/utility/HCIUartTransport.cpp +++ b/src/utility/HCIUartTransport.cpp @@ -21,16 +21,8 @@ #include "HCIUartTransport.h" -#if defined(ARDUINO_PORTENTA_H7_M4) -// SerialHCI is already defined in the variant -#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) -#define SerialHCI Serial2 -#elif defined(ARDUINO_OPTA) -#define SerialHCI Serial3 -#elif defined(ARDUINO_PORTENTA_C33) +#if defined(ARDUINO_PORTENTA_C33) #define SerialHCI Serial5 -#elif defined(ARDUINO_GIGA) -arduino::UART SerialHCI(CYBSP_BT_UART_TX, CYBSP_BT_UART_RX, CYBSP_BT_UART_RTS, CYBSP_BT_UART_CTS); #else #error "Unsupported board selected!" #endif From 4fa765b3faf26c1a8229011d347c6f1eda9e6ab8 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Thu, 9 Jan 2025 09:56:37 +0100 Subject: [PATCH 4/7] changing paradigm for BLE local device Since in the next version for BLE we are delivering HCI commands through spi we don't need to restart the nina device for ble to run, thus removing those commands from this library --- src/local/BLELocalDevice.cpp | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index aa4dee78..7c2ae2c7 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -50,26 +50,7 @@ BLELocalDevice::~BLELocalDevice() int BLELocalDevice::begin() { -#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_NANO_RP2040_CONNECT) - // reset the NINA in BLE mode - pinMode(SPIWIFI_SS, OUTPUT); - pinMode(NINA_RESETN, OUTPUT); - - digitalWrite(SPIWIFI_SS, LOW); -#endif - -#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_AVR_UNO_WIFI_REV2) - digitalWrite(NINA_RESETN, HIGH); - delay(100); - digitalWrite(NINA_RESETN, LOW); - delay(750); -#elif defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_NANO_RP2040_CONNECT) - // inverted reset - digitalWrite(NINA_RESETN, LOW); - delay(100); - digitalWrite(NINA_RESETN, HIGH); - delay(750); -#elif defined(PORTENTA_H7_PINS) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) +#if defined(PORTENTA_H7_PINS) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) // BT_REG_ON -> HIGH pinMode(BT_REG_ON, OUTPUT); digitalWrite(BT_REG_ON, LOW); @@ -216,15 +197,9 @@ void BLELocalDevice::end() HCI.end(); -#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_AVR_UNO_WIFI_REV2) - // disable the NINA - digitalWrite(NINA_RESETN, HIGH); -#elif defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_NANO_RP2040_CONNECT) - // disable the NINA - digitalWrite(NINA_RESETN, LOW); -#elif defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) +#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) digitalWrite(BT_REG_ON, LOW); -#endif +#endif _advertisingData.clear(); _scanResponseData.clear(); } From ff6ebfa1c99bc4dc37f5e83d280ef9896059a9d8 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Thu, 9 Jan 2025 09:57:12 +0100 Subject: [PATCH 5/7] enabling hci through spi commands --- src/utility/HCINinaSpiTransport.cpp | 64 +++++++++++++++++++++++++++++ src/utility/HCINinaSpiTransport.h | 32 +++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/utility/HCINinaSpiTransport.cpp create mode 100644 src/utility/HCINinaSpiTransport.h diff --git a/src/utility/HCINinaSpiTransport.cpp b/src/utility/HCINinaSpiTransport.cpp new file mode 100644 index 00000000..38d46766 --- /dev/null +++ b/src/utility/HCINinaSpiTransport.cpp @@ -0,0 +1,64 @@ +/* + This file is part of the ArduinoBLE library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#if defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(TARGET_NANO_RP2040_CONNECT) +#include "HCINinaSpiTransport.h" +#include + +int HCINinaSpiTransportClass::begin() +{ + WiFiDrv::wifiDriverInit(); + return WiFiDrv::bleBegin(); +} + +void HCINinaSpiTransportClass::end() +{ + WiFiDrv::bleEnd(); +} + +void HCINinaSpiTransportClass::wait(unsigned long timeout) +{ + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (available()) { + break; + } + } +} + +int HCINinaSpiTransportClass::available() +{ + return WiFiDrv::bleAvailable(); +} + +int HCINinaSpiTransportClass::peek() +{ + int res=-1; + WiFiDrv::blePeek((uint8_t*)&res, 1); // read a single byte, if nothing is returned we return -1 + + return res; +} + +int HCINinaSpiTransportClass::read() +{ + int res=-1; + WiFiDrv::bleRead((uint8_t*)&res, 1); // read a single byte, if nothing is returned we return -1 + + return res; +} + +size_t HCINinaSpiTransportClass::write(const uint8_t* data, size_t length) +{ + return WiFiDrv::bleWrite(data, length); +} + +HCINinaSpiTransportClass HCINinaSpiTransport; +HCITransportInterface& HCITransport = HCINinaSpiTransport; + +#endif diff --git a/src/utility/HCINinaSpiTransport.h b/src/utility/HCINinaSpiTransport.h new file mode 100644 index 00000000..55cb1068 --- /dev/null +++ b/src/utility/HCINinaSpiTransport.h @@ -0,0 +1,32 @@ +/* + This file is part of the ArduinoBLE library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#ifndef _HCI_NINA_SPI_TRANSPORT_H_ +#define _HCI_NINA_SPI_TRANSPORT_H_ + +#include "HCITransport.h" + +class HCINinaSpiTransportClass : public HCITransportInterface { +public: + HCINinaSpiTransportClass() {} + + virtual int begin(); + virtual void end(); + + virtual void wait(unsigned long timeout); + + virtual int available(); + virtual int peek(); + virtual int read(); + + virtual size_t write(const uint8_t* data, size_t length); +}; + +#endif From 2d56544b0fe7b3cd52653c25e05a82cab042d5f0 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 15 Jan 2025 14:08:55 +0100 Subject: [PATCH 6/7] Adding dependency to WiFiNINA for boards using nina --- library.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/library.properties b/library.properties index 543998b7..4196e767 100644 --- a/library.properties +++ b/library.properties @@ -8,3 +8,4 @@ category=Communication url=https://www.arduino.cc/en/Reference/ArduinoBLE architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_giga,renesas,renesas_portenta,mbed_opta,renesas_uno,silabs includes=ArduinoBLE.h +depends=WiFiNINA From 999e9d7bf038ecd071f3ccbc959dcb2722d8e214 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 15 Jan 2025 15:18:41 +0100 Subject: [PATCH 7/7] fixing ci for nina based boards --- .github/workflows/compile-examples.yml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 706ccb4c..a5cfe26b 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -35,26 +35,41 @@ jobs: platforms: | - name: arduino:samd artifact-name-suffix: arduino-samd-mkrwifi1010 + type: nina - fqbn: arduino:samd:nano_33_iot platforms: | - name: arduino:samd artifact-name-suffix: arduino-samd-nano_33_iot + type: nina - fqbn: arduino:megaavr:uno2018:mode=on platforms: | - name: arduino:megaavr artifact-name-suffix: arduino-megaavr-uno2018 + type: nina - fqbn: arduino:mbed_nano:nano33ble platforms: | - name: arduino:mbed_nano artifact-name-suffix: arduino-mbed_nano-nano33ble + type: nina - fqbn: arduino:mbed_nano:nanorp2040connect platforms: | - name: arduino:mbed_nano artifact-name-suffix: arduino-mbed_nano-nanorp2040connect + type: nina - fqbn: arduino:renesas_uno:unor4wifi platforms: | - name: arduino:renesas_uno artifact-name-suffix: arduino-renesas_uno-unor4wifi + type: unor4wifi + + include: + - board: + type: nina + libraries: | + - name: WiFiNINA + - board: + type: unor4wifi + libraries: steps: - name: Checkout repository @@ -69,6 +84,7 @@ jobs: libraries: | # Install the library from the local path. - source-path: ./ + ${{ matrix.libraries }} sketch-paths: | - examples enable-deltas-report: true @@ -83,7 +99,7 @@ jobs: build-for-esp32: runs-on: ubuntu-latest - + strategy: matrix: fqbn: @@ -101,6 +117,8 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} fqbn: ${{ matrix.fqbn }} + libraries: | + ${{ matrix.libraries }} platforms: | - name: esp32:esp32 source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json