aboutsummaryrefslogtreecommitdiffstats
path: root/LUFA/Drivers/USB/LowLevel/Endpoint.c
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-04-16 08:50:34 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-04-16 08:50:34 +0000
commit8f6b4ddf764c3a54e42d00a7502c82c5c3e71b1c (patch)
tree65c37548f19c26de3971639067d6f290095f5843 /LUFA/Drivers/USB/LowLevel/Endpoint.c
parentef06bfd1c0ef5272c32808e23d0fd60d2d1bca9c (diff)
downloadlufa-8f6b4ddf764c3a54e42d00a7502c82c5c3e71b1c.tar.gz
lufa-8f6b4ddf764c3a54e42d00a7502c82c5c3e71b1c.tar.bz2
lufa-8f6b4ddf764c3a54e42d00a7502c82c5c3e71b1c.zip
Fixed GenericHIDHost demo report write routine incorrect for control type requests (thanks to Andrei Krainev).
Removed Endpoint_ClearCurrentBank() and Pipe_ClearCurrentBank() in favour of new Endpoint_ClearIN(), Endpoint_ClearOUT(), Endpoint_ClearControlIN(), Endpoint_ClearControlOUT(), Pipe_ClearIN(), Pipe_ClearOUT(), Pipe_ClearControlIN() and Pipe_ClearControlOUT() macros (done to allow for the detection of packets of zero length). Renamed *_ReadWriteAllowed() macros to *_IsReadWriteAllowed() to remain consistent with the rest of the LUFA API. Endpoint_IsSetupReceived() macro has been renamed to Endpoint_IsSETUPReceived(), Endpoint_ClearSetupReceived() macro has been renamed to Endpoint_ClearControlSETUP(), the Pipe_IsSetupSent() macro has been renamed to Pipe_IsSETUPSent() and the Pipe_ClearSetupSent() macro is no longer applicable and should be removed - changes made to compliment the new endpoint and pipe bank management API. Updated all demos, bootloaders and projects to use the new endpoint and pipe management APIs (thanks to Roman Thiel). Updated library doxygen documentation, added groups, changed documentation macro functions to real functions for clarity. Removed old endpoint and pipe aliased read/write/discard routines which did not have an explicit endian specifier for clarity. Removed the ButtLoadTag.h header file, as no one used for its intended purpose anyway.
Diffstat (limited to 'LUFA/Drivers/USB/LowLevel/Endpoint.c')
-rw-r--r--LUFA/Drivers/USB/LowLevel/Endpoint.c105
1 files changed, 62 insertions, 43 deletions
diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.c b/LUFA/Drivers/USB/LowLevel/Endpoint.c
index aa18358c8..b88547177 100644
--- a/LUFA/Drivers/USB/LowLevel/Endpoint.c
+++ b/LUFA/Drivers/USB/LowLevel/Endpoint.c
@@ -88,8 +88,19 @@ uint8_t Endpoint_WaitUntilReady(void)
USB_INT_Clear(USB_INT_SOFI);
- while (!(Endpoint_ReadWriteAllowed()))
+ for (;;)
{
+ if (Endpoint_GetEndpointDirection() == ENDPOINT_DIR_IN)
+ {
+ if (Endpoint_IsINReady())
+ return ENDPOINT_READYWAIT_NoError;
+ }
+ else
+ {
+ if (Endpoint_IsOUTReceived())
+ return ENDPOINT_READYWAIT_NoError;
+ }
+
if (!(USB_IsConnected))
return ENDPOINT_READYWAIT_DeviceDisconnected;
else if (Endpoint_IsStalled())
@@ -103,8 +114,6 @@ uint8_t Endpoint_WaitUntilReady(void)
return ENDPOINT_READYWAIT_Timeout;
}
}
-
- return ENDPOINT_READYWAIT_NoError;
}
uint8_t Endpoint_Discard_Stream(uint16_t Length
@@ -120,9 +129,9 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length
while (Length--)
{
- if (!(Endpoint_ReadWriteAllowed()))
+ if (!(Endpoint_IsReadWriteAllowed()))
{
- Endpoint_ClearCurrentBank();
+ Endpoint_ClearOUT();
#if !defined(NO_STREAM_CALLBACKS)
if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
@@ -132,8 +141,10 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
}
-
- Endpoint_Discard_Byte();
+ else
+ {
+ Endpoint_Discard_Byte();
+ }
}
return ENDPOINT_RWSTREAM_ERROR_NoError;
@@ -153,9 +164,9 @@ uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length
while (Length--)
{
- if (!(Endpoint_ReadWriteAllowed()))
+ if (!(Endpoint_IsReadWriteAllowed()))
{
- Endpoint_ClearCurrentBank();
+ Endpoint_ClearIN();
#if !defined(NO_STREAM_CALLBACKS)
if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
@@ -165,8 +176,10 @@ uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
}
-
- Endpoint_Write_Byte(*(DataStream++));
+ else
+ {
+ Endpoint_Write_Byte(*(DataStream++));
+ }
}
return ENDPOINT_RWSTREAM_ERROR_NoError;
@@ -186,9 +199,9 @@ uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length
while (Length--)
{
- if (!(Endpoint_ReadWriteAllowed()))
+ if (!(Endpoint_IsReadWriteAllowed()))
{
- Endpoint_ClearCurrentBank();
+ Endpoint_ClearIN();
#if !defined(NO_STREAM_CALLBACKS)
if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
@@ -198,8 +211,10 @@ uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
}
-
- Endpoint_Write_Byte(*(DataStream--));
+ else
+ {
+ Endpoint_Write_Byte(*(DataStream--));
+ }
}
return ENDPOINT_RWSTREAM_ERROR_NoError;
@@ -219,9 +234,9 @@ uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length
while (Length--)
{
- if (!(Endpoint_ReadWriteAllowed()))
+ if (!(Endpoint_IsReadWriteAllowed()))
{
- Endpoint_ClearCurrentBank();
+ Endpoint_ClearOUT();
#if !defined(NO_STREAM_CALLBACKS)
if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
@@ -231,8 +246,10 @@ uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
}
-
- *(DataStream++) = Endpoint_Read_Byte();
+ else
+ {
+ *(DataStream++) = Endpoint_Read_Byte();
+ }
}
return ENDPOINT_RWSTREAM_ERROR_NoError;
@@ -252,9 +269,9 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length
while (Length--)
{
- if (!(Endpoint_ReadWriteAllowed()))
+ if (!(Endpoint_IsReadWriteAllowed()))
{
- Endpoint_ClearCurrentBank();
+ Endpoint_ClearOUT();
#if !defined(NO_STREAM_CALLBACKS)
if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
@@ -264,8 +281,10 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
}
-
- *(DataStream--) = Endpoint_Read_Byte();
+ else
+ {
+ *(DataStream--) = Endpoint_Read_Byte();
+ }
}
return ENDPOINT_RWSTREAM_ERROR_NoError;
@@ -276,9 +295,9 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
uint8_t* DataStream = (uint8_t*)Buffer;
bool SendZLP = true;
- while (Length && !(Endpoint_IsSetupOUTReceived()))
+ while (Length && !(Endpoint_IsOUTReceived()))
{
- while (!(Endpoint_IsSetupINReady()));
+ while (!(Endpoint_IsINReady()));
while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))
{
@@ -288,19 +307,19 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
}
SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);
- Endpoint_ClearSetupIN();
+ Endpoint_ClearControlIN();
}
- if (Endpoint_IsSetupOUTReceived())
+ if (Endpoint_IsOUTReceived())
return ENDPOINT_RWCSTREAM_ERROR_HostAborted;
if (SendZLP)
{
- while (!(Endpoint_IsSetupINReady()));
- Endpoint_ClearSetupIN();
+ while (!(Endpoint_IsINReady()));
+ Endpoint_ClearControlIN();
}
- while (!(Endpoint_IsSetupOUTReceived()));
+ while (!(Endpoint_IsOUTReceived()));
return ENDPOINT_RWCSTREAM_ERROR_NoError;
}
@@ -310,9 +329,9 @@ uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)
uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);
bool SendZLP = true;
- while (Length && !(Endpoint_IsSetupOUTReceived()))
+ while (Length && !(Endpoint_IsOUTReceived()))
{
- while (!(Endpoint_IsSetupINReady()));
+ while (!(Endpoint_IsINReady()));
while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))
{
@@ -322,19 +341,19 @@ uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)
}
SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);
- Endpoint_ClearSetupIN();
+ Endpoint_ClearControlIN();
}
- if (Endpoint_IsSetupOUTReceived())
+ if (Endpoint_IsOUTReceived())
return ENDPOINT_RWCSTREAM_ERROR_HostAborted;
if (SendZLP)
{
- while (!(Endpoint_IsSetupINReady()));
- Endpoint_ClearSetupIN();
+ while (!(Endpoint_IsINReady()));
+ Endpoint_ClearControlIN();
}
- while (!(Endpoint_IsSetupOUTReceived()));
+ while (!(Endpoint_IsOUTReceived()));
return ENDPOINT_RWCSTREAM_ERROR_NoError;
}
@@ -345,7 +364,7 @@ uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length)
while (Length)
{
- while (!(Endpoint_IsSetupOUTReceived()));
+ while (!(Endpoint_IsOUTReceived()));
while (Length && Endpoint_BytesInEndpoint())
{
@@ -354,10 +373,10 @@ uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length)
Length--;
}
- Endpoint_ClearSetupOUT();
+ Endpoint_ClearControlOUT();
}
- while (!(Endpoint_IsSetupINReady()));
+ while (!(Endpoint_IsINReady()));
return ENDPOINT_RWCSTREAM_ERROR_NoError;
}
@@ -368,7 +387,7 @@ uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length)
while (Length)
{
- while (!(Endpoint_IsSetupOUTReceived()));
+ while (!(Endpoint_IsOUTReceived()));
while (Length && Endpoint_BytesInEndpoint())
{
@@ -377,10 +396,10 @@ uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length)
Length--;
}
- Endpoint_ClearSetupOUT();
+ Endpoint_ClearControlOUT();
}
- while (!(Endpoint_IsSetupINReady()));
+ while (!(Endpoint_IsINReady()));
return ENDPOINT_RWCSTREAM_ERROR_NoError;
}