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,6 +138,7 @@ static void cdc_task(void)
} }
} }
if (tx) {
int chars = 0; int chars = 0;
while (cdc_tx_any()) { while (cdc_tx_any()) {
if (chars < 64) { if (chars < 64) {
@ -151,11 +152,16 @@ static void cdc_task(void)
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)