extmod/nimble: Add support for reading whole HCI UART packets.
This can improve efficiency for Bluetooth systems that already process whole packets at the lower layers.
This commit is contained in:
parent
19c680ff57
commit
91fb9e7888
@ -27,6 +27,9 @@
|
|||||||
#ifndef MICROPY_INCLUDED_EXTMOD_MPBTHCI_H
|
#ifndef MICROPY_INCLUDED_EXTMOD_MPBTHCI_H
|
||||||
#define MICROPY_INCLUDED_EXTMOD_MPBTHCI_H
|
#define MICROPY_INCLUDED_EXTMOD_MPBTHCI_H
|
||||||
|
|
||||||
|
#define MICROPY_PY_BLUETOOTH_HCI_READ_MODE_BYTE (0)
|
||||||
|
#define MICROPY_PY_BLUETOOTH_HCI_READ_MODE_PACKET (1)
|
||||||
|
|
||||||
// --- Optionally can be implemented by the driver. ---------------------------
|
// --- Optionally can be implemented by the driver. ---------------------------
|
||||||
|
|
||||||
// Start/stop the HCI controller.
|
// Start/stop the HCI controller.
|
||||||
@ -46,7 +49,13 @@ int mp_bluetooth_hci_uart_init(uint32_t port, uint32_t baudrate);
|
|||||||
int mp_bluetooth_hci_uart_deinit(void);
|
int mp_bluetooth_hci_uart_deinit(void);
|
||||||
int mp_bluetooth_hci_uart_set_baudrate(uint32_t baudrate);
|
int mp_bluetooth_hci_uart_set_baudrate(uint32_t baudrate);
|
||||||
int mp_bluetooth_hci_uart_any(void);
|
int mp_bluetooth_hci_uart_any(void);
|
||||||
int mp_bluetooth_hci_uart_readchar(void);
|
|
||||||
int mp_bluetooth_hci_uart_write(const uint8_t *buf, size_t len);
|
int mp_bluetooth_hci_uart_write(const uint8_t *buf, size_t len);
|
||||||
|
|
||||||
|
// Used for mode: MICROPY_PY_BLUETOOTH_HCI_READ_MODE_BYTE
|
||||||
|
int mp_bluetooth_hci_uart_readchar(void);
|
||||||
|
|
||||||
|
// Used for mode: MICROPY_PY_BLUETOOTH_HCI_READ_MODE_PACKET
|
||||||
|
typedef void (*mp_bluetooth_hci_uart_readchar_t)(uint8_t chr);
|
||||||
|
int mp_bluetooth_hci_uart_readpacket(mp_bluetooth_hci_uart_readchar_t handler);
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_EXTMOD_MPBTHCI_H
|
#endif // MICROPY_INCLUDED_EXTMOD_MPBTHCI_H
|
||||||
|
@ -34,6 +34,10 @@
|
|||||||
|
|
||||||
#if MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_NIMBLE
|
#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)
|
#define HCI_TRACE (0)
|
||||||
|
|
||||||
static hal_uart_tx_cb_t hal_uart_tx_cb;
|
static hal_uart_tx_cb_t hal_uart_tx_cb;
|
||||||
@ -86,15 +90,28 @@ int hal_uart_close(uint32_t port) {
|
|||||||
return 0; // success
|
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) {
|
void mp_bluetooth_nimble_hci_uart_process(bool run_events) {
|
||||||
bool host_wake = mp_bluetooth_hci_controller_woken();
|
bool host_wake = mp_bluetooth_hci_controller_woken();
|
||||||
|
|
||||||
int chr;
|
for (;;) {
|
||||||
while ((chr = mp_bluetooth_hci_uart_readchar()) >= 0) {
|
#if MICROPY_PY_BLUETOOTH_HCI_READ_MODE == MICROPY_PY_BLUETOOTH_HCI_READ_MODE_BYTE
|
||||||
#if HCI_TRACE
|
int chr = mp_bluetooth_hci_uart_readchar();
|
||||||
printf("> %02x\n", chr);
|
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
|
#endif
|
||||||
hal_uart_rx_cb(hal_uart_rx_arg, chr);
|
|
||||||
|
|
||||||
// Incoming data may result in events being enqueued. If we're in
|
// Incoming data may result in events being enqueued. If we're in
|
||||||
// scheduler context then we can run those events immediately.
|
// scheduler context then we can run those events immediately.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user