Skip to content

Commit b06501b

Browse files
committed
Fix regression: SerialUSB.available() do not return correct values
Fix #172
1 parent dfe465f commit b06501b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

cores/arduino/USB/SAMD21_USBDevice.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,19 @@ class DoubleBufferedEPOutHandler : public EPHandler {
350350

351351
// Returns how many bytes are stored in the buffers
352352
virtual uint32_t available() const {
353-
return (last0 - first0) + (last1 - first1);
353+
if (current == 0) {
354+
bool ready = false;
355+
synchronized {
356+
ready = ready0;
357+
}
358+
return ready ? (last0 - first0) : 0;
359+
} else {
360+
bool ready = false;
361+
synchronized {
362+
ready = ready1;
363+
}
364+
return ready ? (last1 - first1) : 0;
365+
}
354366
}
355367

356368
void release() {

0 commit comments

Comments
 (0)