Tighten up the Bootloader GetDescriptor() function, as the descriptor size can be extracted from the header after the address has been found.

This commit is contained in:
Dean Camera 2011-02-06 17:04:39 +00:00
parent a95d224185
commit 355d12e039
3 changed files with 31 additions and 49 deletions

View File

@ -210,34 +210,25 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t DescriptorNumber = (wValue & 0xFF);
const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType)
{
case DTYPE_Device:
Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t);
break;
case DTYPE_Configuration:
Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t);
break;
case DTYPE_String:
if (!(DescriptorNumber))
{
Address = &LanguageString;
Size = LanguageString.Header.Size;
}
else
{
Address = &ProductString;
Size = ProductString.Header.Size;
}
break;
}
*DescriptorAddress = Address;
return Size;
return (Address != NULL) ? ((USB_Descriptor_Header_t*)Address)->Size : NO_DESCRIPTOR;
}

View File

@ -151,34 +151,25 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t DescriptorNumber = (wValue & 0xFF);
const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType)
{
case DTYPE_Device:
Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t);
break;
case DTYPE_Configuration:
Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t);
break;
case DTYPE_String:
if (!(DescriptorNumber))
{
Address = &LanguageString;
Size = LanguageString.Header.Size;
}
else
{
Address = &ProductString;
Size = ProductString.Header.Size;
}
break;
}
*DescriptorAddress = Address;
return Size;
return (Address != NULL) ? ((USB_Descriptor_Header_t*)Address)->Size : NO_DESCRIPTOR;
}