3 Copyright (C) Dean Camera, 2011.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
32 * \brief USB Device definitions for the AVR32 UC3B microcontrollers.
33 * \copydetails Group_Device_UC3B
35 * \note This file should not be included directly. It is automatically included as needed by the USB driver
36 * dispatch header located in LUFA/Drivers/USB/USB.h.
39 /** \ingroup Group_Device
40 * \defgroup Group_Device_UC3B Device Management (UC3B)
41 * \brief USB Device definitions for the AVR32 UC3B microcontrollers.
43 * Architecture specific USB Device definitions for the Atmel 32-bit UC3B AVR microcontrollers.
48 #ifndef __USBDEVICE_UC3B_H__
49 #define __USBDEVICE_UC3B_H__
52 #include "../../../../Common/Common.h"
53 #include "../StdDescriptors.h"
54 #include "../USBInterrupt.h"
55 #include "../Endpoint.h"
57 /* Preprocessor Checks: */
58 #if !defined(__INCLUDE_FROM_USB_DRIVER)
59 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
62 /* Public Interface - May be used in end-application: */
64 /** \name USB Device Mode Option Masks */
66 /** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
67 * USB interface should be initialized in low speed (1.5Mb/s) mode.
69 * \note Restrictions apply on the number, size and type of endpoints which can be used
70 * when running in low speed mode - refer to the USB 2.0 specification.
72 #define USB_DEVICE_OPT_LOWSPEED (1 << 0)
74 /** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
75 * USB interface should be initialized in full speed (12Mb/s) mode.
77 #define USB_DEVICE_OPT_FULLSPEED (0 << 0)
80 /** String descriptor index for the device's unique serial number string descriptor within the device.
81 * This unique serial number is used by the host to associate resources to the device (such as drivers or COM port
82 * number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain
83 * a unique serial number internally, and setting the device descriptors serial number string index to this value
84 * will cause it to use the internal serial number.
86 * On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial
87 * number for the device.
89 #define USE_INTERNAL_SERIAL NO_DESCRIPTOR
91 /* Function Prototypes: */
92 /** Sends a Remote Wakeup request to the host. This signals to the host that the device should
93 * be taken out of suspended mode, and communications should resume.
95 * Typically, this is implemented so that HID devices (mice, keyboards, etc.) can wake up the
96 * host computer when the host has suspended all USB devices to enter a low power state.
98 * \note This macro should only be used if the device has indicated to the host that it
99 * supports the Remote Wakeup feature in the device descriptors, and should only be
100 * issued if the host is currently allowing remote wakeup events from the device (i.e.,
101 * the \ref USB_RemoteWakeupEnabled flag is set). When the \c NO_DEVICE_REMOTE_WAKEUP compile
102 * time option is used, this macro is unavailable.
105 * \note The USB clock must be running for this function to operate. If the stack is initialized with
106 * the \ref USB_OPT_MANUAL_PLL option enabled, the user must ensure that the PLL is running
107 * before attempting to call this function.
109 * \see \ref Group_StdDescriptors for more information on the RMWAKEUP feature and device descriptors.
111 void USB_Device_SendRemoteWakeup(void);
113 /* Inline Functions: */
114 /** Returns the current USB frame number, when in device mode. Every millisecond the USB bus is active (i.e. enumerated to a host)
115 * the frame number is incremented by one.
117 static inline uint16_t USB_Device_GetFrameNumber(void)
119 return AVR32_USBB
.UDFNUM
.fnum
;
122 #if !defined(NO_SOF_EVENTS)
123 /** Enables the device mode Start Of Frame events. When enabled, this causes the
124 * \ref EVENT_USB_Device_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,
125 * at the start of each USB frame when enumerated in device mode.
127 * \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
129 static inline void USB_Device_EnableSOFEvents(void) ATTR_ALWAYS_INLINE
;
130 static inline void USB_Device_EnableSOFEvents(void)
132 USB_INT_Enable(USB_INT_SOFI
);
135 /** Disables the device mode Start Of Frame events. When disabled, this stops the firing of the
136 * \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode.
138 * \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
140 static inline void USB_Device_DisableSOFEvents(void) ATTR_ALWAYS_INLINE
;
141 static inline void USB_Device_DisableSOFEvents(void)
143 USB_INT_Disable(USB_INT_SOFI
);
147 /* Private Interface - For use in library only: */
148 #if !defined(__DOXYGEN__)
149 /* Inline Functions: */
150 static inline void USB_Device_SetLowSpeed(void) ATTR_ALWAYS_INLINE
;
151 static inline void USB_Device_SetLowSpeed(void)
153 AVR32_USBB
.UDCON
.ls
= true;
156 static inline void USB_Device_SetFullSpeed(void) ATTR_ALWAYS_INLINE
;
157 static inline void USB_Device_SetFullSpeed(void)
159 AVR32_USBB
.UDCON
.ls
= false;
162 static inline void USB_Device_SetDeviceAddress(const uint8_t Address
) ATTR_ALWAYS_INLINE
;
163 static inline void USB_Device_SetDeviceAddress(const uint8_t Address
)
165 AVR32_USBB
.UDCON
.uadd
= Address
;
166 AVR32_USBB
.UDCON
.adden
= true;
169 static inline bool USB_Device_IsAddressSet(void) ATTR_ALWAYS_INLINE
;
170 static inline bool USB_Device_IsAddressSet(void)
172 return AVR32_USBB
.UDCON
.adden
;