Skip to content

Commit b27b670

Browse files
committed
Enable terminal duplication on the zephyr port.
1 parent 60bafab commit b27b670

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

ports/zephyr/boards/nrf52840dk_nrf52840.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ CONFIG_MAIN_STACK_SIZE=8192
1616
CONFIG_THREAD_CUSTOM_DATA=y
1717
CONFIG_THREAD_MONITOR=y
1818
CONFIG_THREAD_STACK_INFO=y
19+
20+
CONFIG_MICROPY_FROZEN_MODULES=y

ports/zephyr/uart_core.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "py/mpconfig.h"
2828
#include "py/runtime.h"
2929
#include "py/stream.h"
30+
#include "extmod/misc.h"
3031
#include "src/zephyr_getchar.h"
3132
// Zephyr headers
3233
#include <zephyr/kernel.h>
@@ -68,13 +69,26 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
6869
if (poll_flags & MP_STREAM_POLL_WR) {
6970
ret |= MP_STREAM_POLL_WR;
7071
}
72+
73+
#if MICROPY_PY_OS_DUPTERM
74+
ret |= mp_os_dupterm_poll(poll_flags);
75+
#endif
76+
7177
return ret;
7278
}
7379

7480
// Receive single character
7581
int mp_hal_stdin_rx_chr(void) {
7682
for (;;) {
7783
int _chr;
84+
85+
#if MICROPY_PY_OS_DUPTERM
86+
_chr = mp_os_dupterm_rx_chr();
87+
if (_chr >= 0) {
88+
return _chr;
89+
}
90+
#endif
91+
7892
#ifdef CONFIG_CONSOLE_SUBSYS
7993
_chr = mp_console_getchar();
8094
#else
@@ -90,9 +104,11 @@ int mp_hal_stdin_rx_chr(void) {
90104
// Send string of given length
91105
mp_uint_t mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
92106
mp_uint_t ret = len;
107+
mp_uint_t console_len = len;
108+
const char *console_str = str;
93109
#ifdef CONFIG_CONSOLE_SUBSYS
94-
while (len--) {
95-
char c = *str++;
110+
while (console_len--) {
111+
char c = *console_str++;
96112
while (mp_console_putchar(c) == -1) {
97113
MICROPY_EVENT_POLL_HOOK
98114
}
@@ -101,10 +117,18 @@ mp_uint_t mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
101117
static const struct device *uart_console_dev =
102118
DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
103119

104-
while (len--) {
105-
uart_poll_out(uart_console_dev, *str++);
120+
while (console_len--) {
121+
uart_poll_out(uart_console_dev, *console_str++);
122+
}
123+
#endif
124+
125+
#if MICROPY_PY_OS_DUPTERM
126+
int dupterm_res = mp_os_dupterm_tx_strn(str, len);
127+
if (dupterm_res >= 0) {
128+
ret = MIN((mp_uint_t)dupterm_res, ret);
106129
}
107130
#endif
131+
108132
return ret;
109133
}
110134

0 commit comments

Comments
 (0)