X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/a908773a13ee491f2f8907cdf57c26fb39e10658..b462f2d457ec2f0cfa22a1c3db198cb22f6809a1:/LUFA/Drivers/USB/LowLevel/DevChapter9.c?ds=sidebyside diff --git a/LUFA/Drivers/USB/LowLevel/DevChapter9.c b/LUFA/Drivers/USB/LowLevel/DevChapter9.c index 9c319fc07..feaabce46 100644 --- a/LUFA/Drivers/USB/LowLevel/DevChapter9.c +++ b/LUFA/Drivers/USB/LowLevel/DevChapter9.c @@ -62,7 +62,8 @@ void USB_Device_ProcessControlPacket(void) break; case REQ_ClearFeature: case REQ_SetFeature: - if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT)) + if ((bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE)) || + (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT))) { USB_Device_ClearSetFeature(); RequestHandled = true; @@ -105,7 +106,7 @@ void USB_Device_ProcessControlPacket(void) } if (!(RequestHandled)) - RAISE_EVENT(USB_UnhandledControlPacket); + EVENT_USB_UnhandledControlPacket(); if (Endpoint_IsSETUPReceived()) { @@ -118,8 +119,6 @@ static void USB_Device_SetAddress(void) { Endpoint_ClearSETUP(); - while (!(Endpoint_IsINReady())); - Endpoint_ClearIN(); while (!(Endpoint_IsINReady())); @@ -138,7 +137,7 @@ static void USB_Device_SetConfiguration(void) #else USB_Descriptor_Device_t* DevDescriptorPtr; - if ((USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DevDescriptorPtr) == NO_DESCRIPTOR) || + if ((CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DevDescriptorPtr) == NO_DESCRIPTOR) || #if defined(USE_RAM_DESCRIPTORS) ((uint8_t)USB_ControlRequest.wValue > DevDescriptorPtr->NumberOfConfigurations)) #elif defined (USE_EEPROM_DESCRIPTORS) @@ -158,14 +157,14 @@ static void USB_Device_SetConfiguration(void) Endpoint_ClearIN(); if (!(AlreadyConfigured) && USB_ConfigurationNumber) - RAISE_EVENT(USB_DeviceEnumerationComplete); + EVENT_USB_DeviceEnumerationComplete(); - RAISE_EVENT(USB_ConfigurationChanged); + EVENT_USB_ConfigurationChanged(); } void USB_Device_GetConfiguration(void) { - Endpoint_ClearSETUP(); + Endpoint_ClearSETUP(); Endpoint_Write_Byte(USB_ConfigurationNumber); @@ -180,11 +179,66 @@ static void USB_Device_GetDescriptor(void) void* DescriptorPointer; uint16_t DescriptorSize; - if ((DescriptorSize = USB_GetDescriptor(USB_ControlRequest.wValue, USB_ControlRequest.wIndex, &DescriptorPointer)) == NO_DESCRIPTOR) - return; + #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)) + { + struct + { + 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 + + uint8_t SigReadAddress = 0x0E; + bool OddRead = false; + + for (uint8_t SerialCharNum = 0; SerialCharNum < 12; SerialCharNum++) + { + uint8_t SerialByte = boot_signature_byte_get(SigReadAddress); + + if (OddRead) + { + SerialByte >>= 4; + SigReadAddress++; + } + else + { + SerialByte &= 0x0F; + } + + OddRead = !(OddRead); + + if (SerialByte < 0x0A) + SerialByte += '0'; + else + SerialByte += ('A' - 0x0A); + + SignatureDescriptor.UnicodeString[SerialCharNum] = SerialByte; + } + + Endpoint_ClearSETUP(); + Endpoint_Write_Control_Stream_LE(&SignatureDescriptor, sizeof(SignatureDescriptor)); + Endpoint_ClearOUT(); + + return; + } + #endif - Endpoint_ClearSETUP(); + if ((DescriptorSize = CALLBACK_USB_GetDescriptor(USB_ControlRequest.wValue, USB_ControlRequest.wIndex, + &DescriptorPointer)) == NO_DESCRIPTOR) + { + return; + } + Endpoint_ClearSETUP(); + #if defined(USE_RAM_DESCRIPTORS) Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize); #else @@ -207,7 +261,7 @@ static void USB_Device_GetDescriptor(void) while (USB_ControlRequest.wLength && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize)) { #if defined (USE_EEPROM_DESCRIPTORS) - Endpoint_Write_Byte(eeprom_read_byte(DescriptorPointer++)); + Endpoint_Write_Byte(eeprom_read_byte(DescriptorPointer++)); #else Endpoint_Write_Byte(pgm_read_byte(DescriptorPointer++)); #endif @@ -274,6 +328,8 @@ static void USB_Device_ClearSetFeature(void) case REQREC_DEVICE: if ((uint8_t)USB_ControlRequest.wValue == FEATURE_REMOTE_WAKEUP) USB_RemoteWakeupEnabled = (USB_ControlRequest.bRequest == REQ_SetFeature); + else + return; break; #if !defined(CONTROL_ONLY_DEVICE) @@ -282,33 +338,35 @@ static void USB_Device_ClearSetFeature(void) { uint8_t EndpointIndex = ((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK); - if (EndpointIndex != ENDPOINT_CONTROLEP) - { - Endpoint_SelectEndpoint(EndpointIndex); - - if (Endpoint_IsEnabled()) - { - if (USB_ControlRequest.bRequest == REQ_ClearFeature) - { - Endpoint_ClearStall(); - Endpoint_ResetFIFO(EndpointIndex); - Endpoint_ResetDataToggle(); - } - else - { - Endpoint_StallTransaction(); - } + if (EndpointIndex == ENDPOINT_CONTROLEP) + return; + + Endpoint_SelectEndpoint(EndpointIndex); + + if (Endpoint_IsEnabled()) + { + if (USB_ControlRequest.bRequest == REQ_ClearFeature) + { + Endpoint_ClearStall(); + Endpoint_ResetFIFO(EndpointIndex); + Endpoint_ResetDataToggle(); + } + else + { + Endpoint_StallTransaction(); } - - Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); - Endpoint_ClearSETUP(); - Endpoint_ClearIN(); } } break; #endif } + + Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); + + Endpoint_ClearSETUP(); + + Endpoint_ClearIN(); } #endif