Skip to content

Commit 5265e12

Browse files
committed
USB: EP0 ::recv method has been merged with ::read method
It makes no sense to have ::recv calling repeatedly ::read in this case.
1 parent 2e44a4d commit 5265e12

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

cores/arduino/USB/SAMD21_USBDevice.h

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,23 @@ class DoubleBufferedEPOutHandler : public EPHandler {
253253
release();
254254
}
255255

256-
// Read one byte from the buffer, if the buffer is empty -1 is returned
257-
int read() {
256+
virtual uint32_t recv(void *_data, uint32_t len)
257+
{
258+
uint8_t *data = reinterpret_cast<uint8_t *>(_data);
259+
258260
// R/W: current, first0/1, ready0/1, notify
259261
// R : last0/1, data0/1
260262
if (current == 0) {
261263
synchronized {
262264
if (!ready0) {
263-
return -1;
265+
return 0;
264266
}
265267
}
266268
// when ready0==true the buffer is not being filled and last0 is constant
269+
uint32_t i;
270+
for (i=0; i<len && first0 < last0; i++) {
271+
data[i] = data0[first0++];
272+
}
267273
if (first0 == last0) {
268274
first0 = 0;
269275
current = 1;
@@ -274,16 +280,19 @@ class DoubleBufferedEPOutHandler : public EPHandler {
274280
release();
275281
}
276282
}
277-
return -1;
278283
}
279-
return data0[first0++];
284+
return i;
280285
} else {
281286
synchronized {
282287
if (!ready1) {
283-
return -1;
288+
return 0;
284289
}
285290
}
286291
// when ready1==true the buffer is not being filled and last1 is constant
292+
uint32_t i;
293+
for (i=0; i<len && first1 < last1; i++) {
294+
data[i] = data1[first1++];
295+
}
287296
if (first1 == last1) {
288297
first1 = 0;
289298
current = 0;
@@ -294,9 +303,8 @@ class DoubleBufferedEPOutHandler : public EPHandler {
294303
release();
295304
}
296305
}
297-
return -1;
298306
}
299-
return data1[first1++];
307+
return i;
300308
}
301309
}
302310

@@ -340,19 +348,6 @@ class DoubleBufferedEPOutHandler : public EPHandler {
340348
}
341349
}
342350

343-
virtual uint32_t recv(void *_data, uint32_t len)
344-
{
345-
// TODO Write an optimized version of this one
346-
uint8_t *data = reinterpret_cast<uint8_t *>(_data);
347-
uint32_t i;
348-
for (i=0; i<len; i++) {
349-
int c = read();
350-
if (c == -1) break;
351-
data[i] = c;
352-
}
353-
return i;
354-
}
355-
356351
// Returns how many bytes are stored in the buffers
357352
virtual uint32_t available() const {
358353
return (last0 - first0) + (last1 - first1);

0 commit comments

Comments
 (0)