Add fifo empty check.

Signed-off-by: HiFiPhile <admin@hifiphile.com>
This commit is contained in:
HiFiPhile 2021-03-11 20:36:46 +01:00
parent 7fc99a9e11
commit 5caad485f1
1 changed files with 2 additions and 3 deletions

View File

@ -434,11 +434,10 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
{ {
tu_fifo_write_n(&p_cdc->rx_ff, &p_cdc->epout_buf, xferred_bytes); tu_fifo_write_n(&p_cdc->rx_ff, &p_cdc->epout_buf, xferred_bytes);
// TODO search for wanted char first for better performance
if (tud_cdc_rx_wanted_cb && ( ((signed char) p_cdc->wanted_char) != -1)) {
// Check for wanted char and invoke callback if needed // 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++) { for (uint32_t i=0; i<xferred_bytes; i++) {
if ( p_cdc->wanted_char == p_cdc->epout_buf[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); tud_cdc_rx_wanted_cb(itf, p_cdc->wanted_char);
} }
} }