@@ -298,6 +298,7 @@ TU_VERIFY_STATIC(TU_ARRAY_SIZE(serial_drivers) == SERIAL_DRIVER_COUNT, "Serial d
298298//--------------------------------------------------------------------+
299299// INTERNAL OBJECT & FUNCTION DECLARATION
300300//--------------------------------------------------------------------+
301+ static bool open_ep_stream_pair (cdch_interface_t * p_cdc , const tusb_desc_endpoint_t * desc_ep );
301302
302303TU_ATTR_ALWAYS_INLINE static inline cdch_interface_t * get_itf (uint8_t idx ) {
303304 TU_ASSERT (idx < CFG_TUH_CDC , NULL );
@@ -364,7 +365,7 @@ static cdch_interface_t* get_itf_by_xfer(const tuh_xfer_t * xfer) {
364365 #endif
365366
366367 default :
367- break ;
368+ break ; // unknown driver
368369 }
369370 }
370371 }
@@ -389,8 +390,6 @@ static cdch_interface_t * make_new_itf(uint8_t daddr, tusb_desc_interface_t cons
389390 return NULL ;
390391}
391392
392- static bool open_ep_stream_pair (cdch_interface_t * p_cdc , tusb_desc_endpoint_t const * desc_ep );
393-
394393//--------------------------------------------------------------------+
395394// Weak stubs: invoked if no strong implementation is available
396395//--------------------------------------------------------------------+
@@ -519,7 +518,7 @@ bool tuh_cdc_read_clear (uint8_t idx) {
519518 TU_VERIFY (p_cdc );
520519
521520 bool ret = tu_edpt_stream_clear (& p_cdc -> stream .rx );
522- tu_edpt_stream_read_xfer (p_cdc -> daddr , & p_cdc -> stream .rx );
521+ ( void ) tu_edpt_stream_read_xfer (p_cdc -> daddr , & p_cdc -> stream .rx );
523522 return ret ;
524523}
525524
@@ -648,13 +647,10 @@ bool cdch_init(void) {
648647 for (size_t i = 0 ; i < CFG_TUH_CDC ; i ++ ) {
649648 cdch_interface_t * p_cdc = & cdch_data [i ];
650649 cdch_epbuf_t * epbuf = & cdch_epbuf [i ];
651- tu_edpt_stream_init (& p_cdc -> stream .tx , true, true, false,
652- p_cdc -> stream .tx_ff_buf , CFG_TUH_CDC_TX_BUFSIZE ,
653- epbuf -> tx , CFG_TUH_CDC_TX_EPSIZE );
654-
655- tu_edpt_stream_init (& p_cdc -> stream .rx , true, false, false,
656- p_cdc -> stream .rx_ff_buf , CFG_TUH_CDC_RX_BUFSIZE ,
657- epbuf -> rx , CFG_TUH_CDC_RX_EPSIZE );
650+ TU_ASSERT (tu_edpt_stream_init (& p_cdc -> stream .tx , true, true, false, p_cdc -> stream .tx_ff_buf , CFG_TUH_CDC_TX_BUFSIZE ,
651+ epbuf -> tx , CFG_TUH_CDC_TX_EPSIZE ));
652+ TU_ASSERT (tu_edpt_stream_init (& p_cdc -> stream .rx , true, false, false, p_cdc -> stream .rx_ff_buf ,
653+ CFG_TUH_CDC_RX_BUFSIZE , epbuf -> rx , CFG_TUH_CDC_RX_EPSIZE ));
658654 }
659655
660656 return true;
@@ -663,8 +659,8 @@ bool cdch_init(void) {
663659bool cdch_deinit (void ) {
664660 for (size_t i = 0 ; i < CFG_TUH_CDC ; i ++ ) {
665661 cdch_interface_t * p_cdc = & cdch_data [i ];
666- tu_edpt_stream_deinit (& p_cdc -> stream .tx );
667- tu_edpt_stream_deinit (& p_cdc -> stream .rx );
662+ ( void ) tu_edpt_stream_deinit (& p_cdc -> stream .tx );
663+ ( void ) tu_edpt_stream_deinit (& p_cdc -> stream .rx );
668664 }
669665 return true;
670666}
@@ -674,11 +670,9 @@ void cdch_close(uint8_t daddr) {
674670 cdch_interface_t * p_cdc = & cdch_data [idx ];
675671 if (p_cdc -> daddr == daddr ) {
676672 TU_LOG_CDC (p_cdc , "close" );
673+ tuh_cdc_umount_cb (idx ); // invoke callback
677674
678- // Invoke application callback
679- tuh_cdc_umount_cb (idx );
680-
681- p_cdc -> daddr = 0 ;
675+ p_cdc -> daddr = 0 ;
682676 p_cdc -> bInterfaceNumber = 0 ;
683677 p_cdc -> mounted = false;
684678 tu_edpt_stream_close (& p_cdc -> stream .tx );
@@ -696,13 +690,12 @@ bool cdch_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t event, uint32_t
696690 TU_ASSERT (p_cdc );
697691
698692 if (ep_addr == p_cdc -> stream .tx .ep_addr ) {
699- // invoke tx complete callback to possibly refill tx fifo
700- tuh_cdc_tx_complete_cb (idx );
693+ tuh_cdc_tx_complete_cb (idx ); // invoke transmit complete callback
701694
702695 if (0 == tu_edpt_stream_write_xfer (daddr , & p_cdc -> stream .tx )) {
703696 // If there is no data left, a ZLP should be sent if:
704697 // - xferred_bytes is multiple of EP Packet size and not zero
705- tu_edpt_stream_write_zlp_if_needed (daddr , & p_cdc -> stream .tx , xferred_bytes );
698+ ( void ) tu_edpt_stream_write_zlp_if_needed (daddr , & p_cdc -> stream .tx , xferred_bytes );
706699 }
707700 } else if (ep_addr == p_cdc -> stream .rx .ep_addr ) {
708701 #if CFG_TUH_CDC_FTDI
@@ -718,7 +711,6 @@ bool cdch_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t event, uint32_t
718711 #endif
719712 {
720713 tu_edpt_stream_read_xfer_complete (& p_cdc -> stream .rx , xferred_bytes );
721-
722714 tuh_cdc_rx_cb (idx ); // invoke receive callback
723715 }
724716
@@ -727,7 +719,7 @@ bool cdch_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t event, uint32_t
727719 } else if (ep_addr == p_cdc -> ep_notif ) {
728720 // TODO handle notification endpoint
729721 } else {
730- TU_ASSERT ( false) ;
722+ return false;
731723 }
732724
733725 return true;
@@ -736,20 +728,17 @@ bool cdch_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t event, uint32_t
736728//--------------------------------------------------------------------+
737729// Enumeration
738730//--------------------------------------------------------------------+
739-
740731static bool open_ep_stream_pair (cdch_interface_t * p_cdc , tusb_desc_endpoint_t const * desc_ep ) {
741732 for (size_t i = 0 ; i < 2 ; i ++ ) {
742733 TU_ASSERT (TUSB_DESC_ENDPOINT == desc_ep -> bDescriptorType &&
743734 TUSB_XFER_BULK == desc_ep -> bmAttributes .xfer );
744735 TU_ASSERT (tuh_edpt_open (p_cdc -> daddr , desc_ep ));
736+ tu_edpt_stream_t * stream =
737+ (tu_edpt_dir (desc_ep -> bEndpointAddress ) == TUSB_DIR_IN ) ? & p_cdc -> stream .rx : & p_cdc -> stream .tx ;
738+ tu_edpt_stream_open (stream , desc_ep );
739+ tu_edpt_stream_clear (stream );
745740
746- if (tu_edpt_dir (desc_ep -> bEndpointAddress ) == TUSB_DIR_IN ) {
747- tu_edpt_stream_open (& p_cdc -> stream .rx , desc_ep );
748- } else {
749- tu_edpt_stream_open (& p_cdc -> stream .tx , desc_ep );
750- }
751-
752- desc_ep = (tusb_desc_endpoint_t const * ) tu_desc_next (desc_ep );
741+ desc_ep = (const tusb_desc_endpoint_t * )tu_desc_next (desc_ep );
753742 }
754743
755744 return true;
@@ -832,6 +821,7 @@ static void cdch_process_set_config(tuh_xfer_t *xfer) {
832821 }
833822}
834823
824+ // return false if there is no active transfer
835825static bool set_line_state_on_enum (cdch_interface_t * p_cdc , tuh_xfer_t * xfer ) {
836826 enum {
837827 ENUM_SET_LINE_CODING = 0 ,
0 commit comments