From 2863dcdf4f9f1fc421c7b745195259fbf46250a2 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 8 Oct 2019 16:38:04 +1100 Subject: [PATCH] nrf: Add support to activate MICROPY_PY_SYS_STDFILES. Fixes issue #5162. --- ports/nrf/Makefile | 3 ++- ports/nrf/mphalport.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 1b70851eb8..aa6c189aaa 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -156,6 +156,7 @@ SRC_LIB += $(addprefix lib/,\ libc/string0.c \ mp-readline/readline.c \ utils/pyexec.c \ + utils/sys_stdio_mphal.c \ utils/interrupt_char.c \ timeutils/timeutils.c \ ) @@ -342,7 +343,7 @@ $(BUILD)/$(OUTPUT_FILENAME).elf: $(OBJ) $(Q)$(SIZE) $@ # List of sources for qstr extraction -SRC_QSTR += $(SRC_C) $(DRIVERS_SRC_C) $(SRC_BOARD_MODULES) +SRC_QSTR += $(SRC_C) $(SRC_LIB) $(DRIVERS_SRC_C) $(SRC_BOARD_MODULES) # Append any auto-generated sources that are needed by sources listed in # SRC_QSTR diff --git a/ports/nrf/mphalport.c b/ports/nrf/mphalport.c index a050df1470..bf89697083 100644 --- a/ports/nrf/mphalport.c +++ b/ports/nrf/mphalport.c @@ -30,6 +30,7 @@ #include "py/mphal.h" #include "py/mperrno.h" #include "py/runtime.h" +#include "py/stream.h" #include "uart.h" #include "nrfx_errors.h" #include "nrfx_config.h" @@ -53,6 +54,15 @@ void mp_hal_set_interrupt_char(int c) { #endif #if !MICROPY_PY_BLE_NUS +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 + && uart_rx_any(MP_STATE_PORT(board_stdio_uart))) { + ret |= MP_STREAM_POLL_RD; + } + return ret; +} + 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))) {