esp32/usb: Further improve speed of USB CDC output.

Following on from ba940250a5, the change here
makes output about 15 times faster (now up to about 550 kbytes/sec).

tinyusb_cdcacm_write_queue will return the number of bytes written, so
there's no need to use tud_cdc_n_write_available.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2021-10-27 20:15:04 +11:00
parent 5b9c9cd097
commit 1e4849557d
1 changed files with 4 additions and 25 deletions

View File

@ -87,34 +87,13 @@ void usb_init(void) {
}
void usb_tx_strn(const char *str, size_t len) {
// If no HOST is connected, we can exit this early.
if (usb_cdc_connected == 0) {
return;
}
while (len) {
// Get amount of CDC output buffer space available, making sure
// there is at least one byte available.
size_t avail = tud_cdc_n_write_available(CDC_ITF);
if (avail == 0) {
if (tinyusb_cdcacm_write_flush(CDC_ITF, pdMS_TO_TICKS(1000)) != ESP_OK) {
return;
}
avail = tud_cdc_n_write_available(CDC_ITF);
}
// Write as much data as possible.
size_t l = len;
if (l > avail) {
l = avail;
}
tud_cdc_n_write(CDC_ITF, (uint8_t *)str, l);
// Write out the data to the CDC interface, but only while the USB host is connected.
while (usb_cdc_connected && len) {
size_t l = tinyusb_cdcacm_write_queue(CDC_ITF, (uint8_t *)str, len);
str += l;
len -= l;
tud_cdc_n_write_flush(CDC_ITF);
}
// Queue a flush to write out the data in the CDC buffer (if any).
tud_cdc_n_write_flush(CDC_ITF);
}
#endif // CONFIG_USB_ENABLED