Skip to content

Commit 7231f8c

Browse files
authored
Merge pull request #501 from orrmany/develop-multiprotocol-ble
Make Bluferuit52 multiprotocol friendly
2 parents 1f0a587 + ff12326 commit 7231f8c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

libraries/Bluefruit52Lib/src/bluefruit.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ AdafruitBluefruit::AdafruitBluefruit(void)
162162

163163
_ble_event_sem = NULL;
164164
_soc_event_sem = NULL;
165+
#ifdef ANT_LICENSE_KEY
166+
_mprot_event_sem = NULL; //additiona semaphore for multiprotocol
167+
#endif
165168

166169
_led_blink_th = NULL;
167170
_led_conn = true;
@@ -310,7 +313,15 @@ bool AdafruitBluefruit::begin(uint8_t prph_count, uint8_t central_count)
310313
#error Clock Source is not configured, define USE_LFXO or USE_LFRC according to your board in variant.h
311314
#endif
312315

316+
/*------------------------------------------------------------------
317+
** BLE only Softdevices have 2-args sd_softdevice_enable()
318+
** BLE & ANT+ Softdevices have 3-args sd_softdevice_enable()
319+
*/
320+
#ifdef ANT_LICENSE_KEY
321+
VERIFY_STATUS( sd_softdevice_enable(&clock_cfg, nrf_error_cb, ANT_LICENSE_KEY), false );
322+
#else //#ifdef ANT_LICENSE_KEY
313323
VERIFY_STATUS( sd_softdevice_enable(&clock_cfg, nrf_error_cb), false );
324+
#endif //#ifdef ANT_LICENSE_KEY
314325

315326
#ifdef USE_TINYUSB
316327
usb_softdevice_post_enable();
@@ -676,6 +687,10 @@ void SD_EVT_IRQHandler(void)
676687
// Notify both BLE & SOC Task
677688
xSemaphoreGiveFromISR(Bluefruit._soc_event_sem, NULL);
678689
xSemaphoreGiveFromISR(Bluefruit._ble_event_sem, NULL);
690+
#ifdef ANT_LICENSE_KEY
691+
// Notify parallel multiprotocol Task, if any
692+
if (Bluefruit._mprot_event_sem) xSemaphoreGiveFromISR(Bluefruit._mprot_event_sem, NULL);
693+
#endif
679694
}
680695

681696
/**

libraries/Bluefruit52Lib/src/bluefruit.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,17 @@ class AdafruitBluefruit
178178

179179
BLEConnection* Connection(uint16_t conn_hdl);
180180

181+
#ifdef ANT_LICENSE_KEY
182+
/*------------------------------------------------------------------*
183+
* Optional semaphore for additional event handlers for SD event.
184+
* It can be used for handling non-BLE SD events
185+
*------------------------------------------------------------------*/
186+
void setMultiprotocolSemaphore(SemaphoreHandle_t* p_mprot_event_semaphore)
187+
{
188+
_mprot_event_sem= p_mprot_event_semaphore;
189+
}
190+
#endif
191+
181192
/*------------------------------------------------------------------*/
182193
/* Callbacks
183194
*------------------------------------------------------------------*/
@@ -222,6 +233,12 @@ class AdafruitBluefruit
222233

223234
SemaphoreHandle_t _ble_event_sem;
224235
SemaphoreHandle_t _soc_event_sem;
236+
#ifdef ANT_LICENSE_KEY
237+
/* Optional semaphore for additional event handlers for SD event.
238+
* It can be used for handling non-BLE SD events
239+
*/
240+
SemaphoreHandle_t* _mprot_event_sem;
241+
#endif
225242

226243
TimerHandle_t _led_blink_th;
227244
bool _led_conn;

0 commit comments

Comments
 (0)