Skip to content

Commit

Permalink
ports/rp2: Use dupterm for USBD_CDC repl connection.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Leech <[email protected]>
  • Loading branch information
pi-anl committed Oct 27, 2024
1 parent fca4916 commit 2fb8b08
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
1 change: 1 addition & 0 deletions ports/rp2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ set(MICROPY_SOURCE_QSTR
${MICROPY_DIR}/shared/runtime/mpirq.c
${MICROPY_DIR}/shared/runtime/sys_stdio_mphal.c
${MICROPY_DIR}/shared/tinyusb/mp_usbd_runtime.c
${MICROPY_DIR}/shared/tinyusb/mp_usbd_cdc.c
${MICROPY_PORT_DIR}/machine_adc.c
${MICROPY_PORT_DIR}/machine_i2c.c
${MICROPY_PORT_DIR}/machine_pin.c
Expand Down
2 changes: 1 addition & 1 deletion ports/rp2/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
#define MICROPY_EPOCH_IS_1970 (1)
#define MICROPY_PY_OS_INCLUDEFILE "ports/rp2/modos.c"
#ifndef MICROPY_PY_OS_DUPTERM
#define MICROPY_PY_OS_DUPTERM (1)
#define MICROPY_PY_OS_DUPTERM (2)
#define MICROPY_PY_OS_DUPTERM_NOTIFY (1)
#endif
#define MICROPY_PY_OS_SYNC (1)
Expand Down
33 changes: 14 additions & 19 deletions ports/rp2/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,37 +63,34 @@ ringbuf_t stdin_ringbuf = { stdin_ringbuf_array, sizeof(stdin_ringbuf_array) };

uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
uintptr_t ret = 0;
#if MICROPY_HW_USB_CDC
ret |= mp_usbd_cdc_poll_interfaces(poll_flags);
#endif
#if MICROPY_HW_ENABLE_UART_REPL
if (poll_flags & MP_STREAM_POLL_WR) {
ret |= MP_STREAM_POLL_WR;
}
#endif
#if MICROPY_PY_OS_DUPTERM
ret |= mp_os_dupterm_poll(poll_flags);
#elif MICROPY_HW_USB_CDC
ret |= mp_usbd_cdc_poll_interfaces(poll_flags);
#endif
return ret;
}

// Receive single character
int mp_hal_stdin_rx_chr(void) {
for (;;) {
#if MICROPY_HW_USB_CDC
mp_usbd_cdc_poll_interfaces(0);
#endif

int c = ringbuf_get(&stdin_ringbuf);
if (c != -1) {
return c;
}
#if MICROPY_PY_OS_DUPTERM
int dupterm_c = mp_os_dupterm_rx_chr();
if (dupterm_c >= 0) {
return dupterm_c;
}
#elif MICROPY_HW_USB_CDC
mp_usbd_cdc_poll_interfaces(0);
#endif
int c = ringbuf_get(&stdin_ringbuf);
if (c != -1) {
return c;
}
mp_event_wait_indefinite();
}
}
Expand All @@ -107,20 +104,18 @@ mp_uint_t mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
did_write = true;
#endif

#if MICROPY_HW_USB_CDC
mp_uint_t cdc_res = mp_usbd_cdc_tx_strn(str, len);
if (cdc_res > 0) {
did_write = true;
ret = MIN(cdc_res, ret);
}
#endif

#if MICROPY_PY_OS_DUPTERM
int dupterm_res = mp_os_dupterm_tx_strn(str, len);
if (dupterm_res >= 0) {
did_write = true;
ret = MIN((mp_uint_t)dupterm_res, ret);
}
#elif MICROPY_HW_USB_CDC
mp_uint_t cdc_res = mp_usbd_cdc_tx_strn(str, len);
if (cdc_res > 0) {
did_write = true;
ret = MIN(cdc_res, ret);
}
#endif
return did_write ? ret : 0;
}
Expand Down

0 comments on commit 2fb8b08

Please sign in to comment.