Fix HID class device driver -- if a SetIDle request is issued with the LSB of wValue...
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / DevChapter9.c
index f49f5b3..2318216 100644 (file)
@@ -174,59 +174,65 @@ void USB_Device_GetConfiguration(void)
        Endpoint_ClearOUT();\r
 }\r
 \r
-static void USB_Device_GetDescriptor(void)\r
+#if !defined(NO_INTERNAL_SERIAL) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))\r
+static void USB_Device_GetInternalSerialDescriptor(void)\r
 {\r
-       void*    DescriptorPointer;\r
-       uint16_t DescriptorSize;\r
+       struct\r
+       {\r
+               USB_Descriptor_Header_t Header;\r
+               int16_t                 UnicodeString[12];\r
+       } SignatureDescriptor;\r
        \r
-       #if !defined(NO_INTERNAL_SERIAL) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))\r
-       if (USB_ControlRequest.wValue == ((DTYPE_String << 8) | USE_INTERNAL_SERIAL))\r
+       uint8_t SigReadAddress  = 0x0E;         \r
+       bool    OddNibbleRead   = false;\r
+\r
+       #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES)\r
+               SignatureDescriptor.Header.Size            = sizeof(SignatureDescriptor);\r
+               SignatureDescriptor.Header.Type            = DTYPE_String;\r
+       #else\r
+               SignatureDescriptor.Header.bLength         = sizeof(SignatureDescriptor);\r
+               SignatureDescriptor.Header.bDescriptorType = DTYPE_String;\r
+       #endif\r
+\r
+       for (uint8_t SerialCharNum = 0; SerialCharNum < 12; SerialCharNum++)\r
        {\r
-               struct\r
-               {\r
-                       USB_Descriptor_Header_t Header;\r
-                       int16_t                 UnicodeString[12];\r
-               } SignatureDescriptor;\r
-\r
-               #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES)\r
-                       SignatureDescriptor.Header.Size            = sizeof(SignatureDescriptor);\r
-                       SignatureDescriptor.Header.Type            = DTYPE_String;\r
-               #else\r
-                       SignatureDescriptor.Header.bLength         = sizeof(SignatureDescriptor);\r
-                       SignatureDescriptor.Header.bDescriptorType = DTYPE_String;\r
-               #endif\r
+               uint8_t SerialByte = boot_signature_byte_get(SigReadAddress);\r
                \r
-               uint8_t  SigReadAddress  = 0x0E;                \r
-               bool     OddRead         = false;\r
-\r
-               for (uint8_t SerialCharNum = 0; SerialCharNum < 12; SerialCharNum++)\r
+               if (OddNibbleRead)\r
                {\r
-                       uint8_t SerialByte = boot_signature_byte_get(SigReadAddress);\r
-                       \r
-                       if (OddRead)\r
-                       {\r
-                               SerialByte >>= 4;\r
-                               SigReadAddress++;\r
-                       }\r
-                       else\r
-                       {\r
-                               SerialByte &= 0x0F;\r
-                       }\r
-                       \r
-                       OddRead = !(OddRead);\r
-\r
-                       if (SerialByte < 0x0A)\r
-                         SerialByte += '0';\r
-                       else\r
-                         SerialByte += ('A' - 0x0A);\r
-\r
-                       SignatureDescriptor.UnicodeString[SerialCharNum] = SerialByte;\r
+                       SerialByte >>= 4;\r
+                       SigReadAddress++;\r
+               }\r
+               else\r
+               {\r
+                       SerialByte &= 0x0F;\r
                }\r
                \r
-               Endpoint_ClearSETUP();\r
-               Endpoint_Write_Control_Stream_LE(&SignatureDescriptor, sizeof(SignatureDescriptor));\r
-               Endpoint_ClearOUT();\r
+               OddNibbleRead = !(OddNibbleRead);\r
+\r
+               if (SerialByte < 0x0A)\r
+                 SerialByte += '0';\r
+               else\r
+                 SerialByte += ('A' - 0x0A);\r
+\r
+               SignatureDescriptor.UnicodeString[SerialCharNum] = SerialByte;\r
+       }\r
+       \r
+       Endpoint_ClearSETUP();\r
+       Endpoint_Write_Control_Stream_LE(&SignatureDescriptor, sizeof(SignatureDescriptor));\r
+       Endpoint_ClearOUT();\r
+}\r
+#endif\r
 \r
+static void USB_Device_GetDescriptor(void)\r
+{\r
+       void*    DescriptorPointer;\r
+       uint16_t DescriptorSize;\r
+       \r
+       #if !defined(NO_INTERNAL_SERIAL) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))\r
+       if (USB_ControlRequest.wValue == ((DTYPE_String << 8) | USE_INTERNAL_SERIAL))\r
+       {\r
+               USB_Device_GetInternalSerialDescriptor();\r
                return;\r
        }\r
        #endif\r