Skip to content

Commit bebea1a

Browse files
cmagliefacchinm
authored andcommitted
USBDevice: slightly optimized ISR handler
1 parent fc530e2 commit bebea1a

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

cores/arduino/USB/SAMD21_USBDevice.h

+23-22
Original file line numberDiff line numberDiff line change
@@ -319,35 +319,36 @@ class DoubleBufferedEPOutHandler : public EPHandler {
319319
// Ack Transfer complete
320320
usbd.epBank0AckTransferComplete(ep);
321321
//usbd.epBank0AckTransferFailed(ep); // XXX
322+
uint32_t received = usbd.epBank0ByteCount(ep);
323+
if (received == 0) {
324+
release();
325+
return;
326+
}
322327

323328
// Update counters and swap banks for non-ZLP's
324329
if (incoming == 0) {
325-
last0 = usbd.epBank0ByteCount(ep);
326-
if (last0 != 0) {
327-
incoming = 1;
328-
usbd.epBank0SetAddress(ep, const_cast<uint8_t *>(data1));
329-
synchronized {
330-
ready0 = true;
331-
if (ready1) {
332-
notify = true;
333-
return;
334-
}
335-
notify = false;
330+
last0 = received;
331+
incoming = 1;
332+
usbd.epBank0SetAddress(ep, const_cast<uint8_t *>(data1));
333+
synchronized {
334+
ready0 = true;
335+
if (ready1) {
336+
notify = true;
337+
return;
336338
}
339+
notify = false;
337340
}
338341
} else {
339-
last1 = usbd.epBank0ByteCount(ep);
340-
if (last1 != 0) {
341-
incoming = 0;
342-
usbd.epBank0SetAddress(ep, const_cast<uint8_t *>(data0));
343-
synchronized {
344-
ready1 = true;
345-
if (ready0) {
346-
notify = true;
347-
return;
348-
}
349-
notify = false;
342+
last1 = received;
343+
incoming = 0;
344+
usbd.epBank0SetAddress(ep, const_cast<uint8_t *>(data0));
345+
synchronized {
346+
ready1 = true;
347+
if (ready0) {
348+
notify = true;
349+
return;
350350
}
351+
notify = false;
351352
}
352353
}
353354
release();

0 commit comments

Comments
 (0)