]> git.donarmstrong.com Git - qmk_firmware.git/blob - protocol/lufa/LUFA-120730/LUFA/Drivers/USB/Core/AVR8/OTG_AVR8.h
Change TOP_DIR to TMK_DIR in makefiles
[qmk_firmware.git] / protocol / lufa / LUFA-120730 / LUFA / Drivers / USB / Core / AVR8 / OTG_AVR8.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 OTG definitions for the AVR8 microcontrollers.\r
33  *  \copydetails Group_OTG_AVR8\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_OTG\r
40  *  \defgroup Group_OTG_AVR8 USB On The Go (OTG) Management (AVR8)\r
41  *  \brief USB OTG definitions for the AVR8 microcontrollers.\r
42  *\r
43  *  Architecture specific USB OTG definitions for the Atmel 8-bit AVR microcontrollers.\r
44  *\r
45  *  @{\r
46  */\r
47 \r
48 #ifndef __USBOTG_AVR8_H__\r
49 #define __USBOTG_AVR8_H__\r
50 \r
51         /* Includes: */\r
52                 #include "../../../../Common/Common.h"\r
53 \r
54         /* Enable C linkage for C++ Compilers: */\r
55                 #if defined(__cplusplus)\r
56                         extern "C" {\r
57                 #endif\r
58 \r
59         /* Preprocessor Checks: */\r
60                 #if !defined(__INCLUDE_FROM_USB_DRIVER)\r
61                         #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.\r
62                 #endif\r
63 \r
64         /* Public Interface - May be used in end-application: */\r
65                 /* Macros: */\r
66                         /** Mask for the VBUS pulsing method of SRP, supported by some OTG devices.\r
67                          *\r
68                          *  \see \ref USB_OTG_Device_InitiateSRP().\r
69                          */\r
70                         #define USB_OTG_SRP_VBUS                   (1 << SRPSEL)\r
71 \r
72                         /** Mask for the Data + pulsing method of SRP, supported by some OTG devices.\r
73                          *\r
74                          *  \see \ref USB_OTG_Device_InitiateSRP().\r
75                          */\r
76                         #define USB_OTG_STP_DATA                   0\r
77 \r
78                 /* Inline Functions: */\r
79                         /** Initiate a Host Negotiation Protocol request. This indicates to the other connected device\r
80                          *  that the device wishes to change device/host roles.\r
81                          */\r
82                         static inline void USB_OTG_Device_RequestHNP(void) ATTR_ALWAYS_INLINE;\r
83                         static inline void USB_OTG_Device_RequestHNP(void)\r
84                         {\r
85                                 OTGCON |=  (1 << HNPREQ);\r
86                         }\r
87 \r
88                         /** Cancel a Host Negotiation Protocol request. This stops a pending HNP request to the other\r
89                          *  connected device.\r
90                          */\r
91                         static inline void USB_OTG_Device_CancelHNPRequest(void) ATTR_ALWAYS_INLINE;\r
92                         static inline void USB_OTG_Device_CancelHNPRequest(void)\r
93                         {\r
94                                 OTGCON &= ~(1 << HNPREQ);\r
95                         }\r
96 \r
97                         /** Determines if the device is currently sending a HNP to an attached host.\r
98                          *\r
99                          *  \return Boolean \c true if currently sending a HNP to the other connected device, \c false otherwise\r
100                          */\r
101                         static inline bool USB_OTG_Device_IsSendingHNP(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
102                         static inline bool USB_OTG_Device_IsSendingHNP(void)\r
103                         {\r
104                                 return ((OTGCON & (1 << HNPREQ)) ? true : false);\r
105                         }\r
106 \r
107                         /** Initiates a Session Request Protocol request. Most OTG devices turn off VBUS when the USB\r
108                          *  interface is not in use, to conserve power. Sending a SRP to a USB OTG device running in\r
109                          *  host mode indicates that VBUS should be applied and a session started.\r
110                          *\r
111                          *  There are two different methods of sending a SRP - either pulses on the VBUS line, or by\r
112                          *  pulsing the Data + line via the internal pull-up resistor.\r
113                          *\r
114                          *  \param[in] SRPTypeMask  Mask indicating the type of SRP to use, either \ref USB_OTG_SRP_VBUS or\r
115                          *                          \ref USB_OTG_STP_DATA.\r
116                          */\r
117                         static inline void USB_OTG_Device_InitiateSRP(const uint8_t SRPTypeMask) ATTR_ALWAYS_INLINE;\r
118                         static inline void USB_OTG_Device_InitiateSRP(const uint8_t SRPTypeMask)\r
119                         {\r
120                                 OTGCON = ((OTGCON & ~(1 << SRPSEL)) | (SRPTypeMask | (1 << SRPREQ)));\r
121                         }\r
122 \r
123                         /** Accepts a HNP from a connected device, indicating that both devices should exchange\r
124                          *  device/host roles.\r
125                          */\r
126                         static inline void USB_OTG_Host_AcceptHNP(void) ATTR_ALWAYS_INLINE;\r
127                         static inline void USB_OTG_Host_AcceptHNP(void)\r
128                         {\r
129                                 OTGCON |=  (1 << HNPREQ);\r
130                         }\r
131 \r
132                         /** Rejects a HNP from a connected device, indicating that both devices should remain in their\r
133                          *  current device/host roles.\r
134                          */\r
135                         static inline void USB_OTG_Host_RejectHNP(void) ATTR_ALWAYS_INLINE;\r
136                         static inline void USB_OTG_Host_RejectHNP(void)\r
137                         {\r
138                                 OTGCON &= ~(1 << HNPREQ);\r
139                         }\r
140 \r
141                         /** Indicates if the connected device is currently sending a HNP request.\r
142                          *\r
143                          *  \return Boolean \c true if a HNP is currently being issued by the connected device, \c false otherwise.\r
144                          */\r
145                         static inline bool USB_OTG_Host_IsHNPReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
146                         static inline bool USB_OTG_Host_IsHNPReceived(void)\r
147                         {\r
148                                 return ((OTGCON & (1 << HNPREQ)) ? true : false);\r
149                         }\r
150 \r
151         /* Disable C linkage for C++ Compilers: */\r
152                 #if defined(__cplusplus)\r
153                         }\r
154                 #endif\r
155 \r
156 #endif\r
157 \r
158 /** @} */\r
159 \r