X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/0e6d5cf5b4fea133cbd3c16b958617deb42332cf..fc31973daffea3506051ce51a5f79383ce0867d6:/LUFA/Drivers/USB/LowLevel/DevChapter9.c diff --git a/LUFA/Drivers/USB/LowLevel/DevChapter9.c b/LUFA/Drivers/USB/LowLevel/DevChapter9.c index 0d25e3b12..b7f811b5e 100644 --- a/LUFA/Drivers/USB/LowLevel/DevChapter9.c +++ b/LUFA/Drivers/USB/LowLevel/DevChapter9.c @@ -136,22 +136,30 @@ static void USB_Device_SetAddress(void) return; } - if (DeviceAddress) - USB_DeviceState = DEVICE_STATE_Addressed; + USB_DeviceState = (DeviceAddress) ? DEVICE_STATE_Addressed : DEVICE_STATE_Default; - USB_Device_SetDeviceAddress(DeviceAddress); + UDADDR = ((1 << ADDEN) | DeviceAddress); return; } static void USB_Device_SetConfiguration(void) { + if (USB_DeviceState != DEVICE_STATE_Addressed) + return; + #if defined(FIXED_NUM_CONFIGURATIONS) if ((uint8_t)USB_ControlRequest.wValue > FIXED_NUM_CONFIGURATIONS) return; #else - #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS) - uint8_t MemoryAddressSpace; + #if defined(USE_FLASH_DESCRIPTORS) + #define MemoryAddressSpace MEMSPACE_FLASH + #elif defined(USE_EEPROM_DESCRIPTORS) + #define MemoryAddressSpace MEMSPACE_EEPROM + #elif defined(USE_SRAM_DESCRIPTORS) + #define MemoryAddressSpace MEMSPACE_SRAM + #else + uint8_t MemoryAddressSpace; #endif USB_Descriptor_Device_t* DevDescriptorPtr; @@ -165,16 +173,6 @@ static void USB_Device_SetConfiguration(void) return; } - #if defined(USE_RAM_DESCRIPTORS) - if ((uint8_t)USB_ControlRequest.wValue > DevDescriptorPtr->NumberOfConfigurations) - return; - #elif defined (USE_EEPROM_DESCRIPTORS) - if ((uint8_t)USB_ControlRequest.wValue > eeprom_read_byte(&DevDescriptorPtr->NumberOfConfigurations)) - return; - #elif defined (USE_FLASH_DESCRIPTORS) - if ((uint8_t)USB_ControlRequest.wValue > pgm_read_byte(&DevDescriptorPtr->NumberOfConfigurations)) - return; - #else if (MemoryAddressSpace == MEMSPACE_FLASH) { if (((uint8_t)USB_ControlRequest.wValue > pgm_read_byte(&DevDescriptorPtr->NumberOfConfigurations))) @@ -190,7 +188,6 @@ static void USB_Device_SetConfiguration(void) if ((uint8_t)USB_ControlRequest.wValue > DevDescriptorPtr->NumberOfConfigurations) return; } - #endif #endif Endpoint_ClearSETUP(); @@ -234,17 +231,20 @@ static void USB_Device_GetInternalSerialDescriptor(void) uint8_t SigReadAddress = 0x0E; - for (uint8_t SerialCharNum = 0; SerialCharNum < 20; SerialCharNum++) + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { - uint8_t SerialByte = boot_signature_byte_get(SigReadAddress); - - if (SerialCharNum & 0x01) + for (uint8_t SerialCharNum = 0; SerialCharNum < 20; SerialCharNum++) { - SerialByte >>= 4; - SigReadAddress++; + uint8_t SerialByte = boot_signature_byte_get(SigReadAddress); + + if (SerialCharNum & 0x01) + { + SerialByte >>= 4; + SigReadAddress++; + } + + SignatureDescriptor.UnicodeString[SerialCharNum] = USB_Device_NibbleToASCII(SerialByte); } - - SignatureDescriptor.UnicodeString[SerialCharNum] = USB_Device_NibbleToASCII(SerialByte); } Endpoint_ClearSETUP(); @@ -323,7 +323,7 @@ static void USB_Device_GetStatus(void) #endif #if !defined(CONTROL_ONLY_DEVICE) case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT): - Endpoint_SelectEndpoint(USB_ControlRequest.wIndex & 0xFF); + Endpoint_SelectEndpoint((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK); CurrentStatus = Endpoint_IsStalled(); @@ -344,7 +344,7 @@ static void USB_Device_GetStatus(void) } static void USB_Device_ClearSetFeature(void) -{ +{ switch (USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) { #if !defined(NO_DEVICE_REMOTE_WAKEUP) @@ -367,18 +367,18 @@ static void USB_Device_ClearSetFeature(void) Endpoint_SelectEndpoint(EndpointIndex); - if (Endpoint_IsEnabled()) - { - if (USB_ControlRequest.bRequest == REQ_SetFeature) - { - Endpoint_StallTransaction(); - } - else - { - Endpoint_ClearStall(); - Endpoint_ResetFIFO(EndpointIndex); - Endpoint_ResetDataToggle(); - } + if (!(Endpoint_IsEnabled())) + return; + + if (USB_ControlRequest.bRequest == REQ_SetFeature) + { + Endpoint_StallTransaction(); + } + else + { + Endpoint_ClearStall(); + Endpoint_ResetFIFO(EndpointIndex); + Endpoint_ResetDataToggle(); } }