Skip to content

Commit 8c78760

Browse files
committed
ports/rp2: Use dupterm for USBD_CDC repl connection.
Signed-off-by: Andrew Leech <[email protected]>
1 parent 353c3ca commit 8c78760

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

ports/rp2/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ set(MICROPY_SOURCE_QSTR
161161
${MICROPY_DIR}/shared/runtime/mpirq.c
162162
${MICROPY_DIR}/shared/runtime/sys_stdio_mphal.c
163163
${MICROPY_DIR}/shared/tinyusb/mp_usbd_runtime.c
164+
${MICROPY_DIR}/shared/tinyusb/mp_usbd_cdc.c
164165
${MICROPY_PORT_DIR}/machine_adc.c
165166
${MICROPY_PORT_DIR}/machine_i2c.c
166167
${MICROPY_PORT_DIR}/machine_pin.c

ports/rp2/mpconfigport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
#define MICROPY_EPOCH_IS_1970 (1)
105105
#define MICROPY_PY_OS_INCLUDEFILE "ports/rp2/modos.c"
106106
#ifndef MICROPY_PY_OS_DUPTERM
107-
#define MICROPY_PY_OS_DUPTERM (1)
107+
#define MICROPY_PY_OS_DUPTERM (2)
108108
#define MICROPY_PY_OS_DUPTERM_NOTIFY (1)
109109
#endif
110110
#define MICROPY_PY_OS_SYNC (1)

ports/rp2/mphalport.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,37 +61,34 @@ ringbuf_t stdin_ringbuf = { stdin_ringbuf_array, sizeof(stdin_ringbuf_array) };
6161

6262
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
6363
uintptr_t ret = 0;
64-
#if MICROPY_HW_USB_CDC
65-
ret |= mp_usbd_cdc_poll_interfaces(poll_flags);
66-
#endif
6764
#if MICROPY_HW_ENABLE_UART_REPL
6865
if (poll_flags & MP_STREAM_POLL_WR) {
6966
ret |= MP_STREAM_POLL_WR;
7067
}
7168
#endif
7269
#if MICROPY_PY_OS_DUPTERM
7370
ret |= mp_os_dupterm_poll(poll_flags);
71+
#elif MICROPY_HW_USB_CDC
72+
ret |= mp_usbd_cdc_poll_interfaces(poll_flags);
7473
#endif
7574
return ret;
7675
}
7776

7877
// Receive single character
7978
int mp_hal_stdin_rx_chr(void) {
8079
for (;;) {
81-
#if MICROPY_HW_USB_CDC
82-
mp_usbd_cdc_poll_interfaces(0);
83-
#endif
84-
85-
int c = ringbuf_get(&stdin_ringbuf);
86-
if (c != -1) {
87-
return c;
88-
}
8980
#if MICROPY_PY_OS_DUPTERM
9081
int dupterm_c = mp_os_dupterm_rx_chr();
9182
if (dupterm_c >= 0) {
9283
return dupterm_c;
9384
}
85+
#elif MICROPY_HW_USB_CDC
86+
mp_usbd_cdc_poll_interfaces(0);
9487
#endif
88+
int c = ringbuf_get(&stdin_ringbuf);
89+
if (c != -1) {
90+
return c;
91+
}
9592
mp_event_wait_indefinite();
9693
}
9794
}
@@ -105,20 +102,18 @@ mp_uint_t mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
105102
did_write = true;
106103
#endif
107104

108-
#if MICROPY_HW_USB_CDC
109-
mp_uint_t cdc_res = mp_usbd_cdc_tx_strn(str, len);
110-
if (cdc_res > 0) {
111-
did_write = true;
112-
ret = MIN(cdc_res, ret);
113-
}
114-
#endif
115-
116105
#if MICROPY_PY_OS_DUPTERM
117106
int dupterm_res = mp_os_dupterm_tx_strn(str, len);
118107
if (dupterm_res >= 0) {
119108
did_write = true;
120109
ret = MIN((mp_uint_t)dupterm_res, ret);
121110
}
111+
#elif MICROPY_HW_USB_CDC
112+
mp_uint_t cdc_res = mp_usbd_cdc_tx_strn(str, len);
113+
if (cdc_res > 0) {
114+
did_write = true;
115+
ret = MIN(cdc_res, ret);
116+
}
122117
#endif
123118
return did_write ? ret : 0;
124119
}

0 commit comments

Comments
 (0)