Skip to content

Added Long USB RecvControl call for >64 bytes #4317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hardware/arduino/avr/cores/arduino/USBAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 20 additions & 1 deletion hardware/arduino/avr/cores/arduino/USBCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down