From f92da1adc41f8a354c1ca2b7c9b53f0c45d02e87 Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Tue, 1 Mar 2022 21:34:05 +1100 Subject: [PATCH] nrf/drivers/usb: Fix MP_STREAM_POLL_RD support on USB CDC. This gets ipoll working on USB CDC stdin. --- ports/nrf/drivers/usb/usb_cdc.c | 12 ++++++++++++ ports/nrf/mphalport.c | 4 +--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ports/nrf/drivers/usb/usb_cdc.c b/ports/nrf/drivers/usb/usb_cdc.c index fa098c98b8..a1d411a256 100644 --- a/ports/nrf/drivers/usb/usb_cdc.c +++ b/ports/nrf/drivers/usb/usb_cdc.c @@ -34,6 +34,7 @@ #include "nrfx_power.h" #include "nrfx_uart.h" #include "py/ringbuf.h" +#include "py/stream.h" #ifdef BLUETOOTH_SD #include "nrf_sdm.h" @@ -192,6 +193,17 @@ void usb_cdc_sd_event_handler(uint32_t soc_evt) { } #endif +uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { + uintptr_t ret = 0; + if (poll_flags & MP_STREAM_POLL_RD) { + usb_cdc_loop(); + if (cdc_rx_any()) { + ret |= MP_STREAM_POLL_RD; + } + } + return ret; +} + int mp_hal_stdin_rx_chr(void) { for (;;) { usb_cdc_loop(); diff --git a/ports/nrf/mphalport.c b/ports/nrf/mphalport.c index 8ffb256018..1b31ad5acc 100644 --- a/ports/nrf/mphalport.c +++ b/ports/nrf/mphalport.c @@ -172,7 +172,7 @@ void mp_hal_set_interrupt_char(int c) { } #endif -#if !MICROPY_PY_BLE_NUS +#if !MICROPY_PY_BLE_NUS && !MICROPY_HW_USB_CDC uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { uintptr_t ret = 0; if ((poll_flags & MP_STREAM_POLL_RD) && MP_STATE_PORT(board_stdio_uart) != NULL @@ -181,9 +181,7 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { } return ret; } -#endif -#if !MICROPY_PY_BLE_NUS && !MICROPY_HW_USB_CDC int mp_hal_stdin_rx_chr(void) { for (;;) { if (MP_STATE_PORT(board_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(board_stdio_uart))) {