Cleanup and optimization of the internal serial retrieval routines.
authorDean Camera <dean@fourwalledcubicle.com>
Mon, 3 Aug 2009 07:10:54 +0000 (07:10 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Mon, 3 Aug 2009 07:10:54 +0000 (07:10 +0000)
Renamed ATTR_NOINLINE to ATTR_NO_INLINE to fit with the rest of the library function attribute names.

LUFA/Common/FunctionAttributes.h
LUFA/Drivers/USB/LowLevel/DevChapter9.c
LUFA/Drivers/USB/LowLevel/DevChapter9.h

index 9efa440..9a293b6 100644 (file)
@@ -87,7 +87,7 @@
                        /** Prevents the compiler from considering a specified function for inlining. When applied, the given\r
                         *  function will not be inlined under any circumstances.\r
                         */\r
-                       #define ATTR_NOINLINE               __attribute__ ((noinline))\r
+                       #define ATTR_NO_INLINE              __attribute__ ((noinline))\r
 \r
                        /** Forces the compiler to inline the specified function. When applied, the given function will be\r
                         *  inlined under all circumstances.\r
index 7fecd1f..f9c52e6 100644 (file)
@@ -227,6 +227,12 @@ void USB_Device_GetConfiguration(void)
 }\r
 \r
 #if !defined(NO_INTERNAL_SERIAL) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))\r
+static char USB_Device_NibbleToASCII(uint8_t Nibble)\r
+{\r
+       Nibble = ((Nibble & 0x0F) + '0');\r
+       return (Nibble > '9') ? (Nibble + ('A' - '9' - 1)) : Nibble;\r
+}\r
+\r
 static void USB_Device_GetInternalSerialDescriptor(void)\r
 {\r
        struct\r
@@ -234,9 +240,6 @@ static void USB_Device_GetInternalSerialDescriptor(void)
                USB_Descriptor_Header_t Header;\r
                int16_t                 UnicodeString[20];\r
        } SignatureDescriptor;\r
-       \r
-       uint8_t SigReadAddress  = 0x0E;\r
-       bool    OddNibbleRead   = false;\r
 \r
        #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES)\r
                SignatureDescriptor.Header.Size            = sizeof(SignatureDescriptor);\r
@@ -246,28 +249,19 @@ static void USB_Device_GetInternalSerialDescriptor(void)
                SignatureDescriptor.Header.bDescriptorType = DTYPE_String;\r
        #endif\r
 \r
+       uint8_t  SigReadAddress     = 0x0E;\r
+\r
        for (uint8_t SerialCharNum = 0; SerialCharNum < 20; SerialCharNum++)\r
        {\r
                uint8_t SerialByte = boot_signature_byte_get(SigReadAddress);\r
                \r
-               if (OddNibbleRead)\r
+               if (SerialCharNum & 0x01)\r
                {\r
                        SerialByte >>= 4;\r
                        SigReadAddress++;\r
                }\r
-               else\r
-               {\r
-                       SerialByte &= 0x0F;\r
-               }\r
                \r
-               OddNibbleRead = !(OddNibbleRead);\r
-\r
-               if (SerialByte < 0x0A)\r
-                 SerialByte += '0';\r
-               else\r
-                 SerialByte += ('A' - 0x0A);\r
-\r
-               SignatureDescriptor.UnicodeString[SerialCharNum] = SerialByte;\r
+               SignatureDescriptor.UnicodeString[SerialCharNum] = USB_Device_NibbleToASCII(SerialByte);\r
        }\r
        \r
        Endpoint_ClearSETUP();\r
index a856ded..a70dd06 100644 (file)
                                static void USB_Device_ClearSetFeature(void);\r
                                \r
                                #if !defined(NO_INTERNAL_SERIAL) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))\r
+                                       static char USB_Device_NibbleToASCII(uint8_t Nibble) ATTR_ALWAYS_INLINE;\r
                                        static void USB_Device_GetInternalSerialDescriptor(void);\r
                                #endif                          \r
                        #endif\r