diff options
| author | Damien George | 2019-11-01 12:41:37 +1100 |
|---|---|---|
| committer | Damien George | 2019-11-01 12:41:37 +1100 |
| commit | 40ea1915fc06b7abc4fac6649c70f9b89dc51e2b (patch) | |
| tree | 30adedc7500bf608a083f1ec06f99cccb2943017 /ports | |
| parent | 78145b98ef6c755c5cf7745ea643766bec6f9045 (diff) | |
extmod/nimble: Factor out stm32-specific HCI UART RX/TX code.
Diffstat (limited to 'ports')
| -rw-r--r-- | ports/stm32/nimble_hci_uart.c | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/ports/stm32/nimble_hci_uart.c b/ports/stm32/nimble_hci_uart.c index 104a64b73..251f15e3b 100644 --- a/ports/stm32/nimble_hci_uart.c +++ b/ports/stm32/nimble_hci_uart.c @@ -28,6 +28,7 @@ #include "py/mphal.h" #include "uart.h" #include "pendsv.h" +#include "extmod/nimble/nimble/hci_uart.h" #include "drivers/cyw43/cywbt.h" #if MICROPY_BLUETOOTH_NIMBLE @@ -37,6 +38,10 @@ pyb_uart_obj_t bt_hci_uart_obj; static uint8_t hci_uart_rxbuf[512]; +#ifdef pyb_pin_BT_DEV_WAKE +static uint32_t bt_sleep_ticks; +#endif + extern void nimble_poll(void); mp_obj_t mp_uart_interrupt(mp_obj_t self_in) { @@ -81,15 +86,47 @@ int nimble_hci_uart_activate(void) { return 0; } -mp_uint_t nimble_hci_uart_rx_any() { - return uart_rx_any(&bt_hci_uart_obj); -} +void nimble_hci_uart_rx(hal_uart_rx_cb_t rx_cb, void *rx_arg) { + #ifdef pyb_pin_BT_HOST_WAKE + int host_wake = 0; + host_wake = mp_hal_pin_read(pyb_pin_BT_HOST_WAKE); + /* + // this is just for info/tracing purposes + static int last_host_wake = 0; + if (host_wake != last_host_wake) { + printf("HOST_WAKE change %d -> %d\n", last_host_wake, host_wake); + last_host_wake = host_wake; + } + */ + #endif + + while (uart_rx_any(&bt_hci_uart_obj)) { + uint8_t data = uart_rx_char(&bt_hci_uart_obj); + //printf("UART RX: %02x\n", data); + rx_cb(rx_arg, data); + } -int nimble_hci_uart_rx_char() { - return uart_rx_char(&bt_hci_uart_obj); + #ifdef pyb_pin_BT_DEV_WAKE + if (host_wake == 1 && mp_hal_pin_read(pyb_pin_BT_DEV_WAKE) == 0) { + if (mp_hal_ticks_ms() - bt_sleep_ticks > 500) { + //printf("BT SLEEP\n"); + mp_hal_pin_high(pyb_pin_BT_DEV_WAKE); // let sleep + } + } + #endif } void nimble_hci_uart_tx_strn(const char *str, uint len) { + #ifdef pyb_pin_BT_DEV_WAKE + bt_sleep_ticks = mp_hal_ticks_ms(); + + if (mp_hal_pin_read(pyb_pin_BT_DEV_WAKE) == 1) { + //printf("BT WAKE for TX\n"); + mp_hal_pin_low(pyb_pin_BT_DEV_WAKE); // wake up + mp_hal_delay_ms(5); // can't go lower than this + } + #endif + uart_tx_strn(&bt_hci_uart_obj, str, len); } |
