X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/a504a3a010ec2441dda0209f195492fb36e7c97b..526e398986583e2fb65c0a36a2fbf2ce153446e5:/LUFA/Drivers/USB/LowLevel/Endpoint.c diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.c b/LUFA/Drivers/USB/LowLevel/Endpoint.c index 4615baa69..bd264b17f 100644 --- a/LUFA/Drivers/USB/LowLevel/Endpoint.c +++ b/LUFA/Drivers/USB/LowLevel/Endpoint.c @@ -117,7 +117,7 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length if ((ErrorCode = Endpoint_WaitUntilReady())) return ErrorCode; - while (Length--) + while (Length) { if (!(Endpoint_IsReadWriteAllowed())) { @@ -125,7 +125,7 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length #if !defined(NO_STREAM_CALLBACKS) if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return ENDPOINT_RWSTREAM_ERROR_CallbackAborted; + return ENDPOINT_RWSTREAM_CallbackAborted; #endif if ((ErrorCode = Endpoint_WaitUntilReady())) @@ -134,10 +134,11 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length else { Endpoint_Discard_Byte(); + Length--; } } - return ENDPOINT_RWSTREAM_ERROR_NoError; + return ENDPOINT_RWSTREAM_NoError; } uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length @@ -152,7 +153,7 @@ uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length if ((ErrorCode = Endpoint_WaitUntilReady())) return ErrorCode; - while (Length--) + while (Length) { if (!(Endpoint_IsReadWriteAllowed())) { @@ -160,7 +161,7 @@ uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length #if !defined(NO_STREAM_CALLBACKS) if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return ENDPOINT_RWSTREAM_ERROR_CallbackAborted; + return ENDPOINT_RWSTREAM_CallbackAborted; #endif if ((ErrorCode = Endpoint_WaitUntilReady())) @@ -169,10 +170,11 @@ uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length else { Endpoint_Write_Byte(*(DataStream++)); + Length--; } } - return ENDPOINT_RWSTREAM_ERROR_NoError; + return ENDPOINT_RWSTREAM_NoError; } uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length @@ -187,7 +189,7 @@ uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length if ((ErrorCode = Endpoint_WaitUntilReady())) return ErrorCode; - while (Length--) + while (Length) { if (!(Endpoint_IsReadWriteAllowed())) { @@ -195,7 +197,7 @@ uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length #if !defined(NO_STREAM_CALLBACKS) if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return ENDPOINT_RWSTREAM_ERROR_CallbackAborted; + return ENDPOINT_RWSTREAM_CallbackAborted; #endif if ((ErrorCode = Endpoint_WaitUntilReady())) @@ -204,10 +206,11 @@ uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length else { Endpoint_Write_Byte(*(DataStream--)); + Length--; } } - return ENDPOINT_RWSTREAM_ERROR_NoError; + return ENDPOINT_RWSTREAM_NoError; } uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length @@ -222,7 +225,7 @@ uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length if ((ErrorCode = Endpoint_WaitUntilReady())) return ErrorCode; - while (Length--) + while (Length) { if (!(Endpoint_IsReadWriteAllowed())) { @@ -230,7 +233,7 @@ uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length #if !defined(NO_STREAM_CALLBACKS) if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return ENDPOINT_RWSTREAM_ERROR_CallbackAborted; + return ENDPOINT_RWSTREAM_CallbackAborted; #endif if ((ErrorCode = Endpoint_WaitUntilReady())) @@ -239,10 +242,11 @@ uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length else { *(DataStream++) = Endpoint_Read_Byte(); + Length--; } } - return ENDPOINT_RWSTREAM_ERROR_NoError; + return ENDPOINT_RWSTREAM_NoError; } uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length @@ -257,7 +261,7 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length if ((ErrorCode = Endpoint_WaitUntilReady())) return ErrorCode; - while (Length--) + while (Length) { if (!(Endpoint_IsReadWriteAllowed())) { @@ -265,7 +269,7 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length #if !defined(NO_STREAM_CALLBACKS) if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return ENDPOINT_RWSTREAM_ERROR_CallbackAborted; + return ENDPOINT_RWSTREAM_CallbackAborted; #endif if ((ErrorCode = Endpoint_WaitUntilReady())) @@ -274,18 +278,21 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length else { *(DataStream--) = Endpoint_Read_Byte(); + Length--; } } - return ENDPOINT_RWSTREAM_ERROR_NoError; + return ENDPOINT_RWSTREAM_NoError; } #endif uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length) { - uint8_t* DataStream = (uint8_t*)Buffer; + uint8_t* DataStream = (uint8_t*)Buffer; bool LastPacketFull = false; - bool ShortTransfer = (Length < USB_ControlRequest.wLength); + + if (Length > USB_ControlRequest.wLength) + Length = USB_ControlRequest.wLength; while (Length && !(Endpoint_IsOUTReceived())) { @@ -294,7 +301,6 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length) while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize)) { Endpoint_Write_Byte(*(DataStream++)); - Length--; } @@ -303,9 +309,9 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length) } if (Endpoint_IsOUTReceived()) - return ENDPOINT_RWCSTREAM_ERROR_HostAborted; + return ENDPOINT_RWCSTREAM_HostAborted; - if (LastPacketFull || ShortTransfer) + if (LastPacketFull) { while (!(Endpoint_IsINReady())); Endpoint_ClearIN(); @@ -313,34 +319,36 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length) while (!(Endpoint_IsOUTReceived())); - return ENDPOINT_RWCSTREAM_ERROR_NoError; + return ENDPOINT_RWCSTREAM_NoError; } uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length) { uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1); bool LastPacketFull = false; - bool ShortTransfer = (Length < USB_ControlRequest.wLength); + if (Length > USB_ControlRequest.wLength) + Length = USB_ControlRequest.wLength; + while (Length && !(Endpoint_IsOUTReceived())) { - while (!(Endpoint_IsINReady())); - - while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize)) + if (Endpoint_IsINReady()) { - Endpoint_Write_Byte(*(DataStream--)); + while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize)) + { + Endpoint_Write_Byte(*(DataStream--)); + Length--; + } - Length--; + LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); + Endpoint_ClearIN(); } - - LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); - Endpoint_ClearIN(); } if (Endpoint_IsOUTReceived()) - return ENDPOINT_RWCSTREAM_ERROR_HostAborted; + return ENDPOINT_RWCSTREAM_HostAborted; - if (LastPacketFull || ShortTransfer) + if (LastPacketFull) { while (!(Endpoint_IsINReady())); Endpoint_ClearIN(); @@ -348,7 +356,7 @@ uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length) while (!(Endpoint_IsOUTReceived())); - return ENDPOINT_RWCSTREAM_ERROR_NoError; + return ENDPOINT_RWCSTREAM_NoError; } uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length) @@ -357,21 +365,21 @@ uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length) while (Length) { - while (!(Endpoint_IsOUTReceived())); - - while (Length && Endpoint_BytesInEndpoint()) + if (Endpoint_IsOUTReceived()) { - *(DataStream++) = Endpoint_Read_Byte(); + while (Length && Endpoint_BytesInEndpoint()) + { + *(DataStream++) = Endpoint_Read_Byte(); + Length--; + } - Length--; + Endpoint_ClearOUT(); } - - Endpoint_ClearOUT(); } while (!(Endpoint_IsINReady())); - return ENDPOINT_RWCSTREAM_ERROR_NoError; + return ENDPOINT_RWCSTREAM_NoError; } uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length) @@ -380,21 +388,21 @@ uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length) while (Length) { - while (!(Endpoint_IsOUTReceived())); - - while (Length && Endpoint_BytesInEndpoint()) + if (Endpoint_IsOUTReceived()) { - *(DataStream--) = Endpoint_Read_Byte(); + while (Length && Endpoint_BytesInEndpoint()) + { + *(DataStream--) = Endpoint_Read_Byte(); + Length--; + } - Length--; + Endpoint_ClearOUT(); } - - Endpoint_ClearOUT(); } while (!(Endpoint_IsINReady())); - return ENDPOINT_RWCSTREAM_ERROR_NoError; + return ENDPOINT_RWCSTREAM_NoError; } #endif