X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/d0806c817cbf0c1b5c5362d1577eac6075c94dfc..da138684e428a40f7f5a0c32617e5c62c9e3a664:/LUFA/Drivers/USB/LowLevel/DevChapter9.c diff --git a/LUFA/Drivers/USB/LowLevel/DevChapter9.c b/LUFA/Drivers/USB/LowLevel/DevChapter9.c index 9bba23495..f49f5b39b 100644 --- a/LUFA/Drivers/USB/LowLevel/DevChapter9.c +++ b/LUFA/Drivers/USB/LowLevel/DevChapter9.c @@ -179,57 +179,74 @@ static void USB_Device_GetDescriptor(void) void* DescriptorPointer; uint16_t DescriptorSize; - if ((DescriptorSize = CALLBACK_USB_GetDescriptor(USB_ControlRequest.wValue, - USB_ControlRequest.wIndex, &DescriptorPointer)) == NO_DESCRIPTOR) + #if !defined(NO_INTERNAL_SERIAL) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) + if (USB_ControlRequest.wValue == ((DTYPE_String << 8) | USE_INTERNAL_SERIAL)) { - return; - } - - Endpoint_ClearSETUP(); - - #if defined(USE_RAM_DESCRIPTORS) - Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize); - #else - bool SendZLP; - - if (USB_ControlRequest.wLength > DescriptorSize) - USB_ControlRequest.wLength = DescriptorSize; - - while (USB_ControlRequest.wLength) - { - while (!(Endpoint_IsINReady())) + struct { - if (Endpoint_IsOUTReceived()) - { - Endpoint_ClearOUT(); - return; - } - } + USB_Descriptor_Header_t Header; + int16_t UnicodeString[12]; + } SignatureDescriptor; + + #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) + SignatureDescriptor.Header.Size = sizeof(SignatureDescriptor); + SignatureDescriptor.Header.Type = DTYPE_String; + #else + SignatureDescriptor.Header.bLength = sizeof(SignatureDescriptor); + SignatureDescriptor.Header.bDescriptorType = DTYPE_String; + #endif - while (USB_ControlRequest.wLength && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize)) + uint8_t SigReadAddress = 0x0E; + bool OddRead = false; + + for (uint8_t SerialCharNum = 0; SerialCharNum < 12; SerialCharNum++) { - #if defined (USE_EEPROM_DESCRIPTORS) - Endpoint_Write_Byte(eeprom_read_byte(DescriptorPointer++)); - #else - Endpoint_Write_Byte(pgm_read_byte(DescriptorPointer++)); - #endif + uint8_t SerialByte = boot_signature_byte_get(SigReadAddress); - USB_ControlRequest.wLength--; + if (OddRead) + { + SerialByte >>= 4; + SigReadAddress++; + } + else + { + SerialByte &= 0x0F; + } + + OddRead = !(OddRead); + + if (SerialByte < 0x0A) + SerialByte += '0'; + else + SerialByte += ('A' - 0x0A); + + SignatureDescriptor.UnicodeString[SerialCharNum] = SerialByte; } - SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); - Endpoint_ClearIN(); + Endpoint_ClearSETUP(); + Endpoint_Write_Control_Stream_LE(&SignatureDescriptor, sizeof(SignatureDescriptor)); + Endpoint_ClearOUT(); + + return; } + #endif - if (SendZLP) + if ((DescriptorSize = CALLBACK_USB_GetDescriptor(USB_ControlRequest.wValue, USB_ControlRequest.wIndex, + &DescriptorPointer)) == NO_DESCRIPTOR) { - while (!(Endpoint_IsINReady())); - Endpoint_ClearIN(); + return; } + + Endpoint_ClearSETUP(); - while (!(Endpoint_IsOUTReceived())); + #if defined(USE_RAM_DESCRIPTORS) + Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize); + #elif defined(USE_EEPROM_DESCRIPTORS) + Endpoint_Write_Control_EStream_LE(DescriptorPointer, DescriptorSize); + #else + Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize); #endif - + Endpoint_ClearOUT(); }