From 87b4f726a7a996056989ff6fd02280f94ac3cb90 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 19 Dec 2015 01:49:54 +0100 Subject: Added Long USB RecvControl call for >64 bytes --- cores/arduino/USBCore.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'cores/arduino/USBCore.cpp') diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index 3c6610c..4e7e8af 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -426,7 +426,7 @@ static bool USB_SendStringDescriptor(const u8*string_P, u8 string_len, uint8_t f // Does not timeout or cross fifo boundaries // Will only work for transfers <= 64 bytes -// TODO +// Use USB_RecvControlLong for longer transfers int USB_RecvControl(void* d, int len) { WaitOUT(); @@ -435,6 +435,25 @@ int USB_RecvControl(void* d, int len) return len; } +// Does not timeout or cross fifo boundaries +int USB_RecvControlLong(void* d, int len) +{ + auto bytesleft = len; + while(bytesleft > 0) + { + // Dont receive more than the USB Control EP has to offer + // Use fixed 64 because control EP always have 64 bytes even on 16u2. + auto recvLength = bytesleft; + if(recvLength > 64){ + recvLength = 64; + } + + // Write data to fit to the beginning of the array + bytesleft -= USB_RecvControl((u8*)d + len - bytesleft, recvLength); + } + return len; +} + static u8 SendInterfaces() { u8 interfaces = 0; -- cgit v1.2.3-18-g5258