From 87b4f726a7a996056989ff6fd02280f94ac3cb90 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 19 Dec 2015 01:49:54 +0100 Subject: [PATCH] Added Long USB RecvControl call for >64 bytes --- cores/arduino/USBAPI.h | 1 + cores/arduino/USBCore.cpp | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index f22ab6a..358444e 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -193,6 +193,7 @@ bool CDC_Setup(USBSetup& setup); int USB_SendControl(uint8_t flags, const void* d, int len); int USB_RecvControl(void* d, int len); +int USB_RecvControlLong(void* d, int len); uint8_t USB_Available(uint8_t ep); uint8_t USB_SendSpace(uint8_t ep); 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;