25
25
#include < Arduino.h>
26
26
#include < mbed.h>
27
27
28
+ #if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7)
29
+ #include " ble/BLE.h"
30
+ #include < events/mbed_events.h>
31
+ #endif
32
+
28
33
// Parts of this file are based on: https://github.com/ARMmbed/mbed-os-cordio-hci-passthrough/pull/2
29
34
// With permission from the Arm Mbed team to re-license
30
35
@@ -174,6 +179,17 @@ HCICordioTransportClass::~HCICordioTransportClass()
174
179
{
175
180
}
176
181
182
+ #if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7)
183
+ events::EventQueue eventQueue (10 * EVENTS_EVENT_SIZE);
184
+ void scheduleMbedBleEvents (BLE::OnEventsToProcessCallbackContext *context) {
185
+ eventQueue.call (mbed::Callback<void ()>(&context->ble , &BLE::processEvents));
186
+ }
187
+
188
+ void completeCallback (BLE::InitializationCompleteCallbackContext *context) {
189
+ eventQueue.break_dispatch ();
190
+ }
191
+ #endif
192
+
177
193
int HCICordioTransportClass::begin ()
178
194
{
179
195
_rxBuf.clear ();
@@ -183,8 +199,20 @@ int HCICordioTransportClass::begin()
183
199
init_wsf (bufPoolDesc);
184
200
#endif
185
201
202
+ #if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7)
203
+ BLE &ble = BLE::Instance ();
204
+ ble.onEventsToProcess (scheduleMbedBleEvents);
205
+
206
+ ble.init (completeCallback);
207
+ eventQueue.dispatch (10000 );
208
+
209
+ if (!ble.hasInitialized ()){
210
+ return 0 ;
211
+ }
212
+ #else
186
213
CordioHCIHook::getDriver ().initialize ();
187
214
CordioHCIHook::getDriver ().start_reset_sequence ();
215
+ #endif
188
216
189
217
if (bleLoopThread == NULL ) {
190
218
bleLoopThread = new rtos::Thread ();
@@ -205,7 +233,6 @@ void HCICordioTransportClass::end()
205
233
delete bleLoopThread;
206
234
bleLoopThread = NULL ;
207
235
}
208
-
209
236
CordioHCIHook::getDriver ().terminate ();
210
237
211
238
_begun = false ;
0 commit comments