Skip to content

[portenta] Send service pack updates through mbed initialization #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2020
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