Skip to content

Commit 2fb8b08

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

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
@@ -179,6 +179,7 @@ set(MICROPY_SOURCE_QSTR
179179
${MICROPY_DIR}/shared/runtime/mpirq.c
180180
${MICROPY_DIR}/shared/runtime/sys_stdio_mphal.c
181181
${MICROPY_DIR}/shared/tinyusb/mp_usbd_runtime.c
182+
${MICROPY_DIR}/shared/tinyusb/mp_usbd_cdc.c
182183
${MICROPY_PORT_DIR}/machine_adc.c
183184
${MICROPY_PORT_DIR}/machine_i2c.c
184185
${MICROPY_PORT_DIR}/machine_pin.c

ports/rp2/mpconfigport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
#define MICROPY_EPOCH_IS_1970 (1)
120120
#define MICROPY_PY_OS_INCLUDEFILE "ports/rp2/modos.c"
121121
#ifndef MICROPY_PY_OS_DUPTERM
122-
#define MICROPY_PY_OS_DUPTERM (1)
122+
#define MICROPY_PY_OS_DUPTERM (2)
123123
#define MICROPY_PY_OS_DUPTERM_NOTIFY (1)
124124
#endif
125125
#define MICROPY_PY_OS_SYNC (1)

ports/rp2/mphalport.c

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

6464
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
6565
uintptr_t ret = 0;
66-
#if MICROPY_HW_USB_CDC
67-
ret |= mp_usbd_cdc_poll_interfaces(poll_flags);
68-
#endif
6966
#if MICROPY_HW_ENABLE_UART_REPL
7067
if (poll_flags & MP_STREAM_POLL_WR) {
7168
ret |= MP_STREAM_POLL_WR;
7269
}
7370
#endif
7471
#if MICROPY_PY_OS_DUPTERM
7572
ret |= mp_os_dupterm_poll(poll_flags);
73+
#elif MICROPY_HW_USB_CDC
74+
ret |= mp_usbd_cdc_poll_interfaces(poll_flags);
7675
#endif
7776
return ret;
7877
}
7978

8079
// Receive single character
8180
int mp_hal_stdin_rx_chr(void) {
8281
for (;;) {
83-
#if MICROPY_HW_USB_CDC
84-
mp_usbd_cdc_poll_interfaces(0);
85-
#endif
86-
87-
int c = ringbuf_get(&stdin_ringbuf);
88-
if (c != -1) {
89-
return c;
90-
}
9182
#if MICROPY_PY_OS_DUPTERM
9283
int dupterm_c = mp_os_dupterm_rx_chr();
9384
if (dupterm_c >= 0) {
9485
return dupterm_c;
9586
}
87+
#elif MICROPY_HW_USB_CDC
88+
mp_usbd_cdc_poll_interfaces(0);
9689
#endif
90+
int c = ringbuf_get(&stdin_ringbuf);
91+
if (c != -1) {
92+
return c;
93+
}
9794
mp_event_wait_indefinite();
9895
}
9996
}
@@ -107,20 +104,18 @@ mp_uint_t mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
107104
did_write = true;
108105
#endif
109106

110-
#if MICROPY_HW_USB_CDC
111-
mp_uint_t cdc_res = mp_usbd_cdc_tx_strn(str, len);
112-
if (cdc_res > 0) {
113-
did_write = true;
114-
ret = MIN(cdc_res, ret);
115-
}
116-
#endif
117-
118107
#if MICROPY_PY_OS_DUPTERM
119108
int dupterm_res = mp_os_dupterm_tx_strn(str, len);
120109
if (dupterm_res >= 0) {
121110
did_write = true;
122111
ret = MIN((mp_uint_t)dupterm_res, ret);
123112
}
113+
#elif MICROPY_HW_USB_CDC
114+
mp_uint_t cdc_res = mp_usbd_cdc_tx_strn(str, len);
115+
if (cdc_res > 0) {
116+
did_write = true;
117+
ret = MIN(cdc_res, ret);
118+
}
124119
#endif
125120
return did_write ? ret : 0;
126121
}

0 commit comments

Comments
 (0)