aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Odendahl <wesen@ruinwesen.com>2013-01-17 17:42:41 +0100
committerManuel Odendahl <wesen@ruinwesen.com>2013-01-17 21:23:37 +0100
commit419a6796c2d444762e2ae5b7ae8b846690add839 (patch)
treefcf0212506c7abd9e8ba4b802bb0650e3dc427e5
parentb1389732c350b2dcc4c158a149dcdc038a4b6537 (diff)
downloadlibrambutan-419a6796c2d444762e2ae5b7ae8b846690add839.tar.gz
librambutan-419a6796c2d444762e2ae5b7ae8b846690add839.zip
Check if the last packet sent was the full endpoint size, in this case flush the host buffers by sending a 0 byte packet
Signed-off-by: Manuel Odendahl <wesen@ruinwesen.com>
-rw-r--r--wirish/usb_serial.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/wirish/usb_serial.cpp b/wirish/usb_serial.cpp
index 380f197..d21766f 100644
--- a/wirish/usb_serial.cpp
+++ b/wirish/usb_serial.cpp
@@ -92,13 +92,24 @@ void USBSerial::write(const void *buf, uint32 len) {
uint32 old_txed = 0;
uint32 start = millis();
+ uint32 sent = 0;
+
while (txed < len && (millis() - start < USB_TIMEOUT)) {
- txed += usb_cdcacm_tx((const uint8*)buf + txed, len - txed);
+ sent = usb_cdcacm_tx((const uint8*)buf + txed, len - txed);
+ txed += sent;
if (old_txed != txed) {
start = millis();
}
old_txed = txed;
}
+
+
+ if (sent == USB_CDCACM_TX_EPSIZE) {
+ while (usb_cdcacm_is_transmitting() != 0) {
+ }
+ /* flush out to avoid having the pc wait for more data */
+ usb_cdcacm_tx(NULL, 0);
+ }
}
uint32 USBSerial::available(void) {