nrf/drivers/usb: Add a tud_cdc_rx_cb() callback to check interrupt char.

This commit is contained in:
robert-hh 2022-07-08 14:26:53 +02:00 committed by Damien George
parent 60539ea162
commit c985a0b514

View File

@ -46,7 +46,7 @@
extern void tusb_hal_nrf_power_event(uint32_t event); extern void tusb_hal_nrf_power_event(uint32_t event);
static void cdc_task(void); static void cdc_task(bool tx);
static uint8_t rx_ringbuf_array[1024]; static uint8_t rx_ringbuf_array[1024];
static uint8_t tx_ringbuf_array[1024]; static uint8_t tx_ringbuf_array[1024];
@ -121,7 +121,7 @@ static int cdc_tx_char(void) {
return ringbuf_get((ringbuf_t*)&tx_ringbuf); return ringbuf_get((ringbuf_t*)&tx_ringbuf);
} }
static void cdc_task(void) static void cdc_task(bool tx)
{ {
if ( tud_cdc_connected() ) { if ( tud_cdc_connected() ) {
// connected and there are data available // connected and there are data available
@ -138,24 +138,30 @@ static void cdc_task(void)
} }
} }
int chars = 0; if (tx) {
while (cdc_tx_any()) { int chars = 0;
if (chars < 64) { while (cdc_tx_any()) {
tud_cdc_write_char(cdc_tx_char()); if (chars < 64) {
chars++; tud_cdc_write_char(cdc_tx_char());
} else { chars++;
chars = 0; } else {
tud_cdc_write_flush(); chars = 0;
tud_cdc_write_flush();
}
} }
}
tud_cdc_write_flush(); tud_cdc_write_flush();
}
} }
} }
static void usb_cdc_loop(void) { static void usb_cdc_loop(void) {
tud_task(); tud_task();
cdc_task(); cdc_task(true);
}
void tud_cdc_rx_cb(uint8_t itf) {
cdc_task(false);
} }
int usb_cdc_init(void) int usb_cdc_init(void)