@@ -63,37 +63,34 @@ ringbuf_t stdin_ringbuf = { stdin_ringbuf_array, sizeof(stdin_ringbuf_array) };
6363
6464uintptr_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
8180int 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