aboutsummaryrefslogtreecommitdiffstats
path: root/Bootloaders/DFU/Descriptors.c
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2011-02-06 17:04:39 +0000
committerDean Camera <dean@fourwalledcubicle.com>2011-02-06 17:04:39 +0000
commit355d12e039caafbb8e0ae18427be3acef03719d1 (patch)
tree019a8e1ede3d48d085e9ee91fcbd7c9503ac444f /Bootloaders/DFU/Descriptors.c
parenta95d2241851a4877189b11854f25ff65b6a2b411 (diff)
downloadlufa-355d12e039caafbb8e0ae18427be3acef03719d1.tar.gz
lufa-355d12e039caafbb8e0ae18427be3acef03719d1.tar.bz2
lufa-355d12e039caafbb8e0ae18427be3acef03719d1.zip
Tighten up the Bootloader GetDescriptor() function, as the descriptor size can be extracted from the header after the address has been found.
Diffstat (limited to 'Bootloaders/DFU/Descriptors.c')
-rw-r--r--Bootloaders/DFU/Descriptors.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/Bootloaders/DFU/Descriptors.c b/Bootloaders/DFU/Descriptors.c
index 51dfff273..9baa8890d 100644
--- a/Bootloaders/DFU/Descriptors.c
+++ b/Bootloaders/DFU/Descriptors.c
@@ -73,17 +73,17 @@ USB_Descriptor_Configuration_t ConfigurationDescriptor =
{
.Config =
{
- .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
+ .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
- .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
- .TotalInterfaces = 1,
+ .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
+ .TotalInterfaces = 1,
- .ConfigurationNumber = 1,
- .ConfigurationStrIndex = NO_DESCRIPTOR,
+ .ConfigurationNumber = 1,
+ .ConfigurationStrIndex = NO_DESCRIPTOR,
- .ConfigAttributes = USB_CONFIG_ATTR_BUSPOWERED,
+ .ConfigAttributes = USB_CONFIG_ATTR_BUSPOWERED,
- .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
+ .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
},
.DFU_Interface =
@@ -147,38 +147,29 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex,
const void** const DescriptorAddress)
{
- const uint8_t DescriptorType = (wValue >> 8);
- const uint8_t DescriptorNumber = (wValue & 0xFF);
+ const uint8_t DescriptorType = (wValue >> 8);
+ 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;
- }
+ Address = &LanguageString;
else
- {
- Address = &ProductString;
- Size = ProductString.Header.Size;
- }
+ Address = &ProductString;
break;
}
*DescriptorAddress = Address;
- return Size;
+ return (Address != NULL) ? ((USB_Descriptor_Header_t*)Address)->Size : NO_DESCRIPTOR;
}