Skip to content

Commit d9f0475

Browse files
authored
Merge pull request #713 from HiFiPhile/cdc_read
Call One time tu_fifo_write_n on cdcd_xfer_cb
2 parents 1cdd1b0 + 31373fd commit d9f0475

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/class/cdc/cdc_device.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ static void _prep_out_transaction (cdcd_interface_t* p_cdc)
9595
// fifo can be changed before endpoint is claimed
9696
available = tu_fifo_remaining(&p_cdc->rx_ff);
9797

98-
if ( available >= sizeof(p_cdc->epout_buf) ) {
98+
if ( available >= sizeof(p_cdc->epout_buf) )
99+
{
99100
usbd_edpt_xfer(rhport, p_cdc->ep_out, p_cdc->epout_buf, sizeof(p_cdc->epout_buf));
100101
}else
101102
{
@@ -432,25 +433,27 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
432433
// Received new data
433434
if ( ep_addr == p_cdc->ep_out )
434435
{
435-
// TODO search for wanted char first for better performance
436-
for(uint32_t i=0; i<xferred_bytes; i++)
436+
tu_fifo_write_n(&p_cdc->rx_ff, &p_cdc->epout_buf, xferred_bytes);
437+
438+
// Check for wanted char and invoke callback if needed
439+
if ( tud_cdc_rx_wanted_cb && (((signed char) p_cdc->wanted_char) != -1) )
437440
{
438-
tu_fifo_write(&p_cdc->rx_ff, &p_cdc->epout_buf[i]);
439-
440-
// Check for wanted char and invoke callback if needed
441-
if ( tud_cdc_rx_wanted_cb && ( ((signed char) p_cdc->wanted_char) != -1 ) && ( p_cdc->wanted_char == p_cdc->epout_buf[i] ) )
441+
for ( uint32_t i = 0; i < xferred_bytes; i++ )
442442
{
443-
tud_cdc_rx_wanted_cb(itf, p_cdc->wanted_char);
443+
if ( (p_cdc->wanted_char == p_cdc->epout_buf[i]) && !tu_fifo_empty(&p_cdc->rx_ff) )
444+
{
445+
tud_cdc_rx_wanted_cb(itf, p_cdc->wanted_char);
446+
}
444447
}
445448
}
446-
449+
447450
// invoke receive callback (if there is still data)
448-
if (tud_cdc_rx_cb && tu_fifo_count(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf);
449-
451+
if (tud_cdc_rx_cb && !tu_fifo_empty(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf);
452+
450453
// prepare for OUT transaction
451454
_prep_out_transaction(p_cdc);
452455
}
453-
456+
454457
// Data sent to host, we continue to fetch from tx fifo to send.
455458
// Note: This will cause incorrect baudrate set in line coding.
456459
// Though maybe the baudrate is not really important !!!

0 commit comments

Comments
 (0)