summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2021-03-12 12:49:44 +0700
committerhathach <[email protected]>2021-03-12 12:49:44 +0700
commit4310941daac561dd886a0ed48115585c65d42b78 (patch)
treefa94791dec1f8b60d0b0f84276e2edba64136580
parent1cdd1b02098be05b511571457165fa66a27af7bc (diff)
parent5caad485f199ab6acfa237d84bf3d84cf41dcfdd (diff)
Merge branch 'cdc_read' of https://github.com/HiFiPhile/tinyusb into HiFiPhile-cdc_read
-rw-r--r--src/class/cdc/cdc_device.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c
index 5a74b4876..d9b098bb2 100644
--- a/src/class/cdc/cdc_device.c
+++ b/src/class/cdc/cdc_device.c
@@ -432,25 +432,24 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
// Received new data
if ( ep_addr == p_cdc->ep_out )
{
- // TODO search for wanted char first for better performance
- for(uint32_t i=0; i<xferred_bytes; i++)
- {
- tu_fifo_write(&p_cdc->rx_ff, &p_cdc->epout_buf[i]);
-
- // Check for wanted char and invoke callback if needed
- if ( tud_cdc_rx_wanted_cb && ( ((signed char) p_cdc->wanted_char) != -1 ) && ( p_cdc->wanted_char == p_cdc->epout_buf[i] ) )
- {
- tud_cdc_rx_wanted_cb(itf, p_cdc->wanted_char);
+ tu_fifo_write_n(&p_cdc->rx_ff, &p_cdc->epout_buf, xferred_bytes);
+
+ // Check for wanted char and invoke callback if needed
+ if (tud_cdc_rx_wanted_cb && ( ((signed char) p_cdc->wanted_char) != -1)) {
+ for (uint32_t i=0; i<xferred_bytes; i++) {
+ if ( p_cdc->wanted_char == p_cdc->epout_buf[i] && tu_fifo_count(&p_cdc->rx_ff) ) {
+ tud_cdc_rx_wanted_cb(itf, p_cdc->wanted_char);
+ }
}
}
-
+
// invoke receive callback (if there is still data)
if (tud_cdc_rx_cb && tu_fifo_count(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf);
-
+
// prepare for OUT transaction
_prep_out_transaction(p_cdc);
}
-
+
// Data sent to host, we continue to fetch from tx fifo to send.
// Note: This will cause incorrect baudrate set in line coding.
// Though maybe the baudrate is not really important !!!