Skip to content
Snippets Groups Projects
Commit 355d12e0 authored by Dean Camera's avatar Dean Camera
Browse files

Tighten up the Bootloader GetDescriptor() function, as the descriptor size can...

Tighten up the Bootloader GetDescriptor() function, as the descriptor size can be extracted from the header after the address has been found.
parent a95d2241
Branches
No related tags found
No related merge requests found
...@@ -210,34 +210,25 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, ...@@ -210,34 +210,25 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t DescriptorNumber = (wValue & 0xFF); const uint8_t DescriptorNumber = (wValue & 0xFF);
const void* Address = NULL; const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType) switch (DescriptorType)
{ {
case DTYPE_Device: case DTYPE_Device:
Address = &DeviceDescriptor; Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t);
break; break;
case DTYPE_Configuration: case DTYPE_Configuration:
Address = &ConfigurationDescriptor; Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t);
break; break;
case DTYPE_String: case DTYPE_String:
if (!(DescriptorNumber)) if (!(DescriptorNumber))
{
Address = &LanguageString; Address = &LanguageString;
Size = LanguageString.Header.Size;
}
else else
{
Address = &ProductString; Address = &ProductString;
Size = ProductString.Header.Size;
}
break; break;
} }
*DescriptorAddress = Address; *DescriptorAddress = Address;
return Size; return (Address != NULL) ? ((USB_Descriptor_Header_t*)Address)->Size : NO_DESCRIPTOR;
} }
...@@ -151,34 +151,25 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, ...@@ -151,34 +151,25 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t DescriptorNumber = (wValue & 0xFF); const uint8_t DescriptorNumber = (wValue & 0xFF);
const void* Address = NULL; const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType) switch (DescriptorType)
{ {
case DTYPE_Device: case DTYPE_Device:
Address = &DeviceDescriptor; Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t);
break; break;
case DTYPE_Configuration: case DTYPE_Configuration:
Address = &ConfigurationDescriptor; Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t);
break; break;
case DTYPE_String: case DTYPE_String:
if (!(DescriptorNumber)) if (!(DescriptorNumber))
{
Address = &LanguageString; Address = &LanguageString;
Size = LanguageString.Header.Size;
}
else else
{
Address = &ProductString; Address = &ProductString;
Size = ProductString.Header.Size;
}
break; break;
} }
*DescriptorAddress = Address; *DescriptorAddress = Address;
return Size; return (Address != NULL) ? ((USB_Descriptor_Header_t*)Address)->Size : NO_DESCRIPTOR;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment