Skip to content

Commit 537c47f

Browse files
committed
Added >64 byte USB_RecvControl() support
1 parent fd8cb46 commit 537c47f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

Diff for: hardware/arduino/avr/cores/arduino/USBCore.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,24 @@ static bool USB_SendStringDescriptor(const u8*string_P, u8 string_len, uint8_t f
425425
}
426426

427427
// Does not timeout or cross fifo boundaries
428-
// Will only work for transfers <= 64 bytes
429-
// TODO
430428
int USB_RecvControl(void* d, int len)
431429
{
432-
WaitOUT();
433-
Recv((u8*)d,len);
434-
ClearOUT();
430+
auto length = len;
431+
while(length)
432+
{
433+
// Dont receive more than the USB Control EP has to offer
434+
// Use fixed 64 because control EP always have 64 bytes even on 16u2.
435+
auto recvLength = length;
436+
if(recvLength > 64){
437+
recvLength = 64;
438+
}
439+
length -= recvLength;
440+
441+
// Write data to fit to the end (not the beginning) of the array
442+
WaitOUT();
443+
Recv((u8*)d + length, recvLength);
444+
ClearOUT();
445+
}
435446
return len;
436447
}
437448

0 commit comments

Comments
 (0)