Add high speed USB support for the UC3 devices containing a high speed USB controller.
authorDean Camera <dean@fourwalledcubicle.com>
Thu, 14 Jul 2011 02:58:07 +0000 (02:58 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Thu, 14 Jul 2011 02:58:07 +0000 (02:58 +0000)
Add device support preprocessor checks and use symbolic bit names in the UC3 platform clock management driver.

LUFA/Drivers/USB/Core/AVR8/Device_AVR8.h
LUFA/Drivers/USB/Core/UC3/Device_UC3.h
LUFA/Drivers/USB/Core/UC3/USBController_UC3.c
LUFA/Drivers/USB/Core/UC3/USBController_UC3.h
LUFA/Platform/UC3/ClockManagement.h

index 39b4cf7..08604ac 100644 (file)
@@ -50,6 +50,7 @@
 
        /* Includes: */
                #include "../../../../Common/Common.h"
+               #include "../USBController.h"
                #include "../StdDescriptors.h"
                #include "../USBInterrupt.h"
                #include "../Endpoint.h"
                        }
 
                        #if !defined(NO_SOF_EVENTS)
-                       /** Enables the device mode Start Of Frame events. When enabled, this causes the
-                        *  \ref EVENT_USB_Device_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,
-                        *  at the start of each USB frame when enumerated in device mode.
-                        *
-                        *  \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
-                        */
-                       static inline void USB_Device_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;
-                       static inline void USB_Device_EnableSOFEvents(void)
-                       {
-                               USB_INT_Enable(USB_INT_SOFI);
-                       }
+                               /** Enables the device mode Start Of Frame events. When enabled, this causes the
+                                *  \ref EVENT_USB_Device_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,
+                                *  at the start of each USB frame when enumerated in device mode.
+                                *
+                                *  \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
+                                */
+                               static inline void USB_Device_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;
+                               static inline void USB_Device_EnableSOFEvents(void)
+                               {
+                                       USB_INT_Enable(USB_INT_SOFI);
+                               }
 
-                       /** Disables the device mode Start Of Frame events. When disabled, this stops the firing of the
-                        *  \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode.
-                        *
-                        *  \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
-                        */
-                       static inline void USB_Device_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;
-                       static inline void USB_Device_DisableSOFEvents(void)
-                       {
-                               USB_INT_Disable(USB_INT_SOFI);
-                       }
+                               /** Disables the device mode Start Of Frame events. When disabled, this stops the firing of the
+                                *  \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode.
+                                *
+                                *  \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
+                                */
+                               static inline void USB_Device_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;
+                               static inline void USB_Device_DisableSOFEvents(void)
+                               {
+                                       USB_INT_Disable(USB_INT_SOFI);
+                               }
                        #endif
 
        /* Private Interface - For use in library only: */
        #if !defined(__DOXYGEN__)
                /* Inline Functions: */
-                       #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
+                       #if defined(USB_DEVICE_OPT_LOWSPEED)
                        static inline void USB_Device_SetLowSpeed(void) ATTR_ALWAYS_INLINE;
                        static inline void USB_Device_SetLowSpeed(void)
                        {
index 55e4b0c..9b324ab 100644 (file)
@@ -50,6 +50,7 @@
 \r
        /* Includes: */\r
                #include "../../../../Common/Common.h"\r
+               #include "../USBController.h"\r
                #include "../StdDescriptors.h"\r
                #include "../USBInterrupt.h"\r
                #include "../Endpoint.h"\r
                         *  USB interface should be initialized in full speed (12Mb/s) mode.\r
                         */\r
                        #define USB_DEVICE_OPT_FULLSPEED               (0 << 0)\r
+                       \r
+                       #if defined(USB_SERIES_UC3A3_AVR32) || defined(USB_SERIES_UC3A4_AVR32) || defined(__DOXYGEN__)\r
+                               /** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the\r
+                                *  USB interface should be initialized in high speed (480Mb/s) mode.\r
+                                */\r
+                               #define USB_DEVICE_OPT_HIGHSPEED           (1 << 1)                     \r
+                       #endif\r
                        //@}\r
                        \r
                        #if (!defined(NO_INTERNAL_SERIAL) && \\r
                        }\r
 \r
                        #if !defined(NO_SOF_EVENTS)\r
-                       /** Enables the device mode Start Of Frame events. When enabled, this causes the\r
-                        *  \ref EVENT_USB_Device_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,\r
-                        *  at the start of each USB frame when enumerated in device mode.\r
-                        *\r
-                        *  \note Not available when the \c NO_SOF_EVENTS compile time token is defined.\r
-                        */\r
-                       static inline void USB_Device_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;\r
-                       static inline void USB_Device_EnableSOFEvents(void)\r
-                       {\r
-                               USB_INT_Enable(USB_INT_SOFI);\r
-                       }\r
+                               /** Enables the device mode Start Of Frame events. When enabled, this causes the\r
+                                *  \ref EVENT_USB_Device_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,\r
+                                *  at the start of each USB frame when enumerated in device mode.\r
+                                *\r
+                                *  \note Not available when the \c NO_SOF_EVENTS compile time token is defined.\r
+                                */\r
+                               static inline void USB_Device_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;\r
+                               static inline void USB_Device_EnableSOFEvents(void)\r
+                               {\r
+                                       USB_INT_Enable(USB_INT_SOFI);\r
+                               }\r
 \r
-                       /** Disables the device mode Start Of Frame events. When disabled, this stops the firing of the\r
-                        *  \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode.\r
-                        *\r
-                        *  \note Not available when the \c NO_SOF_EVENTS compile time token is defined.\r
-                        */\r
-                       static inline void USB_Device_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;\r
-                       static inline void USB_Device_DisableSOFEvents(void)\r
-                       {\r
-                               USB_INT_Disable(USB_INT_SOFI);\r
-                       }\r
+                               /** Disables the device mode Start Of Frame events. When disabled, this stops the firing of the\r
+                                *  \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode.\r
+                                *\r
+                                *  \note Not available when the \c NO_SOF_EVENTS compile time token is defined.\r
+                                */\r
+                               static inline void USB_Device_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;\r
+                               static inline void USB_Device_DisableSOFEvents(void)\r
+                               {\r
+                                       USB_INT_Disable(USB_INT_SOFI);\r
+                               }\r
                        #endif\r
 \r
        /* Private Interface - For use in library only: */\r
                        static inline void USB_Device_SetLowSpeed(void) ATTR_ALWAYS_INLINE;\r
                        static inline void USB_Device_SetLowSpeed(void)\r
                        {\r
-                               AVR32_USBB.UDCON.ls = true;\r
+                               AVR32_USBB.UDCON.ls      = true;\r
                        }\r
 \r
                        static inline void USB_Device_SetFullSpeed(void) ATTR_ALWAYS_INLINE;\r
                        static inline void USB_Device_SetFullSpeed(void)\r
                        {\r
-                               AVR32_USBB.UDCON.ls = false;\r
+                               AVR32_USBB.UDCON.ls      = false;\r
+                               #if defined(USB_DEVICE_OPT_HIGHSPEED)\r
+                               AVR32_USBB.UDCON.spdconf = 3;\r
+                               #endif\r
                        }\r
 \r
+                       #if defined(USB_DEVICE_OPT_HIGHSPEED)\r
+                       static inline void USB_Device_SetHighSpeed(void) ATTR_ALWAYS_INLINE;\r
+                       static inline void USB_Device_SetHighSpeed(void)\r
+                       {\r
+                               AVR32_USBB.UDCON.ls      = false;\r
+                               AVR32_USBB.UDCON.spdconf = 0;\r
+                       }\r
+                       #endif\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
index 7cfa28e..1472dd6 100644 (file)
@@ -166,9 +166,20 @@ static void USB_Init_Device(void)
        #endif\r
 \r
        if (USB_Options & USB_DEVICE_OPT_LOWSPEED)\r
-         USB_Device_SetLowSpeed();\r
+       {\r
+               USB_Device_SetLowSpeed();\r
+       }\r
        else\r
-         USB_Device_SetFullSpeed();\r
+       {\r
+               #if defined(USB_DEVICE_OPT_HIGHSPEED)\r
+               if (USB_Options & USB_DEVICE_OPT_HIGHSPEED)     \r
+                 USB_Device_SetHighSpeed();\r
+               else\r
+                 USB_Device_SetFullSpeed();\r
+               #else\r
+               USB_Device_SetFullSpeed();\r
+               #endif          \r
+       }\r
 \r
        USB_INT_Enable(USB_INT_VBUSTI);\r
 \r
index eaff222..0bad549 100644 (file)
                         *  generation module. This indicates that an external oscillator should be used directly instead of an\r
                         *  internal PLL clock source.\r
                         */\r
-                       #define USB_OPT_GCLK_SRC_OSC               (1 << 1)\r
+                       #define USB_OPT_GCLK_SRC_OSC               (1 << 2)\r
 \r
                        /** Selects one of the system's PLL oscillators as the input clock to the USB Generic Clock source\r
                         *  generation module. This indicates that one of the device's PLL outputs should be used instead of an\r
                         *  external oscillator source.\r
                         */\r
-                       #define USB_OPT_GCLK_SRC_PLL               (0 << 1)\r
+                       #define USB_OPT_GCLK_SRC_PLL               (0 << 2)\r
 \r
                        /** Selects PLL or External Oscillator 0 as the USB Generic Clock source module input clock. */\r
-                       #define USB_OPT_GCLK_CHANNEL_0             (1 << 2)\r
+                       #define USB_OPT_GCLK_CHANNEL_0             (1 << 3)\r
 \r
                        /** Selects PLL or External Oscillator 1 as the USB Generic Clock source module input clock. */\r
-                       #define USB_OPT_GCLK_CHANNEL_1             (0 << 2)\r
+                       #define USB_OPT_GCLK_CHANNEL_1             (0 << 3)\r
                        //@}\r
 \r
                        /** \name Endpoint/Pipe Type Masks */\r
index 60a3d18..6087020 100644 (file)
                                switch (Source)\r
                                {\r
                                        case CLOCK_SRC_OSC0:\r
-                                               AVR32_PM.GCCTRL[Channel].pllsel = 0;\r
+                                               AVR32_PM.GCCTRL[Channel].pllsel = false;\r
                                                AVR32_PM.GCCTRL[Channel].oscsel = 0;\r
                                                break;\r
                                        case CLOCK_SRC_OSC1:\r
-                                               AVR32_PM.GCCTRL[Channel].pllsel = 0;\r
+                                               AVR32_PM.GCCTRL[Channel].pllsel = false;\r
                                                AVR32_PM.GCCTRL[Channel].oscsel = 1;\r
                                                break;\r
                                        case CLOCK_SRC_PLL0:\r
-                                               AVR32_PM.GCCTRL[Channel].pllsel = 1;\r
+                                               AVR32_PM.GCCTRL[Channel].pllsel = true;\r
                                                AVR32_PM.GCCTRL[Channel].oscsel = 0;\r
                                                break;\r
                                        case CLOCK_SRC_PLL1:\r
-                                               AVR32_PM.GCCTRL[Channel].pllsel = 1;\r
+                                               AVR32_PM.GCCTRL[Channel].pllsel = true;\r
                                                AVR32_PM.GCCTRL[Channel].oscsel = 1;\r
                                                break;\r
                                        default:\r
 \r
                                switch (Source)\r
                                {\r
+                                       #if defined(AVR32_PM_MCCTRL_MCSEL_SLOW)\r
                                        case CLOCK_SRC_SLOW_CLK:\r
-                                               AVR32_PM.MCCTRL.mcsel = 0;\r
+                                               AVR32_PM.MCCTRL.mcsel = AVR32_PM_MCCTRL_MCSEL_SLOW;\r
                                                break;\r
+                                       #endif\r
+                                       #if defined(AVR32_PM_MCCTRL_MCSEL_OSC0)\r
                                        case CLOCK_SRC_OSC0:\r
-                                               AVR32_PM.MCCTRL.mcsel = 1;\r
+                                               AVR32_PM.MCCTRL.mcsel = AVR32_PM_MCCTRL_MCSEL_OSC0;\r
                                                break;\r
+                                       #endif\r
+                                       #if defined(AVR32_PM_MCCTRL_MCSEL_PLL0)\r
                                        case CLOCK_SRC_PLL0:\r
-                                               AVR32_PM.MCCTRL.mcsel = 2;\r
+                                               AVR32_PM.MCCTRL.mcsel = AVR32_PM_MCCTRL_MCSEL_PLL0;\r
                                                break;\r
+                                       #endif\r
                                        default:\r
                                                return false;\r
                                }\r