Implementation of several key core USB driver functions for the new USB XMEGA devices.
[pub/lufa.git] / LUFA / Drivers / USB / Core / XMEGA / Device_XMEGA.h
index 805e8f9..f0a472e 100644 (file)
                         *  \note Restrictions apply on the number, size and type of endpoints which can be used\r
                         *        when running in low speed mode - refer to the USB 2.0 specification.\r
                         */\r
-                       #define USB_DEVICE_OPT_LOWSPEED            (1 << 0)\r
+                       #define USB_DEVICE_OPT_LOWSPEED        (1 << 0)\r
 \r
                        /** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the\r
                         *  USB interface should be initialized in full speed (12Mb/s) mode.\r
                         */\r
-                       #define USB_DEVICE_OPT_FULLSPEED               (0 << 0)\r
+                       #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
                         *  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
+                       #define USE_INTERNAL_SERIAL            0xDC\r
 \r
                        /** Length of the device's unique internal serial number, in bits, if present on the selected microcontroller\r
                         *  model.\r
                         */\r
-                       #define INTERNAL_SERIAL_LENGTH_BITS    0\r
+                       #define INTERNAL_SERIAL_LENGTH_BITS    112\r
                        \r
                        /** Start address of the internal serial number, in the appropriate address space, if present on the selected microcontroller\r
                         *  model.\r
                         */\r
-                       #define INTERNAL_SERIAL_START_ADDRESS  0                        \r
+                       #define INTERNAL_SERIAL_START_ADDRESS  0x08\r
                        \r
                /* Function Prototypes: */\r
                        /** Sends a Remote Wakeup request to the host. This signals to the host that the device should\r
                        static inline void USB_Device_SetLowSpeed(void) ATTR_ALWAYS_INLINE;\r
                        static inline void USB_Device_SetLowSpeed(void)\r
                        {\r
-                               // TODO\r
+                               USB.CTRLA &= ~USB_SPEED_bm;\r
                        }\r
 \r
                        static inline void USB_Device_SetFullSpeed(void) ATTR_ALWAYS_INLINE;\r
                        static inline void USB_Device_SetFullSpeed(void)\r
                        {\r
-                               // TODO\r
+                               USB.CTRLA |=  USB_SPEED_bm;\r
                        }\r
 \r
                        static inline void USB_Device_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE;\r
                        static inline void USB_Device_SetDeviceAddress(const uint8_t Address)\r
                        {\r
-                               // TODO\r
+                               USB.ADDR = Address;\r
                        }\r
 \r
                        static inline bool USB_Device_IsAddressSet(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;\r
                        static inline bool USB_Device_IsAddressSet(void)\r
                        {\r
-                               return false; // TODO\r
+                               return ((USB.ADDR != 0) ? true : false);\r
                        }\r
                \r
-                       #if (USE_INTERNAL_SERIAL != NO_DESCRIPTOR)\r
                        static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString) ATTR_NON_NULL_PTR_ARG(1);\r
                        static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString)\r
                        {\r
-                               // TODO\r
+                               uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();\r
+                               GlobalInterruptDisable();\r
+                               \r
+                               uint8_t SigReadAddress = INTERNAL_SERIAL_START_ADDRESS;\r
+\r
+                               for (uint8_t SerialCharNum = 0; SerialCharNum < (INTERNAL_SERIAL_LENGTH_BITS / 4); SerialCharNum++)\r
+                               {                                       \r
+                                       uint8_t SerialByte;\r
+\r
+                                       NVM.CMD    = NVM_CMD_READ_CALIB_ROW_gc;\r
+                                       SerialByte = pgm_read_byte(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
+                               SetGlobalInterruptMask(CurrentGlobalInt);\r
+\r
+\r
                        }\r
-                       #endif\r
 \r
        #endif\r
 \r