diff --git a/ports/cc3200/hal/cc3200_hal.h b/ports/cc3200/hal/cc3200_hal.h index 71e245eeb..3d0d632d5 100644 --- a/ports/cc3200/hal/cc3200_hal.h +++ b/ports/cc3200/hal/cc3200_hal.h @@ -64,5 +64,6 @@ extern void HAL_SystemDeInit (void); extern void HAL_IncrementTick(void); extern void mp_hal_set_interrupt_char (int c); +#define mp_hal_stdio_poll(poll_flags) (0) // not implemented #define mp_hal_delay_us(usec) UtilsDelay(UTILS_DELAY_US_TO_COUNT(usec)) #define mp_hal_ticks_cpu() (SysTickPeriodGet() - SysTickValueGet()) diff --git a/ports/esp32/mphalport.c b/ports/esp32/mphalport.c index 804c71986..0d1ea74d6 100644 --- a/ports/esp32/mphalport.c +++ b/ports/esp32/mphalport.c @@ -34,6 +34,7 @@ #include "rom/uart.h" #include "py/obj.h" +#include "py/stream.h" #include "py/mpstate.h" #include "py/mphal.h" #include "extmod/misc.h" @@ -45,6 +46,14 @@ TaskHandle_t mp_main_task_handle; STATIC uint8_t stdin_ringbuf_array[256]; ringbuf_t stdin_ringbuf = {stdin_ringbuf_array, sizeof(stdin_ringbuf_array)}; +uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { + uintptr_t ret = 0; + if ((poll_flags & MP_STREAM_POLL_RD) && stdin_ringbuf.iget != stdin_ringbuf.iput) { + ret |= MP_STREAM_POLL_RD; + } + return ret; +} + int mp_hal_stdin_rx_chr(void) { for (;;) { int c = ringbuf_get(&stdin_ringbuf); diff --git a/ports/esp8266/esp_mphal.c b/ports/esp8266/esp_mphal.c index 351bf522c..2ce288ea3 100644 --- a/ports/esp8266/esp_mphal.c +++ b/ports/esp8266/esp_mphal.c @@ -32,6 +32,7 @@ #include "user_interface.h" #include "ets_alt_task.h" #include "py/runtime.h" +#include "py/stream.h" #include "extmod/misc.h" #include "lib/utils/pyexec.h" @@ -56,6 +57,14 @@ void mp_hal_delay_us(uint32_t us) { } } +uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { + uintptr_t ret = 0; + if ((poll_flags & MP_STREAM_POLL_RD) && stdin_ringbuf.iget != stdin_ringbuf.iput) { + ret |= MP_STREAM_POLL_RD; + } + return ret; +} + int mp_hal_stdin_rx_chr(void) { for (;;) { int c = ringbuf_get(&stdin_ringbuf); diff --git a/ports/pic16bit/pic16bit_mphal.c b/ports/pic16bit/pic16bit_mphal.c index 35955f2d3..adab38193 100644 --- a/ports/pic16bit/pic16bit_mphal.c +++ b/ports/pic16bit/pic16bit_mphal.c @@ -25,6 +25,7 @@ */ #include +#include "py/stream.h" #include "py/mphal.h" #include "board.h" @@ -51,6 +52,14 @@ void mp_hal_set_interrupt_char(int c) { interrupt_char = c; } +uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { + uintptr_t ret = 0; + if ((poll_flags & MP_STREAM_POLL_RD) && uart_rx_any()) { + ret |= MP_STREAM_POLL_RD; + } + return ret; +} + int mp_hal_stdin_rx_chr(void) { for (;;) { if (uart_rx_any()) { diff --git a/ports/stm32/mphalport.c b/ports/stm32/mphalport.c index f4ae7293c..79b28bd3d 100644 --- a/ports/stm32/mphalport.c +++ b/ports/stm32/mphalport.c @@ -1,6 +1,7 @@ #include #include "py/runtime.h" +#include "py/stream.h" #include "py/mperrno.h" #include "py/mphal.h" #include "extmod/misc.h" @@ -19,6 +20,16 @@ NORETURN void mp_hal_raise(HAL_StatusTypeDef status) { mp_raise_OSError(mp_hal_status_to_errno_table[status]); } +MP_WEAK uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { + uintptr_t ret = 0; + if (MP_STATE_PORT(pyb_stdio_uart) != NULL) { + int errcode; + const mp_stream_p_t *stream_p = mp_get_stream(MP_STATE_PORT(pyb_stdio_uart)); + ret = stream_p->ioctl(MP_STATE_PORT(pyb_stdio_uart), MP_STREAM_POLL, poll_flags, &errcode); + } + return ret | mp_uos_dupterm_poll(poll_flags); +} + MP_WEAK int mp_hal_stdin_rx_chr(void) { for (;;) { #if 0 diff --git a/ports/teensy/teensy_hal.c b/ports/teensy/teensy_hal.c index 7ce82f1d2..e9cc6778d 100644 --- a/ports/teensy/teensy_hal.c +++ b/ports/teensy/teensy_hal.c @@ -2,6 +2,7 @@ #include #include "py/runtime.h" +#include "py/stream.h" #include "py/mphal.h" #include "usb.h" #include "uart.h" @@ -21,6 +22,19 @@ void mp_hal_set_interrupt_char(int c) { // you can't press Control-C and get your python script to stop. } +uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { + uintptr_t ret = 0; + if (poll_flags & MP_STREAM_POLL_RD) { + if (usb_vcp_rx_num()) { + ret |= MP_STREAM_POLL_RD; + } + if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) { + ret |= MP_STREAM_POLL_RD; + } + } + return ret; +} + int mp_hal_stdin_rx_chr(void) { for (;;) { byte c;