Skip to content

Commit 746133d

Browse files
committed
Merge pull request arduino#4317 from NicoHood/RecvControlLong
Added Long USB RecvControl call for >64 bytes
2 parents 8929485 + ced86a9 commit 746133d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

hardware/arduino/avr/cores/arduino/USBAPI.h

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ bool CDC_Setup(USBSetup& setup);
193193

194194
int USB_SendControl(uint8_t flags, const void* d, int len);
195195
int USB_RecvControl(void* d, int len);
196+
int USB_RecvControlLong(void* d, int len);
196197

197198
uint8_t USB_Available(uint8_t ep);
198199
uint8_t USB_SendSpace(uint8_t ep);

hardware/arduino/avr/cores/arduino/USBCore.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ static bool USB_SendStringDescriptor(const u8*string_P, u8 string_len, uint8_t f
426426

427427
// Does not timeout or cross fifo boundaries
428428
// Will only work for transfers <= 64 bytes
429-
// TODO
429+
// Use USB_RecvControlLong for longer transfers
430430
int USB_RecvControl(void* d, int len)
431431
{
432432
WaitOUT();
@@ -435,6 +435,25 @@ int USB_RecvControl(void* d, int len)
435435
return len;
436436
}
437437

438+
// Does not timeout or cross fifo boundaries
439+
int USB_RecvControlLong(void* d, int len)
440+
{
441+
auto bytesleft = len;
442+
while(bytesleft > 0)
443+
{
444+
// Dont receive more than the USB Control EP has to offer
445+
// Use fixed 64 because control EP always have 64 bytes even on 16u2.
446+
auto recvLength = bytesleft;
447+
if(recvLength > 64){
448+
recvLength = 64;
449+
}
450+
451+
// Write data to fit to the beginning of the array
452+
bytesleft -= USB_RecvControl((u8*)d + len - bytesleft, recvLength);
453+
}
454+
return len;
455+
}
456+
438457
static u8 SendInterfaces()
439458
{
440459
u8 interfaces = 0;

0 commit comments

Comments
 (0)