From 0b32e50365b6e36474e183a7240ccfc8fa56830a Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 13 Feb 2015 15:04:53 +0000 Subject: stmhal: Make pybstdio usable by other ports, and use it. Now all ports can use pybstdio.c to provide sys.stdin/stdout/stderr, so long as they implement mp_hal_stdin_* and mp_hal_stdout_* functions. --- esp8266/esp_mphal.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'esp8266/esp_mphal.c') diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c index 821866f689..53a1700277 100644 --- a/esp8266/esp_mphal.c +++ b/esp8266/esp_mphal.c @@ -49,23 +49,30 @@ void mp_hal_udelay(uint32_t us) { ets_delay_us(us); } -int mp_hal_uart0_rx_chr(void) { - return uart0_rx(); +int mp_hal_stdin_rx_chr(void) { + for (;;) { + int c = uart0_rx(); + if (c != -1) { + return c; + } + mp_hal_udelay(1); + mp_hal_feed_watchdog(); + } } -void mp_hal_uart0_write_str(const char *str) { +void mp_hal_stdout_tx_str(const char *str) { while (*str) { uart_tx_one_char(UART0, *str++); } } -void mp_hal_uart0_write_strn(const char *str, uint32_t len) { +void mp_hal_stdout_tx_strn(const char *str, uint32_t len) { while (len--) { uart_tx_one_char(UART0, *str++); } } -void mp_hal_uart0_write_strn_cooked(const char *str, uint32_t len) { +void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len) { while (len--) { if (*str == '\n') { uart_tx_one_char(UART0, '\r'); -- cgit v1.2.3