X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/a7aaa45ec4c3f415bf6073a5cc016635d5ecf77d..9cad677ebbd2fc4ea069f98335f8467b16dbb2cb:/LUFA/Drivers/USB/LowLevel/LowLevel.h diff --git a/LUFA/Drivers/USB/LowLevel/LowLevel.h b/LUFA/Drivers/USB/LowLevel/LowLevel.h index 3c98c6df3..efa605b72 100644 --- a/LUFA/Drivers/USB/LowLevel/LowLevel.h +++ b/LUFA/Drivers/USB/LowLevel/LowLevel.h @@ -28,6 +28,16 @@ this software. */ +/** \file + * \brief USB low level USB controller definitions. + * + * This file contains structures, function prototypes and macros related to the low level configutation of the + * USB controller, to start, stop and reset the USB library core. + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + /** \ingroup Group_USB * @defgroup Group_USBManagement USB Interface Management * @@ -39,33 +49,18 @@ #ifndef __USBLOWLEVEL_H__ #define __USBLOWLEVEL_H__ - /* External Variables: */ - #if defined(__AVR32__) - #if !defined(CONTROL_ONLY_DEVICE) - extern uint8_t USB_SelectedEPNumber; - #else - #define USB_SelectedEPNumber 0 - #endif - #endif - /* Includes: */ - #if defined(__AVR32__) - #include - #include - #include - #elif defined(__AVR__) - #include - #include - #include - #endif - + #include + #include + #include + #include "../HighLevel/USBMode.h" #include "../../../Common/Common.h" #include "../HighLevel/USBMode.h" #include "../HighLevel/Events.h" #include "../HighLevel/USBTask.h" - #include "../HighLevel/USBInterrupt.h" + #include "USBInterrupt.h" #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__) #include "Host.h" @@ -88,45 +83,41 @@ #if !defined(__INCLUDE_FROM_USB_DRIVER) #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif - - #if defined(__AVR32__) - #define USB_PLL_PSC 0 - #elif defined(__AVR__) - #if !defined(F_CLOCK) - #error F_CLOCK is not defined. You must define F_CLOCK to the frequency of the unprescaled input clock in your project makefile. - #endif - - #if (F_CLOCK == 8000000) - #if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \ - defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || \ - defined(__AVR_ATmega32U2__)) - #define USB_PLL_PSC 0 - #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) - #define USB_PLL_PSC 0 - #elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) || defined(__AVR_ATmega32U6__)) - #define USB_PLL_PSC ((1 << PLLP1) | (1 << PLLP0)) - #elif (defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__)) - #define USB_PLL_PSC ((1 << PLLP1) | (1 << PLLP0)) - #endif - #elif (F_CLOCK == 16000000) - #if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \ - defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || \ - defined(__AVR_ATmega32U2__)) - #define USB_PLL_PSC (1 << PLLP0) - #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) - #define USB_PLL_PSC (1 << PINDIV) - #elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_ATmega32U6__)) - #define USB_PLL_PSC ((1 << PLLP2) | (1 << PLLP1)) - #elif (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)) - #define USB_PLL_PSC ((1 << PLLP2) | (1 << PLLP0)) - #endif + + #if !defined(F_CLOCK) + #error F_CLOCK is not defined. You must define F_CLOCK to the frequency of the unprescaled input clock in your project makefile. + #endif + + #if (F_CLOCK == 8000000) + #if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \ + defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || \ + defined(__AVR_ATmega32U2__)) + #define USB_PLL_PSC 0 + #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) + #define USB_PLL_PSC 0 + #elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) || defined(__AVR_ATmega32U6__)) + #define USB_PLL_PSC ((1 << PLLP1) | (1 << PLLP0)) + #elif (defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__)) + #define USB_PLL_PSC ((1 << PLLP1) | (1 << PLLP0)) #endif - - #if !defined(USB_PLL_PSC) - #error No PLL prescale value available for chosen F_CLOCK value and AVR model. + #elif (F_CLOCK == 16000000) + #if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \ + defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || \ + defined(__AVR_ATmega32U2__)) + #define USB_PLL_PSC (1 << PLLP0) + #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) + #define USB_PLL_PSC (1 << PINDIV) + #elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_ATmega32U6__)) + #define USB_PLL_PSC ((1 << PLLP2) | (1 << PLLP1)) + #elif (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)) + #define USB_PLL_PSC ((1 << PLLP2) | (1 << PLLP0)) #endif #endif + #if !defined(USB_PLL_PSC) + #error No PLL prescale value available for chosen F_CPU value and AVR model. + #endif + /* Public Interface - May be used in end-application: */ /* Macros: */ /** Mode mask for the \ref USB_CurrentMode global. This indicates that the USB interface is currently not @@ -151,7 +142,7 @@ * * \note This token is not available on AVR models which do not support both host and device modes. */ - #define USB_MODE_UID 3 + #define USB_MODE_UID 3 #endif /** Regulator disable option mask for \ref USB_Init(). This indicates that the internal 3.3V USB data pad @@ -210,7 +201,7 @@ * * \note This token is not available on some AVR models which do not support hardware VBUS monitoring. */ - #define USB_VBUS_GetStatus() ((USBSTA & (1 << VBUS)) ? true : false) + #define USB_VBUS_GetStatus() ((USBSTA & (1 << VBUS)) ? true : false) #endif /** Detaches the device from the USB bus. This has the effect of removing the device from any @@ -245,8 +236,12 @@ * allow for device connection to a host when in device mode, or for device enumeration while in * host mode. * - * As the USB library relies on USB interrupts for some of its functionality, this routine will - * enable global interrupts. + * As the USB library relies on interrupts for the device and host mode enumeration processes, + * the user must enable global interrupts before or shortly after this function is called. In + * device mode, interrupts must be enabled within 500ms of this function being called to ensure + * that the host does not time out whilst enumerating the device. In host mode, interrupts may be + * enabled at the application's leisure however enumeration will not begin of an attached device + * until after this has occurred. * * Calling this function when the USB interface is already initialized will cause a complete USB * interface reset and re-enumeration. @@ -261,16 +256,18 @@ * mode speed. * * \note To reduce the FLASH requirements of the library if only device or host mode is required, - * this can be statically set via defining the token USB_DEVICE_ONLY for device mode or - * USB_HOST_ONLY for host mode in the use project makefile, passing the token to the compiler + * the mode can be statically set in the project makefile by defining the token USB_DEVICE_ONLY + * (for device mode) or USB_HOST_ONLY (for host mode), passing the token to the compiler * via the -D switch. If the mode is statically set, this parameter does not exist in the * function prototype. + * \n\n * * \note To reduce the FLASH requirements of the library if only fixed settings are are required, * the options may be set statically in the same manner as the mode (see the Mode parameter of * this function). To statically set the USB options, pass in the USE_STATIC_OPTIONS token, * defined to the appropriate options masks. When the options are statically set, this * parameter does not exist in the function prototype. + * \n\n * * \note The mode parameter does not exist on devices where only one mode is possible, such as USB * AVR models which only implement the USB device mode in hardware. @@ -367,22 +364,16 @@ #define USB_Controller_Disable() MACROS{ USBCON &= ~(1 << USBE); }MACROE #define USB_Controller_Reset() MACROS{ const uint8_t Temp = USBCON; USBCON = (Temp & ~(1 << USBE)); \ USBCON = (Temp | (1 << USBE)); }MACROE + /* Inline Functions: */ #if defined(USB_CAN_BE_BOTH) static inline uint8_t USB_GetUSBModeFromUID(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline uint8_t USB_GetUSBModeFromUID(void) { - #if defined(__AVR32__) - if (AVR32_USBB.USBSTA.id) - return USB_MODE_DEVICE; - else - return USB_MODE_HOST; - #elif defined(__AVR__) if (USBSTA & (1 << ID)) return USB_MODE_DEVICE; else return USB_MODE_HOST; - #endif } #endif