Change Host mode class driver Pipe configuration routines -- better to let the applic...
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / DevChapter9.c
index deaa9c0..8de4bd6 100644 (file)
@@ -117,13 +117,22 @@ void USB_Device_ProcessControlPacket(void)
 \r
 static void USB_Device_SetAddress(void)\r
 {\r
+       uint8_t DeviceAddress = (USB_ControlRequest.wValue & 0x7F);\r
+\r
        Endpoint_ClearSETUP();\r
        \r
        Endpoint_ClearIN();\r
        \r
-       while (!(Endpoint_IsINReady()));\r
+       while (!(Endpoint_IsINReady()))\r
+       {\r
+               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+                 return;\r
+       }\r
+\r
+       UDADDR = ((1 << ADDEN) | DeviceAddress);\r
 \r
-       UDADDR = ((1 << ADDEN) | ((uint8_t)USB_ControlRequest.wValue & 0x7F));\r
+       if (DeviceAddress)\r
+         USB_DeviceState = DEVICE_STATE_Addressed;\r
 \r
        return;\r
 }\r
@@ -144,8 +153,9 @@ static void USB_Device_SetConfiguration(void)
 \r
        if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DevDescriptorPtr\r
        #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS)\r
-                                      , &MemoryAddressSpace) == NO_DESCRIPTOR)\r
+                                      , &MemoryAddressSpace\r
        #endif\r
+                                      ) == NO_DESCRIPTOR)\r
        {\r
                return;\r
        }\r
@@ -184,8 +194,17 @@ static void USB_Device_SetConfiguration(void)
 \r
        Endpoint_ClearIN();\r
 \r
-       if (!(AlreadyConfigured) && USB_ConfigurationNumber)\r
-         EVENT_USB_DeviceEnumerationComplete();\r
+       if (USB_ConfigurationNumber)\r
+       {\r
+               USB_DeviceState = DEVICE_STATE_Configured;\r
+\r
+               if (!(AlreadyConfigured))\r
+                 EVENT_USB_DeviceEnumerationComplete();\r
+       }\r
+       else\r
+       {\r
+               USB_DeviceState = DEVICE_STATE_Addressed;\r
+       }\r
 \r
        EVENT_USB_ConfigurationChanged();\r
 }\r
@@ -198,7 +217,12 @@ void USB_Device_GetConfiguration(void)
        \r
        Endpoint_ClearIN();\r
 \r
-       while (!(Endpoint_IsOUTReceived()));\r
+       while (!(Endpoint_IsOUTReceived()))\r
+       {\r
+               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+                 return;       \r
+       }\r
+\r
        Endpoint_ClearOUT();\r
 }\r
 \r
@@ -331,7 +355,12 @@ static void USB_Device_GetStatus(void)
 \r
        Endpoint_ClearIN();\r
        \r
-       while (!(Endpoint_IsOUTReceived()));\r
+       while (!(Endpoint_IsOUTReceived()))\r
+       {\r
+               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+                 return;       \r
+       }\r
+       \r
        Endpoint_ClearOUT();\r
 }\r
 \r