summaryrefslogtreecommitdiff
path: root/extmod/nimble/hal/hal_uart.c
diff options
context:
space:
mode:
Diffstat (limited to 'extmod/nimble/hal/hal_uart.c')
-rw-r--r--extmod/nimble/hal/hal_uart.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/extmod/nimble/hal/hal_uart.c b/extmod/nimble/hal/hal_uart.c
index 84a964fde..6c17da086 100644
--- a/extmod/nimble/hal/hal_uart.c
+++ b/extmod/nimble/hal/hal_uart.c
@@ -34,6 +34,10 @@
#if MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_NIMBLE
+#ifndef MICROPY_PY_BLUETOOTH_HCI_READ_MODE
+#define MICROPY_PY_BLUETOOTH_HCI_READ_MODE MICROPY_PY_BLUETOOTH_HCI_READ_MODE_BYTE
+#endif
+
#define HCI_TRACE (0)
static hal_uart_tx_cb_t hal_uart_tx_cb;
@@ -86,15 +90,28 @@ int hal_uart_close(uint32_t port) {
return 0; // success
}
+STATIC void mp_bluetooth_hci_uart_char_cb(uint8_t chr) {
+ #if HCI_TRACE
+ printf("> %02x\n", chr);
+ #endif
+ hal_uart_rx_cb(hal_uart_rx_arg, chr);
+}
+
void mp_bluetooth_nimble_hci_uart_process(bool run_events) {
bool host_wake = mp_bluetooth_hci_controller_woken();
- int chr;
- while ((chr = mp_bluetooth_hci_uart_readchar()) >= 0) {
- #if HCI_TRACE
- printf("> %02x\n", chr);
+ for (;;) {
+ #if MICROPY_PY_BLUETOOTH_HCI_READ_MODE == MICROPY_PY_BLUETOOTH_HCI_READ_MODE_BYTE
+ int chr = mp_bluetooth_hci_uart_readchar();
+ if (chr < 0) {
+ break;
+ }
+ mp_bluetooth_hci_uart_char_cb(chr);
+ #elif MICROPY_PY_BLUETOOTH_HCI_READ_MODE == MICROPY_PY_BLUETOOTH_HCI_READ_MODE_PACKET
+ if (mp_bluetooth_hci_uart_readpacket(mp_bluetooth_hci_uart_char_cb) < 0) {
+ break;
+ }
#endif
- hal_uart_rx_cb(hal_uart_rx_arg, chr);
// Incoming data may result in events being enqueued. If we're in
// scheduler context then we can run those events immediately.