\r
uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)\r
{\r
- uint8_t* DataStream = (uint8_t*)Buffer;\r
+ uint8_t* DataStream = (uint8_t*)Buffer;\r
bool LastPacketFull = false;\r
- bool ShortTransfer = (Length < USB_ControlRequest.wLength);\r
+ \r
+ if (Length > USB_ControlRequest.wLength)\r
+ Length = USB_ControlRequest.wLength;\r
\r
while (Length && !(Endpoint_IsOUTReceived()))\r
{\r
if (Endpoint_IsOUTReceived())\r
return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
\r
- if (LastPacketFull || ShortTransfer)\r
+ if (LastPacketFull)\r
{\r
while (!(Endpoint_IsINReady()));\r
Endpoint_ClearIN();\r
{\r
uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);\r
bool LastPacketFull = false;\r
- bool ShortTransfer = (Length < USB_ControlRequest.wLength);\r
\r
+ if (Length > USB_ControlRequest.wLength)\r
+ Length = USB_ControlRequest.wLength;\r
+\r
while (Length && !(Endpoint_IsOUTReceived()))\r
{\r
- while (!(Endpoint_IsINReady()));\r
- \r
- while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
+ if (Endpoint_IsINReady())\r
{\r
- Endpoint_Write_Byte(*(DataStream--));\r
- Length--;\r
+ while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
+ {\r
+ Endpoint_Write_Byte(*(DataStream--));\r
+ Length--;\r
+ }\r
+ \r
+ LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
+ Endpoint_ClearIN();\r
}\r
- \r
- LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
- Endpoint_ClearIN();\r
}\r
\r
if (Endpoint_IsOUTReceived())\r
return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
\r
- if (LastPacketFull || ShortTransfer)\r
+ if (LastPacketFull)\r
{\r
while (!(Endpoint_IsINReady()));\r
Endpoint_ClearIN();\r
\r
while (Length)\r
{\r
- while (!(Endpoint_IsOUTReceived()));\r
- \r
- while (Length && Endpoint_BytesInEndpoint())\r
+ if (Endpoint_IsOUTReceived())\r
{\r
- *(DataStream++) = Endpoint_Read_Byte();\r
- Length--;\r
+ while (Length && Endpoint_BytesInEndpoint())\r
+ {\r
+ *(DataStream++) = Endpoint_Read_Byte();\r
+ Length--;\r
+ }\r
+ \r
+ Endpoint_ClearOUT();\r
}\r
- \r
- Endpoint_ClearOUT();\r
}\r
\r
while (!(Endpoint_IsINReady()));\r
\r
while (Length)\r
{\r
- while (!(Endpoint_IsOUTReceived()));\r
- \r
- while (Length && Endpoint_BytesInEndpoint())\r
+ if (Endpoint_IsOUTReceived())\r
{\r
- *(DataStream--) = Endpoint_Read_Byte();\r
- Length--;\r
+ while (Length && Endpoint_BytesInEndpoint())\r
+ {\r
+ *(DataStream--) = Endpoint_Read_Byte();\r
+ Length--;\r
+ }\r
+ \r
+ Endpoint_ClearOUT();\r
}\r
- \r
- Endpoint_ClearOUT();\r
}\r
\r
while (!(Endpoint_IsINReady()));\r