diff options
author | Damien George <damien@micropython.org> | 2021-10-27 20:15:04 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2021-10-28 11:37:35 +1100 |
commit | 1e4849557d23f3b194f3a056e28f7a8c14dac050 (patch) | |
tree | ee65e7753f2140cc7c12df437d56efed7156aac1 | |
parent | 5b9c9cd0971fda60e7e6375c17bda32d3a3407d6 (diff) |
esp32/usb: Further improve speed of USB CDC output.
Following on from ba940250a5b630018c8d9b0e21c5ed858a20450f, 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>
-rw-r--r-- | ports/esp32/usb.c | 29 |
1 files changed, 4 insertions, 25 deletions
diff --git a/ports/esp32/usb.c b/ports/esp32/usb.c index 95c827729..5a613d244 100644 --- a/ports/esp32/usb.c +++ b/ports/esp32/usb.c @@ -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 |