Added USE_INTERNAL_SERIAL compile time option to automatically read out the internal...
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / DevChapter9.c
index 829bd13..9acf300 100644 (file)
@@ -179,6 +179,36 @@ static void USB_Device_GetDescriptor(void)
        void*    DescriptorPointer;\r
        uint16_t DescriptorSize;\r
        \r
+       #if defined(USE_INTERNAL_SERIAL)\r
+       if (USB_ControlRequest.wValue == ((DTYPE_String << 8) | USE_INTERNAL_SERIAL))\r
+       {\r
+               uint8_t SignatureDescriptor[2 + (sizeof(int16_t) * 20)];\r
+\r
+               SignatureDescriptor[0] = sizeof(SignatureDescriptor);\r
+               SignatureDescriptor[1] = DTYPE_String;\r
+               \r
+               uint16_t* SigUnicodeChars = (uint16_t*)&SignatureDescriptor[2];\r
+\r
+               for (uint8_t SerialByteNum = 0; SerialByteNum < 10; SerialByteNum++)\r
+               {\r
+                       char ConvSigString[3];\r
+\r
+                       itoa(boot_signature_byte_get(0x0E + SerialByteNum), ConvSigString, 16);\r
+                       \r
+                       SigUnicodeChars[0] = toupper(ConvSigString[0]);\r
+                       SigUnicodeChars[1] = toupper(ConvSigString[1]);\r
+                       \r
+                       SigUnicodeChars += 2;\r
+               }\r
+               \r
+               Endpoint_ClearSETUP();\r
+               Endpoint_Write_Control_Stream_LE(SignatureDescriptor, sizeof(SignatureDescriptor));\r
+               Endpoint_ClearOUT();\r
+\r
+               return;\r
+       }\r
+       #endif\r
+       \r
        if ((DescriptorSize = CALLBACK_USB_GetDescriptor(USB_ControlRequest.wValue, USB_ControlRequest.wIndex,\r
                                                         &DescriptorPointer)) == NO_DESCRIPTOR)\r
        {\r
@@ -186,7 +216,7 @@ static void USB_Device_GetDescriptor(void)
        }\r
        \r
        Endpoint_ClearSETUP();\r
-       \r
+\r
        #if defined(USE_RAM_DESCRIPTORS)\r
        Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize);\r
        #else\r