Add experimental support for the AVR32 UC3A4 microcontrollers.
authorDean Camera <dean@fourwalledcubicle.com>
Sun, 13 Mar 2011 22:42:08 +0000 (22:42 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Sun, 13 Mar 2011 22:42:08 +0000 (22:42 +0000)
Add support for the inbuilt unique serial numbers in the UC3A3 and UC3A4 models.

LUFA/Drivers/USB/Core/AVR8/Device_AVR8.h
LUFA/Drivers/USB/Core/DeviceStandardReq.c
LUFA/Drivers/USB/Core/StdDescriptors.h
LUFA/Drivers/USB/Core/UC3/Device_UC3.h
LUFA/Drivers/USB/Core/UC3/USBController_UC3.h
LUFA/Drivers/USB/Core/USBMode.h
LUFA/ManPages/DeviceSupport.txt

index dbbe884..dc86302 100644 (file)
@@ -87,9 +87,9 @@
                        //@}
                        
                        #if (!defined(NO_INTERNAL_SERIAL) && \
-                            (defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__) || \
-                             defined(__AVR_ATmega32U6__) || defined(__AVR_AT90USB646__)  || defined(__AVR_AT90USB1286__) ||  \
-                             defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__)  || defined(__AVR_ATmega8U2__)))
+                            (defined(USB_SERIES_7_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_4_AVR) || \
+                             (defined(USB_SERIES_2_AVR) && (!defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__))) || \
+                                 defined(__DOXYGEN__)))
                                /** String descriptor index for the device's unique serial number string descriptor within the device.
                                 *  This unique serial number is used by the host to associate resources to the device (such as drivers or COM port
                                 *  number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain
                                return (UDADDR & (1 << ADDEN));
                        }
                
-                       static inline uint8_t USB_Device_GetSerialString(wchar_t* UnicodeString, const uint8_t MaxLen)
+                       static inline uint8_t USB_Device_GetSerialString(uint16_t* UnicodeString, const uint8_t MaxLen)
                        {
                                uint8_t SerialCharNum = 0;
 
 
                                                SerialByte &= 0x0F;
 
-                                               UnicodeString[SerialCharNum] = (SerialByte >= 10) ?
-                                                                              (('A' - 10) + SerialByte) : ('0' + SerialByte);
+                                               UnicodeString[SerialCharNum] = cpu_to_le16((SerialByte >= 10) ?
+                                                                                          (('A' - 10) + SerialByte) : ('0' + SerialByte));
                                        }
                                }
                                
index 4ee2fce..a2270f4 100644 (file)
@@ -204,12 +204,12 @@ static void USB_Device_GetInternalSerialDescriptor(void)
        struct
        {
                USB_Descriptor_Header_t Header;
-               wchar_t                 UnicodeString[20];
+               uint16_t                UnicodeString[20];
        } SignatureDescriptor;
 
        SignatureDescriptor.Header.Type = DTYPE_String;
-       SignatureDescriptor.Header.Size = USB_Device_GetSerialString(SignatureDescriptor.UnicodeString,
-                                                                    sizeof(SignatureDescriptor.UnicodeString));
+       SignatureDescriptor.Header.Size = USB_STRING_LEN(USB_Device_GetSerialString(SignatureDescriptor.UnicodeString,
+                                                        sizeof(SignatureDescriptor.UnicodeString) / sizeof(SignatureDescriptor.UnicodeString[0])));
 
        Endpoint_ClearSETUP();
 
index 908f27b..32777cc 100644 (file)
                                uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t
                                                          *   or a value given by the specific class.
                                                          */
-                               int16_t bString[]; /**< String data, as unicode characters (alternatively, string language IDs).
-                                                   *   If normal ASCII characters are to be used, they must be added as an array
-                                                   *   of characters rather than a normal C string so that they are widened to
-                                                   *   Unicode size.
-                                                   *
-                                                   *   Under GCC, strings prefixed with the "L" character (before the opening string
-                                                   *   quotation mark) are considered to be Unicode strings, and may be used instead
-                                                   *   of an explicit array of ASCII characters.
-                                                   */
+                               uint16_t bString[]; /**< String data, as unicode characters (alternatively, string language IDs).
+                                                    *   If normal ASCII characters are to be used, they must be added as an array
+                                                    *   of characters rather than a normal C string so that they are widened to
+                                                    *   Unicode size.
+                                                    *
+                                                    *   Under GCC, strings prefixed with the "L" character (before the opening string
+                                                    *   quotation mark) are considered to be Unicode strings, and may be used instead
+                                                    *   of an explicit array of ASCII characters.
+                                                    */
                        } ATTR_PACKED USB_StdDescriptor_String_t;
 
        /* Private Interface - For use in library only: */
index 653044f..59897a7 100644 (file)
                        #define USB_DEVICE_OPT_FULLSPEED               (0 << 0)\r
                        //@}\r
                        \r
-                       /** String descriptor index for the device's unique serial number string descriptor within the device.\r
-                        *  This unique serial number is used by the host to associate resources to the device (such as drivers or COM port\r
-                        *  number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain\r
-                        *  a unique serial number internally, and setting the device descriptors serial number string index to this value\r
-                        *  will cause it to use the internal serial number.\r
-                        *\r
-                        *  On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial\r
-                        *  number for the device.\r
-                        */\r
-                       #define USE_INTERNAL_SERIAL                    NO_DESCRIPTOR\r
+                       #if (!defined(NO_INTERNAL_SERIAL) && \\r
+                            (defined(USB_SERIES_UC3A3_AVR) || defined(USB_SERIES_UC3A4_AVR) || \\r
+                                 defined(__DOXYGEN__)))\r
+                               /** String descriptor index for the device's unique serial number string descriptor within the device.\r
+                                *  This unique serial number is used by the host to associate resources to the device (such as drivers or COM port\r
+                                *  number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain\r
+                                *  a unique serial number internally, and setting the device descriptors serial number string index to this value\r
+                                *  will cause it to use the internal serial number.\r
+                                *\r
+                                *  On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial\r
+                                *  number for the device.\r
+                                */\r
+                               #define USE_INTERNAL_SERIAL           0xDC\r
+                       #else\r
+                               #define USE_INTERNAL_SERIAL           NO_DESCRIPTOR\r
+                       #endif  \r
                        \r
                /* Function Prototypes: */\r
                        /** Sends a Remote Wakeup request to the host. This signals to the host that the device should\r
                        {\r
                                return AVR32_USBB.UDCON.adden;\r
                        }\r
+\r
+                       static inline uint8_t USB_Device_GetSerialString(uint16_t* UnicodeString, const uint8_t MaxLen)\r
+                       {\r
+                               uint8_t SerialCharNum = 0;\r
+\r
+                               ATOMIC_BLOCK(ATOMIC_RESTORESTATE)\r
+                               {\r
+                                       uint32_t* SigReadAddress = 0x80800204;\r
+\r
+                                       for (SerialCharNum = 0; SerialCharNum < MIN(MaxLen, 30); SerialCharNum++)\r
+                                       {\r
+                                               if (SerialCharNum == MaxLen)\r
+                                                 break;\r
+\r
+                                               uint8_t SerialByte = *SigReadAddress;\r
+\r
+                                               if (SerialCharNum & 0x01)\r
+                                               {\r
+                                                       SerialByte >>= 4;\r
+                                                       SigReadAddress++;\r
+                                               }\r
+\r
+                                               SerialByte &= 0x0F;\r
+\r
+                                               UnicodeString[SerialCharNum] = cpu_to_le16((SerialByte >= 10) ?\r
+                                                                                          (('A' - 10) + SerialByte) : ('0' + SerialByte));\r
+                                       }\r
+                               }\r
+                               \r
+                               return SerialCharNum;\r
+                       }\r
        #endif\r
 \r
 #endif\r
index c975bb3..8b29628 100644 (file)
        /* Private Interface - For use in library only: */\r
        #if !defined(__DOXYGEN__)\r
                /* Macros: */                   \r
-                       #if defined(USB_SERIES_UC3A3_AVR)\r
+                       #if (defined(USB_SERIES_UC3A3_AVR) || defined(USB_SERIES_UC3A4_AVR))\r
                                #define USB_CLOCK_REQUIRED_FREQ  12000000UL\r
                        #else\r
                                #define USB_CLOCK_REQUIRED_FREQ  48000000UL\r
index e563e56..4fb65be 100644 (file)
                                #define USB_SERIES_UC3A3_AVR
                                #define USB_CAN_BE_DEVICE
                                #define USB_CAN_BE_HOST
+                       #elif (defined(__AVR32_UC3A4256__) || defined(__AVR32_UC3A4256S__) || \
+                              defined(__AVR32_UC3A4128__) || defined(__AVR32_UC3A4128S__) || \
+                              defined(__AVR32_UC3A464__)  || defined(__AVR32_UC3A464S__))
+                               #define USB_SERIES_UC3A4_AVR
+                               #define USB_CAN_BE_DEVICE
+                               #define USB_CAN_BE_HOST
                        #elif (defined(__AVR32_UC3B0512__) || defined(__AVR32_UC3B0256__) || \
                               defined(__AVR32_UC3B0128__) || defined(__AVR32_UC3B064__))
                                #define USB_SERIES_UC3B0_AVR
index f93dbb2..2381d2a 100644 (file)
  *   - AT32UC3A164 (USB Host and Device)
  *   - AT32UC3A364 (USB Host and Device)
  *   - AT32UC3A364S (USB Host and Device)
+ *   - AT32UC3A464 (USB Host and Device)
+ *   - AT32UC3A464S (USB Host and Device)
  *   - AT32UC3B064 (USB Host and Device)
  *   - AT32UC3B164 (USB Host and Device)
  *   - AT32UC3A0128 (USB Host and Device)
  *   - AT32UC3A1128 (USB Host and Device)
  *   - AT32UC3A3128 (USB Host and Device)
  *   - AT32UC3A3128S (USB Host and Device)
+ *   - AT32UC3A4128 (USB Host and Device)
+ *   - AT32UC3A4128S (USB Host and Device)
  *   - AT32UC3B0128 (USB Host and Device)
  *   - AT32UC3B1128 (USB Host and Device)
  *   - AT32UC3A0256 (USB Host and Device)
  *   - AT32UC3A1256 (USB Host and Device)
  *   - AT32UC3A3256 (USB Host and Device)
  *   - AT32UC3A3256S (USB Host and Device)
+ *   - AT32UC3A4256 (USB Host and Device)
+ *   - AT32UC3A4256S (USB Host and Device)
  *   - AT32UC3B0256 (USB Host and Device)
  *   - AT32UC3B1256 (USB Host and Device)
  *   - AT32UC3A0512 (USB Host and Device)