qmk_firmware/LUFA/Drivers/USB/LowLevel/Template/Template_Pipe_RW.c
Dean Camera f3c061d5c8 Fixed PrinterHost demo Printer_GetDeviceID() routine not removing the Device ID string length from the start of the returned array (thanks to John Andrews).
Fixed error in new pipe stream function template system not setting the right device token for R/W operations (also thanks to John Andrews).
2009-07-20 10:19:13 +00:00

80 lines
1.8 KiB
C

uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length _CALLBACK_PARAM)
{
uint8_t* DataStream = (uint8_t*)(Buffer + TEMPLATE_BUFFER_OFFSET(Length));
uint8_t ErrorCode;
Pipe_SetToken(TEMPLATE_TOKEN);
if ((ErrorCode = Pipe_WaitUntilReady()))
return ErrorCode;
#if defined(FAST_STREAM_TRANSFERS)
uint8_t BytesRemToAlignment = (Pipe_BytesInPipe() & 0x07);
if (Length >= 8)
{
Length -= BytesRemToAlignment;
switch (BytesRemToAlignment)
{
default:
do
{
if (!(Pipe_IsReadWriteAllowed()))
{
TEMPLATE_CLEAR_PIPE();
#if !defined(NO_STREAM_CALLBACKS)
if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
return PIPE_RWSTREAM_CallbackAborted;
#endif
if ((ErrorCode = Pipe_WaitUntilReady()))
return ErrorCode;
}
Length -= 8;
TEMPLATE_TRANSFER_BYTE(DataStream);
case 7: TEMPLATE_TRANSFER_BYTE(DataStream);
case 6: TEMPLATE_TRANSFER_BYTE(DataStream);
case 5: TEMPLATE_TRANSFER_BYTE(DataStream);
case 4: TEMPLATE_TRANSFER_BYTE(DataStream);
case 3: TEMPLATE_TRANSFER_BYTE(DataStream);
case 2: TEMPLATE_TRANSFER_BYTE(DataStream);
case 1: TEMPLATE_TRANSFER_BYTE(DataStream);
} while (Length >= 8);
}
}
#endif
while (Length)
{
if (!(Pipe_IsReadWriteAllowed()))
{
TEMPLATE_CLEAR_PIPE();
#if !defined(NO_STREAM_CALLBACKS)
if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
return PIPE_RWSTREAM_CallbackAborted;
#endif
if ((ErrorCode = Pipe_WaitUntilReady()))
return ErrorCode;
}
else
{
TEMPLATE_TRANSFER_BYTE(DataStream);
Length--;
}
}
return PIPE_RWSTREAM_NoError;
}
#undef TEMPLATE_FUNC_NAME
#undef TEMPLATE_TOKEN
#undef TEMPLATE_TRANSFER_BYTE
#undef TEMPLATE_CLEAR_PIPE
#undef TEMPLATE_BUFFER_OFFSET