aboutsummaryrefslogtreecommitdiffstats
path: root/LUFA/Drivers/USB/Core/UC3
diff options
context:
space:
mode:
Diffstat (limited to 'LUFA/Drivers/USB/Core/UC3')
-rw-r--r--LUFA/Drivers/USB/Core/UC3/Device_UC3.c47
-rw-r--r--LUFA/Drivers/USB/Core/UC3/Device_UC3.h179
-rw-r--r--LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.c141
-rw-r--r--LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.h839
-rw-r--r--LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c144
-rw-r--r--LUFA/Drivers/USB/Core/UC3/Pipe_UC3.h915
-rw-r--r--LUFA/Drivers/USB/Core/UC3/USBController_UC3.c203
-rw-r--r--LUFA/Drivers/USB/Core/UC3/USBController_UC3.h379
-rw-r--r--LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c204
-rw-r--r--LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.h344
10 files changed, 3395 insertions, 0 deletions
diff --git a/LUFA/Drivers/USB/Core/UC3/Device_UC3.c b/LUFA/Drivers/USB/Core/UC3/Device_UC3.c
new file mode 100644
index 000000000..c6b41a81c
--- /dev/null
+++ b/LUFA/Drivers/USB/Core/UC3/Device_UC3.c
@@ -0,0 +1,47 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2011.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+#define __INCLUDE_FROM_USB_DRIVER
+#include "../USBMode.h"
+
+#if defined(USB_CAN_BE_DEVICE)
+
+#include "../Device.h"
+
+void USB_Device_SendRemoteWakeup(void)
+{
+ USB_CLK_Unfreeze();
+
+ AVR32_USBB.UDCON.rmwkup = true;
+ while (AVR32_USBB.UDCON.rmwkup);
+}
+
+#endif
+
diff --git a/LUFA/Drivers/USB/Core/UC3/Device_UC3.h b/LUFA/Drivers/USB/Core/UC3/Device_UC3.h
new file mode 100644
index 000000000..653044f38
--- /dev/null
+++ b/LUFA/Drivers/USB/Core/UC3/Device_UC3.h
@@ -0,0 +1,179 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2011.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ * \brief USB Device definitions for the AVR32 UC3 microcontrollers.
+ * \copydetails Group_Device_UC3
+ *
+ * \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_Device
+ * \defgroup Group_Device_UC3 Device Management (UC3)
+ * \brief USB Device definitions for the AVR32 UC3 microcontrollers.
+ *
+ * Architecture specific USB Device definitions for the Atmel 32-bit UC3 AVR microcontrollers.
+ *
+ * @{
+ */
+
+#ifndef __USBDEVICE_UC3_H__
+#define __USBDEVICE_UC3_H__
+
+ /* Includes: */
+ #include "../../../../Common/Common.h"
+ #include "../StdDescriptors.h"
+ #include "../USBInterrupt.h"
+ #include "../Endpoint.h"
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_USB_DRIVER)
+ #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Macros: */
+ /** \name USB Device Mode Option Masks */
+ //@{
+ /** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
+ * USB interface should be initialized in low speed (1.5Mb/s) mode.
+ *
+ * \note Restrictions apply on the number, size and type of endpoints which can be used
+ * when running in low speed mode - refer to the USB 2.0 specification.
+ */
+ #define USB_DEVICE_OPT_LOWSPEED (1 << 0)
+
+ /** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
+ * USB interface should be initialized in full speed (12Mb/s) mode.
+ */
+ #define USB_DEVICE_OPT_FULLSPEED (0 << 0)
+ //@}
+
+ /** 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
+ * a unique serial number internally, and setting the device descriptors serial number string index to this value
+ * will cause it to use the internal serial number.
+ *
+ * On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial
+ * number for the device.
+ */
+ #define USE_INTERNAL_SERIAL NO_DESCRIPTOR
+
+ /* Function Prototypes: */
+ /** Sends a Remote Wakeup request to the host. This signals to the host that the device should
+ * be taken out of suspended mode, and communications should resume.
+ *
+ * Typically, this is implemented so that HID devices (mice, keyboards, etc.) can wake up the
+ * host computer when the host has suspended all USB devices to enter a low power state.
+ *
+ * \note This macro should only be used if the device has indicated to the host that it
+ * supports the Remote Wakeup feature in the device descriptors, and should only be
+ * issued if the host is currently allowing remote wakeup events from the device (i.e.,
+ * the \ref USB_RemoteWakeupEnabled flag is set). When the \c NO_DEVICE_REMOTE_WAKEUP compile
+ * time option is used, this macro is unavailable.
+ * \n\n
+ *
+ * \note The USB clock must be running for this function to operate. If the stack is initialized with
+ * the \ref USB_OPT_MANUAL_PLL option enabled, the user must ensure that the PLL is running
+ * before attempting to call this function.
+ *
+ * \see \ref Group_StdDescriptors for more information on the RMWAKEUP feature and device descriptors.
+ */
+ void USB_Device_SendRemoteWakeup(void);
+
+ /* Inline Functions: */
+ /** Returns the current USB frame number, when in device mode. Every millisecond the USB bus is active (i.e. enumerated to a host)
+ * the frame number is incremented by one.
+ */
+ static inline uint16_t USB_Device_GetFrameNumber(void)
+ {
+ return AVR32_USBB.UDFNUM.fnum;
+ }
+
+ #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);
+ }
+
+ /** 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: */
+ static inline void USB_Device_SetLowSpeed(void) ATTR_ALWAYS_INLINE;
+ static inline void USB_Device_SetLowSpeed(void)
+ {
+ AVR32_USBB.UDCON.ls = true;
+ }
+
+ static inline void USB_Device_SetFullSpeed(void) ATTR_ALWAYS_INLINE;
+ static inline void USB_Device_SetFullSpeed(void)
+ {
+ AVR32_USBB.UDCON.ls = false;
+ }
+
+ static inline void USB_Device_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE;
+ static inline void USB_Device_SetDeviceAddress(const uint8_t Address)
+ {
+ AVR32_USBB.UDCON.uadd = Address;
+ AVR32_USBB.UDCON.adden = true;
+ }
+
+ static inline bool USB_Device_IsAddressSet(void) ATTR_ALWAYS_INLINE;
+ static inline bool USB_Device_IsAddressSet(void)
+ {
+ return AVR32_USBB.UDCON.adden;
+ }
+ #endif
+
+#endif
+
+/** @} */
+
diff --git a/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.c b/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.c
new file mode 100644
index 000000000..14f66d922
--- /dev/null
+++ b/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.c
@@ -0,0 +1,141 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2011.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+#define __INCLUDE_FROM_USB_DRIVER
+#include "../USBMode.h"
+
+#if defined(USB_CAN_BE_DEVICE)
+
+#include "../Endpoint.h"
+
+#if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
+uint8_t USB_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE;
+#endif
+
+volatile uint8_t USB_SelectedEndpoint = ENDPOINT_CONTROLEP;
+volatile uint8_t* USB_EndpointFIFOPos[ENDPOINT_TOTAL_ENDPOINTS];
+
+bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
+ const uint32_t UECFG0Data)
+{
+ Endpoint_SelectEndpoint(Number);
+ Endpoint_EnableEndpoint();
+
+ (&AVR32_USBB.uecfg0)[Number] = 0;
+ (&AVR32_USBB.uecfg0)[Number] = UECFG0Data;
+ USB_EndpointFIFOPos[Number] = &AVR32_USBB_SLAVE[Number * 0x10000];
+
+ return Endpoint_IsConfigured();
+}
+
+void Endpoint_ClearEndpoints(void)
+{
+ for (uint8_t EPNum = 0; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++)
+ {
+ Endpoint_SelectEndpoint(EPNum);
+ (&AVR32_USBB.uecfg0)[EPNum] = 0;
+ (&AVR32_USBB.uecon0clr)[EPNum] = 0xFFFFFFFF;
+ USB_EndpointFIFOPos[EPNum] = &AVR32_USBB_SLAVE[EPNum * 0x10000];
+ Endpoint_DisableEndpoint();
+ }
+}
+
+void Endpoint_ClearStatusStage(void)
+{
+ if (USB_ControlRequest.bmRequestType & REQDIR_DEVICETOHOST)
+ {
+ while (!(Endpoint_IsOUTReceived()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
+
+ Endpoint_ClearOUT();
+ }
+ else
+ {
+ while (!(Endpoint_IsINReady()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
+
+ Endpoint_ClearIN();
+ }
+}
+
+#if !defined(CONTROL_ONLY_DEVICE)
+uint8_t Endpoint_WaitUntilReady(void)
+{
+ #if (USB_STREAM_TIMEOUT_MS < 0xFF)
+ uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
+ #else
+ uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
+ #endif
+
+ uint16_t PreviousFrameNumber = USB_Device_GetFrameNumber();
+
+ for (;;)
+ {
+ if (Endpoint_GetEndpointDirection() == ENDPOINT_DIR_IN)
+ {
+ if (Endpoint_IsINReady())
+ return ENDPOINT_READYWAIT_NoError;
+ }
+ else
+ {
+ if (Endpoint_IsOUTReceived())
+ return ENDPOINT_READYWAIT_NoError;
+ }
+
+ uint8_t USB_DeviceState_LCL = USB_DeviceState;
+
+ if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
+ return ENDPOINT_READYWAIT_DeviceDisconnected;
+ else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
+ return ENDPOINT_READYWAIT_BusSuspended;
+ else if (Endpoint_IsStalled())
+ return ENDPOINT_READYWAIT_EndpointStalled;
+
+ uint16_t CurrentFrameNumber = USB_Device_GetFrameNumber();
+
+ if (CurrentFrameNumber != PreviousFrameNumber)
+ {
+ PreviousFrameNumber = CurrentFrameNumber;
+
+ if (!(TimeoutMSRem--))
+ return ENDPOINT_READYWAIT_Timeout;
+ }
+ }
+}
+#endif
+
+#endif
+
diff --git a/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.h b/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.h
new file mode 100644
index 000000000..38f68834e
--- /dev/null
+++ b/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.h
@@ -0,0 +1,839 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2011.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ * \brief USB Endpoint definitions for the AVR32 UC3 microcontrollers.
+ * \copydetails Group_EndpointManagement_UC3
+ *
+ * \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_EndpointRW
+ * \defgroup Group_EndpointRW_UC3 Endpoint Data Reading and Writing (UC3)
+ * \brief Endpoint data read/write definitions for the Atmel AVR32 UC3 architecture.
+ *
+ * Functions, macros, variables, enums and types related to data reading and writing from and to endpoints.
+ */
+
+/** \ingroup Group_EndpointPrimitiveRW
+ * \defgroup Group_EndpointPrimitiveRW_UC3 Read/Write of Primitive Data Types (UC3)
+ * \brief Endpoint primative read/write definitions for the Atmel AVR32 UC3 architecture.
+ *
+ * Functions, macros, variables, enums and types related to data reading and writing of primitive data types
+ * from and to endpoints.
+ */
+
+/** \ingroup Group_EndpointPacketManagement
+ * \defgroup Group_EndpointPacketManagement_UC3 Endpoint Packet Management (UC3)
+ * \brief Endpoint packet management definitions for the Atmel AVR32 UC3 architecture.
+ *
+ * Functions, macros, variables, enums and types related to packet management of endpoints.
+ */
+
+/** \ingroup Group_EndpointManagement
+ * \defgroup Group_EndpointManagement_UC3 Endpoint Management (UC3)
+ * \brief Endpoint management definitions for the Atmel AVR32 UC3 architecture.
+ *
+ * Functions, macros and enums related to endpoint management when in USB Device mode. This
+ * module contains the endpoint management macros, as well as endpoint interrupt and data
+ * send/receive functions for various data types.
+ *
+ * @{
+ */
+
+#ifndef __ENDPOINT_UC3_H__
+#define __ENDPOINT_UC3_H__
+
+ /* Includes: */
+ #include "../../../../Common/Common.h"
+ #include "../USBTask.h"
+ #include "../USBInterrupt.h"
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_USB_DRIVER)
+ #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
+ #endif
+
+ /* Private Interface - For use in library only: */
+ #if !defined(__DOXYGEN__)
+ /* Macros: */
+ #define _ENDPOINT_GET_MAXSIZE(EPIndex) _ENDPOINT_GET_MAXSIZE2(ENDPOINT_DETAILS_EP ## EPIndex)
+ #define _ENDPOINT_GET_MAXSIZE2(EPDetails) _ENDPOINT_GET_MAXSIZE3(EPDetails)
+ #define _ENDPOINT_GET_MAXSIZE3(MaxSize, Banks) (MaxSize)
+
+ #define _ENDPOINT_GET_BANKS(EPIndex) _ENDPOINT_GET_BANKS2(ENDPOINT_DETAILS_EP ## EPIndex)
+ #define _ENDPOINT_GET_BANKS2(EPDetails) _ENDPOINT_GET_BANKS3(EPDetails)
+ #define _ENDPOINT_GET_BANKS3(MaxSize, Banks) (Banks)
+
+ #define ENDPOINT_DETAILS_MAXEP 7
+
+ #define ENDPOINT_DETAILS_EP0 64, 1
+ #define ENDPOINT_DETAILS_EP1 64, 2
+ #define ENDPOINT_DETAILS_EP2 64, 2
+ #define ENDPOINT_DETAILS_EP3 64, 2
+ #define ENDPOINT_DETAILS_EP4 64, 2
+ #define ENDPOINT_DETAILS_EP5 256, 2
+ #define ENDPOINT_DETAILS_EP6 256, 2
+
+ /* Inline Functions: */
+ static inline uint32_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST
+ ATTR_ALWAYS_INLINE;
+ static inline uint32_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes)
+ {
+ uint8_t MaskVal = 0;
+ uint16_t CheckBytes = 8;
+
+ while (CheckBytes < Bytes)
+ {
+ MaskVal++;
+ CheckBytes <<= 1;
+ }
+
+ return (MaskVal << AVR32_USBB_EPSIZE_OFFSET);
+ }
+
+ /* Function Prototypes: */
+ void Endpoint_ClearEndpoints(void);
+ bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
+ const uint32_t UECFGXData);
+
+ /* External Variables: */
+ extern volatile uint8_t USB_SelectedEndpoint;
+ extern volatile uint8_t* USB_EndpointFIFOPos[];
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Macros: */
+ /** \name Endpoint Direction Masks */
+ //@{
+ /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
+ * should be initialized in the OUT direction - i.e. data flows from host to device.
+ */
+ #define ENDPOINT_DIR_OUT AVR32_USBB_UECFG0_EPDIR_OUT
+
+ /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
+ * should be initialized in the IN direction - i.e. data flows from device to host.
+ */
+ #define ENDPOINT_DIR_IN AVR32_USBB_UECFG0_EPDIR_IN
+ //@}
+
+ /** \name Endpoint Bank Mode Masks */
+ //@{
+ /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
+ * that the endpoint should have one single bank, which requires less USB FIFO memory but results
+ * in slower transfers as only one USB device (the AVR or the host) can access the endpoint's
+ * bank at the one time.
+ */
+ #define ENDPOINT_BANK_SINGLE AVR32_USBB_UECFG0_EPBK_SINGLE
+
+ /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
+ * that the endpoint should have two banks, which requires more USB FIFO memory but results
+ * in faster transfers as one USB device (the AVR or the host) can access one bank while the other
+ * accesses the second bank.
+ */
+ #define ENDPOINT_BANK_DOUBLE AVR32_USBB_UECFG0_EPBK_DOUBLE
+ //@}
+
+ #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
+ /** Default size of the default control endpoint's bank, until altered by the control endpoint bank size
+ * value in the device descriptor. Not available if the \c FIXED_CONTROL_ENDPOINT_SIZE token is defined.
+ */
+ #define ENDPOINT_CONTROLEP_DEFAULT_SIZE 8
+ #endif
+
+ /** Retrives the maximum bank size in bytes of a given endpoint.
+ *
+ * \note This macro will only work correctly on endpoint indexes that are compile-time constants
+ * defined by the preprocessor.
+ *
+ * \param[in] EPIndex Endpoint number, a value between 0 and (\ref ENDPOINT_TOTAL_ENDPOINTS - 1)
+ */
+ #define ENDPOINT_MAX_SIZE(EPIndex) _ENDPOINT_GET_MAXSIZE(EPIndex)
+
+ /** Retrieves the total number of banks supported by the given endpoint.
+ *
+ * \note This macro will only work correctly on endpoint indexes that are compile-time constants
+ * defined by the preprocessor.
+ *
+ * \param[in] EPIndex Endpoint number, a value between 0 and (\ref ENDPOINT_TOTAL_ENDPOINTS - 1)
+ */
+ #define ENDPOINT_BANKS_SUPPORTED(EPIndex) _ENDPOINT_GET_BANKS(EPIndex)
+
+ #if !defined(CONTROL_ONLY_DEVICE) || defined(__DOXYGEN__)
+ /** Total number of endpoints (including the default control endpoint at address 0) which may
+ * be used in the device. Different AVR models support different amounts of endpoints,
+ * this value reflects the maximum number of endpoints for the currently selected AVR model.
+ */
+ #define ENDPOINT_TOTAL_ENDPOINTS ENDPOINT_DETAILS_MAXEP
+ #else
+ #define ENDPOINT_TOTAL_ENDPOINTS 1
+ #endif
+
+ /* Enums: */
+ /** Enum for the possible error return codes of the \ref Endpoint_WaitUntilReady() function.
+ *
+ * \ingroup Group_EndpointRW_UC3
+ */
+ enum Endpoint_WaitUntilReady_ErrorCodes_t
+ {
+ ENDPOINT_READYWAIT_NoError = 0, /**< Endpoint is ready for next packet, no error. */
+ ENDPOINT_READYWAIT_EndpointStalled = 1, /**< The endpoint was stalled during the stream
+ * transfer by the host or device.
+ */
+ ENDPOINT_READYWAIT_DeviceDisconnected = 2, /**< Device was disconnected from the host while
+ * waiting for the endpoint to become ready.
+ */
+ ENDPOINT_READYWAIT_BusSuspended = 3, /**< The USB bus has been suspended by the host and
+ * no USB endpoint traffic can occur until the bus
+ * has resumed.
+ */
+ ENDPOINT_READYWAIT_Timeout = 4, /**< The host failed to accept or send the next packet
+ * within the software timeout period set by the
+ * \ref USB_STREAM_TIMEOUT_MS macro.
+ */
+ };
+
+ /* Inline Functions: */
+ /** Configures the specified endpoint number with the given endpoint type, direction, bank size
+ * and banking mode. Once configured, the endpoint may be read from or written to, depending
+ * on its direction.
+ *
+ * \param[in] Number Endpoint number to configure. This must be more than 0 and less than
+ * \ref ENDPOINT_TOTAL_ENDPOINTS.
+ *
+ * \param[in] Type Type of endpoint to configure, a \c EP_TYPE_* mask. Not all endpoint types
+ * are available on Low Speed USB devices - refer to the USB 2.0 specification.
+ *
+ * \param[in] Direction Endpoint data direction, either \ref ENDPOINT_DIR_OUT or \ref ENDPOINT_DIR_IN.
+ * All endpoints (except Control type) are unidirectional - data may only be read
+ * from or written to the endpoint bank based on its direction, not both.
+ *
+ * \param[in] Size Size of the endpoint's bank, where packets are stored before they are transmitted
+ * to the USB host, or after they have been received from the USB host (depending on
+ * the endpoint's data direction). The bank size must indicate the maximum packet size
+ * that the endpoint can handle.
+ *
+ * \param[in] Banks Number of banks to use for the endpoint being configured, an \c ENDPOINT_BANK_* mask.
+ * More banks uses more USB DPRAM, but offers better performance. Isochronous type
+ * endpoints <b>must</b> have at least two banks.
+ *
+ * \note When the \c ORDERED_EP_CONFIG compile time option is used, Endpoints <b>must</b> be configured in
+ * ascending order, or bank corruption will occur.
+ * \n\n
+ *
+ * \note Different endpoints may have different maximum packet sizes based on the endpoint's index - refer to
+ * the chosen microcontroller model's datasheet to determine the maximum bank size for each endpoint.
+ * \n\n
+ *
+ * \note The default control endpoint should not be manually configured by the user application, as
+ * it is automatically configured by the library internally.
+ * \n\n
+ *
+ * \note This routine will automatically select the specified endpoint upon success. Upon failure, the endpoint
+ * which failed to reconfigure correctly will be selected.
+ *
+ * \return Boolean \c true if the configuration succeeded, \c false otherwise.
+ */
+ static inline bool Endpoint_ConfigureEndpoint(const uint8_t Number,
+ const uint8_t Type,
+ const uint8_t Direction,
+ const uint16_t Size,
+ const uint8_t Banks) ATTR_ALWAYS_INLINE;
+ static inline bool Endpoint_ConfigureEndpoint(const uint8_t Number,
+ const uint8_t Type,
+ const uint8_t Direction,
+ const uint16_t Size,
+ const uint8_t Banks)
+ {
+ return Endpoint_ConfigureEndpoint_Prv(Number, (AVR32_USBB_ALLOC_MASK |
+ ((uint32_t)Type << AVR32_USBB_EPTYPE_OFFSET) |
+ ((uint32_t)Direction << AVR32_USBB_EPDIR_OFFSET) |
+ ((uint32_t)Banks << AVR32_USBB_EPBK_OFFSET) |
+ Endpoint_BytesToEPSizeMask(Size)));
+ }
+
+ /** Indicates the number of bytes currently stored in the current endpoint's selected bank.
+ *
+ * \note The return width of this function may differ, depending on the maximum endpoint bank size
+ * of the selected AVR model.
+ *
+ * \ingroup Group_EndpointRW_UC3
+ *
+ * \return Total number of bytes in the currently selected Endpoint's FIFO buffer.
+ */
+ static inline uint16_t Endpoint_BytesInEndpoint(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint16_t Endpoint_BytesInEndpoint(void)
+ {
+ return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].byct;
+ }
+
+ /** Get the endpoint address of the currently selected endpoint. This is typically used to save
+ * the currently selected endpoint number so that it can be restored after another endpoint has
+ * been manipulated.
+ *
+ * \return Index of the currently selected endpoint.
+ */
+ static inline uint8_t Endpoint_GetCurrentEndpoint(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint8_t Endpoint_GetCurrentEndpoint(void)
+ {
+ return USB_SelectedEndpoint;
+ }
+
+ /** Selects the given endpoint number. If the address from the device descriptors is used, the
+ * value should be masked with the \ref ENDPOINT_EPNUM_MASK constant to extract only the endpoint
+ * number (and discarding the endpoint direction bit).
+ *
+ * Any endpoint operations which do not require the endpoint number to be indicated will operate on
+ * the currently selected endpoint.
+ *
+ * \param[in] EndpointNumber Endpoint number to select.
+ */
+ static inline void Endpoint_SelectEndpoint(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_SelectEndpoint(const uint8_t EndpointNumber)
+ {
+ USB_SelectedEndpoint = EndpointNumber;
+ }
+
+ /** Resets the endpoint bank FIFO. This clears all the endpoint banks and resets the USB controller's
+ * data In and Out pointers to the bank's contents.
+ *
+ * \param[in] EndpointNumber Endpoint number whose FIFO buffers are to be reset.
+ */
+ static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber)
+ {
+ AVR32_USBB.uerst |= (AVR32_USBB_EPRST0_MASK << EndpointNumber);
+ AVR32_USBB.uerst &= ~(AVR32_USBB_EPRST0_MASK << EndpointNumber);
+ USB_EndpointFIFOPos[EndpointNumber] = &AVR32_USBB_SLAVE[EndpointNumber * 0x10000];
+ }
+
+ /** Enables the currently selected endpoint so that data can be sent and received through it to
+ * and from a host.
+ *
+ * \note Endpoints must first be configured properly via \ref Endpoint_ConfigureEndpoint().
+ */
+ static inline void Endpoint_EnableEndpoint(void) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_EnableEndpoint(void)
+ {
+ AVR32_USBB.uerst |= (AVR32_USBB_EPEN0_MASK << USB_SelectedEndpoint);
+ }
+
+ /** Disables the currently selected endpoint so that data cannot be sent and received through it
+ * to and from a host.
+ */
+ static inline void Endpoint_DisableEndpoint(void) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_DisableEndpoint(void)
+ {
+ AVR32_USBB.uerst &= ~(AVR32_USBB_EPEN0_MASK << USB_SelectedEndpoint);
+ }
+
+ /** Determines if the currently selected endpoint is enabled, but not necessarily configured.
+ *
+ * \return Boolean \c true if the currently selected endpoint is enabled, \c false otherwise.
+ */
+ static inline bool Endpoint_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Endpoint_IsEnabled(void)
+ {
+ return ((AVR32_USBB.uerst & (AVR32_USBB_EPEN0_MASK << USB_SelectedEndpoint)) ? true : false);
+ }
+
+ /** Retrieves the number of busy banks in the currently selected endpoint, which have been queued for
+ * transmission via the \ref Endpoint_ClearIN() command, or are awaiting acknowledgement via the
+ * \ref Endpoint_ClearOUT() command.
+ *
+ * \ingroup Group_EndpointPacketManagement_UC3
+ *
+ * \return Total number of busy banks in the selected endpoint.
+ */
+ static inline uint8_t Endpoint_GetBusyBanks(void)
+ {
+ return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].nbusybk;
+ }
+
+ /** Aborts all pending IN transactions on the currently selected endpoint, once the bank
+ * has been queued for transmission to the host via \ref Endpoint_ClearIN(). This function
+ * will terminate all queued transactions, resetting the endpoint banks ready for a new
+ * packet.
+ *
+ * \ingroup Group_EndpointPacketManagement_UC3
+ */
+ static inline void Endpoint_AbortPendingIN(void)
+ {
+ while (Endpoint_GetBusyBanks() != 0)
+ {
+ (&AVR32_USBB.UECON0SET)[USB_SelectedEndpoint].killbks = true;
+ while ((&AVR32_USBB.UECON0)[USB_SelectedEndpoint].killbk);
+ }
+ }
+
+ /** Determines if the currently selected endpoint may be read from (if data is waiting in the endpoint
+ * bank and the endpoint is an OUT direction, or if the bank is not yet full if the endpoint is an IN
+ * direction). This function will return false if an error has occurred in the endpoint, if the endpoint
+ * is an OUT direction and no packet (or an empty packet) has been received, or if the endpoint is an IN
+ * direction and the endpoint bank is full.
+ *
+ * \ingroup Group_EndpointPacketManagement_UC3
+ *
+ * \return Boolean \c true if the currently selected endpoint may be read from or written to, depending
+ * on its direction.
+ */
+ static inline bool Endpoint_IsReadWriteAllowed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Endpoint_IsReadWriteAllowed(void)
+ {
+ return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].rwall;
+ }
+
+ /** Determines if the currently selected endpoint is configured.
+ *
+ * \return Boolean \c true if the currently selected endpoint has been configured, \c false otherwise.
+ */
+ static inline bool Endpoint_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Endpoint_IsConfigured(void)
+ {
+ return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].cfgok;
+ }
+
+ /** Returns a mask indicating which INTERRUPT type endpoints have interrupted - i.e. their
+ * interrupt duration has elapsed. Which endpoints have interrupted can be determined by
+ * masking the return value against <tt>(1 << <i>{Endpoint Number}</i>)</tt>.
+ *
+ * \return Mask whose bits indicate which endpoints have interrupted.
+ */
+ static inline uint8_t Endpoint_GetEndpointInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint8_t Endpoint_GetEndpointInterrupts(void)
+ {
+ return ((AVR32_USBB.udint & (AVR32_USBB_EP6INT_MASK | AVR32_USBB_EP5INT_MASK |
+ AVR32_USBB_EP4INT_MASK | AVR32_USBB_EP3INT_MASK |
+ AVR32_USBB_EP2INT_MASK | AVR32_USBB_EP1INT_MASK |
+ AVR32_USBB_EP0INT_MASK)) >> AVR32_USBB_EP0INT_OFFSET);
+ }
+
+ /** Determines if the specified endpoint number has interrupted (valid only for INTERRUPT type
+ * endpoints).
+ *
+ * \param[in] EndpointNumber Index of the endpoint whose interrupt flag should be tested.
+ *
+ * \return Boolean \c true if the specified endpoint has interrupted, \c false otherwise.
+ */
+ static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber)
+ {
+ return ((Endpoint_GetEndpointInterrupts() & (AVR32_USBB_EP0INT_MASK << EndpointNumber)) ? true : false);
+ }
+
+ /** Determines if the selected IN endpoint is ready for a new packet to be sent to the host.
+ *
+ * \ingroup Group_EndpointPacketManagement_UC3
+ *
+ * \return Boolean \c true if the current endpoint is ready for an IN packet, \c false otherwise.
+ */
+ static inline bool Endpoint_IsINReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Endpoint_IsINReady(void)
+ {
+ return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].txini;
+ }
+
+ /** Determines if the selected OUT endpoint has received new packet from the host.
+ *
+ * \ingroup Group_EndpointPacketManagement_UC3
+ *
+ * \return Boolean \c true if current endpoint is has received an OUT packet, \c false otherwise.
+ */
+ static inline bool Endpoint_IsOUTReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Endpoint_IsOUTReceived(void)
+ {
+ return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].rxouti;
+ }
+
+ /** Determines if the current CONTROL type endpoint has received a SETUP packet.
+ *
+ * \ingroup Group_EndpointPacketManagement_UC3
+ *
+ * \return Boolean \c true if the selected endpoint has received a SETUP packet, \c false otherwise.
+ */
+ static inline bool Endpoint_IsSETUPReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Endpoint_IsSETUPReceived(void)
+ {
+ return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].rxstpi;
+ }
+
+ /** Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the
+ * endpoint for the next packet.
+ *
+ * \ingroup Group_EndpointPacketManagement_UC3
+ *
+ * \note This is not applicable for non CONTROL type endpoints.
+ */
+ static inline void Endpoint_ClearSETUP(void) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_ClearSETUP(void)
+ {
+ (&AVR32_USBB.UESTA0CLR)[USB_SelectedEndpoint].rxstpic = true;
+ USB_EndpointFIFOPos[USB_SelectedEndpoint] = &AVR32_USBB_SLAVE[USB_SelectedEndpoint * 0x10000];
+ }
+
+ /** Sends an IN packet to the host on the currently selected endpoint, freeing up the endpoint for the
+ * next packet and switching to the alternative endpoint bank if double banked.
+ *
+ * \ingroup Group_EndpointPacketManagement_UC3
+ */
+ static inline void Endpoint_ClearIN(void) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_ClearIN(void)
+ {
+ (&AVR32_USBB.UESTA0CLR)[USB_SelectedEndpoint].txinic = true;
+ (&AVR32_USBB.UECON0CLR)[USB_SelectedEndpoint].fifoconc = true;
+ USB_EndpointFIFOPos[USB_SelectedEndpoint] = &AVR32_USBB_SLAVE[USB_SelectedEndpoint * 0x10000];
+ }
+
+ /** Acknowledges an OUT packet to the host on the currently selected endpoint, freeing up the endpoint
+ * for the next packet and switching to the alternative endpoint bank if double banked.
+ *
+ * \ingroup Group_EndpointPacketManagement_UC3
+ */
+ static inline void Endpoint_ClearOUT(void) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_ClearOUT(void)
+ {
+ (&AVR32_USBB.UESTA0CLR)[USB_SelectedEndpoint].rxoutic = true;
+ (&AVR32_USBB.UECON0CLR)[USB_SelectedEndpoint].fifoconc = true;
+ USB_EndpointFIFOPos[USB_SelectedEndpoint] = &AVR32_USBB_SLAVE[USB_SelectedEndpoint * 0x10000];
+ }
+
+ /** Stalls the current endpoint, indicating to the host that a logical problem occurred with the
+ * indicated endpoint and that the current transfer sequence should be aborted. This provides a
+ * way for devices to indicate invalid commands to the host so that the current transfer can be
+ * aborted and the host can begin its own recovery sequence.
+ *
+ * The currently selected endpoint remains stalled until either the \ref Endpoint_ClearStall() macro
+ * is called, or the host issues a CLEAR FEATURE request to the device for the currently selected
+ * endpoint.
+ *
+ * \ingroup Group_EndpointPacketManagement_UC3
+ */
+ static inline void Endpoint_StallTransaction(void) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_StallTransaction(void)
+ {
+ (&AVR32_USBB.UECON0SET)[USB_SelectedEndpoint].stallrqs = true;
+ }
+
+ /** Clears the STALL condition on the currently selected endpoint.
+ *
+ * \ingroup Group_EndpointPacketManagement_UC3
+ */
+ static inline void Endpoint_ClearStall(void) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_ClearStall(void)
+ {
+ (&AVR32_USBB.UECON0CLR)[USB_SelectedEndpoint].stallrqc = true;
+ }
+
+ /** Determines if the currently selected endpoint is stalled, false otherwise.
+ *
+ * \ingroup Group_EndpointPacketManagement_UC3
+ *
+ * \return Boolean \c true if the currently selected endpoint is stalled, \c false otherwise.
+ */
+ static inline bool Endpoint_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Endpoint_IsStalled(void)
+ {
+ return (&AVR32_USBB.UECON0)[USB_SelectedEndpoint].stallrq;
+ }
+
+ /** Resets the data toggle of the currently selected endpoint. */
+ static inline void Endpoint_ResetDataToggle(void) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_ResetDataToggle(void)
+ {
+ (&AVR32_USBB.UECON0SET)[USB_SelectedEndpoint].rstdts = true;
+ }
+
+ /** Determines the currently selected endpoint's direction.
+ *
+ * \return The currently selected endpoint's direction, as a \c ENDPOINT_DIR_* mask.
+ */
+ static inline uint32_t Endpoint_GetEndpointDirection(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint32_t Endpoint_GetEndpointDirection(void)
+ {
+ return ((&AVR32_USBB.UECFG0)[USB_SelectedEndpoint].epdir ? ENDPOINT_DIR_IN : ENDPOINT_DIR_OUT);
+ }
+
+ /** Sets the direction of the currently selected endpoint.
+ *
+ * \param[in] DirectionMask New endpoint direction, as a \c ENDPOINT_DIR_* mask.
+ */
+ static inline void Endpoint_SetEndpointDirection(const uint32_t DirectionMask) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_SetEndpointDirection(const uint32_t DirectionMask)
+ {
+ (&AVR32_USBB.UECFG0)[USB_SelectedEndpoint].epdir = (DirectionMask == ENDPOINT_DIR_IN);
+ }
+
+ /** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW_AVR32
+ *
+ * \return Next byte in the currently selected endpoint's FIFO buffer.
+ */
+ static inline uint8_t Endpoint_Read_Byte(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint8_t Endpoint_Read_Byte(void)
+ {
+ return *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+ }
+
+ /** Writes one byte from the currently selected endpoint's bank, for IN direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW_AVR32
+ *
+ * \param[in] Byte Next byte to write into the the currently selected endpoint's FIFO buffer.
+ */
+ static inline void Endpoint_Write_Byte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_Write_Byte(const uint8_t Byte)
+ {
+ *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++) = Byte;
+ }
+
+ /** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW_UC3
+ */
+ static inline void Endpoint_Discard_Byte(void) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_Discard_Byte(void)
+ {
+ uint8_t Dummy;
+
+ Dummy = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+ }
+
+ /** Reads two bytes from the currently selected endpoint's bank in little endian format, for OUT
+ * direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW_UC3
+ *
+ * \return Next word in the currently selected endpoint's FIFO buffer.
+ */
+ static inline uint16_t Endpoint_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint16_t Endpoint_Read_Word_LE(void)
+ {
+ uint16_t Byte1 = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+ uint16_t Byte0 = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+
+ return ((Byte0 << 8) | Byte1);
+ }
+
+ /** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT
+ * direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW_UC3
+ *
+ * \return Next word in the currently selected endpoint's FIFO buffer.
+ */
+ static inline uint16_t Endpoint_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint16_t Endpoint_Read_Word_BE(void)
+ {
+ uint16_t Byte0 = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+ uint16_t Byte1 = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+
+ return ((Byte0 << 8) | Byte1);
+ }
+
+ /** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN
+ * direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW_UC3
+ *
+ * \param[in] Word Next word to write to the currently selected endpoint's FIFO buffer.
+ */
+ static inline void Endpoint_Write_Word_LE(const uint16_t Word) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_Write_Word_LE(const uint16_t Word)
+ {
+ *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++) = (Word >> 8);
+ *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++) = (Word & 0xFF);
+ }
+
+ /** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN
+ * direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW_UC3
+ *
+ * \param[in] Word Next word to write to the currently selected endpoint's FIFO buffer.
+ */
+ static inline void Endpoint_Write_Word_BE(const uint16_t Word) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_Write_Word_BE(const uint16_t Word)
+ {
+ *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++) = (Word & 0xFF);
+ *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++) = (Word >> 8);
+ }
+
+ /** Discards two bytes from the currently selected endpoint's bank, for OUT direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW_UC3
+ */
+ static inline void Endpoint_Discard_Word(void) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_Discard_Word(void)
+ {
+ uint8_t Dummy;
+
+ Dummy = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+ Dummy = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+ }
+
+ /** Reads four bytes from the currently selected endpoint's bank in little endian format, for OUT
+ * direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW_UC3
+ *
+ * \return Next double word in the currently selected endpoint's FIFO buffer.
+ */
+ static inline uint32_t Endpoint_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint32_t Endpoint_Read_DWord_LE(void)
+ {
+ uint32_t Byte3 = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+ uint32_t Byte2 = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+ uint32_t Byte1 = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+ uint32_t Byte0 = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+
+ return ((Byte0 << 24) | (Byte1 << 16) | (Byte2 << 8) | Byte3);
+ }
+
+ /** Reads four bytes from the currently selected endpoint's bank in big endian format, for OUT
+ * direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW_UC3
+ *
+ * \return Next double word in the currently selected endpoint's FIFO buffer.
+ */
+ static inline uint32_t Endpoint_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint32_t Endpoint_Read_DWord_BE(void)
+ {
+ uint32_t Byte0 = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+ uint32_t Byte1 = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+ uint32_t Byte2 = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+ uint32_t Byte3 = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+
+ return ((Byte0 << 24) | (Byte1 << 16) | (Byte2 << 8) | Byte3);
+ }
+
+ /** Writes four bytes to the currently selected endpoint's bank in little endian format, for IN
+ * direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW_UC3
+ *
+ * \param[in] DWord Next double word to write to the currently selected endpoint's FIFO buffer.
+ */
+ static inline void Endpoint_Write_DWord_LE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_Write_DWord_LE(const uint32_t DWord)
+ {
+ *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++) = (DWord >> 24);
+ *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++) = (DWord >> 16);
+ *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++) = (DWord >> 8);
+ *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++) = (DWord & 0xFF);
+ }
+
+ /** Writes four bytes to the currently selected endpoint's bank in big endian format, for IN
+ * direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW_UC3
+ *
+ * \param[in] DWord Next double word to write to the currently selected endpoint's FIFO buffer.
+ */
+ static inline void Endpoint_Write_DWord_BE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_Write_DWord_BE(const uint32_t DWord)
+ {
+ *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++) = (DWord & 0xFF);
+ *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++) = (DWord >> 8);
+ *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++) = (DWord >> 16);
+ *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++) = (DWord >> 24);
+ }
+
+ /** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW_UC3
+ */
+ static inline void Endpoint_Discard_DWord(void) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_Discard_DWord(void)
+ {
+ uint8_t Dummy;
+
+ Dummy = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+ Dummy = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+ Dummy = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+ Dummy = *(USB_EndpointFIFOPos[USB_SelectedEndpoint]++);
+ }
+
+ /* External Variables: */
+ /** Global indicating the maximum packet size of the default control endpoint located at address
+ * 0 in the device. This value is set to the value indicated in the device descriptor in the user
+ * project once the USB interface is initialized into device mode.
+ *
+ * If space is an issue, it is possible to fix this to a static value by defining the control
+ * endpoint size in the \c FIXED_CONTROL_ENDPOINT_SIZE token passed to the compiler in the makefile
+ * via the -D switch. When a fixed control endpoint size is used, the size is no longer dynamically
+ * read from the descriptors at runtime and instead fixed to the given value. When used, it is
+ * important that the descriptor control endpoint size value matches the size given as the
+ * \c FIXED_CONTROL_ENDPOINT_SIZE token - it is recommended that the \c FIXED_CONTROL_ENDPOINT_SIZE token
+ * be used in the device descriptors to ensure this.
+ *
+ * \note This variable should be treated as read-only in the user application, and never manually
+ * changed in value.
+ */
+ #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
+ extern uint8_t USB_ControlEndpointSize;
+ #else
+ #define USB_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE
+ #endif
+
+ /* Function Prototypes: */
+ /** Completes the status stage of a control transfer on a CONTROL type endpoint automatically,
+ * with respect to the data direction. This is a convenience function which can be used to
+ * simplify user control request handling.
+ */
+ void Endpoint_ClearStatusStage(void);
+
+ /** Spin-loops until the currently selected non-control endpoint is ready for the next packet of data
+ * to be read or written to it.
+ *
+ * \note This routine should not be called on CONTROL type endpoints.
+ *
+ * \ingroup Group_EndpointRW_UC3
+ *
+ * \return A value from the \ref Endpoint_WaitUntilReady_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_WaitUntilReady(void);
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
+
diff --git a/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c b/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c
new file mode 100644
index 000000000..870828ec1
--- /dev/null
+++ b/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c
@@ -0,0 +1,144 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2011.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+#define __INCLUDE_FROM_USB_DRIVER
+#include "../USBMode.h"
+
+#if defined(USB_CAN_BE_HOST)
+
+#include "../Pipe.h"
+
+uint8_t USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;
+
+volatile uint8_t USB_SelectedPipe = PIPE_CONTROLPIPE;
+volatile uint8_t* USB_PipeFIFOPos[PIPE_TOTAL_PIPES];
+
+bool Pipe_ConfigurePipe(const uint8_t Number,
+ const uint8_t Type,
+ const uint8_t Token,
+ const uint8_t EndpointNumber,
+ const uint16_t Size,
+ const uint8_t Banks)
+{
+ Pipe_SelectPipe(Number);
+ Pipe_EnablePipe();
+
+ (&AVR32_USBB.upcfg0)[Number] = 0;
+ (&AVR32_USBB.upcfg0)[Number] = (AVR32_USBB_ALLOC_MASK |
+ ((uint32_t)Type << AVR32_USBB_PTYPE_OFFSET) |
+ ((uint32_t)Token << AVR32_USBB_PTOKEN_OFFSET) |
+ ((uint32_t)Banks << AVR32_USBB_PBK_OFFSET) |
+ ((EndpointNumber & PIPE_EPNUM_MASK) << AVR32_USBB_PEPNUM_OFFSET));
+ USB_PipeFIFOPos[Number] = &AVR32_USBB_SLAVE[Number * 0x10000];
+
+ Pipe_SetInfiniteINRequests();
+
+ return Pipe_IsConfigured();
+}
+
+void Pipe_ClearPipes(void)
+{
+ for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++)
+ {
+ Pipe_SelectPipe(PNum);
+ (&AVR32_USBB.upcfg0)[PNum] = 0;
+ (&AVR32_USBB.upcon0clr)[PNum] = 0xFFFFFFFF;
+ USB_PipeFIFOPos[PNum] = &AVR32_USBB_SLAVE[PNum * 0x10000];
+ Pipe_DisablePipe();
+ }
+}
+
+bool Pipe_IsEndpointBound(const uint8_t EndpointAddress)
+{
+ uint8_t PrevPipeNumber = Pipe_GetCurrentPipe();
+
+ for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++)
+ {
+ Pipe_SelectPipe(PNum);
+
+ if (!(Pipe_IsConfigured()))
+ continue;
+
+ uint8_t PipeToken = Pipe_GetPipeToken();
+ bool PipeTokenCorrect = true;
+
+ if (PipeToken != PIPE_TOKEN_SETUP)
+ PipeTokenCorrect = (PipeToken == ((EndpointAddress & PIPE_EPDIR_MASK) ? PIPE_TOKEN_IN : PIPE_TOKEN_OUT));
+
+ if (PipeTokenCorrect && (Pipe_BoundEndpointNumber() == (EndpointAddress & PIPE_EPNUM_MASK)))
+ return true;
+ }
+
+ Pipe_SelectPipe(PrevPipeNumber);
+ return false;
+}
+
+uint8_t Pipe_WaitUntilReady(void)
+{
+ #if (USB_STREAM_TIMEOUT_MS < 0xFF)
+ uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
+ #else
+ uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
+ #endif
+
+ uint16_t PreviousFrameNumber = USB_Host_GetFrameNumber();
+
+ for (;;)
+ {
+ if (Pipe_GetPipeToken() == PIPE_TOKEN_IN)
+ {
+ if (Pipe_IsINReceived())
+ return PIPE_READYWAIT_NoError;
+ }
+ else
+ {
+ if (Pipe_IsOUTReady())
+ return PIPE_READYWAIT_NoError;
+ }
+
+ if (Pipe_IsStalled())
+ return PIPE_READYWAIT_PipeStalled;
+ else if (USB_HostState == HOST_STATE_Unattached)
+ return PIPE_READYWAIT_DeviceDisconnected;
+
+ uint16_t CurrentFrameNumber = USB_Host_GetFrameNumber();
+
+ if (CurrentFrameNumber != PreviousFrameNumber)
+ {
+ PreviousFrameNumber = CurrentFrameNumber;
+
+ if (!(TimeoutMSRem--))
+ return PIPE_READYWAIT_Timeout;
+ }
+ }
+}
+
+#endif
+
diff --git a/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.h b/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.h
new file mode 100644
index 000000000..204169f00
--- /dev/null
+++ b/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.h
@@ -0,0 +1,915 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2011.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ * \brief USB Pipe definitions for the AVR32 UC3 microcontrollers.
+ * \copydetails Group_PipeManagement_UC3
+ *
+ * \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_PipeRW
+ * \defgroup Group_PipeRW_UC3 Pipe Data Reading and Writing (UC3)
+ * \brief Pipe data read/write definitions for the Atmel AVR32 UC3 architecture.
+ *
+ * Functions, macros, variables, enums and types related to data reading and writing from and to pipes.
+ */
+
+/** \ingroup Group_PipePrimitiveRW
+ * \defgroup Group_PipePrimitiveRW_UC3 Read/Write of Primitive Data Types (UC3)
+ * \brief Pipe primative data read/write definitions for the Atmel AVR32 UC3 architecture.
+ *
+ * Functions, macros, variables, enums and types related to data reading and writing of primitive data types
+ * from and to pipes.
+ */
+
+/** \ingroup Group_PipePacketManagement
+ * \defgroup Group_PipePacketManagement_UC3 Pipe Packet Management (UC3)
+ * \brief Pipe packet management definitions for the Atmel AVR32 UC3 architecture.
+ *
+ * Functions, macros, variables, enums and types related to packet management of pipes.
+ */
+
+/** \ingroup Group_PipeControlReq
+ * \defgroup Group_PipeControlReq_UC3 Pipe Control Request Management (UC3)
+ * \brief Pipe control request management definitions for the Atmel AVR32 UC3 architecture.
+ *
+ * Module for host mode request processing. This module allows for the transmission of standard, class and
+ * vendor control requests to the default control endpoint of an attached device while in host mode.
+ *
+ * \see Chapter 9 of the USB 2.0 specification.
+ */
+
+/** \ingroup Group_PipeManagement
+ * \defgroup Group_PipeManagement_UC3 Pipe Management (UC3)
+ * \brief Pipe management definitions for the Atmel AVR32 UC3 architecture.
+ *
+ * This module contains functions, macros and enums related to pipe management when in USB Host mode. This
+ * module contains the pipe management macros, as well as pipe interrupt and data send/receive functions
+ * for various data types.
+ *
+ * @{
+ */
+
+#ifndef __PIPE_UC3_H__
+#define __PIPE_UC3_H__
+
+ /* Includes: */
+ #include "../../../../Common/Common.h"
+ #include "../USBTask.h"
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_USB_DRIVER)
+ #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
+ #endif
+
+ /* Private Interface - For use in library only: */
+ #if !defined(__DOXYGEN__)
+ /* External Variables: */
+ extern volatile uint8_t USB_SelectedPipe;
+ extern volatile uint8_t* USB_PipeFIFOPos[];
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Macros: */
+ /** \name Pipe Error Flag Masks */
+ //@{
+ /** Mask for \ref Pipe_GetErrorFlags(), indicating that an overflow error occurred in the pipe on the received data. */
+ #define PIPE_ERRORFLAG_OVERFLOW (AVR32_USBB_UPSTA0_OVERFI_MASK << 8)
+
+ /** Mask for \ref Pipe_GetErrorFlags(), indicating that a CRC error occurred in the pipe on the received data. */
+ #define PIPE_ERRORFLAG_CRC16 AVR32_USBB_UPERR0_CRC16_MASK
+
+ /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware timeout error occurred in the pipe. */
+ #define PIPE_ERRORFLAG_TIMEOUT AVR32_USBB_UPERR0_TIMEOUT_MASK
+
+ /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware PID error occurred in the pipe. */
+ #define PIPE_ERRORFLAG_PID AVR32_USBB_UPERR0_PID_MASK
+
+ /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware data PID error occurred in the pipe. */
+ #define PIPE_ERRORFLAG_DATAPID AVR32_USBB_UPERR0_DATAPID_MASK
+
+ /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware data toggle error occurred in the pipe. */
+ #define PIPE_ERRORFLAG_DATATGL AVR32_USBB_UPERR0_DATATGL_MASK
+ //@}
+
+ /** \name Pipe Token Masks */
+ //@{
+ /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a SETUP token (for CONTROL type pipes),
+ * which will trigger a control request on the attached device when data is written to the pipe.
+ */
+ #define PIPE_TOKEN_SETUP AVR32_USBB_UPCFG0_PTOKEN_SETUP
+
+ /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a IN token (for non-CONTROL type pipes),
+ * indicating that the pipe data will flow from device to host.
+ */
+ #define PIPE_TOKEN_IN AVR32_USBB_UPCFG0_PTOKEN_IN
+
+ /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a OUT token (for non-CONTROL type pipes),
+ * indicating that the pipe data will flow from host to device.
+ */
+ #define PIPE_TOKEN_OUT AVR32_USBB_UPCFG0_PTOKEN_OUT
+ //@}
+
+ /** \name Pipe Bank Mode Masks */
+ //@{
+ /** Mask for the bank mode selection for the \ref Pipe_ConfigurePipe() macro. This indicates that the pipe
+ * should have one single bank, which requires less USB FIFO memory but results in slower transfers as
+ * only one USB device (the AVR or the attached device) can access the pipe's bank at the one time.
+ */
+ #define PIPE_BANK_SINGLE AVR32_USBB_UPCFG0_PBK_SINGLE
+
+ /** Mask for the bank mode selection for the \ref Pipe_ConfigurePipe() macro. This indicates that the pipe
+ * should have two banks, which requires more USB FIFO memory but results in faster transfers as one
+ * USB device (the AVR or the attached device) can access one bank while the other accesses the second
+ * bank.
+ */
+ #define PIPE_BANK_DOUBLE AVR32_USBB_UPCFG0_PBK_DOUBLE
+
+ /** Mask for the bank mode selection for the \ref Pipe_ConfigurePipe() macro. This indicates that the pipe
+ * should have three banks, which requires more USB FIFO memory but results in faster transfers as one
+ * USB device (the AVR or the attached device) can access one bank while the other accesses the remaining
+ * banks.
+ */
+ #define PIPE_BANK_TRIPLE AVR32_USBB_UPCFG0_PBK_TRIPLE
+ //@}
+
+ /** Default size of the default control pipe's bank, until altered by the Endpoint0Size value
+ * in the device descriptor of the attached device.
+ */
+ #define PIPE_CONTROLPIPE_DEFAULT_SIZE 64
+
+ /** Total number of pipes (including the default control pipe at address 0) which may be used in
+ * the device.
+ */
+ #define PIPE_TOTAL_PIPES 7
+
+ /** Size in bytes of the largest pipe bank size possible in the device. Not all banks on each AVR
+ * model supports the largest bank size possible on the device; different pipe numbers support
+ * different maximum bank sizes. This value reflects the largest possible bank of any pipe on the
+ * currently selected UC3 AVR model.
+ */
+ #define PIPE_MAX_SIZE 256
+
+ /* Enums: */
+ /** Enum for the possible error return codes of the \ref Pipe_WaitUntilReady() function.
+ *
+ * \ingroup Group_PipeRW_UC3
+ */
+ enum Pipe_WaitUntilReady_ErrorCodes_t
+ {
+ PIPE_READYWAIT_NoError = 0, /**< Pipe ready for next packet, no error. */
+ PIPE_READYWAIT_PipeStalled = 1, /**< The device stalled the pipe while waiting. */
+ PIPE_READYWAIT_DeviceDisconnected = 2, /**< Device was disconnected from the host while waiting. */
+ PIPE_READYWAIT_Timeout = 3, /**< The device failed to accept or send the next packet
+ * within the software timeout period set by the
+ * \ref USB_STREAM_TIMEOUT_MS macro.
+ */
+ };
+
+ /* Inline Functions: */
+ /** Indicates the number of bytes currently stored in the current pipes's selected bank.
+ *
+ * \note The return width of this function may differ, depending on the maximum pipe bank size
+ * of the selected AVR model.
+ *
+ * \ingroup Group_PipeRW_UC3
+ *
+ * \return Total number of bytes in the currently selected pipe's FIFO buffer.
+ */
+ static inline uint16_t Pipe_BytesInPipe(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint16_t Pipe_BytesInPipe(void)
+ {
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].pbyct;
+ }
+
+ /** Returns the pipe address of the currently selected pipe. This is typically used to save the
+ * currently selected pipe number so that it can be restored after another pipe has been manipulated.
+ *
+ * \return Index of the currently selected pipe.
+ */
+ static inline uint8_t Pipe_GetCurrentPipe(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint8_t Pipe_GetCurrentPipe(void)
+ {
+ return USB_SelectedPipe;
+ }
+
+ /** Selects the given pipe number. Any pipe operations which do not require the pipe number to be
+ * indicated will operate on the currently selected pipe.
+ *
+ * \param[in] PipeNumber Index of the pipe to select.
+ */
+ static inline void Pipe_SelectPipe(const uint8_t PipeNumber) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_SelectPipe(const uint8_t PipeNumber)
+ {
+ USB_SelectedPipe = PipeNumber;
+ }
+
+ /** Resets the desired pipe, including the pipe banks and flags.
+ *
+ * \param[in] PipeNumber Index of the pipe to reset.
+ */
+ static inline void Pipe_ResetPipe(const uint8_t PipeNumber) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_ResetPipe(const uint8_t PipeNumber)
+ {
+ AVR32_USBB.uprst |= (AVR32_USBB_PRST0_MASK << PipeNumber);
+ AVR32_USBB.uprst &= ~(AVR32_USBB_PRST0_MASK << PipeNumber);
+ USB_PipeFIFOPos[USB_SelectedPipe] = &AVR32_USBB_SLAVE[USB_SelectedPipe * 0x10000];
+ }
+
+ /** Enables the currently selected pipe so that data can be sent and received through it to and from
+ * an attached device.
+ *
+ * \pre The currently selected pipe must first be configured properly via \ref Pipe_ConfigurePipe().
+ */
+ static inline void Pipe_EnablePipe(void) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_EnablePipe(void)
+ {
+ AVR32_USBB.uprst |= (AVR32_USBB_PEN0_MASK << USB_SelectedPipe);
+ }
+
+ /** Disables the currently selected pipe so that data cannot be sent and received through it to and
+ * from an attached device.
+ */
+ static inline void Pipe_DisablePipe(void) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_DisablePipe(void)
+ {
+ AVR32_USBB.uprst &= ~(AVR32_USBB_PEN0_MASK << USB_SelectedPipe);
+ }
+
+ /** Determines if the currently selected pipe is enabled, but not necessarily configured.
+ *
+ * \return Boolean \c true if the currently selected pipe is enabled, \c false otherwise.
+ */
+ static inline bool Pipe_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Pipe_IsEnabled(void)
+ {
+ return ((AVR32_USBB.uprst & (AVR32_USBB_PEN0_MASK << USB_SelectedPipe)) ? true : false);
+ }
+
+ /** Gets the current pipe token, indicating the pipe's data direction and type.
+ *
+ * \return The current pipe token, as a \c PIPE_TOKEN_* mask.
+ */
+ static inline uint8_t Pipe_GetPipeToken(void) ATTR_ALWAYS_INLINE;
+ static inline uint8_t Pipe_GetPipeToken(void)
+ {
+ return (&AVR32_USBB.UPCFG0)[USB_SelectedPipe].ptoken;
+ }
+
+ /** Sets the token for the currently selected pipe to one of the tokens specified by the \c PIPE_TOKEN_*
+ * masks. This can be used on CONTROL type pipes, to allow for bidirectional transfer of data during
+ * control requests, or on regular pipes to allow for half-duplex bidirectional data transfer to devices
+ * which have two endpoints of opposite direction sharing the same endpoint address within the device.
+ *
+ * \param[in] Token New pipe token to set the selected pipe to, as a \c PIPE_TOKEN_* mask.
+ */
+ static inline void Pipe_SetPipeToken(const uint8_t Token) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_SetPipeToken(const uint8_t Token)
+ {
+ (&AVR32_USBB.UPCFG0)[USB_SelectedPipe].ptoken = Token;
+ }
+
+ /** Configures the currently selected pipe to allow for an unlimited number of IN requests. */
+ static inline void Pipe_SetInfiniteINRequests(void) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_SetInfiniteINRequests(void)
+ {
+ (&AVR32_USBB.UPINRQ0)[USB_SelectedPipe].inmode = true;
+ }
+
+ /** Configures the currently selected pipe to only allow the specified number of IN requests to be
+ * accepted by the pipe before it is automatically frozen.
+ *
+ * \param[in] TotalINRequests Total number of IN requests that the pipe may receive before freezing.
+ */
+ static inline void Pipe_SetFiniteINRequests(const uint8_t TotalINRequests) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_SetFiniteINRequests(const uint8_t TotalINRequests)
+ {
+ (&AVR32_USBB.UPINRQ0)[USB_SelectedPipe].inmode = false;
+ (&AVR32_USBB.UPINRQ0)[USB_SelectedPipe].inrq = TotalINRequests;
+ }
+
+ /** Determines if the currently selected pipe is configured.
+ *
+ * \return Boolean \c true if the selected pipe is configured, \c false otherwise.
+ */
+ static inline bool Pipe_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Pipe_IsConfigured(void)
+ {
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].cfgok;
+ }
+
+ /** Retrieves the endpoint number of the endpoint within the attached device that the currently selected
+ * pipe is bound to.
+ *
+ * \return Endpoint number the currently selected pipe is bound to.
+ */
+ static inline uint8_t Pipe_BoundEndpointNumber(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint8_t Pipe_BoundEndpointNumber(void)
+ {
+ return (&AVR32_USBB.UPCFG0)[USB_SelectedPipe].pepnum;
+ }
+
+ /** Sets the period between interrupts for an INTERRUPT type pipe to a specified number of milliseconds.
+ *
+ * \param[in] Milliseconds Number of milliseconds between each pipe poll.
+ */
+ static inline void Pipe_SetInterruptPeriod(const uint8_t Milliseconds) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_SetInterruptPeriod(const uint8_t Milliseconds)
+ {
+ (&AVR32_USBB.UPCFG0)[USB_SelectedPipe].intfrq = Milliseconds;
+ }
+
+ /** Returns a mask indicating which pipe's interrupt periods have elapsed, indicating that the pipe should
+ * be serviced.
+ *
+ * \return Mask whose bits indicate which pipes have interrupted.
+ */
+ static inline uint8_t Pipe_GetPipeInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint8_t Pipe_GetPipeInterrupts(void)
+ {
+ return ((AVR32_USBB.uhint & (AVR32_USBB_P6INT_MASK | AVR32_USBB_P5INT_MASK |
+ AVR32_USBB_P4INT_MASK | AVR32_USBB_P3INT_MASK |
+ AVR32_USBB_P2INT_MASK | AVR32_USBB_P1INT_MASK |
+ AVR32_USBB_P0INT_MASK)) >> AVR32_USBB_P0INT_OFFSET);
+ }
+
+ /** Determines if the specified pipe number has interrupted (valid only for INTERRUPT type
+ * pipes).
+ *
+ * \param[in] PipeNumber Index of the pipe whose interrupt flag should be tested.
+ *
+ * \return Boolean \c true if the specified pipe has interrupted, \c false otherwise.
+ */
+ static inline bool Pipe_HasPipeInterrupted(const uint8_t PipeNumber) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Pipe_HasPipeInterrupted(const uint8_t PipeNumber)
+ {
+ return ((AVR32_USBB.uhint & (AVR32_USBB_P0INTES_MASK << USB_SelectedPipe)) ? true : false);
+ }
+
+ /** Unfreezes the selected pipe, allowing it to communicate with an attached device. */
+ static inline void Pipe_Unfreeze(void) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Unfreeze(void)
+ {
+ (&AVR32_USBB.UPCON0CLR)[USB_SelectedPipe].pfreezec = true;
+ }
+
+ /** Freezes the selected pipe, preventing it from communicating with an attached device. */
+ static inline void Pipe_Freeze(void) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Freeze(void)
+ {
+ (&AVR32_USBB.UPCON0SET)[USB_SelectedPipe].pfreezes = true;
+ }
+
+ /** Determines if the currently selected pipe is frozen, and not able to accept data.
+ *
+ * \return Boolean \c true if the currently selected pipe is frozen, \c false otherwise.
+ */
+ static inline bool Pipe_IsFrozen(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Pipe_IsFrozen(void)
+ {
+ return (((&AVR32_USBB.UPCON0)[USB_SelectedPipe].pfreeze) ? true : false);
+ }
+
+ /** Clears the error flags for the currently selected pipe. */
+ static inline void Pipe_ClearError(void) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_ClearError(void)
+ {
+ (&AVR32_USBB.uperr0)[USB_SelectedPipe] = 0;
+ (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].overfic = true;
+ }
+
+ /** Determines if the master pipe error flag is set for the currently selected pipe, indicating that
+ * some sort of hardware error has occurred on the pipe.
+ *
+ * \see \ref Pipe_GetErrorFlags() macro for information on retrieving the exact error flag.
+ *
+ * \return Boolean \c true if an error has occurred on the selected pipe, \c false otherwise.
+ */
+ static inline bool Pipe_IsError(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Pipe_IsError(void)
+ {
+ return (((&AVR32_USBB.upsta0)[USB_SelectedPipe] &
+ (AVR32_USBB_PERRI_MASK | AVR32_USBB_OVERFI_MASK)) ? true : false);
+ }
+
+ /** Gets a mask of the hardware error flags which have occurred on the currently selected pipe. This
+ * value can then be masked against the \c PIPE_ERRORFLAG_* masks to determine what error has occurred.
+ *
+ * \return Mask comprising of \c PIPE_ERRORFLAG_* bits indicating what error has occurred on the selected pipe.
+ */
+ static inline uint8_t Pipe_GetErrorFlags(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint8_t Pipe_GetErrorFlags(void)
+ {
+
+ return (((&AVR32_USBB.uperr0)[USB_SelectedPipe] &
+ (PIPE_ERRORFLAG_CRC16 | PIPE_ERRORFLAG_TIMEOUT |
+ PIPE_ERRORFLAG_PID | PIPE_ERRORFLAG_DATAPID |
+ PIPE_ERRORFLAG_DATATGL)) |
+ (((&AVR32_USBB.upsta0)[USB_SelectedPipe] << 8) &
+ PIPE_ERRORFLAG_OVERFLOW));
+ }
+
+ /** Retrieves the number of busy banks in the currently selected pipe, which have been queued for
+ * transmission via the \ref Pipe_ClearOUT() command, or are awaiting acknowledgement via the
+ * \ref Pipe_ClearIN() command.
+ *
+ * \ingroup Group_PipePacketManagement_UC3
+ *
+ * \return Total number of busy banks in the selected pipe.
+ */
+ static inline uint8_t Pipe_GetBusyBanks(void)
+ {
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].nbusybk;
+ }
+
+ /** Determines if the currently selected pipe may be read from (if data is waiting in the pipe
+ * bank and the pipe is an IN direction, or if the bank is not yet full if the pipe is an OUT
+ * direction). This function will return false if an error has occurred in the pipe, or if the pipe
+ * is an IN direction and no packet (or an empty packet) has been received, or if the pipe is an OUT
+ * direction and the pipe bank is full.
+ *
+ * \note This function is not valid on CONTROL type pipes.
+ *
+ * \ingroup Group_PipePacketManagement_UC3
+ *
+ * \return Boolean \c true if the currently selected pipe may be read from or written to, depending
+ * on its direction.
+ */
+ static inline bool Pipe_IsReadWriteAllowed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Pipe_IsReadWriteAllowed(void)
+ {
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].rwall;
+ }
+
+ /** Determines if a packet has been received on the currently selected IN pipe from the attached device.
+ *
+ * \ingroup Group_PipePacketManagement_UC3
+ *
+ * \return Boolean \c true if the current pipe has received an IN packet, \c false otherwise.
+ */
+ static inline bool Pipe_IsINReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Pipe_IsINReceived(void)
+ {
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].rxini;
+ }
+
+ /** Determines if the currently selected OUT pipe is ready to send an OUT packet to the attached device.
+ *
+ * \ingroup Group_PipePacketManagement_UC3
+ *
+ * \return Boolean \c true if the current pipe is ready for an OUT packet, \c false otherwise.
+ */
+ static inline bool Pipe_IsOUTReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Pipe_IsOUTReady(void)
+ {
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].txouti;
+ }
+
+ /** Determines if no SETUP request is currently being sent to the attached device on the selected
+ * CONTROL type pipe.
+ *
+ * \ingroup Group_PipePacketManagement_UC3
+ *
+ * \return Boolean \c true if the current pipe is ready for a SETUP packet, \c false otherwise.
+ */
+ static inline bool Pipe_IsSETUPSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Pipe_IsSETUPSent(void)
+ {
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].txstpi;
+ }
+
+ /** Sends the currently selected CONTROL type pipe's contents to the device as a SETUP packet.
+ *
+ * \ingroup Group_PipePacketManagement_UC3
+ */
+ static inline void Pipe_ClearSETUP(void) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_ClearSETUP(void)
+ {
+ (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].txstpic = true;
+ USB_PipeFIFOPos[USB_SelectedPipe] = &AVR32_USBB_SLAVE[USB_SelectedPipe * 0x10000];
+ }
+
+ /** Acknowledges the reception of a setup IN request from the attached device on the currently selected
+ * pipe, freeing the bank ready for the next packet.
+ *
+ * \ingroup Group_PipePacketManagement_UC3
+ */
+ static inline void Pipe_ClearIN(void) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_ClearIN(void)
+ {
+ (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].rxinic = true;
+ (&AVR32_USBB.UPCON0CLR)[USB_SelectedPipe].fifoconc = true;
+ USB_PipeFIFOPos[USB_SelectedPipe] = &AVR32_USBB_SLAVE[USB_SelectedPipe * 0x10000];
+ }
+
+ /** Sends the currently selected pipe's contents to the device as an OUT packet on the selected pipe, freeing
+ * the bank ready for the next packet.
+ *
+ * \ingroup Group_PipePacketManagement_UC3
+ */
+ static inline void Pipe_ClearOUT(void) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_ClearOUT(void)
+ {
+ (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].txoutic = true;
+ (&AVR32_USBB.UPCON0CLR)[USB_SelectedPipe].fifoconc = true;
+ USB_PipeFIFOPos[USB_SelectedPipe] = &AVR32_USBB_SLAVE[USB_SelectedPipe * 0x10000];
+ }
+
+ /** Determines if the device sent a NAK (Negative Acknowledge) in response to the last sent packet on
+ * the currently selected pipe. This occurs when the host sends a packet to the device, but the device
+ * is not currently ready to handle the packet (i.e. its endpoint banks are full). Once a NAK has been
+ * received, it must be cleared using \ref Pipe_ClearNAKReceived() before the previous (or any other) packet
+ * can be re-sent.
+ *
+ * \ingroup Group_PipePacketManagement_UC3
+ *
+ * \return Boolean \c true if an NAK has been received on the current pipe, \c false otherwise.
+ */
+ static inline bool Pipe_IsNAKReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Pipe_IsNAKReceived(void)
+ {
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].nakedi;
+ }
+
+ /** Clears the NAK condition on the currently selected pipe.
+ *
+ * \ingroup Group_PipePacketManagement_UC3
+ *
+ * \see \ref Pipe_IsNAKReceived() for more details.
+ */
+ static inline void Pipe_ClearNAKReceived(void) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_ClearNAKReceived(void)
+ {
+ (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].nakedic = true;
+ }
+
+ /** Determines if the currently selected pipe has had the STALL condition set by the attached device.
+ *
+ * \ingroup Group_PipePacketManagement_UC3
+ *
+ * \return Boolean \c true if the current pipe has been stalled by the attached device, \c false otherwise.
+ */
+ static inline bool Pipe_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool Pipe_IsStalled(void)
+ {
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].rxstalldi;
+ }
+
+ /** Clears the STALL condition detection flag on the currently selected pipe, but does not clear the
+ * STALL condition itself (this must be done via a ClearFeature control request to the device).
+ *
+ * \ingroup Group_PipePacketManagement_UC3
+ */
+ static inline void Pipe_ClearStall(void) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_ClearStall(void)
+ {
+ (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].rxstalldic = true;
+ USB_PipeFIFOPos[USB_SelectedPipe] = &AVR32_USBB_SLAVE[USB_SelectedPipe * 0x10000];
+ }
+
+ /** Reads one byte from the currently selected pipe's bank, for OUT direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW_UC3
+ *
+ * \return Next byte in the currently selected pipe's FIFO buffer.
+ */
+ static inline uint8_t Pipe_Read_Byte(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint8_t Pipe_Read_Byte(void)
+ {
+ return *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+ }
+
+ /** Writes one byte from the currently selected pipe's bank, for IN direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW_UC3
+ *
+ * \param[in] Byte Next byte to write into the the currently selected pipe's FIFO buffer.
+ */
+ static inline void Pipe_Write_Byte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Write_Byte(const uint8_t Byte)
+ {
+ *(USB_PipeFIFOPos[USB_SelectedPipe]++) = Byte;
+ }
+
+ /** Discards one byte from the currently selected pipe's bank, for OUT direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW_UC3
+ */
+ static inline void Pipe_Discard_Byte(void) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Discard_Byte(void)
+ {
+ uint8_t Dummy;
+
+ Dummy = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+ }
+
+ /** Reads two bytes from the currently selected pipe's bank in little endian format, for OUT
+ * direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW_UC3
+ *
+ * \return Next word in the currently selected pipe's FIFO buffer.
+ */
+ static inline uint16_t Pipe_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint16_t Pipe_Read_Word_LE(void)
+ {
+ uint16_t Byte1 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+ uint16_t Byte0 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+
+ return ((Byte0 << 8) | Byte1);
+ }
+
+ /** Reads two bytes from the currently selected pipe's bank in big endian format, for OUT
+ * direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW_UC3
+ *
+ * \return Next word in the currently selected pipe's FIFO buffer.
+ */
+ static inline uint16_t Pipe_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint16_t Pipe_Read_Word_BE(void)
+ {
+ uint16_t Byte0 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+ uint16_t Byte1 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+
+ return ((Byte0 << 8) | Byte1);
+ }
+
+ /** Writes two bytes to the currently selected pipe's bank in little endian format, for IN
+ * direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW_UC3
+ *
+ * \param[in] Word Next word to write to the currently selected pipe's FIFO buffer.
+ */
+ static inline void Pipe_Write_Word_LE(const uint16_t Word) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Write_Word_LE(const uint16_t Word)
+ {
+ *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (Word >> 8);
+ *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (Word & 0xFF);
+ }
+
+ /** Writes two bytes to the currently selected pipe's bank in big endian format, for IN
+ * direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW_UC3
+ *
+ * \param[in] Word Next word to write to the currently selected pipe's FIFO buffer.
+ */
+ static inline void Pipe_Write_Word_BE(const uint16_t Word) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Write_Word_BE(const uint16_t Word)
+ {
+ *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (Word & 0xFF);
+ *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (Word >> 8);
+ }
+
+ /** Discards two bytes from the currently selected pipe's bank, for OUT direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW_UC3
+ */
+ static inline void Pipe_Discard_Word(void) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Discard_Word(void)
+ {
+ uint8_t Dummy;
+
+ Dummy = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+ Dummy = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+ }
+
+ /** Reads four bytes from the currently selected pipe's bank in little endian format, for OUT
+ * direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW_UC3
+ *
+ * \return Next double word in the currently selected pipe's FIFO buffer.
+ */
+ static inline uint32_t Pipe_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint32_t Pipe_Read_DWord_LE(void)
+ {
+ uint32_t Byte3 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+ uint32_t Byte2 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+ uint32_t Byte1 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+ uint32_t Byte0 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+
+ return ((Byte0 << 24) | (Byte1 << 16) | (Byte2 << 8) | Byte3);
+ }
+
+ /** Reads four bytes from the currently selected pipe's bank in big endian format, for OUT
+ * direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW_UC3
+ *
+ * \return Next double word in the currently selected pipe's FIFO buffer.
+ */
+ static inline uint32_t Pipe_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint32_t Pipe_Read_DWord_BE(void)
+ {
+ uint32_t Byte0 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+ uint32_t Byte1 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+ uint32_t Byte2 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+ uint32_t Byte3 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+
+ return ((Byte0 << 24) | (Byte1 << 16) | (Byte2 << 8) | Byte3);
+ }
+
+ /** Writes four bytes to the currently selected pipe's bank in little endian format, for IN
+ * direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW_UC3
+ *
+ * \param[in] DWord Next double word to write to the currently selected pipe's FIFO buffer.
+ */
+ static inline void Pipe_Write_DWord_LE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Write_DWord_LE(const uint32_t DWord)
+ {
+ *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (DWord >> 24);
+ *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (DWord >> 16);
+ *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (DWord >> 8);
+ *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (DWord & 0xFF);
+ }
+
+ /** Writes four bytes to the currently selected pipe's bank in big endian format, for IN
+ * direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW_UC3
+ *
+ * \param[in] DWord Next double word to write to the currently selected pipe's FIFO buffer.
+ */
+ static inline void Pipe_Write_DWord_BE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Write_DWord_BE(const uint32_t DWord)
+ {
+ *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (DWord & 0xFF);
+ *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (DWord >> 8);
+ *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (DWord >> 16);
+ *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (DWord >> 24);
+ }
+
+ /** Discards four bytes from the currently selected pipe's bank, for OUT direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW_UC3
+ */
+ static inline void Pipe_Discard_DWord(void) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Discard_DWord(void)
+ {
+ uint8_t Dummy;
+
+ Dummy = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+ Dummy = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+ Dummy = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+ Dummy = *(USB_PipeFIFOPos[USB_SelectedPipe]++);
+ }
+
+ /* External Variables: */
+ /** Global indicating the maximum packet size of the default control pipe located at address
+ * 0 in the device. This value is set to the value indicated in the attached device's device
+ * descriptor once the USB interface is initialized into host mode and a device is attached
+ * to the USB bus.
+ *
+ * \note This variable should be treated as read-only in the user application, and never manually
+ * changed in value.
+ */
+ extern uint8_t USB_ControlPipeSize;
+
+ /* Function Prototypes: */
+ /** Configures the specified pipe number with the given pipe type, token, target endpoint number in the
+ * attached device, bank size and banking mode.
+ *
+ * A newly configured pipe is frozen by default, and must be unfrozen before use via the \ref Pipe_Unfreeze()
+ * before being used. Pipes should be kept frozen unless waiting for data from a device while in IN mode, or
+ * sending data to the device in OUT mode. IN type pipes are also automatically configured to accept infinite
+ * numbers of IN requests without automatic freezing - this can be overridden by a call to
+ * \ref Pipe_SetFiniteINRequests().
+ *
+ * \param[in] Number Pipe number to configure. This must be more than 0 and less than \ref PIPE_TOTAL_PIPES.
+ *
+ * \param[in] Type Type of pipe to configure, an \c EP_TYPE_* mask. Not all pipe types are available on Low
+ * Speed USB devices - refer to the USB 2.0 specification.
+ *
+ * \param[in] Token Pipe data token, either \ref PIPE_TOKEN_SETUP, \ref PIPE_TOKEN_OUT or \ref PIPE_TOKEN_IN.
+ * All pipes (except Control type) are unidirectional - data may only be read from or
+ * written to the pipe bank based on its direction, not both.
+ *
+ * \param[in] EndpointNumber Endpoint index within the attached device that the pipe should interface to.
+ *
+ * \param[in] Size Size of the pipe's bank, where packets are stored before they are transmitted to
+ * the USB device, or after they have been received from the USB device (depending on
+ * the pipe's data direction). The bank size must indicate the maximum packet size that
+ * the pipe can handle.
+ *
+ * \param[in] Banks Number of banks to use for the pipe being configured, a \c PIPE_BANK_* mask. More banks
+ * uses more USB DPRAM, but offers better performance. Isochronous type pipes <b>must</b>
+ * have at least two banks.
+ *
+ * \note When the \c ORDERED_EP_CONFIG compile time option is used, Pipes <b>must</b> be configured in ascending order,
+ * or bank corruption will occur.
+ * \n\n
+ *
+ * \note Certain microcontroller model's pipes may have different maximum packet sizes based on the pipe's
+ * index - refer to the chosen microcontroller's datasheet to determine the maximum bank size for each pipe.
+ * \n\n
+ *
+ * \note The default control pipe should not be manually configured by the user application, as it is
+ * automatically configured by the library internally.
+ * \n\n
+ *
+ * \note This routine will automatically select the specified pipe upon success. Upon failure, the pipe which
+ * failed to reconfigure correctly will be selected.
+ *
+ * \return Boolean \c true if the configuration succeeded, \c false otherwise.
+ */
+ bool Pipe_ConfigurePipe(const uint8_t Number,
+ const uint8_t Type,
+ const uint8_t Token,
+ const uint8_t EndpointNumber,
+ const uint16_t Size,
+ const uint8_t Banks);
+
+ /** Spin-loops until the currently selected non-control pipe is ready for the next packed of data to be read
+ * or written to it, aborting in the case of an error condition (such as a timeout or device disconnect).
+ *
+ * \ingroup Group_PipeRW_UC3
+ *
+ * \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_WaitUntilReady(void);
+
+ /** Determines if a pipe has been bound to the given device endpoint address. If a pipe which is bound to the given
+ * endpoint is found, it is automatically selected.
+ *
+ * \param[in] EndpointAddress Address and direction mask of the endpoint within the attached device to check.
+ *
+ * \return Boolean \c true if a pipe bound to the given endpoint address of the specified direction is found,
+ * \c false otherwise.
+ */
+ bool Pipe_IsEndpointBound(const uint8_t EndpointAddress);
+
+ /* Private Interface - For use in library only: */
+ #if !defined(__DOXYGEN__)
+ /* Macros: */
+ #if !defined(ENDPOINT_CONTROLEP)
+ #define ENDPOINT_CONTROLEP 0
+ #endif
+
+ /* Inline Functions: */
+ static inline uint8_t Pipe_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE;
+ static inline uint8_t Pipe_BytesToEPSizeMask(const uint16_t Bytes)
+ {
+ uint8_t MaskVal = 0;
+ uint16_t CheckBytes = 8;
+
+ while ((CheckBytes < Bytes) && (CheckBytes < PIPE_MAX_SIZE))
+ {
+ MaskVal++;
+ CheckBytes <<= 1;
+ }
+
+ return (MaskVal << AVR32_USBB_PSIZE_OFFSET);
+ }
+
+ /* Function Prototypes: */
+ void Pipe_ClearPipes(void);
+ #endif
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
+
diff --git a/LUFA/Drivers/USB/Core/UC3/USBController_UC3.c b/LUFA/Drivers/USB/Core/UC3/USBController_UC3.c
new file mode 100644
index 000000000..40ac381f6
--- /dev/null
+++ b/LUFA/Drivers/USB/Core/UC3/USBController_UC3.c
@@ -0,0 +1,203 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2011.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+#define __INCLUDE_FROM_USB_DRIVER
+#define __INCLUDE_FROM_USB_CONTROLLER_C
+#include "../USBController.h"
+
+#if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY))
+volatile uint8_t USB_CurrentMode = USB_MODE_None;
+#endif
+
+#if !defined(USE_STATIC_OPTIONS)
+volatile uint8_t USB_Options;
+#endif
+
+void USB_Init(
+ #if defined(USB_CAN_BE_BOTH)
+ const uint8_t Mode
+ #endif
+
+ #if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS))
+ ,
+ #elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS))
+ void
+ #endif
+
+ #if !defined(USE_STATIC_OPTIONS)
+ const uint8_t Options
+ #endif
+ )
+{
+ #if !defined(USE_STATIC_OPTIONS)
+ USB_Options = Options;
+ #endif
+
+ #if defined(USB_CAN_BE_BOTH)
+ if (Mode == USB_MODE_UID)
+ {
+ AVR32_USBB.USBCON.uide = true;
+ USB_INT_Enable(USB_INT_IDTI);
+ USB_CurrentMode = USB_GetUSBModeFromUID();
+ }
+ else
+ {
+ AVR32_USBB.USBCON.uide = false;
+ USB_CurrentMode = Mode;
+ }
+ #endif
+
+ USB_IsInitialized = true;
+
+ USB_ResetInterface();
+}
+
+void USB_Disable(void)
+{
+ USB_INT_DisableAllInterrupts();
+ USB_INT_ClearAllInterrupts();
+
+ USB_Detach();
+ USB_Controller_Disable();
+
+ USB_OTGPAD_Off();
+
+ #if defined(USB_CAN_BE_BOTH)
+ USB_CurrentMode = USB_MODE_None;
+ #endif
+
+ AVR32_PM.GCCTRL[3].cen = false;
+
+ USB_IsInitialized = false;
+}
+
+void USB_ResetInterface(void)
+{
+ #if defined(USB_CAN_BE_BOTH)
+ bool UIDModeSelectEnabled = AVR32_USBB.USBCON.uide;
+ #endif
+
+ AVR32_PM.GCCTRL[AVR32_PM_GCLK_USBB].pllsel = !(USB_Options & USB_OPT_GCLK_SRC_OSC);
+ AVR32_PM.GCCTRL[AVR32_PM_GCLK_USBB].oscsel = !(USB_Options & USB_OPT_GCLK_CHANNEL_0);
+ AVR32_PM.GCCTRL[AVR32_PM_GCLK_USBB].diven = (F_CLOCK != USB_CLOCK_REQUIRED_FREQ);
+ AVR32_PM.GCCTRL[AVR32_PM_GCLK_USBB].div = (F_CLOCK == USB_CLOCK_REQUIRED_FREQ) ? 0 : (uint32_t)(((F_CLOCK / USB_CLOCK_REQUIRED_FREQ) - 1) / 2);
+ AVR32_PM.GCCTRL[AVR32_PM_GCLK_USBB].cen = true;
+
+ USB_INT_DisableAllInterrupts();
+ USB_INT_ClearAllInterrupts();
+
+ USB_Controller_Reset();
+
+ #if defined(USB_CAN_BE_BOTH)
+ if (UIDModeSelectEnabled)
+ {
+ AVR32_USBB.USBCON.uide = true;
+ USB_INT_Enable(USB_INT_IDTI);
+ }
+ #endif
+
+ USB_CLK_Unfreeze();
+
+ if (USB_CurrentMode == USB_MODE_Device)
+ {
+ #if defined(USB_CAN_BE_DEVICE)
+ AVR32_USBB.USBCON.uimod = true;
+ USB_Init_Device();
+ #endif
+ }
+ else if (USB_CurrentMode == USB_MODE_Host)
+ {
+ #if defined(USB_CAN_BE_HOST)
+ AVR32_USBB.USBCON.uimod = false;
+ USB_Init_Host();
+ #endif
+ }
+
+ USB_OTGPAD_On();
+}
+
+#if defined(USB_CAN_BE_DEVICE)
+static void USB_Init_Device(void)
+{
+ USB_DeviceState = DEVICE_STATE_Unattached;
+ USB_ConfigurationNumber = 0;
+
+ #if !defined(NO_DEVICE_REMOTE_WAKEUP)
+ USB_RemoteWakeupEnabled = false;
+ #endif
+
+ #if !defined(NO_DEVICE_SELF_POWER)
+ USB_CurrentlySelfPowered = false;
+ #endif
+
+ #if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
+ USB_Descriptor_Device_t* DeviceDescriptorPtr;
+
+ if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr) != NO_DESCRIPTOR)
+ USB_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;
+ #endif
+
+ if (USB_Options & USB_DEVICE_OPT_LOWSPEED)
+ USB_Device_SetLowSpeed();
+ else
+ USB_Device_SetFullSpeed();
+
+ USB_INT_Enable(USB_INT_VBUSTI);
+
+ Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
+ ENDPOINT_DIR_OUT, USB_ControlEndpointSize,
+ ENDPOINT_BANK_SINGLE);
+
+ USB_INT_Clear(USB_INT_SUSPI);
+ USB_INT_Enable(USB_INT_SUSPI);
+ USB_INT_Enable(USB_INT_EORSTI);
+
+ USB_Attach();
+ USB_Device_SetDeviceAddress(0);
+}
+#endif
+
+#if defined(USB_CAN_BE_HOST)
+static void USB_Init_Host(void)
+{
+ USB_HostState = HOST_STATE_Unattached;
+ USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;
+
+ USB_Host_HostMode_On();
+
+ USB_Host_VBUS_Auto_On();
+
+ USB_INT_Enable(USB_INT_DCONNI);
+ USB_INT_Enable(USB_INT_BCERRI);
+
+ USB_Attach();
+}
+#endif
+
diff --git a/LUFA/Drivers/USB/Core/UC3/USBController_UC3.h b/LUFA/Drivers/USB/Core/UC3/USBController_UC3.h
new file mode 100644
index 000000000..c975bb3e9
--- /dev/null
+++ b/LUFA/Drivers/USB/Core/UC3/USBController_UC3.h
@@ -0,0 +1,379 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2011.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ * \brief USB Controller definitions for the AVR32 UC3 microcontrollers.
+ * \copydetails Group_USBManagement_UC3
+ *
+ * \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_USBManagement
+ * \defgroup Group_USBManagement_UC3 USB Interface Management (UC3)
+ * \brief USB Controller definitions for the AVR32 UC3 microcontrollers.
+ *
+ * Functions, macros, variables, enums and types related to the setup and management of the USB interface.
+ *
+ * @{
+ */
+
+#ifndef __USBCONTROLLER_UC3_H__
+#define __USBCONTROLLER_UC3_H__
+
+ /* Includes: */
+ #include "../../../../Common/Common.h"
+ #include "../USBMode.h"
+ #include "../Events.h"
+ #include "../USBTask.h"
+ #include "../USBInterrupt.h"
+
+ #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__)
+ #include "../Host.h"
+ #include "../OTG.h"
+ #include "../Pipe.h"
+ #include "../HostStandardReq.h"
+ #include "../PipeStream.h"
+ #endif
+
+ #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)
+ #include "../Device.h"
+ #include "../Endpoint.h"
+ #include "../DeviceStandardReq.h"
+ #include "../EndpointStream.h"
+ #endif
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Preprocessor Checks and Defines: */
+ #if !defined(__INCLUDE_FROM_USB_DRIVER)
+ #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
+ #endif
+
+ /* Public Interface - May be used in end-application: */
+ /* Macros: */
+ /** \name USB Controller Option Masks */
+ //@{
+ /** Selects one of the system's main clock oscillators as the input clock to the USB Generic Clock source
+ * generation module. This indicates that an external oscillator should be used directly instead of an
+ * internal PLL clock source.
+ */
+ #define USB_OPT_GCLK_SRC_OSC (1 << 1)
+
+ /** Selects one of the system's PLL oscillators as the input clock to the USB Generic Clock source
+ * generation module. This indicates that one of the device's PLL outputs should be used instead of an
+ * external oscillator source.
+ */
+ #define USB_OPT_GCLK_SRC_PLL (0 << 1)
+
+ /** Selects PLL or External Oscillator 0 as the USB Generic Clock source module input clock. */
+ #define USB_OPT_GCLK_CHANNEL_0 (1 << 2)
+
+ /** Selects PLL or External Oscillator 1 as the USB Generic Clock source module input clock. */
+ #define USB_OPT_GCLK_CHANNEL_1 (0 << 2)
+ //@}
+
+ /** \name Endpoint/Pipe Type Masks */
+ //@{
+ /** Mask for a CONTROL type endpoint or pipe.
+ *
+ * \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
+ */
+ #define EP_TYPE_CONTROL 0x00
+
+ /** Mask for an ISOCHRONOUS type endpoint or pipe.
+ *
+ * \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
+ */
+ #define EP_TYPE_ISOCHRONOUS 0x01
+
+ /** Mask for a BULK type endpoint or pipe.
+ *
+ * \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
+ */
+ #define EP_TYPE_BULK 0x02
+
+ /** Mask for an INTERRUPT type endpoint or pipe.
+ *
+ * \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
+ */
+ #define EP_TYPE_INTERRUPT 0x03
+ //@}
+
+ #if !defined(USB_STREAM_TIMEOUT_MS) || defined(__DOXYGEN__)
+ /** Constant for the maximum software timeout period of the USB data stream transfer functions
+ * (both control and standard) when in either device or host mode. If the next packet of a stream
+ * is not received or acknowledged within this time period, the stream function will fail.
+ *
+ * This value may be overridden in the user project makefile as the value of the
+ * \ref USB_STREAM_TIMEOUT_MS token, and passed to the compiler using the -D switch.
+ */
+ #define USB_STREAM_TIMEOUT_MS 100
+ #endif
+
+ /* Inline Functions: */
+ /** Determines if the VBUS line is currently high (i.e. the USB host is supplying power).
+ *
+ * \return Boolean \c true if the VBUS line is currently detecting power from a host, \c false otherwise.
+ */
+ static inline bool USB_VBUS_GetStatus(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline bool USB_VBUS_GetStatus(void)
+ {
+ return AVR32_USBB.USBSTA.vbus;
+ }
+
+ /** Detaches the device from the USB bus. This has the effect of removing the device from any
+ * attached host, ceasing USB communications. If no host is present, this prevents any host from
+ * enumerating the device once attached until \ref USB_Attach() is called.
+ */
+ static inline void USB_Detach(void) ATTR_ALWAYS_INLINE;
+ static inline void USB_Detach(void)
+ {
+ AVR32_USBB.UDCON.detach = true;
+ }
+
+ /** Attaches the device to the USB bus. This announces the device's presence to any attached
+ * USB host, starting the enumeration process. If no host is present, attaching the device
+ * will allow for enumeration once a host is connected to the device.
+ *
+ * This is inexplicably also required for proper operation while in host mode, to enable the
+ * attachment of a device to the host. This is despite the bit being located in the device-mode
+ * register and despite the datasheet making no mention of its requirement in host mode.
+ */
+ static inline void USB_Attach(void) ATTR_ALWAYS_INLINE;
+ static inline void USB_Attach(void)
+ {
+ AVR32_USBB.UDCON.detach = false;
+ }
+
+ /* Function Prototypes: */
+ /** Main function to initialize and start the USB interface. Once active, the USB interface will
+ * 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 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.
+ *
+ * \param[in] Mode This is a mask indicating what mode the USB interface is to be initialized to, a value
+ * from the \ref USB_Modes_t enum.
+ *
+ * \param[in] Options Mask indicating the options which should be used when initializing the USB
+ * interface to control the USB interface's behaviour. This should be comprised of
+ * a \c USB_OPT_REG_* mask to control the regulator, a \c USB_OPT_*_PLL mask to control the
+ * PLL, and a \c USB_DEVICE_OPT_* mask (when the device mode is enabled) to set the device
+ * mode speed.
+ *
+ * \note To reduce the FLASH requirements of the library if only device or host mode is required,
+ * the mode can be statically set in the project makefile by defining the token \c USB_DEVICE_ONLY
+ * (for device mode) or \c 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 \c 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.
+ *
+ * \see \ref Group_Device for the \c USB_DEVICE_OPT_* masks.
+ */
+ void USB_Init(
+ #if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__)
+ const uint8_t Mode
+ #endif
+
+ #if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS)) || defined(__DOXYGEN__)
+ ,
+ #elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS))
+ void
+ #endif
+
+ #if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__)
+ const uint8_t Options
+ #endif
+ );
+
+ /** Shuts down the USB interface. This turns off the USB interface after deallocating all USB FIFO
+ * memory, endpoints and pipes. When turned off, no USB functionality can be used until the interface
+ * is restarted with the \ref USB_Init() function.
+ */
+ void USB_Disable(void);
+
+ /** Resets the interface, when already initialized. This will re-enumerate the device if already connected
+ * to a host, or re-enumerate an already attached device when in host mode.
+ */
+ void USB_ResetInterface(void);
+
+ /* Global Variables: */
+ #if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY)) || defined(__DOXYGEN__)
+ /** Indicates the mode that the USB interface is currently initialized to, a value from the
+ * \ref USB_Modes_t enum.
+ *
+ * \note This variable should be treated as read-only in the user application, and never manually
+ * changed in value.
+ * \n\n
+ *
+ * \note When the controller is initialized into UID auto-detection mode, this variable will hold the
+ * currently selected USB mode (i.e. \ref USB_MODE_Device or \ref USB_MODE_Host). If the controller
+ * is fixed into a specific mode (either through the \c USB_DEVICE_ONLY or \c USB_HOST_ONLY compile time
+ * options, or a limitation of the USB controller in the chosen device model) this will evaluate to
+ * a constant of the appropriate value and will never evaluate to \ref USB_MODE_None even when the
+ * USB interface is not initialized.
+ */
+ extern volatile uint8_t USB_CurrentMode;
+ #elif defined(USB_HOST_ONLY)
+ #define USB_CurrentMode USB_MODE_Host
+ #elif defined(USB_DEVICE_ONLY)
+ #define USB_CurrentMode USB_MODE_Device
+ #endif
+
+ #if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__)
+ /** Indicates the current USB options that the USB interface was initialized with when \ref USB_Init()
+ * was called. This value will be one of the \c USB_MODE_* masks defined elsewhere in this module.
+ *
+ * \note This variable should be treated as read-only in the user application, and never manually
+ * changed in value.
+ */
+ extern volatile uint8_t USB_Options;
+ #elif defined(USE_STATIC_OPTIONS)
+ #define USB_Options USE_STATIC_OPTIONS
+ #endif
+
+ /* Enums: */
+ /** Enum for the possible USB controller modes, for initialization via \ref USB_Init() and indication back to the
+ * user application via \ref USB_CurrentMode.
+ */
+ enum USB_Modes_t
+ {
+ USB_MODE_None = 0, /**< Indicates that the controller is currently not initialized in any specific USB mode. */
+ USB_MODE_Device = 1, /**< Indicates that the controller is currently initialized in USB Device mode. */
+ USB_MODE_Host = 2, /**< Indicates that the controller is currently initialized in USB Host mode. */
+ USB_MODE_UID = 3, /**< Indicates that the controller should determine the USB mode from the UID pin of the
+ * USB connector.
+ */
+ };
+
+ /* Private Interface - For use in library only: */
+ #if !defined(__DOXYGEN__)
+ /* Macros: */
+ #if defined(USB_SERIES_UC3A3_AVR)
+ #define USB_CLOCK_REQUIRED_FREQ 12000000UL
+ #else
+ #define USB_CLOCK_REQUIRED_FREQ 48000000UL
+ #endif
+
+ /* Function Prototypes: */
+ #if defined(__INCLUDE_FROM_USB_CONTROLLER_C)
+ #if defined(USB_CAN_BE_DEVICE)
+ static void USB_Init_Device(void);
+ #endif
+
+ #if defined(USB_CAN_BE_HOST)
+ static void USB_Init_Host(void);
+ #endif
+ #endif
+
+ /* Inline Functions: */
+ static inline void USB_OTGPAD_On(void) ATTR_ALWAYS_INLINE;
+ static inline void USB_OTGPAD_On(void)
+ {
+ AVR32_USBB.USBCON.otgpade = true;
+ }
+
+ static inline void USB_OTGPAD_Off(void) ATTR_ALWAYS_INLINE;
+ static inline void USB_OTGPAD_Off(void)
+ {
+ AVR32_USBB.USBCON.otgpade = false;
+ }
+
+ static inline void USB_CLK_Freeze(void) ATTR_ALWAYS_INLINE;
+ static inline void USB_CLK_Freeze(void)
+ {
+ AVR32_USBB.USBCON.frzclk = true;
+ }
+
+ static inline void USB_CLK_Unfreeze(void) ATTR_ALWAYS_INLINE;
+ static inline void USB_CLK_Unfreeze(void)
+ {
+ AVR32_USBB.USBCON.frzclk = false;
+ }
+
+ static inline void USB_Controller_Enable(void) ATTR_ALWAYS_INLINE;
+ static inline void USB_Controller_Enable(void)
+ {
+ AVR32_USBB.USBCON.usbe = true;
+ }
+
+ static inline void USB_Controller_Disable(void) ATTR_ALWAYS_INLINE;
+ static inline void USB_Controller_Disable(void)
+ {
+ AVR32_USBB.USBCON.usbe = false;
+ }
+
+ static inline void USB_Controller_Reset(void) ATTR_ALWAYS_INLINE;
+ static inline void USB_Controller_Reset(void)
+ {
+ AVR32_USBB.USBCON.usbe = false;
+ AVR32_USBB.USBCON.usbe = true;
+ }
+
+ #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 (AVR32_USBB.USBSTA.id)
+ return USB_MODE_Device;
+ else
+ return USB_MODE_Host;
+ }
+ #endif
+
+ #endif
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
+
diff --git a/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c b/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c
new file mode 100644
index 000000000..aee8940e3
--- /dev/null
+++ b/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c
@@ -0,0 +1,204 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2011.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+#define __INCLUDE_FROM_USB_DRIVER
+#include "../USBInterrupt.h"
+
+void USB_INT_DisableAllInterrupts(void)
+{
+ AVR32_USBB.USBCON.vbuste = false;
+ AVR32_USBB.USBCON.idte = false;
+
+ AVR32_USBB.uhinteclr = 0xFFFFFFFF;
+ AVR32_USBB.udinteclr = 0xFFFFFFFF;
+}
+
+void USB_INT_ClearAllInterrupts(void)
+{
+ AVR32_USBB.USBSTACLR.vbustic = true;
+ AVR32_USBB.USBSTACLR.idtic = true;
+
+ AVR32_USBB.uhintclr = 0xFFFFFFFF;
+ AVR32_USBB.udintclr = 0xFFFFFFFF;
+}
+
+ISR(USB_GEN_vect)
+{
+ #if defined(USB_CAN_BE_DEVICE)
+ #if !defined(NO_SOF_EVENTS)
+ if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI))
+ {
+ USB_INT_Clear(USB_INT_SOFI);
+
+ EVENT_USB_Device_StartOfFrame();
+ }
+ #endif
+
+ if (USB_INT_HasOccurred(USB_INT_VBUSTI) && USB_INT_IsEnabled(USB_INT_VBUSTI))
+ {
+ USB_INT_Clear(USB_INT_VBUSTI);
+
+ if (USB_VBUS_GetStatus())
+ {
+ USB_DeviceState = DEVICE_STATE_Powered;
+ EVENT_USB_Device_Connect();
+ }
+ else
+ {
+ USB_DeviceState = DEVICE_STATE_Unattached;
+ EVENT_USB_Device_Disconnect();
+ }
+ }
+
+ if (USB_INT_HasOccurred(USB_INT_SUSPI) && USB_INT_IsEnabled(USB_INT_SUSPI))
+ {
+ USB_INT_Clear(USB_INT_SUSPI);
+
+ USB_INT_Disable(USB_INT_SUSPI);
+ USB_INT_Enable(USB_INT_WAKEUPI);
+
+ USB_CLK_Freeze();
+
+ USB_DeviceState = DEVICE_STATE_Suspended;
+ EVENT_USB_Device_Suspend();
+ }
+
+ if (USB_INT_HasOccurred(USB_INT_WAKEUPI) && USB_INT_IsEnabled(USB_INT_WAKEUPI))
+ {
+ USB_CLK_Unfreeze();
+
+ USB_INT_Clear(USB_INT_WAKEUPI);
+
+ USB_INT_Disable(USB_INT_WAKEUPI);
+ USB_INT_Enable(USB_INT_SUSPI);
+
+ if (USB_ConfigurationNumber)
+ USB_DeviceState = DEVICE_STATE_Configured;
+ else
+ USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered;
+
+ EVENT_USB_Device_WakeUp();
+ }
+
+ if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI))
+ {
+ USB_INT_Clear(USB_INT_EORSTI);
+
+ USB_DeviceState = DEVICE_STATE_Default;
+ USB_ConfigurationNumber = 0;
+
+ USB_INT_Clear(USB_INT_SUSPI);
+ USB_INT_Disable(USB_INT_SUSPI);
+ USB_INT_Enable(USB_INT_WAKEUPI);
+
+ USB_Device_SetDeviceAddress(0);
+ Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
+ ENDPOINT_DIR_OUT, USB_ControlEndpointSize,
+ ENDPOINT_BANK_SINGLE);
+
+ EVENT_USB_Device_Reset();
+ }
+ #endif
+
+ #if defined(USB_CAN_BE_HOST)
+ #if !defined(NO_SOF_EVENTS)
+ if (USB_INT_HasOccurred(USB_INT_HSOFI) && USB_INT_IsEnabled(USB_INT_HSOFI))
+ {
+ USB_INT_Clear(USB_INT_HSOFI);
+
+ EVENT_USB_Host_StartOfFrame();
+ }
+ #endif
+
+ if (USB_INT_HasOccurred(USB_INT_DDISCI) && USB_INT_IsEnabled(USB_INT_DDISCI))
+ {
+ USB_INT_Clear(USB_INT_DDISCI);
+ USB_INT_Clear(USB_INT_DCONNI);
+ USB_INT_Disable(USB_INT_DDISCI);
+
+ EVENT_USB_Host_DeviceUnattached();
+
+ USB_ResetInterface();
+ }
+
+ if (USB_INT_HasOccurred(USB_INT_VBERRI) && USB_INT_IsEnabled(USB_INT_VBERRI))
+ {
+ USB_INT_Clear(USB_INT_VBERRI);
+
+ USB_Host_VBUS_Manual_Off();
+ USB_Host_VBUS_Auto_Off();
+
+ EVENT_USB_Host_HostError(HOST_ERROR_VBusVoltageDip);
+ EVENT_USB_Host_DeviceUnattached();
+
+ USB_HostState = HOST_STATE_Unattached;
+ }
+
+ if (USB_INT_HasOccurred(USB_INT_DCONNI) && USB_INT_IsEnabled(USB_INT_DCONNI))
+ {
+ USB_INT_Clear(USB_INT_DCONNI);
+ USB_INT_Disable(USB_INT_DCONNI);
+
+ EVENT_USB_Host_DeviceAttached();
+
+ USB_INT_Enable(USB_INT_DDISCI);
+
+ USB_HostState = HOST_STATE_Powered;
+ }
+
+ if (USB_INT_HasOccurred(USB_INT_BCERRI) && USB_INT_IsEnabled(USB_INT_BCERRI))
+ {
+ USB_INT_Clear(USB_INT_BCERRI);
+
+ EVENT_USB_Host_DeviceEnumerationFailed(HOST_ENUMERROR_NoDeviceDetected, 0);
+ EVENT_USB_Host_DeviceUnattached();
+
+ USB_ResetInterface();
+ }
+ #endif
+
+ #if defined(USB_CAN_BE_BOTH)
+ if (USB_INT_HasOccurred(USB_INT_IDTI) && USB_INT_IsEnabled(USB_INT_IDTI))
+ {
+ USB_INT_Clear(USB_INT_IDTI);
+
+ if (USB_DeviceState != DEVICE_STATE_Unattached)
+ EVENT_USB_Device_Disconnect();
+
+ if (USB_HostState != HOST_STATE_Unattached)
+ EVENT_USB_Host_DeviceUnattached();
+
+ USB_CurrentMode = USB_GetUSBModeFromUID();
+ USB_ResetInterface();
+
+ EVENT_USB_UIDChange();
+ }
+ #endif
+}
diff --git a/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.h b/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.h
new file mode 100644
index 000000000..119243360
--- /dev/null
+++ b/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.h
@@ -0,0 +1,344 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2011.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ * \brief USB Controller Interrupt definitions for the AVR32 UC3 microcontrollers.
+ *
+ * This file contains definitions required for the correct handling of low level USB service routine interrupts
+ * from the USB controller.
+ *
+ * \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.
+ */
+
+#ifndef __USBINTERRUPT_UC3_H__
+#define __USBINTERRUPT_UC3_H__
+
+ /* Includes: */
+ #include "../../../../Common/Common.h"
+
+ /* Enable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ extern "C" {
+ #endif
+
+ /* Preprocessor Checks: */
+ #if !defined(__INCLUDE_FROM_USB_DRIVER)
+ #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
+ #endif
+
+ /* Private Interface - For use in library only: */
+ #if !defined(__DOXYGEN__)
+ /* Macros: */
+ enum USB_Interrupts_t
+ {
+ USB_INT_VBUSTI = 0,
+ #if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__))
+ USB_INT_IDTI = 1,
+ #endif
+ #if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__))
+ USB_INT_WAKEUPI = 2,
+ USB_INT_SUSPI = 3,
+ USB_INT_EORSTI = 4,
+ USB_INT_SOFI = 5,
+ #endif
+ #if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__))
+ USB_INT_HSOFI = 6,
+ USB_INT_DCONNI = 7,
+ USB_INT_DDISCI = 8,
+ USB_INT_RSTI = 9,
+ USB_INT_BCERRI = 10,
+ USB_INT_VBERRI = 11,
+ #endif
+ };
+
+ /* ISR Prototypes: */
+ ISR(USB_GEN_vect);
+
+ /* Inline Functions: */
+ static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
+ static inline void USB_INT_Enable(const uint8_t Interrupt)
+ {
+ switch (Interrupt)
+ {
+ case USB_INT_VBUSTI:
+ AVR32_USBB.USBCON.vbuste = true;
+ break;
+ #if defined(USB_CAN_BE_BOTH)
+ case USB_INT_IDTI:
+ AVR32_USBB.USBCON.idte = true;
+ break;
+ #endif
+ #if defined(USB_CAN_BE_DEVICE)
+ case USB_INT_WAKEUPI:
+ AVR32_USBB.UDINTESET.wakeupes = true;
+ break;
+ case USB_INT_SUSPI:
+ AVR32_USBB.UDINTESET.suspes = true;
+ break;
+ case USB_INT_EORSTI:
+ AVR32_USBB.UDINTESET.eorstes = true;
+ break;
+ case USB_INT_SOFI:
+ AVR32_USBB.UDINTESET.sofes = true;
+ break;
+ #endif
+ #if defined(USB_CAN_BE_HOST)
+ case USB_INT_HSOFI:
+ AVR32_USBB.UHINTESET.hsofies = true;
+ break;
+ case USB_INT_DCONNI:
+ AVR32_USBB.UHINTESET.dconnies = true;
+ break;
+ case USB_INT_DDISCI:
+ AVR32_USBB.UHINTESET.ddiscies = true;
+ break;
+ case USB_INT_RSTI:
+ AVR32_USBB.UHINTESET.rsties = true;
+ break;
+ case USB_INT_BCERRI:
+ AVR32_USBB.USBCON.bcerre = true;
+ break;
+ case USB_INT_VBERRI:
+ AVR32_USBB.USBCON.vberre = true;
+ break;
+ #endif
+ }
+ }
+
+ static inline void USB_INT_Disable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
+ static inline void USB_INT_Disable(const uint8_t Interrupt)
+ {
+ switch (Interrupt)
+ {
+ case USB_INT_VBUSTI:
+ AVR32_USBB.USBCON.vbuste = false;
+ break;
+ #if defined(USB_CAN_BE_BOTH)
+ case USB_INT_IDTI:
+ AVR32_USBB.USBCON.idte = false;
+ break;
+ #endif
+ #if defined(USB_CAN_BE_DEVICE)
+ case USB_INT_WAKEUPI:
+ AVR32_USBB.UDINTECLR.wakeupec = true;
+ break;
+ case USB_INT_SUSPI:
+ AVR32_USBB.UDINTECLR.suspec = true;
+ break;
+ case USB_INT_EORSTI:
+ AVR32_USBB.UDINTECLR.eorstec = true;
+ break;
+ case USB_INT_SOFI:
+ AVR32_USBB.UDINTECLR.sofec = true;
+ break;
+ #endif
+ #if defined(USB_CAN_BE_HOST)
+ case USB_INT_HSOFI:
+ AVR32_USBB.UHINTECLR.hsofiec = true;
+ break;
+ case USB_INT_DCONNI:
+ AVR32_USBB.UHINTECLR.dconniec = true;
+ break;
+ case USB_INT_DDISCI:
+ AVR32_USBB.UHINTECLR.ddisciec = true;
+ break;
+ case USB_INT_RSTI:
+ AVR32_USBB.UHINTECLR.rstiec = true;
+ break;
+ case USB_INT_BCERRI:
+ AVR32_USBB.USBCON.bcerre = false;
+ break;
+ case USB_INT_VBERRI:
+ AVR32_USBB.USBCON.vberre = false;
+ break;
+ #endif
+ }
+ }
+
+ static inline void USB_INT_Clear(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
+ static inline void USB_INT_Clear(const uint8_t Interrupt)
+ {
+ switch (Interrupt)
+ {
+ case USB_INT_VBUSTI:
+ AVR32_USBB.USBSTACLR.vbustic = true;
+ (void)AVR32_USBB.USBSTACLR;
+ break;
+ #if defined(USB_CAN_BE_BOTH)
+ case USB_INT_IDTI:
+ AVR32_USBB.USBSTACLR.idtic = true;
+ (void)AVR32_USBB.USBSTACLR;
+ break;
+ #endif
+ #if defined(USB_CAN_BE_DEVICE)
+ case USB_INT_WAKEUPI:
+ AVR32_USBB.UDINTCLR.wakeupc = true;
+ (void)AVR32_USBB.UDINTCLR;
+ break;
+ case USB_INT_SUSPI:
+ AVR32_USBB.UDINTCLR.suspc = true;
+ (void)AVR32_USBB.UDINTCLR;
+ break;
+ case USB_INT_EORSTI:
+ AVR32_USBB.UDINTCLR.eorstc = true;
+ (void)AVR32_USBB.UDINTCLR;
+ break;
+ case USB_INT_SOFI:
+ AVR32_USBB.UDINTCLR.sofc = true;
+ (void)AVR32_USBB.UDINTCLR;
+ break;
+ #endif
+ #if defined(USB_CAN_BE_HOST)
+ case USB_INT_HSOFI:
+ AVR32_USBB.UHINTCLR.hsofic = true;
+ (void)AVR32_USBB.UHINTCLR;
+ break;
+ case USB_INT_DCONNI:
+ AVR32_USBB.UHINTCLR.dconnic = true;
+ (void)AVR32_USBB.UHINTCLR;
+ break;
+ case USB_INT_DDISCI:
+ AVR32_USBB.UHINTCLR.ddiscic = true;
+ (void)AVR32_USBB.UHINTCLR;
+ break;
+ case USB_INT_RSTI:
+ AVR32_USBB.UHINTCLR.rstic = true;
+ (void)AVR32_USBB.UHINTCLR;
+ break;
+ case USB_INT_BCERRI:
+ AVR32_USBB.USBSTACLR.bcerric = true;
+ (void)AVR32_USBB.USBSTACLR;
+ break;
+ case USB_INT_VBERRI:
+ AVR32_USBB.USBSTACLR.vberric = true;
+ (void)AVR32_USBB.USBSTACLR;
+ break;
+ #endif
+ }
+ }
+
+ static inline bool USB_INT_IsEnabled(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
+ static inline bool USB_INT_IsEnabled(const uint8_t Interrupt)
+ {
+ switch (Interrupt)
+ {
+ case USB_INT_VBUSTI:
+ return AVR32_USBB.USBCON.vbuste;
+ #if defined(USB_CAN_BE_BOTH)
+ case USB_INT_IDTI:
+ return AVR32_USBB.USBCON.idte;
+ #endif
+ #if defined(USB_CAN_BE_DEVICE)
+ case USB_INT_WAKEUPI:
+ return AVR32_USBB.UDINTE.wakeupe;
+ case USB_INT_SUSPI:
+ return AVR32_USBB.UDINTE.suspe;
+ case USB_INT_EORSTI:
+ return AVR32_USBB.UDINTE.eorste;
+ case USB_INT_SOFI:
+ return AVR32_USBB.UDINTE.sofe;
+ #endif
+ #if defined(USB_CAN_BE_HOST)
+ case USB_INT_HSOFI:
+ return AVR32_USBB.UHINTE.hsofie;
+ case USB_INT_DCONNI:
+ return AVR32_USBB.UHINTE.dconnie;
+ case USB_INT_DDISCI:
+ return AVR32_USBB.UHINTE.ddiscie;
+ case USB_INT_RSTI:
+ return AVR32_USBB.UHINTE.rstie;
+ case USB_INT_BCERRI:
+ return AVR32_USBB.USBCON.bcerre;
+ case USB_INT_VBERRI:
+ return AVR32_USBB.USBCON.vberre;
+ #endif
+ }
+
+ return false;
+ }
+
+ static inline bool USB_INT_HasOccurred(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
+ static inline bool USB_INT_HasOccurred(const uint8_t Interrupt)
+ {
+ switch (Interrupt)
+ {
+ case USB_INT_VBUSTI:
+ return AVR32_USBB.USBSTA.vbusti;
+ #if defined(USB_CAN_BE_BOTH)
+ case USB_INT_IDTI:
+ return AVR32_USBB.USBSTA.idti;
+ #endif
+ #if defined(USB_CAN_BE_DEVICE)
+ case USB_INT_WAKEUPI:
+ return AVR32_USBB.UDINT.wakeup;
+ case USB_INT_SUSPI:
+ return AVR32_USBB.UDINT.susp;
+ case USB_INT_EORSTI:
+ return AVR32_USBB.UDINT.eorst;
+ case USB_INT_SOFI:
+ return AVR32_USBB.UDINT.sof;
+ #endif
+ #if defined(USB_CAN_BE_HOST)
+ case USB_INT_HSOFI:
+ return AVR32_USBB.UHINT.hsofi;
+ case USB_INT_DCONNI:
+ return AVR32_USBB.UHINT.dconni;
+ case USB_INT_DDISCI:
+ return AVR32_USBB.UHINT.ddisci;
+ case USB_INT_RSTI:
+ return AVR32_USBB.UHINT.rsti;
+ case USB_INT_BCERRI:
+ return AVR32_USBB.USBSTA.bcerri;
+ case USB_INT_VBERRI:
+ return AVR32_USBB.USBSTA.vberri;
+ #endif
+ }
+
+ return false;
+ }
+
+ /* Includes: */
+ #include "../USBMode.h"
+ #include "../Events.h"
+ #include "../USBController.h"
+
+ /* Function Prototypes: */
+ void USB_INT_ClearAllInterrupts(void);
+ void USB_INT_DisableAllInterrupts(void);
+ #endif
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+