Fixed GenericHIDHost demo report write routine incorrect for control type requests...
[pub/USBasp.git] / Demos / Device / GenericHID / GenericHID.c
index 3b5f972..a9ecfa7 100644 (file)
 \r
 #include "GenericHID.h"\r
 \r
-/* Project Tags, for reading out using the ButtLoad project */\r
-BUTTLOADTAG(ProjName,    "LUFA GenHID App");\r
-BUTTLOADTAG(BuildTime,   __TIME__);\r
-BUTTLOADTAG(BuildDate,   __DATE__);\r
-BUTTLOADTAG(LUFAVersion, "LUFA V" LUFA_VERSION_STRING);\r
-\r
 /* Scheduler Task List */\r
 TASK_LIST\r
 {\r
@@ -171,7 +165,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                case REQ_GetReport:\r
                        if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
-                               Endpoint_ClearSetupReceived();\r
+                               Endpoint_ClearControlSETUP();\r
        \r
                                uint8_t GenericData[GENERIC_REPORT_SIZE];\r
                                \r
@@ -181,32 +175,32 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                Endpoint_Write_Control_Stream_LE(&GenericData, sizeof(GenericData));\r
 \r
                                /* Finalize the stream transfer to send the last packet or clear the host abort */\r
-                               Endpoint_ClearSetupOUT();\r
+                               Endpoint_ClearControlOUT();\r
                        }\r
                \r
                        break;\r
                case REQ_SetReport:\r
                        if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
-                               Endpoint_ClearSetupReceived();\r
+                               Endpoint_ClearControlSETUP();\r
                                \r
                                /* Wait until the generic report has been sent by the host */\r
-                               while (!(Endpoint_IsSetupOUTReceived()));\r
+                               while (!(Endpoint_IsOUTReceived()));\r
 \r
                                uint8_t GenericData[GENERIC_REPORT_SIZE];\r
 \r
-                               Endpoint_Read_Control_Stream(&GenericData, sizeof(GenericData));\r
+                               Endpoint_Read_Control_Stream_LE(&GenericData, sizeof(GenericData));\r
 \r
                                ProcessGenericHIDReport(GenericData);\r
                        \r
                                /* Clear the endpoint data */\r
-                               Endpoint_ClearSetupOUT();\r
+                               Endpoint_ClearControlOUT();\r
 \r
                                /* Wait until the host is ready to receive the request confirmation */\r
-                               while (!(Endpoint_IsSetupINReady()));\r
+                               while (!(Endpoint_IsINReady()));\r
                                \r
                                /* Handshake the request by sending an empty IN packet */\r
-                               Endpoint_ClearSetupIN();\r
+                               Endpoint_ClearControlIN();\r
                        }\r
                        \r
                        break;\r
@@ -280,24 +274,30 @@ TASK(USB_HID_Report)
        {\r
                Endpoint_SelectEndpoint(GENERIC_OUT_EPNUM);\r
                \r
-               if (Endpoint_ReadWriteAllowed())\r
+               /* Check to see if a packet has been sent from the host */\r
+               if (Endpoint_IsOUTReceived())\r
                {\r
-                       /* Create a temporary buffer to hold the read in report from the host */\r
-                       uint8_t GenericData[GENERIC_REPORT_SIZE];\r
-                       \r
-                       /* Read Generic Report Data */\r
-                       Endpoint_Read_Stream_LE(&GenericData, sizeof(GenericData));\r
-                       \r
-                       /* Process Generic Report Data */\r
-                       ProcessGenericHIDReport(GenericData);\r
+                       /* Check to see if the packet contains data */\r
+                       if (Endpoint_IsReadWriteAllowed())\r
+                       {\r
+                               /* Create a temporary buffer to hold the read in report from the host */\r
+                               uint8_t GenericData[GENERIC_REPORT_SIZE];\r
+                               \r
+                               /* Read Generic Report Data */\r
+                               Endpoint_Read_Stream_LE(&GenericData, sizeof(GenericData));\r
+                               \r
+                               /* Process Generic Report Data */\r
+                               ProcessGenericHIDReport(GenericData);\r
+                       }\r
 \r
                        /* Finalize the stream transfer to send the last packet */\r
-                       Endpoint_ClearCurrentBank();\r
+                       Endpoint_ClearOUT();\r
                }       \r
 \r
                Endpoint_SelectEndpoint(GENERIC_IN_EPNUM);\r
                \r
-               if (Endpoint_ReadWriteAllowed())\r
+               /* Check to see if the host is ready to accept another packet */\r
+               if (Endpoint_IsINReady())\r
                {\r
                        /* Create a temporary buffer to hold the report to send to the host */\r
                        uint8_t GenericData[GENERIC_REPORT_SIZE];\r
@@ -309,7 +309,7 @@ TASK(USB_HID_Report)
                        Endpoint_Write_Stream_LE(&GenericData, sizeof(GenericData));\r
 \r
                        /* Finalize the stream transfer to send the last packet */\r
-                       Endpoint_ClearCurrentBank();\r
+                       Endpoint_ClearIN();\r
                }\r
        }\r
 }\r
@@ -363,7 +363,7 @@ ISR(ENDPOINT_PIPE_vect, ISR_BLOCK)
                Endpoint_Write_Stream_LE(&GenericData, sizeof(GenericData));\r
 \r
                /* Finalize the stream transfer to send the last packet */\r
-               Endpoint_ClearCurrentBank();\r
+               Endpoint_ClearIN();\r
        }\r
 \r
        /* Check if Generic OUT endpoint has interrupted */\r
@@ -388,7 +388,7 @@ ISR(ENDPOINT_PIPE_vect, ISR_BLOCK)
                ProcessGenericHIDReport(GenericData);\r
 \r
                /* Finalize the stream transfer to send the last packet */\r
-               Endpoint_ClearCurrentBank();\r
+               Endpoint_ClearOUT();\r
        }\r
        #endif\r
 \r