Fix build error in TestApp demo caused by previous commit.
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / DevChapter9.c
index deaa9c0..7fecd1f 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
@@ -132,8 +141,8 @@ static void USB_Device_SetConfiguration(void)
 {\r
        bool AlreadyConfigured = (USB_ConfigurationNumber != 0);\r
 \r
-#if defined(TOTAL_NUM_CONFIGURATIONS)\r
-       if ((uint8_t)USB_ControlRequest.wValue > TOTAL_NUM_CONFIGURATIONS)\r
+#if defined(FIXED_NUM_CONFIGURATIONS)\r
+       if ((uint8_t)USB_ControlRequest.wValue > FIXED_NUM_CONFIGURATIONS)\r
          return;\r
 #else\r
        #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS)\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
@@ -208,10 +232,10 @@ static void USB_Device_GetInternalSerialDescriptor(void)
        struct\r
        {\r
                USB_Descriptor_Header_t Header;\r
-               int16_t                 UnicodeString[12];\r
+               int16_t                 UnicodeString[20];\r
        } SignatureDescriptor;\r
        \r
-       uint8_t SigReadAddress  = 0x0E;         \r
+       uint8_t SigReadAddress  = 0x0E;\r
        bool    OddNibbleRead   = false;\r
 \r
        #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES)\r
@@ -222,7 +246,7 @@ static void USB_Device_GetInternalSerialDescriptor(void)
                SignatureDescriptor.Header.bDescriptorType = DTYPE_String;\r
        #endif\r
 \r
-       for (uint8_t SerialCharNum = 0; SerialCharNum < 12; SerialCharNum++)\r
+       for (uint8_t SerialCharNum = 0; SerialCharNum < 20; SerialCharNum++)\r
        {\r
                uint8_t SerialByte = boot_signature_byte_get(SigReadAddress);\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