Fixed inability to enumerate any devices while in host mode (broken in a previous...
[pub/USBasp.git] / Demos / Device / KeyboardMouse / KeyboardMouse.c
index 9cae69a..5c93328 100644 (file)
@@ -139,17 +139,15 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
        uint8_t  ReportSize;\r
 \r
        /* Handle HID Class specific requests */\r
        uint8_t  ReportSize;\r
 \r
        /* Handle HID Class specific requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_GetReport:\r
        {\r
                case REQ_GetReport:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                        {\r
-                               Endpoint_Discard_Word();\r
-                       \r
-                               uint16_t wIndex = Endpoint_Read_Word_LE();\r
-                               \r
+                               Endpoint_ClearSETUP();\r
+       \r
                                /* Determine if it is the mouse or the keyboard data that is being requested */\r
                                /* Determine if it is the mouse or the keyboard data that is being requested */\r
-                               if (!(wIndex))\r
+                               if (!(USB_ControlRequest.wIndex))\r
                                {\r
                                        ReportData = (uint8_t*)&KeyboardReportData;\r
                                        ReportSize = sizeof(KeyboardReportData);\r
                                {\r
                                        ReportData = (uint8_t*)&KeyboardReportData;\r
                                        ReportSize = sizeof(KeyboardReportData);\r
@@ -160,17 +158,8 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                        ReportSize = sizeof(MouseReportData);\r
                                }\r
 \r
                                        ReportSize = sizeof(MouseReportData);\r
                                }\r
 \r
-                               /* Read in the number of bytes in the report to send to the host */\r
-                               uint16_t wLength = Endpoint_Read_Word_LE();\r
-                               \r
-                               /* If trying to send more bytes than exist to the host, clamp the value at the report size */\r
-                               if (wLength > ReportSize)\r
-                                 wLength = ReportSize;\r
-\r
-                               Endpoint_ClearSETUP();\r
-       \r
                                /* Write the report data to the control endpoint */\r
                                /* Write the report data to the control endpoint */\r
-                               Endpoint_Write_Control_Stream_LE(ReportData, wLength);\r
+                               Endpoint_Write_Control_Stream_LE(ReportData, ReportSize);\r
 \r
                                /* Clear the report data afterwards */\r
                                memset(ReportData, 0, ReportSize);\r
 \r
                                /* Clear the report data afterwards */\r
                                memset(ReportData, 0, ReportSize);\r
@@ -181,7 +170,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                \r
                        break;\r
                case REQ_SetReport:\r
                \r
                        break;\r
                case REQ_SetReport:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                Endpoint_ClearSETUP();\r
                                \r
                        {\r
                                Endpoint_ClearSETUP();\r
                                \r
@@ -251,8 +240,8 @@ TASK(USB_Keyboard)
 {\r
        uint8_t JoyStatus_LCL = Joystick_GetStatus();\r
 \r
 {\r
        uint8_t JoyStatus_LCL = Joystick_GetStatus();\r
 \r
-       /* Check if HWB is not pressed, if so mouse mode enabled */\r
-       if (!(HWB_GetStatus()))\r
+       /* Check if board button is not pressed, if so mouse mode enabled */\r
+       if (!(Buttons_GetStatus() & BUTTONS_BUTTON1))\r
        {\r
                if (JoyStatus_LCL & JOY_UP)\r
                  KeyboardReportData.KeyCode[0] = 0x04; // A\r
        {\r
                if (JoyStatus_LCL & JOY_UP)\r
                  KeyboardReportData.KeyCode[0] = 0x04; // A\r
@@ -322,8 +311,8 @@ TASK(USB_Mouse)
 {\r
        uint8_t JoyStatus_LCL = Joystick_GetStatus();\r
 \r
 {\r
        uint8_t JoyStatus_LCL = Joystick_GetStatus();\r
 \r
-       /* Check if HWB is pressed, if so mouse mode enabled */\r
-       if (HWB_GetStatus())\r
+       /* Check if board button is pressed, if so mouse mode enabled */\r
+       if (Buttons_GetStatus() & BUTTONS_BUTTON1)\r
        {\r
                if (JoyStatus_LCL & JOY_UP)\r
                  MouseReportData.Y =  1;\r
        {\r
                if (JoyStatus_LCL & JOY_UP)\r
                  MouseReportData.Y =  1;\r