Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[portenta] Send service pack updates through mbed initialization
The mbed ble stack is initialized at the beginning in order to exploit the service pack transfer.
Once it has been initialized, the queue used to dispatch the ble events is stopped.
At this point the mbed stack is no more used and ArduinoBLE exploits directly the low level uart transport layer.
  • Loading branch information
polldo committed Sep 4, 2020
commit de44016689091c99425f671082ba65495f5e962a
29 changes: 28 additions & 1 deletion src/utility/HCICordioTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#include <Arduino.h>
#include <mbed.h>

#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7)
#include "ble/BLE.h"
#include <events/mbed_events.h>
#endif

// Parts of this file are based on: https://github.com/ARMmbed/mbed-os-cordio-hci-passthrough/pull/2
// With permission from the Arm Mbed team to re-license

Expand Down Expand Up @@ -174,6 +179,17 @@ HCICordioTransportClass::~HCICordioTransportClass()
{
}

#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7)
events::EventQueue eventQueue(10 * EVENTS_EVENT_SIZE);
void scheduleMbedBleEvents(BLE::OnEventsToProcessCallbackContext *context) {
eventQueue.call(mbed::Callback<void()>(&context->ble, &BLE::processEvents));
}

void completeCallback(BLE::InitializationCompleteCallbackContext *context) {
eventQueue.break_dispatch();
}
#endif

int HCICordioTransportClass::begin()
{
_rxBuf.clear();
Expand All @@ -183,8 +199,20 @@ int HCICordioTransportClass::begin()
init_wsf(bufPoolDesc);
#endif

#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7)
BLE &ble = BLE::Instance();
ble.onEventsToProcess(scheduleMbedBleEvents);

ble.init(completeCallback);
eventQueue.dispatch(10000);

if (!ble.hasInitialized()){
return 0;
}
#else
CordioHCIHook::getDriver().initialize();
CordioHCIHook::getDriver().start_reset_sequence();
#endif

if (bleLoopThread == NULL) {
bleLoopThread = new rtos::Thread();
Expand All @@ -205,7 +233,6 @@ void HCICordioTransportClass::end()
delete bleLoopThread;
bleLoopThread = NULL;
}

CordioHCIHook::getDriver().terminate();

_begun = false;
Expand Down