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
1 changed files with 19 additions and 13 deletions

View File

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