@@ -82,7 +82,7 @@ typedef struct {
8282static cdcd_interface_t _cdcd_itf [CFG_TUD_CDC ];
8383CFG_TUD_MEM_SECTION static cdcd_epbuf_t _cdcd_epbuf [CFG_TUD_CDC ];
8484
85- static tud_cdc_configure_fifo_t _cdcd_fifo_cfg ;
85+ static tud_cdc_configure_t _cdcd_cfg = TUD_CDC_CONFIGURE_DEFAULT () ;
8686
8787static bool _prep_out_transaction (uint8_t itf ) {
8888 const uint8_t rhport = 0 ;
@@ -119,9 +119,9 @@ static bool _prep_out_transaction(uint8_t itf) {
119119// APPLICATION API
120120//--------------------------------------------------------------------+
121121
122- bool tud_cdc_configure_fifo (const tud_cdc_configure_fifo_t * cfg ) {
123- TU_VERIFY (cfg );
124- _cdcd_fifo_cfg = ( * cfg ) ;
122+ bool tud_cdc_configure (const tud_cdc_configure_t * driver_cfg ) {
123+ TU_VERIFY (driver_cfg );
124+ _cdcd_cfg = * driver_cfg ;
125125 return true;
126126}
127127
@@ -175,7 +175,7 @@ void tud_cdc_n_read_flush(uint8_t itf) {
175175//--------------------------------------------------------------------+
176176uint32_t tud_cdc_n_write (uint8_t itf , const void * buffer , uint32_t bufsize ) {
177177 cdcd_interface_t * p_cdc = & _cdcd_itf [itf ];
178- uint16_t ret = tu_fifo_write_n (& p_cdc -> tx_ff , buffer , (uint16_t ) TU_MIN (bufsize , UINT16_MAX ));
178+ uint16_t wr_count = tu_fifo_write_n (& p_cdc -> tx_ff , buffer , (uint16_t ) TU_MIN (bufsize , UINT16_MAX ));
179179
180180 // flush if queue more than packet size
181181 if (tu_fifo_count (& p_cdc -> tx_ff ) >= BULK_PACKET_SIZE
@@ -186,7 +186,7 @@ uint32_t tud_cdc_n_write(uint8_t itf, const void* buffer, uint32_t bufsize) {
186186 tud_cdc_n_write_flush (itf );
187187 }
188188
189- return ret ;
189+ return wr_count ;
190190}
191191
192192uint32_t tud_cdc_n_write_flush (uint8_t itf ) {
@@ -233,8 +233,6 @@ bool tud_cdc_n_write_clear(uint8_t itf) {
233233//--------------------------------------------------------------------+
234234void cdcd_init (void ) {
235235 tu_memclr (_cdcd_itf , sizeof (_cdcd_itf ));
236- tu_memclr (& _cdcd_fifo_cfg , sizeof (_cdcd_fifo_cfg ));
237-
238236 for (uint8_t i = 0 ; i < CFG_TUD_CDC ; i ++ ) {
239237 cdcd_interface_t * p_cdc = & _cdcd_itf [i ];
240238
@@ -249,10 +247,10 @@ void cdcd_init(void) {
249247 // Config RX fifo
250248 tu_fifo_config (& p_cdc -> rx_ff , p_cdc -> rx_ff_buf , TU_ARRAY_SIZE (p_cdc -> rx_ff_buf ), 1 , false);
251249
252- // Config TX fifo as overwritable at initialization and will be changed to non-overwritable
253- // if terminal supports DTR bit. Without DTR we do not know if data is actually polled by terminal .
254- // In this way, the most current data is prioritized.
255- tu_fifo_config (& p_cdc -> tx_ff , p_cdc -> tx_ff_buf , TU_ARRAY_SIZE (p_cdc -> tx_ff_buf ), 1 , true );
250+ // TX fifo can be configured to change to overwritable if not connected (DTR bit not set). Without DTR we do not
251+ // know if data is actually polled by terminal. This way the most current data is prioritized .
252+ // Default: is overwritable
253+ tu_fifo_config (& p_cdc -> tx_ff , p_cdc -> tx_ff_buf , TU_ARRAY_SIZE (p_cdc -> tx_ff_buf ), 1 , _cdcd_cfg . tx_overwritabe_if_not_connected );
256254
257255 #if OSAL_MUTEX_REQUIRED
258256 osal_mutex_t mutex_rd = osal_mutex_create (& p_cdc -> rx_ff_mutex );
@@ -294,13 +292,13 @@ void cdcd_reset(uint8_t rhport) {
294292 cdcd_interface_t * p_cdc = & _cdcd_itf [i ];
295293
296294 tu_memclr (p_cdc , ITF_MEM_RESET_SIZE );
297- if (!_cdcd_fifo_cfg .rx_persistent ) {
295+ if (!_cdcd_cfg .rx_persistent ) {
298296 tu_fifo_clear (& p_cdc -> rx_ff );
299297 }
300- if (!_cdcd_fifo_cfg .tx_persistent ) {
298+ if (!_cdcd_cfg .tx_persistent ) {
301299 tu_fifo_clear (& p_cdc -> tx_ff );
302300 }
303- tu_fifo_set_overwritable (& p_cdc -> tx_ff , true );
301+ tu_fifo_set_overwritable (& p_cdc -> tx_ff , _cdcd_cfg . tx_overwritabe_if_not_connected );
304302 }
305303}
306304
@@ -414,8 +412,12 @@ bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control_requ
414412
415413 p_cdc -> line_state = (uint8_t ) request -> wValue ;
416414
417- // Disable fifo overwriting if DTR bit is set
418- tu_fifo_set_overwritable (& p_cdc -> tx_ff , !dtr );
415+ // If enabled: fifo overwriting is disabled if DTR bit is set and vice versa
416+ if (_cdcd_cfg .tx_overwritabe_if_not_connected ) {
417+ tu_fifo_set_overwritable (& p_cdc -> tx_ff , !dtr );
418+ } else {
419+ tu_fifo_set_overwritable (& p_cdc -> tx_ff , false);
420+ }
419421
420422 TU_LOG_DRV (" Set Control Line State: DTR = %d, RTS = %d\r\n" , dtr , rts );
421423
@@ -496,7 +498,7 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
496498 // xferred_bytes is multiple of EP Packet size and not zero
497499 if (!tu_fifo_count (& p_cdc -> tx_ff ) && xferred_bytes && (0 == (xferred_bytes & (BULK_PACKET_SIZE - 1 )))) {
498500 if (usbd_edpt_claim (rhport , p_cdc -> ep_in )) {
499- usbd_edpt_xfer (rhport , p_cdc -> ep_in , NULL , 0 );
501+ TU_ASSERT ( usbd_edpt_xfer (rhport , p_cdc -> ep_in , NULL , 0 ) );
500502 }
501503 }
502504 }
0 commit comments