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 <damien@micropython.org>
This commit is contained in:
Damien George
2023-11-29 12:21:54 +11:00
parent cc8fc450a6
commit e3c4c32c64
4 changed files with 15 additions and 16 deletions

View File

@@ -171,7 +171,7 @@ soft_reset:
MP_OBJ_NEW_SMALL_INT(0), MP_OBJ_NEW_SMALL_INT(0),
MP_OBJ_NEW_SMALL_INT(115200), 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 #endif

View File

@@ -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. // 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) { STATIC mp_obj_t os_dupterm(mp_uint_t n_args, const mp_obj_t *args) {
if (n_args == 0) { 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; return mp_const_none;
} else { } else {
return MP_STATE_PORT(board_stdio_uart); return MP_STATE_VM(dupterm_objs[0]);
} }
} else { } else {
if (args[0] == mp_const_none) { 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) { } 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 { } else {
mp_raise_ValueError(MP_ERROR_TEXT("need a UART object")); mp_raise_ValueError(MP_ERROR_TEXT("need a UART object"));
} }

View File

@@ -135,6 +135,7 @@
// Use port specific os module rather than extmod variant. // Use port specific os module rather than extmod variant.
#define MICROPY_PY_OS (0) #define MICROPY_PY_OS (0)
#define MICROPY_PY_OS_DUPTERM (1)
#define MICROPY_STREAMS_NON_BLOCK (1) #define MICROPY_STREAMS_NON_BLOCK (1)
#define MICROPY_CAN_OVERRIDE_BUILTINS (1) #define MICROPY_CAN_OVERRIDE_BUILTINS (1)

View File

@@ -175,11 +175,11 @@ void mp_hal_set_interrupt_char(int c) {
#if !MICROPY_PY_BLE_NUS && !MICROPY_HW_USB_CDC #if !MICROPY_PY_BLE_NUS && !MICROPY_HW_USB_CDC
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
uintptr_t ret = 0; uintptr_t ret = 0;
if ((poll_flags & MP_STREAM_POLL_RD) && MP_STATE_PORT(board_stdio_uart) != NULL if ((poll_flags & MP_STREAM_POLL_RD) && MP_STATE_VM(dupterm_objs[0]) != MP_OBJ_NULL
&& uart_rx_any(MP_STATE_PORT(board_stdio_uart))) { && uart_rx_any(MP_STATE_VM(dupterm_objs[0]))) {
ret |= MP_STREAM_POLL_RD; 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; ret |= MP_STREAM_POLL_WR;
} }
return ret; return ret;
@@ -187,8 +187,8 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
int mp_hal_stdin_rx_chr(void) { int mp_hal_stdin_rx_chr(void) {
for (;;) { for (;;) {
if (MP_STATE_PORT(board_stdio_uart) != NULL && uart_rx_any(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_PORT(board_stdio_uart)); return uart_rx_char(MP_STATE_VM(dupterm_objs[0]));
} }
MICROPY_EVENT_POLL_HOOK 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) { void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
if (MP_STATE_PORT(board_stdio_uart) != NULL) { if (MP_STATE_VM(dupterm_objs[0]) != MP_OBJ_NULL) {
uart_tx_strn(MP_STATE_PORT(board_stdio_uart), str, len); 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) { void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
if (MP_STATE_PORT(board_stdio_uart) != NULL) { if (MP_STATE_VM(dupterm_objs[0]) != MP_OBJ_NULL) {
uart_tx_strn_cooked(MP_STATE_PORT(board_stdio_uart), str, len); uart_tx_strn_cooked(MP_STATE_VM(dupterm_objs[0]), str, len);
} }
} }
#endif #endif
@@ -377,5 +377,3 @@ const char *nrfx_error_code_lookup(uint32_t err_code) {
} }
#endif // NRFX_LOG_ENABLED #endif // NRFX_LOG_ENABLED
MP_REGISTER_ROOT_POINTER(struct _machine_uart_obj_t *board_stdio_uart);