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
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