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.
diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c
index 821866f..53a1700 100644
--- a/esp8266/esp_mphal.c
+++ b/esp8266/esp_mphal.c
@@ -49,23 +49,30 @@
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');