aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-06-21 13:52:21 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-06-21 13:52:21 +0000
commita34cccf09931a54a607a56d4ded88f3b7a4752b4 (patch)
treeb415d53b8f238bdc04432a55cfbfa09ccf15f8c8
parent7d391eb04c116b8a79c1a99df3708a0b2200fab0 (diff)
downloadlufa-a34cccf09931a54a607a56d4ded88f3b7a4752b4.tar.gz
lufa-a34cccf09931a54a607a56d4ded88f3b7a4752b4.tar.bz2
lufa-a34cccf09931a54a607a56d4ded88f3b7a4752b4.zip
Optimize unique serial number reading code for size -- remove atoi/toupper references, replace with hand-rolled code as the input has known size constraints.
-rw-r--r--LUFA/Drivers/USB/LowLevel/DevChapter9.c48
1 files changed, 35 insertions, 13 deletions
diff --git a/LUFA/Drivers/USB/LowLevel/DevChapter9.c b/LUFA/Drivers/USB/LowLevel/DevChapter9.c
index 4014ed1ca..feaabce46 100644
--- a/LUFA/Drivers/USB/LowLevel/DevChapter9.c
+++ b/LUFA/Drivers/USB/LowLevel/DevChapter9.c
@@ -182,27 +182,49 @@ static void USB_Device_GetDescriptor(void)
#if !defined(NO_INTERNAL_SERIAL) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
if (USB_ControlRequest.wValue == ((DTYPE_String << 8) | USE_INTERNAL_SERIAL))
{
- uint8_t SignatureDescriptor[2 + (sizeof(int16_t) * 12)];
-
- SignatureDescriptor[0] = sizeof(SignatureDescriptor);
- SignatureDescriptor[1] = DTYPE_String;
+ struct
+ {
+ USB_Descriptor_Header_t Header;
+ int16_t UnicodeString[12];
+ } SignatureDescriptor;
+
+ #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES)
+ SignatureDescriptor.Header.Size = sizeof(SignatureDescriptor);
+ SignatureDescriptor.Header.Type = DTYPE_String;
+ #else
+ SignatureDescriptor.Header.bLength = sizeof(SignatureDescriptor);
+ SignatureDescriptor.Header.bDescriptorType = DTYPE_String;
+ #endif
- uint16_t* SigUnicodeChars = (uint16_t*)&SignatureDescriptor[2];
+ uint8_t SigReadAddress = 0x0E;
+ bool OddRead = false;
- for (uint8_t SerialByteNum = 0; SerialByteNum < 6; SerialByteNum++)
+ for (uint8_t SerialCharNum = 0; SerialCharNum < 12; SerialCharNum++)
{
- char ConvSigString[3];
-
- itoa(boot_signature_byte_get(0x0E + SerialByteNum), ConvSigString, 16);
+ uint8_t SerialByte = boot_signature_byte_get(SigReadAddress);
- SigUnicodeChars[0] = toupper(ConvSigString[0]);
- SigUnicodeChars[1] = toupper(ConvSigString[1]);
+ if (OddRead)
+ {
+ SerialByte >>= 4;
+ SigReadAddress++;
+ }
+ else
+ {
+ SerialByte &= 0x0F;
+ }
- SigUnicodeChars += 2;
+ OddRead = !(OddRead);
+
+ if (SerialByte < 0x0A)
+ SerialByte += '0';
+ else
+ SerialByte += ('A' - 0x0A);
+
+ SignatureDescriptor.UnicodeString[SerialCharNum] = SerialByte;
}
Endpoint_ClearSETUP();
- Endpoint_Write_Control_Stream_LE(SignatureDescriptor, sizeof(SignatureDescriptor));
+ Endpoint_Write_Control_Stream_LE(&SignatureDescriptor, sizeof(SignatureDescriptor));
Endpoint_ClearOUT();
return;