Skip to content

Commit 70b011b

Browse files
committed
USB: Only swap incoming buffers for non-ZLP's
1 parent 0cbc68f commit 70b011b

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

cores/arduino/USB/SAMD21_USBDevice.h

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -319,30 +319,34 @@ class DoubleBufferedEPOutHandler : public EPHandler {
319319
usbd.epBank0AckTransferComplete(ep);
320320
//usbd.epBank0AckTransferFailed(ep); // XXX
321321

322-
// Update counters and swap banks
322+
// Update counters and swap banks for non-ZLP's
323323
if (incoming == 0) {
324324
last0 = usbd.epBank0ByteCount(ep);
325-
incoming = 1;
326-
usbd.epBank0SetAddress(ep, const_cast<uint8_t *>(data1));
327-
ready0 = true;
328-
synchronized {
329-
if (ready1) {
330-
notify = true;
331-
return;
325+
if (last0 != 0) {
326+
incoming = 1;
327+
usbd.epBank0SetAddress(ep, const_cast<uint8_t *>(data1));
328+
synchronized {
329+
ready0 = true;
330+
if (ready1) {
331+
notify = true;
332+
return;
333+
}
334+
notify = false;
332335
}
333-
notify = false;
334336
}
335337
} else {
336338
last1 = usbd.epBank0ByteCount(ep);
337-
incoming = 0;
338-
usbd.epBank0SetAddress(ep, const_cast<uint8_t *>(data0));
339-
synchronized {
340-
ready1 = true;
341-
if (ready0) {
342-
notify = true;
343-
return;
339+
if (last1 != 0) {
340+
incoming = 0;
341+
usbd.epBank0SetAddress(ep, const_cast<uint8_t *>(data0));
342+
synchronized {
343+
ready1 = true;
344+
if (ready0) {
345+
notify = true;
346+
return;
347+
}
348+
notify = false;
344349
}
345-
notify = false;
346350
}
347351
}
348352
release();

0 commit comments

Comments
 (0)