stm32/mpbthciport: Allow a board to hook BT HCI poll functions.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2021-10-13 18:37:48 +11:00
parent 5f2f9044ff
commit 69522822de
3 changed files with 30 additions and 6 deletions

View File

@ -66,6 +66,18 @@
#define MICROPY_BOARD_USBD_CDC_RX_EVENT usbd_cdc_rx_event_callback #define MICROPY_BOARD_USBD_CDC_RX_EVENT usbd_cdc_rx_event_callback
#endif #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. // Constants to return from boardctrl_run_boot_py, boardctrl_run_main_py.
enum { enum {
BOARDCTRL_CONTINUE, BOARDCTRL_CONTINUE,

View File

@ -71,7 +71,7 @@ STATIC void mp_bluetooth_hci_start_polling(void) {
mp_bluetooth_hci_poll_now(); 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); 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 // Called periodically (systick) or directly (e.g. UART RX IRQ) in order to
// request that processing happens ASAP in the scheduler. // 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) { if (!events_task_is_scheduled) {
events_task_is_scheduled = mp_sched_schedule(MP_OBJ_FROM_PTR(&run_events_scheduled_task_obj), mp_const_none); events_task_is_scheduled = mp_sched_schedule(MP_OBJ_FROM_PTR(&run_events_scheduled_task_obj), mp_const_none);
if (!events_task_is_scheduled) { if (!events_task_is_scheduled) {
@ -104,7 +104,7 @@ void mp_bluetooth_hci_poll_now(void) {
#else // !MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS #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); pendsv_schedule_dispatch(PENDSV_DISPATCH_BLUETOOTH_HCI, mp_bluetooth_hci_poll);
} }

View File

@ -26,12 +26,24 @@
#ifndef MICROPY_INCLUDED_STM32_MPBTHCIPORT_H #ifndef MICROPY_INCLUDED_STM32_MPBTHCIPORT_H
#define MICROPY_INCLUDED_STM32_MPBTHCIPORT_H #define MICROPY_INCLUDED_STM32_MPBTHCIPORT_H
#include "boardctrl.h"
// Initialise the HCI subsystem (should be called once, early on). // Initialise the HCI subsystem (should be called once, early on).
void mp_bluetooth_hci_init(void); void mp_bluetooth_hci_init(void);
// Poll the HCI now, or after a certain timeout. // Default implementations of poll functions (a board can override them).
void mp_bluetooth_hci_poll_now(void); void mp_bluetooth_hci_poll_now_default(void);
void mp_bluetooth_hci_poll_in_ms(uint32_t ms); 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). // 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. // Request new data from the uart and pass to the stack, and run pending events/callouts.