Fix up the incomplete Webserver project so that it integrates with the uIP stack...
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / HID.c
index b44d4db..a5c03f7 100644 (file)
@@ -1,21 +1,21 @@
 /*\r
              LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
+     Copyright (C) Dean Camera, 2010.\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  copies and that both that the copyright notice and this\r
-  permission notice and warranty disclaimer appear in supporting\r
-  documentation, and that the name of the author not be used in\r
-  advertising or publicity pertaining to distribution of the\r
+  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+  Permission to use, copy, modify, distribute, and sell this \r
+  software and its documentation for any purpose is hereby granted\r
+  without fee, provided that the above copyright notice appear in \r
+  all copies and that both that the copyright notice and this\r
+  permission notice and warranty disclaimer appear in supporting \r
+  documentation, and that the name of the author not be used in \r
+  advertising or publicity pertaining to distribution of the \r
   software without specific, written prior permission.\r
 \r
   The author disclaim all warranties with regard to this\r
@@ -48,14 +48,16 @@ void HID_Device_ProcessControlRequest(USB_ClassInfo_HID_Device_t* const HIDInter
                        {\r
                                Endpoint_ClearSETUP();  \r
 \r
-                               uint16_t ReportINSize;\r
-                               uint8_t  ReportID = (USB_ControlRequest.wValue & 0xFF);\r
+                               uint16_t ReportINSize = 0;\r
+                               uint8_t  ReportID     = (USB_ControlRequest.wValue & 0xFF);\r
+                               uint8_t  ReportType   = (USB_ControlRequest.wValue >> 8) - 1;\r
 \r
                                memset(HIDInterfaceInfo->Config.PrevReportINBuffer, 0, HIDInterfaceInfo->Config.PrevReportINBufferSize);\r
                                \r
-                               CALLBACK_HID_Device_CreateHIDReport(HIDInterfaceInfo, &ReportID,\r
+                               CALLBACK_HID_Device_CreateHIDReport(HIDInterfaceInfo, &ReportID, ReportType,\r
                                                                    HIDInterfaceInfo->Config.PrevReportINBuffer, &ReportINSize);\r
 \r
+                               Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);\r
                                Endpoint_Write_Control_Stream_LE(HIDInterfaceInfo->Config.PrevReportINBuffer, ReportINSize);\r
                                Endpoint_ClearOUT();\r
                        }\r
@@ -94,7 +96,7 @@ void HID_Device_ProcessControlRequest(USB_ClassInfo_HID_Device_t* const HIDInter
                        {\r
                                Endpoint_ClearSETUP();\r
 \r
-                               HIDInterfaceInfo->State.UsingReportProtocol = (USB_ControlRequest.wValue != 0x0000);\r
+                               HIDInterfaceInfo->State.UsingReportProtocol = ((USB_ControlRequest.wValue & 0xFF) != 0x00);\r
                                \r
                                Endpoint_ClearStatusStage();\r
                        }\r
@@ -133,7 +135,8 @@ bool HID_Device_ConfigureEndpoints(USB_ClassInfo_HID_Device_t* const HIDInterfac
        HIDInterfaceInfo->State.IdleCount = 500;\r
 \r
        if (!(Endpoint_ConfigureEndpoint(HIDInterfaceInfo->Config.ReportINEndpointNumber, EP_TYPE_INTERRUPT,\r
-                                                                        ENDPOINT_DIR_IN, HIDInterfaceInfo->Config.ReportINEndpointSize, ENDPOINT_BANK_SINGLE)))\r
+                                                                        ENDPOINT_DIR_IN, HIDInterfaceInfo->Config.ReportINEndpointSize,\r
+                                                                        HIDInterfaceInfo->Config.ReportINEndpointDoubleBank ? ENDPOINT_BANK_DOUBLE : ENDPOINT_BANK_SINGLE)))\r
        {\r
                return false;\r
        }\r
@@ -151,22 +154,28 @@ void HID_Device_USBTask(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo)
        if (Endpoint_IsReadWriteAllowed())\r
        {\r
                uint8_t  ReportINData[HIDInterfaceInfo->Config.PrevReportINBufferSize];\r
-               uint8_t  ReportID = 0;\r
-               uint16_t ReportINSize;\r
+               uint8_t  ReportID     = 0;\r
+               uint16_t ReportINSize = 0;\r
 \r
                memset(ReportINData, 0, sizeof(ReportINData));\r
 \r
-               bool ForceSend = CALLBACK_HID_Device_CreateHIDReport(HIDInterfaceInfo, &ReportID, ReportINData, &ReportINSize);\r
-\r
-               bool StatesChanged     = (memcmp(ReportINData, HIDInterfaceInfo->Config.PrevReportINBuffer, ReportINSize) != 0);\r
+               bool ForceSend         = CALLBACK_HID_Device_CreateHIDReport(HIDInterfaceInfo, &ReportID, REPORT_ITEM_TYPE_In,\r
+                                                                            ReportINData, &ReportINSize);\r
+               bool StatesChanged     = false;\r
                bool IdlePeriodElapsed = (HIDInterfaceInfo->State.IdleCount && !(HIDInterfaceInfo->State.IdleMSRemaining));\r
                \r
-               memcpy(HIDInterfaceInfo->Config.PrevReportINBuffer, ReportINData, ReportINSize);\r
+               if (HIDInterfaceInfo->Config.PrevReportINBuffer != NULL)\r
+               {\r
+                       StatesChanged = (memcmp(ReportINData, HIDInterfaceInfo->Config.PrevReportINBuffer, ReportINSize) != 0);\r
+                       memcpy(HIDInterfaceInfo->Config.PrevReportINBuffer, ReportINData, ReportINSize);\r
+               }\r
 \r
                if (ReportINSize && (ForceSend || StatesChanged || IdlePeriodElapsed))\r
                {\r
                        HIDInterfaceInfo->State.IdleMSRemaining = HIDInterfaceInfo->State.IdleCount;\r
 \r
+                       Endpoint_SelectEndpoint(HIDInterfaceInfo->Config.ReportINEndpointNumber);\r
+\r
                        if (ReportID)\r
                          Endpoint_Write_Byte(ReportID);\r
 \r
@@ -177,10 +186,4 @@ void HID_Device_USBTask(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo)
        }\r
 }\r
 \r
-void HID_Device_MillisecondElapsed(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo)\r
-{\r
-       if (HIDInterfaceInfo->State.IdleMSRemaining)\r
-         HIDInterfaceInfo->State.IdleMSRemaining--;\r
-}\r
-\r
 #endif\r