@@ -61,37 +61,34 @@ ringbuf_t stdin_ringbuf = { stdin_ringbuf_array, sizeof(stdin_ringbuf_array) };
6161
6262uintptr_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
7978int 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