X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/840d386deb6736169085ec86ac9cb4d204072281..4f74075fad7f1e7a35d04ff534d9d6a57d2b97fc:/LUFA/Drivers/USB/LowLevel/DevChapter9.c diff --git a/LUFA/Drivers/USB/LowLevel/DevChapter9.c b/LUFA/Drivers/USB/LowLevel/DevChapter9.c index f9c52e666..6e7b2c718 100644 --- a/LUFA/Drivers/USB/LowLevel/DevChapter9.c +++ b/LUFA/Drivers/USB/LowLevel/DevChapter9.c @@ -39,7 +39,7 @@ uint8_t USB_ConfigurationNumber; bool USB_RemoteWakeupEnabled; bool USB_CurrentlySelfPowered; -void USB_Device_ProcessControlPacket(void) +void USB_Device_ProcessControlRequest(void) { bool RequestHandled = false; uint8_t* RequestHeader = (uint8_t*)&USB_ControlRequest; @@ -106,7 +106,7 @@ void USB_Device_ProcessControlPacket(void) } if (!(RequestHandled)) - EVENT_USB_UnhandledControlPacket(); + EVENT_USB_Device_UnhandledControlRequest(); if (Endpoint_IsSETUPReceived()) { @@ -121,7 +121,7 @@ static void USB_Device_SetAddress(void) Endpoint_ClearSETUP(); - Endpoint_ClearIN(); + Endpoint_ClearStatusStage(); while (!(Endpoint_IsINReady())) { @@ -129,18 +129,16 @@ static void USB_Device_SetAddress(void) return; } - UDADDR = ((1 << ADDEN) | DeviceAddress); - if (DeviceAddress) USB_DeviceState = DEVICE_STATE_Addressed; + UDADDR = ((1 << ADDEN) | DeviceAddress); + return; } static void USB_Device_SetConfiguration(void) { - bool AlreadyConfigured = (USB_ConfigurationNumber != 0); - #if defined(FIXED_NUM_CONFIGURATIONS) if ((uint8_t)USB_ControlRequest.wValue > FIXED_NUM_CONFIGURATIONS) return; @@ -192,21 +190,11 @@ static void USB_Device_SetConfiguration(void) USB_ConfigurationNumber = (uint8_t)USB_ControlRequest.wValue; - Endpoint_ClearIN(); + Endpoint_ClearStatusStage(); - if (USB_ConfigurationNumber) - { - USB_DeviceState = DEVICE_STATE_Configured; + USB_DeviceState = (USB_ConfigurationNumber) ? DEVICE_STATE_Configured : DEVICE_STATE_Addressed; - if (!(AlreadyConfigured)) - EVENT_USB_DeviceEnumerationComplete(); - } - else - { - USB_DeviceState = DEVICE_STATE_Addressed; - } - - EVENT_USB_ConfigurationChanged(); + EVENT_USB_Device_ConfigurationChanged(); } void USB_Device_GetConfiguration(void) @@ -214,16 +202,9 @@ void USB_Device_GetConfiguration(void) Endpoint_ClearSETUP(); Endpoint_Write_Byte(USB_ConfigurationNumber); - Endpoint_ClearIN(); - while (!(Endpoint_IsOUTReceived())) - { - if (USB_DeviceState == DEVICE_STATE_Unattached) - return; - } - - Endpoint_ClearOUT(); + Endpoint_ClearStatusStage(); } #if !defined(NO_INTERNAL_SERIAL) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) @@ -241,15 +222,10 @@ static void USB_Device_GetInternalSerialDescriptor(void) int16_t UnicodeString[20]; } 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; + SignatureDescriptor.Header.Type = DTYPE_String; + SignatureDescriptor.Header.Size = sizeof(SignatureDescriptor); + + uint8_t SigReadAddress = 0x0E; for (uint8_t SerialCharNum = 0; SerialCharNum < 20; SerialCharNum++) { @@ -265,7 +241,9 @@ static void USB_Device_GetInternalSerialDescriptor(void) } Endpoint_ClearSETUP(); + Endpoint_Write_Control_Stream_LE(&SignatureDescriptor, sizeof(SignatureDescriptor)); + Endpoint_ClearOUT(); } #endif @@ -333,7 +311,7 @@ static void USB_Device_GetStatus(void) break; #if !defined(CONTROL_ONLY_DEVICE) case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT): - Endpoint_SelectEndpoint((uint8_t)USB_ControlRequest.wIndex); + Endpoint_SelectEndpoint(USB_ControlRequest.wIndex & 0xFF); CurrentStatus = Endpoint_IsStalled(); @@ -341,21 +319,16 @@ static void USB_Device_GetStatus(void) break; #endif + default: + return; } Endpoint_ClearSETUP(); Endpoint_Write_Word_LE(CurrentStatus); - Endpoint_ClearIN(); - while (!(Endpoint_IsOUTReceived())) - { - if (USB_DeviceState == DEVICE_STATE_Unattached) - return; - } - - Endpoint_ClearOUT(); + Endpoint_ClearStatusStage(); } static void USB_Device_ClearSetFeature(void) @@ -382,16 +355,16 @@ static void USB_Device_ClearSetFeature(void) if (Endpoint_IsEnabled()) { - if (USB_ControlRequest.bRequest == REQ_ClearFeature) + if (USB_ControlRequest.bRequest == REQ_SetFeature) { - Endpoint_ClearStall(); - Endpoint_ResetFIFO(EndpointIndex); - Endpoint_ResetDataToggle(); + Endpoint_StallTransaction(); } else { - Endpoint_StallTransaction(); - } + Endpoint_ClearStall(); + Endpoint_ResetFIFO(EndpointIndex); + Endpoint_ResetDataToggle(); + } } } @@ -403,7 +376,7 @@ static void USB_Device_ClearSetFeature(void) Endpoint_ClearSETUP(); - Endpoint_ClearIN(); + Endpoint_ClearStatusStage(); } #endif