]> git.donarmstrong.com Git - qmk_firmware.git/blob - protocol/lufa/LUFA-120730/LUFA/Drivers/USB/Core/UC3/Host_UC3.h
Squashed 'tmk_core/' content from commit 05caacc
[qmk_firmware.git] / protocol / lufa / LUFA-120730 / LUFA / Drivers / USB / Core / UC3 / Host_UC3.h
1 /*\r
2              LUFA Library\r
3      Copyright (C) Dean Camera, 2012.\r
4 \r
5   dean [at] fourwalledcubicle [dot] com\r
6            www.lufa-lib.org\r
7 */\r
8 \r
9 /*\r
10   Copyright 2012  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
11 \r
12   Permission to use, copy, modify, distribute, and sell this\r
13   software and its documentation for any purpose is hereby granted\r
14   without fee, provided that the above copyright notice appear in\r
15   all copies and that both that the copyright notice and this\r
16   permission notice and warranty disclaimer appear in supporting\r
17   documentation, and that the name of the author not be used in\r
18   advertising or publicity pertaining to distribution of the\r
19   software without specific, written prior permission.\r
20 \r
21   The author disclaim all warranties with regard to this\r
22   software, including all implied warranties of merchantability\r
23   and fitness.  In no event shall the author be liable for any\r
24   special, indirect or consequential damages or any damages\r
25   whatsoever resulting from loss of use, data or profits, whether\r
26   in an action of contract, negligence or other tortious action,\r
27   arising out of or in connection with the use or performance of\r
28   this software.\r
29 */\r
30 \r
31 /** \file\r
32  *  \brief USB Host definitions for the AVR32 UC3B microcontrollers.\r
33  *  \copydetails Group_Host_UC3B\r
34  *\r
35  *  \note This file should not be included directly. It is automatically included as needed by the USB driver\r
36  *        dispatch header located in LUFA/Drivers/USB/USB.h.\r
37  */\r
38 \r
39 /** \ingroup Group_Host\r
40  *  \defgroup Group_Host_UC3B Host Management (UC3B)\r
41  *  \brief USB Host definitions for the AVR32 UC3B microcontrollers.\r
42  *\r
43  *  Architecture specific USB Host definitions for the Atmel 32-bit AVR UC3B microcontrollers.\r
44  *\r
45  *  @{\r
46  */\r
47 \r
48 #ifndef __USBHOST_UC3B_H__\r
49 #define __USBHOST_UC3B_H__\r
50 \r
51         /* Includes: */\r
52                 #include "../../../../Common/Common.h"\r
53                 #include "../StdDescriptors.h"\r
54                 #include "../Pipe.h"\r
55                 #include "../USBInterrupt.h"\r
56 \r
57         /* Enable C linkage for C++ Compilers: */\r
58                 #if defined(__cplusplus)\r
59                         extern "C" {\r
60                 #endif\r
61 \r
62         /* Preprocessor Checks: */\r
63                 #if !defined(__INCLUDE_FROM_USB_DRIVER)\r
64                         #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.\r
65                 #endif\r
66 \r
67         /* Public Interface - May be used in end-application: */\r
68                 /* Macros: */\r
69                         /** Indicates the fixed USB device address which any attached device is enumerated to when in\r
70                          *  host mode. As only one USB device may be attached to the AVR in host mode at any one time\r
71                          *  and that the address used is not important (other than the fact that it is non-zero), a\r
72                          *  fixed value is specified by the library.\r
73                          */\r
74                         #define USB_HOST_DEVICEADDRESS                 1\r
75 \r
76                         #if !defined(HOST_DEVICE_SETTLE_DELAY_MS) || defined(__DOXYGEN__)\r
77                                 /** Constant for the delay in milliseconds after a device is connected before the library\r
78                                  *  will start the enumeration process. Some devices require a delay of up to 5 seconds\r
79                                  *  after connection before the enumeration process can start or incorrect operation will\r
80                                  *  occur.\r
81                                  *\r
82                                  *  The default delay value may be overridden in the user project makefile by defining the\r
83                                  *  \c HOST_DEVICE_SETTLE_DELAY_MS token to the required delay in milliseconds, and passed to the\r
84                                  *  compiler using the -D switch.\r
85                                  */\r
86                                 #define HOST_DEVICE_SETTLE_DELAY_MS        1000\r
87                         #endif\r
88 \r
89                 /* Enums: */\r
90                         /** Enum for the error codes for the \ref EVENT_USB_Host_HostError() event.\r
91                          *\r
92                          *  \see \ref Group_Events for more information on this event.\r
93                          */\r
94                         enum USB_Host_ErrorCodes_t\r
95                         {\r
96                                 HOST_ERROR_VBusVoltageDip       = 0, /**< VBUS voltage dipped to an unacceptable level. This\r
97                                                                       *   error may be the result of an attached device drawing\r
98                                                                       *   too much current from the VBUS line, or due to the\r
99                                                                       *   AVR's power source being unable to supply sufficient\r
100                                                                       *   current.\r
101                                                                       */\r
102                         };\r
103 \r
104                         /** Enum for the error codes for the \ref EVENT_USB_Host_DeviceEnumerationFailed() event.\r
105                          *\r
106                          *  \see \ref Group_Events for more information on this event.\r
107                          */\r
108                         enum USB_Host_EnumerationErrorCodes_t\r
109                         {\r
110                                 HOST_ENUMERROR_NoError          = 0, /**< No error occurred. Used internally, this is not a valid\r
111                                                                       *   ErrorCode parameter value for the \ref EVENT_USB_Host_DeviceEnumerationFailed()\r
112                                                                       *   event.\r
113                                                                       */\r
114                                 HOST_ENUMERROR_WaitStage        = 1, /**< One of the delays between enumeration steps failed\r
115                                                                       *   to complete successfully, due to a timeout or other\r
116                                                                       *   error.\r
117                                                                       */\r
118                                 HOST_ENUMERROR_NoDeviceDetected = 2, /**< No device was detected, despite the USB data lines\r
119                                                                       *   indicating the attachment of a device.\r
120                                                                       */\r
121                                 HOST_ENUMERROR_ControlError     = 3, /**< One of the enumeration control requests failed to\r
122                                                                       *   complete successfully.\r
123                                                                       */\r
124                                 HOST_ENUMERROR_PipeConfigError  = 4, /**< The default control pipe (address 0) failed to\r
125                                                                       *   configure correctly.\r
126                                                                       */\r
127                         };\r
128 \r
129                 /* Inline Functions: */\r
130                         /** Returns the current USB frame number, when in host mode. Every millisecond the USB bus is active (i.e. not suspended)\r
131                          *  the frame number is incremented by one.\r
132                          *\r
133                          *  \return Current USB frame number from the USB controller.\r
134                          */\r
135                         static inline uint16_t USB_Host_GetFrameNumber(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
136                         static inline uint16_t USB_Host_GetFrameNumber(void)\r
137                         {\r
138                                 return AVR32_USBB_UHFNUM;\r
139                         }\r
140 \r
141                         #if !defined(NO_SOF_EVENTS)\r
142                                 /** Enables the host mode Start Of Frame events. When enabled, this causes the\r
143                                  *  \ref EVENT_USB_Host_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,\r
144                                  *  at the start of each USB frame when a device is enumerated while in host mode.\r
145                                  *\r
146                                  *  \note This function is not available when the \c NO_SOF_EVENTS compile time token is defined.\r
147                                  */\r
148                                 static inline void USB_Host_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;\r
149                                 static inline void USB_Host_EnableSOFEvents(void)\r
150                                 {\r
151                                         USB_INT_Enable(USB_INT_HSOFI);\r
152                                 }\r
153 \r
154                                 /** Disables the host mode Start Of Frame events. When disabled, this stops the firing of the\r
155                                  *  \ref EVENT_USB_Host_StartOfFrame() event when enumerated in host mode.\r
156                                  *\r
157                                  *  \note This function is not available when the \c NO_SOF_EVENTS compile time token is defined.\r
158                                  */\r
159                                 static inline void USB_Host_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;\r
160                                 static inline void USB_Host_DisableSOFEvents(void)\r
161                                 {\r
162                                         USB_INT_Disable(USB_INT_HSOFI);\r
163                                 }\r
164                         #endif\r
165 \r
166                         /** Resets the USB bus, including the endpoints in any attached device and pipes on the AVR host.\r
167                          *  USB bus resets leave the default control pipe configured (if already configured).\r
168                          *\r
169                          *  If the USB bus has been suspended prior to issuing a bus reset, the attached device will be\r
170                          *  woken up automatically and the bus resumed after the reset has been correctly issued.\r
171                          */\r
172                         static inline void USB_Host_ResetBus(void) ATTR_ALWAYS_INLINE;\r
173                         static inline void USB_Host_ResetBus(void)\r
174                         {\r
175                                 AVR32_USBB.UHCON.reset = true;\r
176                         }\r
177 \r
178                         /** Determines if a previously issued bus reset (via the \ref USB_Host_ResetBus() macro) has\r
179                          *  completed.\r
180                          *\r
181                          *  \return Boolean \c true if no bus reset is currently being sent, \c false otherwise.\r
182                          */\r
183                         static inline bool USB_Host_IsBusResetComplete(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
184                         static inline bool USB_Host_IsBusResetComplete(void)\r
185                         {\r
186                                 return AVR32_USBB.UHCON.reset;\r
187                         }\r
188 \r
189                         /** Resumes USB communications with an attached and enumerated device, by resuming the transmission\r
190                          *  of the 1MS Start Of Frame messages to the device. When resumed, USB communications between the\r
191                          *  host and attached device may occur.\r
192                          */\r
193                         static inline void USB_Host_ResumeBus(void) ATTR_ALWAYS_INLINE;\r
194                         static inline void USB_Host_ResumeBus(void)\r
195                         {\r
196                                 AVR32_USBB.UHCON.sofe = true;\r
197                         }\r
198 \r
199                         /** Suspends the USB bus, preventing any communications from occurring between the host and attached\r
200                          *  device until the bus has been resumed. This stops the transmission of the 1MS Start Of Frame\r
201                          *  messages to the device.\r
202                          *\r
203                          *  \note While the USB bus is suspended, all USB interrupt sources are also disabled; this means that\r
204                          *        some events (such as device disconnections) will not fire until the bus is resumed.\r
205                          */\r
206                         static inline void USB_Host_SuspendBus(void) ATTR_ALWAYS_INLINE;\r
207                         static inline void USB_Host_SuspendBus(void)\r
208                         {\r
209                                 AVR32_USBB.UHCON.sofe = false;\r
210                         }\r
211 \r
212                         /** Determines if the USB bus has been suspended via the use of the \ref USB_Host_SuspendBus() macro,\r
213                          *  false otherwise. While suspended, no USB communications can occur until the bus is resumed,\r
214                          *  except for the Remote Wakeup event from the device if supported.\r
215                          *\r
216                          *  \return Boolean \c true if the bus is currently suspended, \c false otherwise.\r
217                          */\r
218                         static inline bool USB_Host_IsBusSuspended(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
219                         static inline bool USB_Host_IsBusSuspended(void)\r
220                         {\r
221                                 return AVR32_USBB.UHCON.sofe;\r
222                         }\r
223 \r
224                         /** Determines if the attached device is currently enumerated in Full Speed mode (12Mb/s), or\r
225                          *  false if the attached device is enumerated in Low Speed mode (1.5Mb/s).\r
226                          *\r
227                          *  \return Boolean \c true if the attached device is enumerated in Full Speed mode, \c false otherwise.\r
228                          */\r
229                         static inline bool USB_Host_IsDeviceFullSpeed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
230                         static inline bool USB_Host_IsDeviceFullSpeed(void)\r
231                         {\r
232                                 return (AVR32_USBB.USBSTA.speed == AVR32_USBB_SPEED_FULL);\r
233                         }\r
234 \r
235                         /** Determines if the attached device is currently issuing a Remote Wakeup request, requesting\r
236                          *  that the host resume the USB bus and wake up the device, false otherwise.\r
237                          *\r
238                          *  \return Boolean \c true if the attached device has sent a Remote Wakeup request, \c false otherwise.\r
239                          */\r
240                         static inline bool USB_Host_IsRemoteWakeupSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
241                         static inline bool USB_Host_IsRemoteWakeupSent(void)\r
242                         {\r
243                                 return AVR32_USBB.UHINT.rxrsmi;\r
244                         }\r
245 \r
246                         /** Clears the flag indicating that a Remote Wakeup request has been issued by an attached device. */\r
247                         static inline void USB_Host_ClearRemoteWakeupSent(void) ATTR_ALWAYS_INLINE;\r
248                         static inline void USB_Host_ClearRemoteWakeupSent(void)\r
249                         {\r
250                                 AVR32_USBB.UHINTCLR.rxrsmic = true;\r
251                         }\r
252 \r
253                         /** Accepts a Remote Wakeup request from an attached device. This must be issued in response to\r
254                          *  a device's Remote Wakeup request within 2ms for the request to be accepted and the bus to\r
255                          *  be resumed.\r
256                          */\r
257                         static inline void USB_Host_ResumeFromWakeupRequest(void) ATTR_ALWAYS_INLINE;\r
258                         static inline void USB_Host_ResumeFromWakeupRequest(void)\r
259                         {\r
260                                 AVR32_USBB.UHCON.resume = true;\r
261                         }\r
262 \r
263                         /** Determines if a resume from Remote Wakeup request is currently being sent to an attached\r
264                          *  device.\r
265                          *\r
266                          *  \return Boolean \c true if no resume request is currently being sent, \c false otherwise.\r
267                          */\r
268                         static inline bool USB_Host_IsResumeFromWakeupRequestSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
269                         static inline bool USB_Host_IsResumeFromWakeupRequestSent(void)\r
270                         {\r
271                                 return AVR32_USBB.UHCON.resume;\r
272                         }\r
273 \r
274         /* Private Interface - For use in library only: */\r
275         #if !defined(__DOXYGEN__)\r
276                 /* Macros: */\r
277                         static inline void USB_Host_HostMode_On(void) ATTR_ALWAYS_INLINE;\r
278                         static inline void USB_Host_HostMode_On(void)\r
279                         {\r
280                                 // Not required for UC3B\r
281                         }\r
282 \r
283                         static inline void USB_Host_HostMode_Off(void) ATTR_ALWAYS_INLINE;\r
284                         static inline void USB_Host_HostMode_Off(void)\r
285                         {\r
286                                 // Not required for UC3B\r
287                         }\r
288 \r
289                         static inline void USB_Host_VBUS_Auto_Enable(void) ATTR_ALWAYS_INLINE;\r
290                         static inline void USB_Host_VBUS_Auto_Enable(void)\r
291                         {\r
292                                 AVR32_USBB.USBCON.vbushwc = false;\r
293                         }\r
294 \r
295                         static inline void USB_Host_VBUS_Manual_Enable(void) ATTR_ALWAYS_INLINE;\r
296                         static inline void USB_Host_VBUS_Manual_Enable(void)\r
297                         {\r
298                                 AVR32_USBB.USBCON.vbushwc = true;\r
299                         }\r
300 \r
301                         static inline void USB_Host_VBUS_Auto_On(void) ATTR_ALWAYS_INLINE;\r
302                         static inline void USB_Host_VBUS_Auto_On(void)\r
303                         {\r
304                                 AVR32_USBB.USBSTASET.vbusrqs = true;\r
305                         }\r
306 \r
307                         static inline void USB_Host_VBUS_Manual_On(void) ATTR_ALWAYS_INLINE;\r
308                         static inline void USB_Host_VBUS_Manual_On(void)\r
309                         {\r
310                                 AVR32_USBB.USBSTASET.vbusrqs = true;\r
311                         }\r
312 \r
313                         static inline void USB_Host_VBUS_Auto_Off(void) ATTR_ALWAYS_INLINE;\r
314                         static inline void USB_Host_VBUS_Auto_Off(void)\r
315                         {\r
316                                 AVR32_USBB.USBSTACLR.vbusrqc = true;\r
317                         }\r
318 \r
319                         static inline void USB_Host_VBUS_Manual_Off(void) ATTR_ALWAYS_INLINE;\r
320                         static inline void USB_Host_VBUS_Manual_Off(void)\r
321                         {\r
322                                 AVR32_USBB.USBSTACLR.vbusrqc = true;\r
323                         }\r
324 \r
325                         static inline void USB_Host_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE;\r
326                         static inline void USB_Host_SetDeviceAddress(const uint8_t Address)\r
327                         {\r
328                                 AVR32_USBB.UHADDR1.uhaddr_p0 = Address;\r
329                                 AVR32_USBB.UHADDR1.uhaddr_p1 = Address;\r
330                                 AVR32_USBB.UHADDR1.uhaddr_p2 = Address;\r
331                                 AVR32_USBB.UHADDR1.uhaddr_p3 = Address;\r
332                                 AVR32_USBB.UHADDR2.uhaddr_p4 = Address;\r
333                                 AVR32_USBB.UHADDR2.uhaddr_p5 = Address;\r
334                                 AVR32_USBB.UHADDR2.uhaddr_p6 = Address;\r
335                         }\r
336 \r
337                 /* Enums: */\r
338                         enum USB_Host_WaitMSErrorCodes_t\r
339                         {\r
340                                 HOST_WAITERROR_Successful       = 0,\r
341                                 HOST_WAITERROR_DeviceDisconnect = 1,\r
342                                 HOST_WAITERROR_PipeError        = 2,\r
343                                 HOST_WAITERROR_SetupStalled     = 3,\r
344                         };\r
345 \r
346                 /* Function Prototypes: */\r
347                         void    USB_Host_ProcessNextHostState(void);\r
348                         uint8_t USB_Host_WaitMS(uint8_t MS);\r
349 \r
350                         #if defined(__INCLUDE_FROM_HOST_C)\r
351                                 static void USB_Host_ResetDevice(void);\r
352                         #endif\r
353         #endif\r
354 \r
355         /* Disable C linkage for C++ Compilers: */\r
356                 #if defined(__cplusplus)\r
357                         }\r
358                 #endif\r
359 \r
360 #endif\r
361 \r
362 /** @} */\r
363 \r