diff --git a/ports/stm32/boardctrl.h b/ports/stm32/boardctrl.h index 851922f412..c870af32a4 100644 --- a/ports/stm32/boardctrl.h +++ b/ports/stm32/boardctrl.h @@ -66,6 +66,18 @@ #define MICROPY_BOARD_USBD_CDC_RX_EVENT usbd_cdc_rx_event_callback #endif +// Called to poll Bluetooth HCI now. +// Default function defined in mpbthciport.h. +#ifndef MICROPY_BOARD_BT_HCI_POLL_NOW +#define MICROPY_BOARD_BT_HCI_POLL_NOW mp_bluetooth_hci_poll_now_default +#endif + +// Called to poll Bluetooth HCI after the given timeout. +// Default function defined in mpbthciport.h. +#ifndef MICROPY_BOARD_BT_HCI_POLL_IN_MS +#define MICROPY_BOARD_BT_HCI_POLL_IN_MS mp_bluetooth_hci_poll_in_ms_default +#endif + // Constants to return from boardctrl_run_boot_py, boardctrl_run_main_py. enum { BOARDCTRL_CONTINUE, diff --git a/ports/stm32/mpbthciport.c b/ports/stm32/mpbthciport.c index 369c91e303..a1ab3258b6 100644 --- a/ports/stm32/mpbthciport.c +++ b/ports/stm32/mpbthciport.c @@ -71,7 +71,7 @@ STATIC void mp_bluetooth_hci_start_polling(void) { mp_bluetooth_hci_poll_now(); } -void mp_bluetooth_hci_poll_in_ms(uint32_t ms) { +void mp_bluetooth_hci_poll_in_ms_default(uint32_t ms) { soft_timer_reinsert(&mp_bluetooth_hci_soft_timer, ms); } @@ -92,7 +92,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(run_events_scheduled_task_obj, run_events_sched // Called periodically (systick) or directly (e.g. UART RX IRQ) in order to // request that processing happens ASAP in the scheduler. -void mp_bluetooth_hci_poll_now(void) { +void mp_bluetooth_hci_poll_now_default(void) { if (!events_task_is_scheduled) { events_task_is_scheduled = mp_sched_schedule(MP_OBJ_FROM_PTR(&run_events_scheduled_task_obj), mp_const_none); if (!events_task_is_scheduled) { @@ -104,7 +104,7 @@ void mp_bluetooth_hci_poll_now(void) { #else // !MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS -void mp_bluetooth_hci_poll_now(void) { +void mp_bluetooth_hci_poll_now_default(void) { pendsv_schedule_dispatch(PENDSV_DISPATCH_BLUETOOTH_HCI, mp_bluetooth_hci_poll); } diff --git a/ports/stm32/mpbthciport.h b/ports/stm32/mpbthciport.h index 77919ee0e6..d510ab52ad 100644 --- a/ports/stm32/mpbthciport.h +++ b/ports/stm32/mpbthciport.h @@ -26,12 +26,24 @@ #ifndef MICROPY_INCLUDED_STM32_MPBTHCIPORT_H #define MICROPY_INCLUDED_STM32_MPBTHCIPORT_H +#include "boardctrl.h" + // Initialise the HCI subsystem (should be called once, early on). void mp_bluetooth_hci_init(void); -// Poll the HCI now, or after a certain timeout. -void mp_bluetooth_hci_poll_now(void); -void mp_bluetooth_hci_poll_in_ms(uint32_t ms); +// Default implementations of poll functions (a board can override them). +void mp_bluetooth_hci_poll_now_default(void); +void mp_bluetooth_hci_poll_in_ms_default(uint32_t ms); + +// Call this to poll the HCI now. +static inline void mp_bluetooth_hci_poll_now(void) { + MICROPY_BOARD_BT_HCI_POLL_NOW(); +} + +// Call this to poll the HCI after a certain timeout. +static inline void mp_bluetooth_hci_poll_in_ms(uint32_t ms) { + MICROPY_BOARD_BT_HCI_POLL_IN_MS(ms); +} // Must be provided by the stack bindings (e.g. mpnimbleport.c or mpbtstackport.c). // Request new data from the uart and pass to the stack, and run pending events/callouts.