Add missing doxygen group terminator to the new CompilerSpecific.h header file.
[pub/USBasp.git] / LUFA / Drivers / USB / Core / AVR8 / Device_AVR8.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2011.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
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
28 this software.
29 */
30
31 /** \file
32 * \brief USB Device definitions for the AVR8 microcontrollers.
33 * \copydetails Group_Device_AVR8
34 *
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.
37 */
38
39 /** \ingroup Group_Device
40 * \defgroup Group_Device_AVR8 Device Management (AVR8)
41 * \brief USB Device definitions for the AVR8 microcontrollers.
42 *
43 * Architecture specific USB Device definitions for the Atmel 8-bit AVR microcontrollers.
44 *
45 * @{
46 */
47
48 #ifndef __USBDEVICE_AVR8_H__
49 #define __USBDEVICE_AVR8_H__
50
51 /* Includes: */
52 #include "../../../../Common/Common.h"
53 #include "../StdDescriptors.h"
54 #include "../USBInterrupt.h"
55 #include "../Endpoint.h"
56
57 /* Enable C linkage for C++ Compilers: */
58 #if defined(__cplusplus)
59 extern "C" {
60 #endif
61
62 /* Preprocessor Checks: */
63 #if !defined(__INCLUDE_FROM_USB_DRIVER)
64 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
65 #endif
66
67 #if (defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS))
68 #error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive.
69 #endif
70
71 /* Public Interface - May be used in end-application: */
72 /* Macros: */
73 /** \name USB Device Mode Option Masks */
74 //@{
75 #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)
76 /** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
77 * USB interface should be initialized in low speed (1.5Mb/s) mode.
78 *
79 * \note Low Speed mode is not available on all USB AVR models.
80 * \n
81 *
82 * \note Restrictions apply on the number, size and type of endpoints which can be used
83 * when running in low speed mode - refer to the USB 2.0 specification.
84 */
85 #define USB_DEVICE_OPT_LOWSPEED (1 << 0)
86 #endif
87
88 /** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
89 * USB interface should be initialized in full speed (12Mb/s) mode.
90 */
91 #define USB_DEVICE_OPT_FULLSPEED (0 << 0)
92 //@}
93
94 #if (!defined(NO_INTERNAL_SERIAL) && \
95 (defined(USB_SERIES_7_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_4_AVR) || \
96 (defined(USB_SERIES_2_AVR) && (!defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__))) || \
97 defined(__DOXYGEN__)))
98 /** String descriptor index for the device's unique serial number string descriptor within the device.
99 * This unique serial number is used by the host to associate resources to the device (such as drivers or COM port
100 * number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain
101 * a unique serial number internally, and setting the device descriptors serial number string index to this value
102 * will cause it to use the internal serial number.
103 *
104 * On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial
105 * number for the device.
106 */
107 #define USE_INTERNAL_SERIAL 0xDC
108
109 /** Length of the device's unique internal serial number, in bits, if present on the selected microcontroller
110 * model.
111 */
112 #define INTERNAL_SERIAL_LENGTH_BITS 80
113
114 /** Start address of the internal serial number, in the appropriate address space, if present on the selected microcontroller
115 * model.
116 */
117 #define INTERNAL_SERIAL_START_ADDRESS 0x0E
118 #else
119 #define USE_INTERNAL_SERIAL NO_DESCRIPTOR
120
121 #define INTERNAL_SERIAL_LENGTH_BITS 0
122 #define INTERNAL_SERIAL_START_ADDRESS 0
123 #endif
124
125 /* Function Prototypes: */
126 /** Sends a Remote Wakeup request to the host. This signals to the host that the device should
127 * be taken out of suspended mode, and communications should resume.
128 *
129 * Typically, this is implemented so that HID devices (mice, keyboards, etc.) can wake up the
130 * host computer when the host has suspended all USB devices to enter a low power state.
131 *
132 * \note This macro should only be used if the device has indicated to the host that it
133 * supports the Remote Wakeup feature in the device descriptors, and should only be
134 * issued if the host is currently allowing remote wakeup events from the device (i.e.,
135 * the \ref USB_RemoteWakeupEnabled flag is set). When the \c NO_DEVICE_REMOTE_WAKEUP compile
136 * time option is used, this macro is unavailable.
137 * \n\n
138 *
139 * \note The USB clock must be running for this function to operate. If the stack is initialized with
140 * the \ref USB_OPT_MANUAL_PLL option enabled, the user must ensure that the PLL is running
141 * before attempting to call this function.
142 *
143 * \see \ref Group_StdDescriptors for more information on the RMWAKEUP feature and device descriptors.
144 */
145 void USB_Device_SendRemoteWakeup(void);
146
147 /* Inline Functions: */
148 /** Returns the current USB frame number, when in device mode. Every millisecond the USB bus is active (i.e. enumerated to a host)
149 * the frame number is incremented by one.
150 */
151 static inline uint16_t USB_Device_GetFrameNumber(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
152 static inline uint16_t USB_Device_GetFrameNumber(void)
153 {
154 return UDFNUM;
155 }
156
157 #if !defined(NO_SOF_EVENTS)
158 /** Enables the device mode Start Of Frame events. When enabled, this causes the
159 * \ref EVENT_USB_Device_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,
160 * at the start of each USB frame when enumerated in device mode.
161 *
162 * \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
163 */
164 static inline void USB_Device_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;
165 static inline void USB_Device_EnableSOFEvents(void)
166 {
167 USB_INT_Enable(USB_INT_SOFI);
168 }
169
170 /** Disables the device mode Start Of Frame events. When disabled, this stops the firing of the
171 * \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode.
172 *
173 * \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
174 */
175 static inline void USB_Device_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;
176 static inline void USB_Device_DisableSOFEvents(void)
177 {
178 USB_INT_Disable(USB_INT_SOFI);
179 }
180 #endif
181
182 /* Private Interface - For use in library only: */
183 #if !defined(__DOXYGEN__)
184 /* Inline Functions: */
185 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
186 static inline void USB_Device_SetLowSpeed(void) ATTR_ALWAYS_INLINE;
187 static inline void USB_Device_SetLowSpeed(void)
188 {
189 UDCON |= (1 << LSM);
190 }
191
192 static inline void USB_Device_SetFullSpeed(void) ATTR_ALWAYS_INLINE;
193 static inline void USB_Device_SetFullSpeed(void)
194 {
195 UDCON &= ~(1 << LSM);
196 }
197 #endif
198
199 static inline void USB_Device_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE;
200 static inline void USB_Device_SetDeviceAddress(const uint8_t Address)
201 {
202 uint8_t Temp = (UDADDR & (1 << ADDEN)) | (Address & 0x7F);
203
204 UDADDR = Temp;
205 UDADDR = Temp | (1 << ADDEN);
206 }
207
208 static inline bool USB_Device_IsAddressSet(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
209 static inline bool USB_Device_IsAddressSet(void)
210 {
211 return (UDADDR & (1 << ADDEN));
212 }
213
214 #if (USE_INTERNAL_SERIAL != NO_DESCRIPTOR)
215 static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString)
216 {
217 uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
218 GlobalInterruptDisable();
219
220 uint8_t SigReadAddress = INTERNAL_SERIAL_START_ADDRESS;
221
222 for (uint8_t SerialCharNum = 0; SerialCharNum < (INTERNAL_SERIAL_LENGTH_BITS / 4); SerialCharNum++)
223 {
224 uint8_t SerialByte = boot_signature_byte_get(SigReadAddress);
225
226 if (SerialCharNum & 0x01)
227 {
228 SerialByte >>= 4;
229 SigReadAddress++;
230 }
231
232 SerialByte &= 0x0F;
233
234 UnicodeString[SerialCharNum] = cpu_to_le16((SerialByte >= 10) ?
235 (('A' - 10) + SerialByte) : ('0' + SerialByte));
236 }
237
238 SetGlobalInterruptMask(CurrentGlobalInt);
239 }
240 #endif
241
242 #endif
243
244 /* Disable C linkage for C++ Compilers: */
245 #if defined(__cplusplus)
246 }
247 #endif
248
249 #endif
250
251 /** @} */
252