X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/1d433d4506113c95285f633e3553ff62d4cfd05d..039a714ee46268c07928c79b30403f29d4040fe8:/LUFA/Drivers/USB/HighLevel/EndpointStream.c diff --git a/LUFA/Drivers/USB/HighLevel/EndpointStream.c b/LUFA/Drivers/USB/HighLevel/EndpointStream.c index 76875b258..974af682c 100644 --- a/LUFA/Drivers/USB/HighLevel/EndpointStream.c +++ b/LUFA/Drivers/USB/HighLevel/EndpointStream.c @@ -36,72 +36,78 @@ #include "EndpointStream.h" #if !defined(CONTROL_ONLY_DEVICE) -uint8_t Endpoint_Discard_Stream(uint16_t Length - __CALLBACK_PARAM) +uint8_t Endpoint_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed) { - uint8_t ErrorCode; + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; if ((ErrorCode = Endpoint_WaitUntilReady())) return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; - #if defined(FAST_STREAM_TRANSFERS) - uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07); - - if (Length >= 8) + while (Length) { - Length -= BytesRemToAlignment; + if (!(Endpoint_IsReadWriteAllowed())) + { + Endpoint_ClearOUT(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return ENDPOINT_RWSTREAM_IncompleteTransfer; + } - switch (BytesRemToAlignment) + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + else { - default: - do - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearOUT(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return ENDPOINT_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - - Length -= 8; - - Endpoint_Discard_Byte(); - case 7: Endpoint_Discard_Byte(); - case 6: Endpoint_Discard_Byte(); - case 5: Endpoint_Discard_Byte(); - case 4: Endpoint_Discard_Byte(); - case 3: Endpoint_Discard_Byte(); - case 2: Endpoint_Discard_Byte(); - case 1: Endpoint_Discard_Byte(); - } while (Length >= 8); + Endpoint_Discard_Byte(); + + Length--; + BytesInTransfer++; } } - #endif + + return ENDPOINT_RWSTREAM_NoError; +} + +uint8_t Endpoint_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; while (Length) { if (!(Endpoint_IsReadWriteAllowed())) { - Endpoint_ClearOUT(); + Endpoint_ClearIN(); - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return ENDPOINT_RWSTREAM_CallbackAborted; - #endif + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return ENDPOINT_RWSTREAM_IncompleteTransfer; + } if ((ErrorCode = Endpoint_WaitUntilReady())) return ErrorCode; } else { - Endpoint_Discard_Byte(); + Endpoint_Write_Byte(0); + Length--; + BytesInTransfer++; } } @@ -112,122 +118,142 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length #define TEMPLATE_BUFFER_TYPE const void* #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() #define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr++)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*BufferPtr) #include "Template/Template_Endpoint_RW.c" #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE #define TEMPLATE_BUFFER_TYPE const void* #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() #define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr)) #include "Template/Template_Endpoint_RW.c" #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE #define TEMPLATE_BUFFER_TYPE const void* #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() #define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr)) #include "Template/Template_Endpoint_RW.c" #define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE #define TEMPLATE_BUFFER_TYPE const void* #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr--)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*BufferPtr) #include "Template/Template_Endpoint_RW.c" #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE #define TEMPLATE_BUFFER_TYPE const void* #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr)) #include "Template/Template_Endpoint_RW.c" #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE #define TEMPLATE_BUFFER_TYPE const void* #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr)) #include "Template/Template_Endpoint_RW.c" #define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE #define TEMPLATE_BUFFER_TYPE void* #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() #define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Endpoint_Read_Byte() +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_Byte() #include "Template/Template_Endpoint_RW.c" #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE #define TEMPLATE_BUFFER_TYPE void* #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() #define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr++, Endpoint_Read_Byte()) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_Byte()) #include "Template/Template_Endpoint_RW.c" #define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE #define TEMPLATE_BUFFER_TYPE void* #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Endpoint_Read_Byte() +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_Byte() #include "Template/Template_Endpoint_RW.c" #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE #define TEMPLATE_BUFFER_TYPE void* #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr--, Endpoint_Read_Byte()) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_Byte()) #include "Template/Template_Endpoint_RW.c" #endif #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE #define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr++)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*BufferPtr) #include "Template/Template_Endpoint_Control_W.c" #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE #define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr)) #include "Template/Template_Endpoint_Control_W.c" #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE #define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr)) #include "Template/Template_Endpoint_Control_W.c" #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr--)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*BufferPtr) #include "Template/Template_Endpoint_Control_W.c" #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr)) #include "Template/Template_Endpoint_Control_W.c" #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr)) #include "Template/Template_Endpoint_Control_W.c" #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE #define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Endpoint_Read_Byte() +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_Byte() #include "Template/Template_Endpoint_Control_R.c" #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE #define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr++, Endpoint_Read_Byte()) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_Byte()) #include "Template/Template_Endpoint_Control_R.c" #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Endpoint_Read_Byte() +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_Byte() #include "Template/Template_Endpoint_Control_R.c" #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr--, Endpoint_Read_Byte()) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_Byte()) #include "Template/Template_Endpoint_Control_R.c" #endif