Endpoint_SelectEndpoint(Number);\r
Endpoint_EnableEndpoint();\r
\r
- UECFG1X = 0; \r
+ UECFG1X = 0;\r
\r
UECFG0X = UECFG0XData;\r
UECFG1X = UECFG1XData;\r
\r
uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)\r
{\r
- uint8_t* DataStream = (uint8_t*)Buffer;\r
- bool SendZLP = true;\r
+ uint8_t* DataStream = (uint8_t*)Buffer;\r
+ bool LastPacketFull = false;\r
+ bool ShortTransfer = (Length < USB_ControlRequest.wLength);\r
\r
while (Length && !(Endpoint_IsOUTReceived()))\r
{\r
Length--;\r
}\r
\r
- SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
- Endpoint_ClearControlIN();\r
+ LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
+ Endpoint_ClearIN();\r
}\r
\r
if (Endpoint_IsOUTReceived())\r
return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
\r
- if (SendZLP)\r
+ if (LastPacketFull || ShortTransfer)\r
{\r
while (!(Endpoint_IsINReady()));\r
- Endpoint_ClearControlIN();\r
+ Endpoint_ClearIN();\r
}\r
\r
while (!(Endpoint_IsOUTReceived()));\r
\r
uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)\r
{\r
- uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);\r
- bool SendZLP = true;\r
+ uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);\r
+ bool LastPacketFull = false;\r
+ bool ShortTransfer = (Length < USB_ControlRequest.wLength);\r
\r
while (Length && !(Endpoint_IsOUTReceived()))\r
{\r
Length--;\r
}\r
\r
- SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
- Endpoint_ClearControlIN();\r
+ LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
+ Endpoint_ClearIN();\r
}\r
\r
if (Endpoint_IsOUTReceived())\r
return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
\r
- if (SendZLP)\r
+ if (LastPacketFull || ShortTransfer)\r
{\r
while (!(Endpoint_IsINReady()));\r
- Endpoint_ClearControlIN();\r
+ Endpoint_ClearIN();\r
}\r
\r
while (!(Endpoint_IsOUTReceived()));\r
Length--;\r
}\r
\r
- Endpoint_ClearControlOUT();\r
+ Endpoint_ClearOUT();\r
}\r
\r
while (!(Endpoint_IsINReady()));\r
Length--;\r
}\r
\r
- Endpoint_ClearControlOUT();\r
+ Endpoint_ClearOUT();\r
}\r
\r
while (!(Endpoint_IsINReady()));\r