+++ /dev/null
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2012.\r
-\r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this\r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in\r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/** \file\r
- * \brief USB Controller definitions for the AVR XMEGA microcontrollers.\r
- * \copydetails Group_USBManagement_XMEGA\r
- *\r
- * \note This file should not be included directly. It is automatically included as needed by the USB driver\r
- * dispatch header located in LUFA/Drivers/USB/USB.h.\r
- */\r
-\r
-/** \ingroup Group_USBManagement\r
- * \defgroup Group_USBManagement_XMEGA USB Interface Management (XMEGA)\r
- * \brief USB Controller definitions for the AVR XMEGA microcontrollers.\r
- *\r
- * Functions, macros, variables, enums and types related to the setup and management of the USB interface.\r
- *\r
- * @{\r
- */\r
-\r
-#ifndef __USBCONTROLLER_XMEGA_H__\r
-#define __USBCONTROLLER_XMEGA_H__\r
-\r
- /* Includes: */\r
- #include "../../../../Common/Common.h"\r
- #include "../USBMode.h"\r
- #include "../Events.h"\r
- #include "../USBTask.h"\r
- #include "../USBInterrupt.h"\r
-\r
- /* Private Interface - For use in library only: */\r
- #if !defined(__DOXYGEN__)\r
- /* Type Defines: */\r
- typedef struct\r
- {\r
- struct\r
- {\r
- USB_EP_t OUT;\r
- USB_EP_t IN;\r
- } Endpoints[16];\r
- uint16_t FrameNum;\r
- } ATTR_PACKED USB_EndpointTable_t;\r
-\r
- /* External Variables: */\r
- extern uint8_t USB_EndpointTable[];\r
-\r
- #endif\r
-\r
- /* Includes: */\r
- #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)\r
- #include "../Device.h"\r
- #include "../Endpoint.h"\r
- #include "../DeviceStandardReq.h"\r
- #include "../EndpointStream.h"\r
- #endif\r
-\r
- /* Enable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- extern "C" {\r
- #endif\r
-\r
- /* Preprocessor Checks and Defines: */\r
- #if !defined(__INCLUDE_FROM_USB_DRIVER)\r
- #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.\r
- #endif\r
-\r
- #if !defined(F_USB)\r
- #error F_USB is not defined. You must define F_USB to the frequency of the unprescaled USB controller clock in your project makefile.\r
- #endif\r
-\r
- #if ((F_USB % 6000000) || (F_USB < 6000000))\r
- #error Invalid F_USB specified. F_USB must be a multiple of 6MHz for USB Low Speed operation, and a multiple of 48MHz for Full Speed operation.\r
- #endif\r
-\r
- /* Public Interface - May be used in end-application: */\r
- /* Macros: */\r
- /** \name USB Controller Option Masks */\r
- //@{\r
- /** Sets the USB bus interrupt priority level to be low priority. The USB bus interrupt is used for Start of Frame events, bus suspend\r
- * and resume events, bus reset events and other events related to the management of the USB bus.\r
- */\r
- #define USB_OPT_BUSEVENT_PRILOW ((0 << 2) | (0 << 1))\r
-\r
- /** Sets the USB bus interrupt priority level to be medium priority. The USB bus interrupt is used for Start of Frame events, bus suspend\r
- * and resume events, bus reset events and other events related to the management of the USB bus.\r
- */\r
- #define USB_OPT_BUSEVENT_PRIMED ((0 << 2) | (1 << 1))\r
-\r
- /** Sets the USB bus interrupt priority level to be high priority. The USB bus interrupt is used for Start of Frame events, bus suspend\r
- * and resume events, bus reset events and other events related to the management of the USB bus.\r
- */\r
- #define USB_OPT_BUSEVENT_PRIHIGH ((1 << 2) | (0 << 1))\r
-\r
- /** Sets the USB controller to source its clock from the internal RC 32MHz clock, once it has been DFLL calibrated to 48MHz. */\r
- #define USB_OPT_RC32MCLKSRC (0 << 3)\r
-\r
- /** Sets the USB controller to source its clock from the internal PLL. */\r
- #define USB_OPT_PLLCLKSRC (1 << 3)\r
- //@}\r
-\r
- #if !defined(USB_STREAM_TIMEOUT_MS) || defined(__DOXYGEN__)\r
- /** Constant for the maximum software timeout period of the USB data stream transfer functions\r
- * (both control and standard) when in either device or host mode. If the next packet of a stream\r
- * is not received or acknowledged within this time period, the stream function will fail.\r
- *\r
- * This value may be overridden in the user project makefile as the value of the\r
- * \ref USB_STREAM_TIMEOUT_MS token, and passed to the compiler using the -D switch.\r
- */\r
- #define USB_STREAM_TIMEOUT_MS 100\r
- #endif\r
-\r
- /* Inline Functions: */\r
- /** Detaches the device from the USB bus. This has the effect of removing the device from any\r
- * attached host, ceasing USB communications. If no host is present, this prevents any host from\r
- * enumerating the device once attached until \ref USB_Attach() is called.\r
- */\r
- static inline void USB_Detach(void) ATTR_ALWAYS_INLINE;\r
- static inline void USB_Detach(void)\r
- {\r
- USB.CTRLB &= ~USB_ATTACH_bm;\r
- }\r
-\r
- /** Attaches the device to the USB bus. This announces the device's presence to any attached\r
- * USB host, starting the enumeration process. If no host is present, attaching the device\r
- * will allow for enumeration once a host is connected to the device.\r
- *\r
- * This is inexplicably also required for proper operation while in host mode, to enable the\r
- * attachment of a device to the host. This is despite the bit being located in the device-mode\r
- * register and despite the datasheet making no mention of its requirement in host mode.\r
- */\r
- static inline void USB_Attach(void) ATTR_ALWAYS_INLINE;\r
- static inline void USB_Attach(void)\r
- {\r
- USB.CTRLB |= USB_ATTACH_bm;\r
- }\r
-\r
- /* Function Prototypes: */\r
- /** Main function to initialize and start the USB interface. Once active, the USB interface will\r
- * allow for device connection to a host when in device mode, or for device enumeration while in\r
- * host mode.\r
- *\r
- * As the USB library relies on interrupts for the device and host mode enumeration processes,\r
- * the user must enable global interrupts before or shortly after this function is called. In\r
- * device mode, interrupts must be enabled within 500ms of this function being called to ensure\r
- * that the host does not time out whilst enumerating the device. In host mode, interrupts may be\r
- * enabled at the application's leisure however enumeration will not begin of an attached device\r
- * until after this has occurred.\r
- *\r
- * Calling this function when the USB interface is already initialized will cause a complete USB\r
- * interface reset and re-enumeration.\r
- *\r
- * \param[in] Mode This is a mask indicating what mode the USB interface is to be initialized to, a value\r
- * from the \ref USB_Modes_t enum.\r
- *\r
- * \param[in] Options Mask indicating the options which should be used when initializing the USB\r
- * interface to control the USB interface's behavior. This should be comprised of\r
- * a \c USB_OPT_REG_* mask to control the regulator, a \c USB_OPT_*_PLL mask to control the\r
- * PLL, and a \c USB_DEVICE_OPT_* mask (when the device mode is enabled) to set the device\r
- * mode speed.\r
- *\r
- * \note To reduce the FLASH requirements of the library if only device or host mode is required,\r
- * the mode can be statically set in the project makefile by defining the token \c USB_DEVICE_ONLY\r
- * (for device mode) or \c USB_HOST_ONLY (for host mode), passing the token to the compiler\r
- * via the -D switch. If the mode is statically set, this parameter does not exist in the\r
- * function prototype.\r
- * \n\n\r
- *\r
- * \note To reduce the FLASH requirements of the library if only fixed settings are required,\r
- * the options may be set statically in the same manner as the mode (see the Mode parameter of\r
- * this function). To statically set the USB options, pass in the \c USE_STATIC_OPTIONS token,\r
- * defined to the appropriate options masks. When the options are statically set, this\r
- * parameter does not exist in the function prototype.\r
- * \n\n\r
- *\r
- * \note The mode parameter does not exist on devices where only one mode is possible, such as USB\r
- * AVR models which only implement the USB device mode in hardware.\r
- *\r
- * \see \ref Group_Device for the \c USB_DEVICE_OPT_* masks.\r
- */\r
- void USB_Init(\r
- #if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__)\r
- const uint8_t Mode\r
- #endif\r
-\r
- #if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS)) || defined(__DOXYGEN__)\r
- ,\r
- #elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS))\r
- void\r
- #endif\r
-\r
- #if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__)\r
- const uint8_t Options\r
- #endif\r
- );\r
-\r
- /** Shuts down the USB interface. This turns off the USB interface after deallocating all USB FIFO\r
- * memory, endpoints and pipes. When turned off, no USB functionality can be used until the interface\r
- * is restarted with the \ref USB_Init() function.\r
- */\r
- void USB_Disable(void);\r
-\r
- /** Resets the interface, when already initialized. This will re-enumerate the device if already connected\r
- * to a host, or re-enumerate an already attached device when in host mode.\r
- */\r
- void USB_ResetInterface(void);\r
-\r
- /* Global Variables: */\r
- #if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY)) || defined(__DOXYGEN__)\r
- /** Indicates the mode that the USB interface is currently initialized to, a value from the\r
- * \ref USB_Modes_t enum.\r
- *\r
- * \attention This variable should be treated as read-only in the user application, and never manually\r
- * changed in value.\r
- *\r
- * \note When the controller is initialized into UID auto-detection mode, this variable will hold the\r
- * currently selected USB mode (i.e. \ref USB_MODE_Device or \ref USB_MODE_Host). If the controller\r
- * is fixed into a specific mode (either through the \c USB_DEVICE_ONLY or \c USB_HOST_ONLY compile time\r
- * options, or a limitation of the USB controller in the chosen device model) this will evaluate to\r
- * a constant of the appropriate value and will never evaluate to \ref USB_MODE_None even when the\r
- * USB interface is not initialized.\r
- */\r
- extern volatile uint8_t USB_CurrentMode;\r
- #elif defined(USB_DEVICE_ONLY)\r
- #define USB_CurrentMode USB_MODE_Device\r
- #endif\r
-\r
- #if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__)\r
- /** Indicates the current USB options that the USB interface was initialized with when \ref USB_Init()\r
- * was called. This value will be one of the \c USB_MODE_* masks defined elsewhere in this module.\r
- *\r
- * \attention This variable should be treated as read-only in the user application, and never manually\r
- * changed in value.\r
- */\r
- extern volatile uint8_t USB_Options;\r
- #elif defined(USE_STATIC_OPTIONS)\r
- #define USB_Options USE_STATIC_OPTIONS\r
- #endif\r
-\r
- /* Enums: */\r
- /** Enum for the possible USB controller modes, for initialization via \ref USB_Init() and indication back to the\r
- * user application via \ref USB_CurrentMode.\r
- */\r
- enum USB_Modes_t\r
- {\r
- USB_MODE_None = 0, /**< Indicates that the controller is currently not initialized in any specific USB mode. */\r
- USB_MODE_Device = 1, /**< Indicates that the controller is currently initialized in USB Device mode. */\r
- };\r
-\r
- /* Private Interface - For use in library only: */\r
- #if !defined(__DOXYGEN__)\r
- /* Function Prototypes: */\r
- #if defined(__INCLUDE_FROM_USB_CONTROLLER_C)\r
- static void USB_Init_Device(void);\r
- #endif\r
-\r
- /* Inline Functions: */\r
- static inline void USB_Controller_Enable(void) ATTR_ALWAYS_INLINE;\r
- static inline void USB_Controller_Enable(void)\r
- {\r
- USB.CTRLA |= USB_ENABLE_bm;\r
- }\r
-\r
- static inline void USB_Controller_Disable(void) ATTR_ALWAYS_INLINE;\r
- static inline void USB_Controller_Disable(void)\r
- {\r
- USB.CTRLA &= ~USB_ENABLE_bm;\r
- }\r
-\r
- static inline void USB_Controller_Reset(void) ATTR_ALWAYS_INLINE;\r
- static inline void USB_Controller_Reset(void)\r
- {\r
- USB.CTRLA &= ~USB_ENABLE_bm;\r
- USB.CTRLA |= USB_ENABLE_bm;\r
- }\r
-\r
- #endif\r
-\r
- /* Disable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- }\r
- #endif\r
-\r
-#endif\r
-\r
-/** @} */\r
-\r