Added Long USB RecvControl call for >64 bytes

This commit is contained in:
NicoHood 2015-12-19 01:49:54 +01:00
parent 513dbdd690
commit 87b4f726a7
2 changed files with 21 additions and 1 deletions

View File

@ -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);

View File

@ -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;