Skip to content

Commit

Permalink
nrf/drivers/usb: Add a tud_cdc_rx_cb() callback to check interrupt char.
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-hh authored and dpgeorge committed Jul 16, 2022
1 parent 60539ea commit c985a0b
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions ports/nrf/drivers/usb/usb_cdc.c
Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit c985a0b

Please sign in to comment.