diff --git a/Bootloaders/TeensyHID/Descriptors.c b/Bootloaders/TeensyHID/Descriptors.c index 2832ec393515e07524e8e591720e0dd189ddece9..4142f12474948a5f29c8c3ba0df4c08ae8850d6b 100644 --- a/Bootloaders/TeensyHID/Descriptors.c +++ b/Bootloaders/TeensyHID/Descriptors.c @@ -157,26 +157,29 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void* Address = NULL; uint16_t Size = NO_DESCRIPTOR; - switch (DescriptorType) + /* If/Else If chain compiles slightly smaller than a switch case */ + + if (DescriptorType == DTYPE_Device) + { + Address = (void*)&DeviceDescriptor; + Size = sizeof(USB_Descriptor_Device_t); + } + else if (DescriptorType == DTYPE_Device) + { + Address = (void*)&ConfigurationDescriptor; + Size = sizeof(USB_Descriptor_Configuration_t); + } + else if (DescriptorType == DTYPE_HID) + { + Address = (void*)&ConfigurationDescriptor.HID_VendorHID; + Size = sizeof(USB_Descriptor_HID_t); + } + else { - case DTYPE_Device: - Address = (void*)&DeviceDescriptor; - Size = sizeof(USB_Descriptor_Device_t); - break; - case DTYPE_Configuration: - Address = (void*)&ConfigurationDescriptor; - Size = sizeof(USB_Descriptor_Configuration_t); - break; - case DTYPE_HID: - Address = (void*)&ConfigurationDescriptor.HID_VendorHID; - Size = sizeof(USB_Descriptor_HID_t); - break; - case DTYPE_Report: - Address = (void*)&HIDReport; - Size = sizeof(HIDReport); - break; + Address = (void*)&HIDReport; + Size = sizeof(HIDReport); } - + *DescriptorAddress = Address; return Size; } diff --git a/LUFA/Drivers/USB/LowLevel/DevChapter9.c b/LUFA/Drivers/USB/LowLevel/DevChapter9.c index 17a5fd4714b5f17e38553ac7cf7677bdd4663d39..b7f811b5eb0b0e4faeac604c53bd463f02aec689 100644 --- a/LUFA/Drivers/USB/LowLevel/DevChapter9.c +++ b/LUFA/Drivers/USB/LowLevel/DevChapter9.c @@ -136,8 +136,7 @@ static void USB_Device_SetAddress(void) return; } - if (DeviceAddress) - USB_DeviceState = DEVICE_STATE_Addressed; + USB_DeviceState = (DeviceAddress) ? DEVICE_STATE_Addressed : DEVICE_STATE_Default; UDADDR = ((1 << ADDEN) | DeviceAddress); @@ -146,12 +145,21 @@ static void USB_Device_SetAddress(void) 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(); diff --git a/LUFA/Drivers/USB/LowLevel/DevChapter9.h b/LUFA/Drivers/USB/LowLevel/DevChapter9.h index d591327390c4c79323c7c85f2bab95b5c674276f..868c3fab2160c81a62f3026b9fb59e17392d6c0c 100644 --- a/LUFA/Drivers/USB/LowLevel/DevChapter9.h +++ b/LUFA/Drivers/USB/LowLevel/DevChapter9.h @@ -46,6 +46,7 @@ #include <avr/pgmspace.h> #include <avr/eeprom.h> #include <avr/boot.h> + #include <util/atomic.h> #include "../HighLevel/StdDescriptors.h" #include "../HighLevel/Events.h" diff --git a/LUFA/ManPages/ChangeLog.txt b/LUFA/ManPages/ChangeLog.txt index 8d5a7ab6a4a4c9cdc38515cb8a8e09d0a10b5875..c38f9e73e666bb96fa27485d5394f78355899773 100644 --- a/LUFA/ManPages/ChangeLog.txt +++ b/LUFA/ManPages/ChangeLog.txt @@ -52,6 +52,12 @@ * - Fixed Set/Clear Feature requests directed to a non-configured endpoint not returning a stall to the host * - Fixed HID Device Class Driver not allocating a temporary buffer when the host requests a report via the control endpoint and the * user has set the PrevReportINBuffer driver configuration element to NULL (thanks to Lars Noschinski) + * - Fixed device state not being reset to DEVICE_STATE_Default if the host sets a 0x00 device address + * - Fixed device not stalling configuration requests before the device's address has been set + * - Fixed possibility of internal signature retrieval being corrupted if an interrupt occurs during a signature byte + * read (thanks to Andrei Krainev) + * - Fixed device state not being reset back to the default state if the host sets the address to 0 + * - Fixed Set Configuration requests not being stalled until the host has set the device's address * * \section Sec_ChangeLog100219 Version 100219 * diff --git a/Projects/AVRISP-MKII/AVRISP.txt b/Projects/AVRISP-MKII/AVRISP.txt index fddae6d2bbc3644a445671f7487e86f17d9b4c2c..61090311064f553d6731349811414f5d9fdb7b13 100644 --- a/Projects/AVRISP-MKII/AVRISP.txt +++ b/Projects/AVRISP-MKII/AVRISP.txt @@ -56,14 +56,15 @@ * Note that this design currently has the following limitations: * - Minimum ISP target clock speed of 500KHz due to hardware SPI module prescaler limitations * - No reversed/shorted target connector detection and notification + * - Very slow TPI and PDI programming when in software emulated USART mode * * On AVR models with an ADC converter, AVCC should be tied to 5V (e.g. VBUS) and the VTARGET_ADC_CHANNEL token should be * set to an appropriate ADC channel number in the project makefile for VTARGET detection to operate correctly. On models * without an ADC converter, VTARGET will report a fixed 5V level at all times. * * When compiled for the XPLAIN board target, this will automatically configure itself for the correct connections to the - * XPLAIN's XMEGA AVR, and will enable PDI/TPI only programming support (since ISP mode is not needed). Note that the - * first revision XPLAIN board lacks a bootloader on the AT90USB1287, and thus for this firmware to be loaded, an external + * XPLAIN's XMEGA AVR, and will enable hardware PDI/TPI only programming support (since ISP mode is not needed). Note that + * the first revision XPLAIN board lacks a bootloader on the AT90USB1287, and thus for this firmware to be loaded, an external * programmer will be required. * * While this application can be compiled for USB AVRs with as little as 8KB of FLASH, for full functionality 16KB or more