summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/pybstdio.c
diff options
context:
space:
mode:
Diffstat (limited to 'stmhal/pybstdio.c')
-rw-r--r--stmhal/pybstdio.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/stmhal/pybstdio.c b/stmhal/pybstdio.c
index 5597bbd689..d8ccc1be0a 100644
--- a/stmhal/pybstdio.c
+++ b/stmhal/pybstdio.c
@@ -29,6 +29,7 @@
#include <string.h>
#include <errno.h>
+#include "py/mpstate.h"
#include "py/obj.h"
#include "py/stream.h"
#include "usb.h"
@@ -40,16 +41,13 @@
// be changed by Python code. This requires some changes, as these
// objects are in a read-only module (py/modsys.c).
-// stdio is repeated on this UART object if it's not null
-pyb_uart_obj_t *pyb_stdio_uart = NULL;
-
void stdout_tx_str(const char *str) {
stdout_tx_strn(str, strlen(str));
}
void stdout_tx_strn(const char *str, mp_uint_t len) {
- if (pyb_stdio_uart != PYB_UART_NONE) {
- uart_tx_strn(pyb_stdio_uart, str, len);
+ if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
+ uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len);
}
#if 0 && defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
lcd_print_strn(str, len);
@@ -61,8 +59,8 @@ void stdout_tx_strn(const char *str, mp_uint_t len) {
void stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
// send stdout to UART and USB CDC VCP
- if (pyb_stdio_uart != PYB_UART_NONE) {
- uart_tx_strn_cooked(pyb_stdio_uart, str, len);
+ if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
+ uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len);
}
if (usb_vcp_is_enabled()) {
usb_vcp_send_strn_cooked(str, len);
@@ -84,8 +82,8 @@ int stdin_rx_chr(void) {
byte c;
if (usb_vcp_recv_byte(&c) != 0) {
return c;
- } else if (pyb_stdio_uart != PYB_UART_NONE && uart_rx_any(pyb_stdio_uart)) {
- return uart_rx_char(pyb_stdio_uart);
+ } else if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) {
+ return uart_rx_char(MP_STATE_PORT(pyb_stdio_uart));
}
__WFI();
}