From e3c4c32c640465a3596acdb1bd6a2b8f1eb89a29 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 29 Nov 2023 12:21:54 +1100 Subject: [PATCH] nrf: Use dupterm_objs[0] instead of board_stdio_uart. To make this a little more consistent with other ports. Signed-off-by: Damien George --- ports/nrf/main.c | 2 +- ports/nrf/modules/os/modos.c | 8 ++++---- ports/nrf/mpconfigport.h | 1 + ports/nrf/mphalport.c | 20 +++++++++----------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/ports/nrf/main.c b/ports/nrf/main.c index 8e57be8dec..bcd0bb9d71 100644 --- a/ports/nrf/main.c +++ b/ports/nrf/main.c @@ -171,7 +171,7 @@ soft_reset: MP_OBJ_NEW_SMALL_INT(0), MP_OBJ_NEW_SMALL_INT(115200), }; - MP_STATE_PORT(board_stdio_uart) = MP_OBJ_TYPE_GET_SLOT(&machine_uart_type, make_new)((mp_obj_t)&machine_uart_type, MP_ARRAY_SIZE(args), 0, args); + MP_STATE_VM(dupterm_objs[0]) = MP_OBJ_TYPE_GET_SLOT(&machine_uart_type, make_new)((mp_obj_t)&machine_uart_type, MP_ARRAY_SIZE(args), 0, args); } #endif diff --git a/ports/nrf/modules/os/modos.c b/ports/nrf/modules/os/modos.c index ebe5045515..6ff7200a12 100644 --- a/ports/nrf/modules/os/modos.c +++ b/ports/nrf/modules/os/modos.c @@ -118,16 +118,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_urandom_obj, os_urandom); // TODO should accept any object with read/write methods. STATIC mp_obj_t os_dupterm(mp_uint_t n_args, const mp_obj_t *args) { if (n_args == 0) { - if (MP_STATE_PORT(board_stdio_uart) == NULL) { + if (MP_STATE_VM(dupterm_objs[0]) == MP_OBJ_NULL) { return mp_const_none; } else { - return MP_STATE_PORT(board_stdio_uart); + return MP_STATE_VM(dupterm_objs[0]); } } else { if (args[0] == mp_const_none) { - MP_STATE_PORT(board_stdio_uart) = NULL; + MP_STATE_VM(dupterm_objs[0]) = MP_OBJ_NULL; } else if (mp_obj_get_type(args[0]) == &machine_uart_type) { - MP_STATE_PORT(board_stdio_uart) = args[0]; + MP_STATE_VM(dupterm_objs[0]) = args[0]; } else { mp_raise_ValueError(MP_ERROR_TEXT("need a UART object")); } diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h index 264b0dfe8d..85db263648 100644 --- a/ports/nrf/mpconfigport.h +++ b/ports/nrf/mpconfigport.h @@ -135,6 +135,7 @@ // Use port specific os module rather than extmod variant. #define MICROPY_PY_OS (0) +#define MICROPY_PY_OS_DUPTERM (1) #define MICROPY_STREAMS_NON_BLOCK (1) #define MICROPY_CAN_OVERRIDE_BUILTINS (1) diff --git a/ports/nrf/mphalport.c b/ports/nrf/mphalport.c index 7a51e187b7..f6c934a8b5 100644 --- a/ports/nrf/mphalport.c +++ b/ports/nrf/mphalport.c @@ -175,11 +175,11 @@ void mp_hal_set_interrupt_char(int c) { #if !MICROPY_PY_BLE_NUS && !MICROPY_HW_USB_CDC 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))) { + if ((poll_flags & MP_STREAM_POLL_RD) && MP_STATE_VM(dupterm_objs[0]) != MP_OBJ_NULL + && uart_rx_any(MP_STATE_VM(dupterm_objs[0]))) { ret |= MP_STREAM_POLL_RD; } - if ((poll_flags & MP_STREAM_POLL_WR) && MP_STATE_PORT(board_stdio_uart) != NULL) { + if ((poll_flags & MP_STREAM_POLL_WR) && MP_STATE_VM(dupterm_objs[0]) != MP_OBJ_NULL) { ret |= MP_STREAM_POLL_WR; } return ret; @@ -187,8 +187,8 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { 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))) { - return uart_rx_char(MP_STATE_PORT(board_stdio_uart)); + if (MP_STATE_VM(dupterm_objs[0]) != MP_OBJ_NULL && uart_rx_any(MP_STATE_VM(dupterm_objs[0]))) { + return uart_rx_char(MP_STATE_VM(dupterm_objs[0])); } MICROPY_EVENT_POLL_HOOK } @@ -197,14 +197,14 @@ int mp_hal_stdin_rx_chr(void) { } void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { - if (MP_STATE_PORT(board_stdio_uart) != NULL) { - uart_tx_strn(MP_STATE_PORT(board_stdio_uart), str, len); + if (MP_STATE_VM(dupterm_objs[0]) != MP_OBJ_NULL) { + uart_tx_strn(MP_STATE_VM(dupterm_objs[0]), str, len); } } void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) { - if (MP_STATE_PORT(board_stdio_uart) != NULL) { - uart_tx_strn_cooked(MP_STATE_PORT(board_stdio_uart), str, len); + if (MP_STATE_VM(dupterm_objs[0]) != MP_OBJ_NULL) { + uart_tx_strn_cooked(MP_STATE_VM(dupterm_objs[0]), str, len); } } #endif @@ -377,5 +377,3 @@ const char *nrfx_error_code_lookup(uint32_t err_code) { } #endif // NRFX_LOG_ENABLED - -MP_REGISTER_ROOT_POINTER(struct _machine_uart_obj_t *board_stdio_uart);