diff options
author | Glenn Ruben Bakke <glennbakke@gmail.com> | 2020-06-25 23:32:28 +0200 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2020-07-01 22:50:41 +1000 |
commit | ab0c14dba014d0ac27b8a5472bd795809a9be885 (patch) | |
tree | 74f76ffe28648171f095929189b0d0a0f3c7aec7 | |
parent | fc1f22a097ac2c6eb418605f36b53936e5138451 (diff) |
nrf/bluetooth/ble_uart: Add mp_hal_stdio_poll function.
This adds support for enabling MICROPY_PY_SYS_STDFILES when running UART
over Bluetooth (NUS).
-rw-r--r-- | ports/nrf/drivers/bluetooth/ble_uart.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/ports/nrf/drivers/bluetooth/ble_uart.c b/ports/nrf/drivers/bluetooth/ble_uart.c index f6bc7f719..86cd08474 100644 --- a/ports/nrf/drivers/bluetooth/ble_uart.c +++ b/ports/nrf/drivers/bluetooth/ble_uart.c @@ -33,6 +33,10 @@ #include "lib/utils/interrupt_char.h" #include "py/runtime.h" +#if MICROPY_PY_SYS_STDFILES +#include "py/stream.h" +#endif + #if MICROPY_PY_BLE_NUS static ubluepy_uuid_obj_t uuid_obj_service = { @@ -136,6 +140,17 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) { mp_hal_stdout_tx_strn(str, len); } +#if MICROPY_PY_SYS_STDFILES +uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { + uintptr_t ret = 0; + if ((poll_flags & MP_STREAM_POLL_RD) && ble_uart_enabled() + && !isBufferEmpty(mp_rx_ring_buffer)) { + ret |= MP_STREAM_POLL_RD; + } + return ret; +} +#endif + STATIC void gap_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t conn_handle, uint16_t length, uint8_t * data) { ubluepy_peripheral_obj_t * self = MP_OBJ_TO_PTR(self_in); |