Fixed inability to enumerate any devices while in host mode (broken in a previous...
[pub/USBasp.git] / Demos / Device / KeyboardMouse / KeyboardMouse.c
index 3ee101b..5c93328 100644 (file)
  \r
 #include "KeyboardMouse.h"\r
 \r
-/* Project Tags, for reading out using the ButtLoad project */\r
-BUTTLOADTAG(ProjName,    "LUFA MouseKBD 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
-       { Task: USB_USBTask               , TaskStatus: TASK_STOP },\r
-       { Task: USB_Mouse                 , TaskStatus: TASK_RUN },\r
-       { Task: USB_Keyboard              , TaskStatus: TASK_RUN },\r
+       { .Task = USB_USBTask               , .TaskStatus = TASK_STOP },\r
+       { .Task = USB_Mouse                 , .TaskStatus = TASK_RUN  },\r
+       { .Task = USB_Keyboard              , .TaskStatus = TASK_RUN  },\r
 };\r
 \r
 /* Global Variables */\r
@@ -145,17 +139,15 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
        uint8_t  ReportSize;\r
 \r
        /* Handle HID Class specific requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\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
-                               Endpoint_Ignore_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
-                               if (!(wIndex))\r
+                               if (!(USB_ControlRequest.wIndex))\r
                                {\r
                                        ReportData = (uint8_t*)&KeyboardReportData;\r
                                        ReportSize = sizeof(KeyboardReportData);\r
@@ -166,33 +158,24 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                        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_ClearSetupReceived();\r
-       \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
                                /* Finalize the stream transfer to send the last packet or clear the host abort */\r
-                               Endpoint_ClearSetupOUT();\r
+                               Endpoint_ClearOUT();\r
                        }\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_ClearSetupReceived();\r
+                               Endpoint_ClearSETUP();\r
                                \r
                                /* Wait until the LED report has been sent by the host */\r
-                               while (!(Endpoint_IsSetupOUTReceived()));\r
+                               while (!(Endpoint_IsOUTReceived()));\r
 \r
                                /* Read in the LED report from the host */\r
                                uint8_t LEDStatus = Endpoint_Read_Byte();\r
@@ -211,11 +194,11 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                LEDs_SetAllLEDs(LEDMask);\r
 \r
                                /* Clear the endpoint data */\r
-                               Endpoint_ClearSetupOUT();\r
+                               Endpoint_ClearOUT();\r
 \r
                                /* Acknowledge status stage */\r
-                               while (!(Endpoint_IsSetupINReady()));\r
-                               Endpoint_ClearSetupIN();\r
+                               while (!(Endpoint_IsINReady()));\r
+                               Endpoint_ClearIN();\r
                        }\r
                        \r
                        break;\r
@@ -257,8 +240,8 @@ TASK(USB_Keyboard)
 {\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
@@ -281,13 +264,13 @@ TASK(USB_Keyboard)
                Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM);\r
 \r
                /* Check if Keyboard Endpoint Ready for Read/Write */\r
-               if (Endpoint_ReadWriteAllowed())\r
+               if (Endpoint_IsReadWriteAllowed())\r
                {\r
                        /* Write Keyboard Report Data */\r
                        Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));\r
 \r
                        /* Finalize the stream transfer to send the last packet */\r
-                       Endpoint_ClearCurrentBank();\r
+                       Endpoint_ClearIN();\r
 \r
                        /* Clear the report data afterwards */\r
                        memset(&KeyboardReportData, 0, sizeof(KeyboardReportData));\r
@@ -297,7 +280,7 @@ TASK(USB_Keyboard)
                Endpoint_SelectEndpoint(KEYBOARD_OUT_EPNUM);\r
 \r
                /* Check if Keyboard LED Endpoint Ready for Read/Write */\r
-               if (Endpoint_ReadWriteAllowed())\r
+               if (Endpoint_IsReadWriteAllowed())\r
                {               \r
                        /* Read in the LED report from the host */\r
                        uint8_t LEDStatus = Endpoint_Read_Byte();\r
@@ -316,7 +299,7 @@ TASK(USB_Keyboard)
                        LEDs_SetAllLEDs(LEDMask);\r
 \r
                        /* Handshake the OUT Endpoint - clear endpoint and ready for next report */\r
-                       Endpoint_ClearCurrentBank();\r
+                       Endpoint_ClearOUT();\r
                }\r
        }\r
 }\r
@@ -328,8 +311,8 @@ TASK(USB_Mouse)
 {\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
@@ -352,13 +335,13 @@ TASK(USB_Mouse)
                Endpoint_SelectEndpoint(MOUSE_IN_EPNUM);\r
 \r
                /* Check if Mouse Endpoint Ready for Read/Write */\r
-               if (Endpoint_ReadWriteAllowed())\r
+               if (Endpoint_IsReadWriteAllowed())\r
                {\r
                        /* Write Mouse Report Data */\r
                        Endpoint_Write_Stream_LE(&MouseReportData, sizeof(MouseReportData));\r
 \r
                        /* Finalize the stream transfer to send the last packet */\r
-                       Endpoint_ClearCurrentBank();\r
+                       Endpoint_ClearIN();\r
 \r
                        /* Clear the report data afterwards */\r
                        memset(&MouseReportData, 0, sizeof(MouseReportData));\r