@@ -82,7 +82,7 @@ typedef struct {
82
82
static cdcd_interface_t _cdcd_itf [CFG_TUD_CDC ];
83
83
CFG_TUD_MEM_SECTION static cdcd_epbuf_t _cdcd_epbuf [CFG_TUD_CDC ];
84
84
85
- static tud_cdc_configure_fifo_t _cdcd_fifo_cfg ;
85
+ static tud_cdc_configure_t _cdcd_cfg = TUD_CDC_CONFIGURE_DEFAULT () ;
86
86
87
87
static bool _prep_out_transaction (uint8_t itf ) {
88
88
const uint8_t rhport = 0 ;
@@ -119,9 +119,9 @@ static bool _prep_out_transaction(uint8_t itf) {
119
119
// APPLICATION API
120
120
//--------------------------------------------------------------------+
121
121
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 ;
125
125
return true;
126
126
}
127
127
@@ -175,7 +175,7 @@ void tud_cdc_n_read_flush(uint8_t itf) {
175
175
//--------------------------------------------------------------------+
176
176
uint32_t tud_cdc_n_write (uint8_t itf , const void * buffer , uint32_t bufsize ) {
177
177
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 ));
179
179
180
180
// flush if queue more than packet size
181
181
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) {
186
186
tud_cdc_n_write_flush (itf );
187
187
}
188
188
189
- return ret ;
189
+ return wr_count ;
190
190
}
191
191
192
192
uint32_t tud_cdc_n_write_flush (uint8_t itf ) {
@@ -233,8 +233,6 @@ bool tud_cdc_n_write_clear(uint8_t itf) {
233
233
//--------------------------------------------------------------------+
234
234
void cdcd_init (void ) {
235
235
tu_memclr (_cdcd_itf , sizeof (_cdcd_itf ));
236
- tu_memclr (& _cdcd_fifo_cfg , sizeof (_cdcd_fifo_cfg ));
237
-
238
236
for (uint8_t i = 0 ; i < CFG_TUD_CDC ; i ++ ) {
239
237
cdcd_interface_t * p_cdc = & _cdcd_itf [i ];
240
238
@@ -249,10 +247,10 @@ void cdcd_init(void) {
249
247
// Config RX fifo
250
248
tu_fifo_config (& p_cdc -> rx_ff , p_cdc -> rx_ff_buf , TU_ARRAY_SIZE (p_cdc -> rx_ff_buf ), 1 , false);
251
249
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 );
256
254
257
255
#if OSAL_MUTEX_REQUIRED
258
256
osal_mutex_t mutex_rd = osal_mutex_create (& p_cdc -> rx_ff_mutex );
@@ -294,13 +292,13 @@ void cdcd_reset(uint8_t rhport) {
294
292
cdcd_interface_t * p_cdc = & _cdcd_itf [i ];
295
293
296
294
tu_memclr (p_cdc , ITF_MEM_RESET_SIZE );
297
- if (!_cdcd_fifo_cfg .rx_persistent ) {
295
+ if (!_cdcd_cfg .rx_persistent ) {
298
296
tu_fifo_clear (& p_cdc -> rx_ff );
299
297
}
300
- if (!_cdcd_fifo_cfg .tx_persistent ) {
298
+ if (!_cdcd_cfg .tx_persistent ) {
301
299
tu_fifo_clear (& p_cdc -> tx_ff );
302
300
}
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 );
304
302
}
305
303
}
306
304
@@ -414,8 +412,12 @@ bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control_requ
414
412
415
413
p_cdc -> line_state = (uint8_t ) request -> wValue ;
416
414
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
+ }
419
421
420
422
TU_LOG_DRV (" Set Control Line State: DTR = %d, RTS = %d\r\n" , dtr , rts );
421
423
@@ -496,7 +498,7 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
496
498
// xferred_bytes is multiple of EP Packet size and not zero
497
499
if (!tu_fifo_count (& p_cdc -> tx_ff ) && xferred_bytes && (0 == (xferred_bytes & (BULK_PACKET_SIZE - 1 )))) {
498
500
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 ) );
500
502
}
501
503
}
502
504
}
0 commit comments