Add Benito board LED driver to the Benito Programmer project.
[pub/USBasp.git] / Demos / Host / ClassDriver / MouseHost / MouseHost.c
index 88518a8..76a1238 100644 (file)
@@ -50,11 +50,6 @@ USB_ClassInfo_HID_Host_t Mouse_HID_Interface =
                                .MatchInterfaceProtocol = true,\r
                                .HIDInterfaceProtocol   = 0x02,\r
                        },\r
                                .MatchInterfaceProtocol = true,\r
                                .HIDInterfaceProtocol   = 0x02,\r
                        },\r
-                       \r
-               .State =\r
-                       {\r
-                               // Leave all state values to their defaults                     \r
-                       }\r
        };\r
 \r
        \r
        };\r
 \r
        \r
@@ -76,10 +71,23 @@ int main(void)
                        case HOST_STATE_Addressed:\r
                                LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
                        \r
                        case HOST_STATE_Addressed:\r
                                LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
                        \r
-                               if (HID_Host_ConfigurePipes(&Mouse_HID_Interface, 512) != HID_ENUMERROR_NoError)\r
+                               uint16_t ConfigDescriptorSize;\r
+                               uint8_t  ConfigDescriptorData[512];\r
+\r
+                               if ((USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) ||\r
+                                   (ConfigDescriptorSize > sizeof(ConfigDescriptorData)) ||\r
+                                       (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData)))\r
+                               {\r
+                                       printf("Error Retrieving Configuration Descriptor.\r\n");\r
+                                       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+                                       USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
+                                       break;\r
+                               }\r
+\r
+                               if (HID_Host_ConfigurePipes(&Mouse_HID_Interface,\r
+                                                           ConfigDescriptorSize, ConfigDescriptorData) != HID_ENUMERROR_NoError)\r
                                {\r
                                {\r
-                                       printf("Attached device is not a valid Mouse.\r\n");\r
-                                       \r
+                                       printf("Attached Device Not a Valid Mouse.\r\n");\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
@@ -88,7 +96,6 @@ int main(void)
                                if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful)\r
                                {\r
                                        printf("Error Setting Device Configuration.\r\n");\r
                                if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful)\r
                                {\r
                                        printf("Error Setting Device Configuration.\r\n");\r
-\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
@@ -125,7 +132,7 @@ void SetupHardware(void)
 /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and\r
  *  starts the library USB task to begin the enumeration and USB management process.\r
  */\r
 /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and\r
  *  starts the library USB task to begin the enumeration and USB management process.\r
  */\r
-void EVENT_USB_DeviceAttached(void)\r
+void EVENT_USB_Host_DeviceAttached(void)\r
 {\r
        puts_P(PSTR("Device Attached.\r\n"));\r
        LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
 {\r
        puts_P(PSTR("Device Attached.\r\n"));\r
        LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
@@ -134,7 +141,7 @@ void EVENT_USB_DeviceAttached(void)
 /** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and\r
  *  stops the library USB task management process.\r
  */\r
 /** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and\r
  *  stops the library USB task management process.\r
  */\r
-void EVENT_USB_DeviceUnattached(void)\r
+void EVENT_USB_Host_DeviceUnattached(void)\r
 {\r
        puts_P(PSTR("\r\nDevice Unattached.\r\n"));\r
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
 {\r
        puts_P(PSTR("\r\nDevice Unattached.\r\n"));\r
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
@@ -143,13 +150,13 @@ void EVENT_USB_DeviceUnattached(void)
 /** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully\r
  *  enumerated by the host and is now ready to be used by the application.\r
  */\r
 /** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully\r
  *  enumerated by the host and is now ready to be used by the application.\r
  */\r
-void EVENT_USB_DeviceEnumerationComplete(void)\r
+void EVENT_USB_Host_DeviceEnumerationComplete(void)\r
 {\r
        LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
 }\r
 \r
 /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */\r
 {\r
        LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
 }\r
 \r
 /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */\r
-void EVENT_USB_HostError(const uint8_t ErrorCode)\r
+void EVENT_USB_Host_HostError(const uint8_t ErrorCode)\r
 {\r
        USB_ShutDown();\r
 \r
 {\r
        USB_ShutDown();\r
 \r
@@ -163,7 +170,7 @@ void EVENT_USB_HostError(const uint8_t ErrorCode)
 /** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while\r
  *  enumerating an attached USB device.\r
  */\r
 /** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while\r
  *  enumerating an attached USB device.\r
  */\r
-void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)\r
+void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)\r
 {\r
        puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"));\r
        printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
 {\r
        puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"));\r
        printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r