@@ -75,7 +75,7 @@ mp_uint_t mp_usbd_cdc_rx_strn(const char *buf, mp_uint_t len) {
7575}
7676
7777void tud_cdc_rx_cb (uint8_t itf ) {
78- #if 0
78+ #if ! MICROPY_PY_OS_DUPTERM
7979 // consume pending USB data immediately to free usb buffer and keep the endpoint from stalling.
8080 // in case the ringbuffer is full, mark the CDC interface that need attention later on for polling
8181 cdc_itf_pending &= ~(1 << itf );
@@ -230,18 +230,19 @@ const machine_usbd_cdc_obj_t machine_usbd_cdc_obj = {{&machine_usbd_cdc_type}};/
230230
231231static bool machine_usbd_cdc_irq_scheduled ;// [MICROPY_HW_USB_CDC_NUM];
232232
233- static void machine_usbd_cdc_init0 (void ) {
233+ void machine_usbd_cdc_init0 (void ) {
234234 // for (size_t i = 0; i < MICROPY_HW_USB_CDC_NUM; ++i) {
235235 MP_STATE_PORT (machine_usbd_cdc_irq ) = mp_const_none ;
236236 machine_usbd_cdc_irq_scheduled = false;
237237 // }
238238
239+ #if MICROPY_PY_OS_DUPTERM
239240 // #if MICROPY_HW_USB_CDC_REPL
240241 // Activate USB_CDC(0) on dupterm slot 1 for the REPL
241242 // todo auto detect appropriate slot
242243 MP_STATE_VM (dupterm_objs [1 ]) = MP_OBJ_FROM_PTR (& machine_usbd_cdc_obj );
243244 usb_vcp_attach_to_repl (& machine_usbd_cdc_obj , true);
244- // #endif
245+ #endif
245246
246247}
247248
@@ -349,7 +350,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(machine_usbd_cdc_isconnected_obj, machine_usbd_
349350/// Return `True` if any characters waiting, else `False`.
350351static mp_obj_t machine_usbd_cdc_any (mp_obj_t self_in ) {
351352 UNUSED (self_in );
352- if (ringbuf_peek ( & stdin_ringbuf ) != -1 ) {
353+ if (tud_cdc_available () ) {
353354 return mp_const_true ;
354355 } else {
355356 return mp_const_false ;
@@ -488,8 +489,9 @@ static const mp_rom_map_elem_t machine_usbd_cdc_locals_dict_table[] = {
488489static MP_DEFINE_CONST_DICT (machine_usbd_cdc_locals_dict , machine_usbd_cdc_locals_dict_table ) ;
489490
490491static mp_uint_t machine_usbd_cdc_read (mp_obj_t self_in , void * buf , mp_uint_t size , int * errcode ) {
492+ UNUSED (self_in );
491493 machine_usbd_cdc_obj_t * self = MP_OBJ_TO_PTR (self_in );
492- int ret = usbd_cdc_rx ( self , (byte * )buf , size , 0 );
494+ int ret = mp_usbd_cdc_rx_strn ( (byte * )buf , size );
493495 if (ret == 0 ) {
494496 // return EAGAIN error to indicate non-blocking
495497 * errcode = MP_EAGAIN ;
@@ -499,7 +501,7 @@ static mp_uint_t machine_usbd_cdc_read(mp_obj_t self_in, void *buf, mp_uint_t si
499501}
500502
501503static mp_uint_t machine_usbd_cdc_write (mp_obj_t self_in , const void * buf , mp_uint_t size , int * errcode ) {
502- machine_usbd_cdc_obj_t * self = MP_OBJ_TO_PTR (self_in );
504+ UNUSED (self_in );
503505 int ret = mp_usbd_cdc_tx_strn ((const char * )buf , size );
504506 if (ret == 0 ) {
505507 // return EAGAIN error to indicate non-blocking
@@ -514,13 +516,7 @@ static mp_uint_t machine_usbd_cdc_ioctl(mp_obj_t self_in, mp_uint_t request, uin
514516 machine_usbd_cdc_obj_t * self = MP_OBJ_TO_PTR (self_in );
515517 if (request == MP_STREAM_POLL ) {
516518 uintptr_t flags = arg ;
517- ret = 0 ;
518- if ((flags & MP_STREAM_POLL_RD ) && usbd_cdc_rx_num (self ) > 0 ) {
519- ret |= MP_STREAM_POLL_RD ;
520- }
521- if ((flags & MP_STREAM_POLL_WR ) && usbd_cdc_tx_half_empty (self )) {
522- ret |= MP_STREAM_POLL_WR ;
523- }
519+ ret = mp_usbd_cdc_poll_interfaces (flags );
524520 } else if (request == MP_STREAM_CLOSE ) {
525521 ret = 0 ;
526522 } else if (request == MP_STREAM_REPL_ATTACHED ) {
0 commit comments