summaryrefslogtreecommitdiff
path: root/ports/nrf/bluetooth
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2019-12-05 22:45:53 -0500
committerDan Halbert <halbert@halwitz.org>2019-12-05 22:45:53 -0500
commit40434d691934cf7f5792f91ce0288beb568bab85 (patch)
treee2f7d0191685f0b519e98c3e1551626fbbf49585 /ports/nrf/bluetooth
parent1505da784f228d43df41a773cfe504e7e4da330a (diff)
parent15886b1505d854d76e353b9c5261568c7065d2bf (diff)
wip
Diffstat (limited to 'ports/nrf/bluetooth')
-rw-r--r--ports/nrf/bluetooth/ble_drv.c28
-rw-r--r--ports/nrf/bluetooth/ble_drv.h7
2 files changed, 28 insertions, 7 deletions
diff --git a/ports/nrf/bluetooth/ble_drv.c b/ports/nrf/bluetooth/ble_drv.c
index 6b17e7af2..16475e4b3 100644
--- a/ports/nrf/bluetooth/ble_drv.c
+++ b/ports/nrf/bluetooth/ble_drv.c
@@ -38,6 +38,8 @@
#include "py/misc.h"
#include "py/mpstate.h"
+#include "supervisor/shared/bluetooth.h"
+
nrf_nvic_state_t nrf_nvic_state = { 0 };
// Flag indicating progress of internal flash operation.
@@ -52,6 +54,14 @@ void ble_drv_reset() {
sd_flash_operation_status = SD_FLASH_OPERATION_DONE;
}
+void ble_drv_add_event_handler_entry(ble_drv_evt_handler_entry_t* entry, ble_drv_evt_handler_t func, void *param) {
+ entry->next = MP_STATE_VM(ble_drv_evt_handler_entries);
+ entry->param = param;
+ entry->func = func;
+
+ MP_STATE_VM(ble_drv_evt_handler_entries) = entry;
+}
+
void ble_drv_add_event_handler(ble_drv_evt_handler_t func, void *param) {
ble_drv_evt_handler_entry_t *it = MP_STATE_VM(ble_drv_evt_handler_entries);
while (it != NULL) {
@@ -64,11 +74,7 @@ void ble_drv_add_event_handler(ble_drv_evt_handler_t func, void *param) {
// Add a new handler to the front of the list
ble_drv_evt_handler_entry_t *handler = m_new_ll(ble_drv_evt_handler_entry_t, 1);
- handler->next = MP_STATE_VM(ble_drv_evt_handler_entries);
- handler->param = param;
- handler->func = func;
-
- MP_STATE_VM(ble_drv_evt_handler_entries) = handler;
+ ble_drv_add_event_handler_entry(handler, func, param);
}
void ble_drv_remove_event_handler(ble_drv_evt_handler_t func, void *param) {
@@ -127,10 +133,20 @@ void SD_EVT_IRQHandler(void) {
break;
}
+ ble_evt_t* event = (ble_evt_t *)m_ble_evt_buf;
+
+ if (supervisor_bluetooth_hook(event)) {
+ continue;
+ }
+
ble_drv_evt_handler_entry_t *it = MP_STATE_VM(ble_drv_evt_handler_entries);
+ bool done = false;
while (it != NULL) {
- it->func((ble_evt_t *)m_ble_evt_buf, it->param);
+ done = it->func(event, it->param) || done;
it = it->next;
}
+ if (!done) {
+ //mp_printf(&mp_plat_print, "Unhandled ble event: 0x%04x\n", event->header.evt_id);
+ }
}
}
diff --git a/ports/nrf/bluetooth/ble_drv.h b/ports/nrf/bluetooth/ble_drv.h
index a066f588f..7716cab8b 100644
--- a/ports/nrf/bluetooth/ble_drv.h
+++ b/ports/nrf/bluetooth/ble_drv.h
@@ -29,6 +29,8 @@
#ifndef MICROPY_INCLUDED_NRF_BLUETOOTH_BLE_DRV_H
#define MICROPY_INCLUDED_NRF_BLUETOOTH_BLE_DRV_H
+#include <stdbool.h>
+
#include "ble.h"
#define MAX_TX_IN_PROGRESS 10
@@ -48,7 +50,7 @@
#define UNIT_1_25_MS (1250)
#define UNIT_10_MS (10000)
-typedef void (*ble_drv_evt_handler_t)(ble_evt_t*, void*);
+typedef bool (*ble_drv_evt_handler_t)(ble_evt_t*, void*);
typedef enum {
SD_FLASH_OPERATION_DONE,
@@ -69,4 +71,7 @@ void ble_drv_reset(void);
void ble_drv_add_event_handler(ble_drv_evt_handler_t func, void *param);
void ble_drv_remove_event_handler(ble_drv_evt_handler_t func, void *param);
+// Allow for user provided entries to prevent allocations outside the VM.
+void ble_drv_add_event_handler_entry(ble_drv_evt_handler_entry_t* entry, ble_drv_evt_handler_t func, void *param);
+
#endif // MICROPY_INCLUDED_NRF_BLUETOOTH_BLE_DRV_H