Fixed GenericHIDHost demo report write routine incorrect for control type requests...
[pub/USBasp.git] / LUFA / Drivers / USB / HighLevel / USBInterrupt.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 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 *
33 * Main USB interrupt vector handler. This file manages the main USB interrupt vector, for handling such
34 * events as VBUS interrupts (on supported USB AVR models), device connections and disconnections, etc.
35 */
36
37 /** \ingroup Group_USB
38 * @defgroup Group_USBInterrupt Endpoint and Pipe Interrupts
39 *
40 * Functions, macros, variables, enums and types related to endpoint and pipe interrupts.
41 *
42 * @{
43 */
44
45 #ifndef __USBINTERRUPT_H__
46 #define __USBINTERRUPT_H__
47
48 /* Includes: */
49 #include <avr/io.h>
50 #include <stdbool.h>
51
52 #include "../../../Common/Common.h"
53 #include "../LowLevel/LowLevel.h"
54 #include "USBMode.h"
55 #include "Events.h"
56
57 /* Enable C linkage for C++ Compilers: */
58 #if defined(__cplusplus)
59 extern "C" {
60 #endif
61
62 /* Public Interface - May be used in end-application: */
63 /* Macros: */
64 /** Vector name for the common endpoint and pipe vector. This can be used to write an ISR handler
65 * for the endpoint and pipe events, to make certain USB functions interrupt rather than poll
66 * driven.
67 */
68 #define ENDPOINT_PIPE_vect USB_COM_vect
69
70 /** Enables the given USB interrupt vector (such as the ENDPOINT_INT_* and PIPE_INT_* vectors in
71 * Endpoint.h and Pipe.h).
72 */
73 #define USB_INT_Enable(int) MACROS{ USB_INT_GET_EN_REG(int) |= USB_INT_GET_EN_MASK(int); }MACROE
74
75 /** Disables the given USB interrupt vector.
76 *
77 * \see USB_INT_Enable()
78 */
79 #define USB_INT_Disable(int) MACROS{ USB_INT_GET_EN_REG(int) &= ~(USB_INT_GET_EN_MASK(int)); }MACROE
80
81 /** Resets the given USB interrupt flag, so that the interrupt is re-primed for the next firing. */
82 #define USB_INT_Clear(int) MACROS{ USB_INT_GET_INT_REG(int) &= ~(USB_INT_GET_INT_MASK(int)); }MACROE
83
84 /** Returns boolean false if the given USB interrupt is disabled, or true if the interrupt is currently
85 * enabled.
86 */
87 #define USB_INT_IsEnabled(int) ((USB_INT_GET_EN_REG(int) & USB_INT_GET_EN_MASK(int)) ? true : false)
88
89 /** Returns boolean true if the given interrupt flag is set (i.e. the condition for the interrupt has occurred,
90 * but the interrupt vector is not necessarily enabled), otherwise returns false.
91 */
92 #define USB_INT_HasOccurred(int) ((USB_INT_GET_INT_REG(int) & USB_INT_GET_INT_MASK(int)) ? true : false)
93
94 /* Throwable Events: */
95 /** This module raises the USB Connected interrupt when the AVR is attached to a host while in device
96 * USB mode.
97 *
98 * \note For the smaller USB AVRs (AT90USBXX2) with limited USB controllers, VBUS is not available to the USB controller.
99 * this means that the current connection state is derived from the bus suspension and wake up events by default,
100 * which is not always accurate (host may suspend the bus while still connected). If the actual connection state
101 * needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by
102 * passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection
103 * and disconnection events may be manually fired by RAISE_EVENT(), and the USB_IsConnected global changed manually.
104 */
105 RAISES_EVENT(USB_Connect);
106
107 /** This module raises the USB Disconnected interrupt when the AVR is removed from a host while in
108 * device USB mode.
109 *
110 * \note For the smaller USB AVRs (AT90USBXX2) with limited USB controllers, VBUS is not available to the USB controller.
111 * this means that the current connection state is derived from the bus suspension and wake up events by default,
112 * which is not always accurate (host may suspend the bus while still connected). If the actual connection state
113 * needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by
114 * passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection
115 * and disconnection events may be manually fired by RAISE_EVENT(), and the USB_IsConnected global changed manually.
116 */
117 RAISES_EVENT(USB_Disconnect);
118
119 #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) || defined(__DOXYGEN__)
120 /** This module raises the VBUS Change event when the current VBUS status (present or not present) has
121 * changed.
122 *
123 * \note Not all USB AVR models support VBUS interrupts; this event only exists on supported AVRs.
124 *
125 * \see Events.h for more information on this event.
126 */
127 RAISES_EVENT(USB_VBUSChange);
128
129 /** This module raises the VBUS Connect event when the VBUS line is powered.
130 *
131 * \note Not all USB AVR models support VBUS interrupts; this event only exists on supported AVRs.
132 *
133 * \see Events.h for more information on this event.
134 */
135 RAISES_EVENT(USB_VBUSConnect);
136
137 /** This module raises the VBUS Disconnect event when power is removed from the VBUS line.
138 *
139 * \note Not all USB AVR models support VBUS interrupts; this event only exists on supported AVRs.
140 *
141 * \see Events.h for more information on this event.
142 */
143 RAISES_EVENT(USB_VBUSDisconnect);
144 #endif
145
146 #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)
147 /** This module raises the Suspended event when the host suspends the USB interface of the AVR
148 * whilst running in device mode.
149 *
150 * \see Events.h for more information on this event.
151 */
152 RAISES_EVENT(USB_Suspend);
153
154 /** This module raises the Wake Up event when the host resumes the USB interface of the AVR
155 * whilst running in device mode.
156 *
157 * \see Events.h for more information on this event.
158 */
159 RAISES_EVENT(USB_WakeUp);
160
161 /** This module raises the USB Reset event when the host resets the USB interface of the AVR
162 * whilst running in device mode.
163 *
164 * \see Events.h for more information on this event.
165 */
166 RAISES_EVENT(USB_Reset);
167 #endif
168
169 #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__)
170 /** This module raises the Host Error event when the VBUS line voltage dips below the minimum threshold
171 * while running in host mode.
172 *
173 * \note Not all USB AVR models support host mode; this event only exists on supported AVRs.
174 *
175 * \see Events.h for more information on this event.
176 */
177 RAISES_EVENT(USB_HostError);
178
179 /** This module raises the Device Unattached event when an attached device is removed from the AVR whilst
180 * running in host mode.
181 *
182 * \note Not all USB AVR models support host mode; this event only exists on supported AVRs.
183 *
184 * \see Events.h for more information on this event.
185 */
186 RAISES_EVENT(USB_DeviceUnattached);
187 #endif
188
189 #if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__)
190 /** This module raises the UID Change event when the UID line changes in value on dual-role devices.
191 *
192 * \note Not all USB AVR models support host mode and thus the UID pin; this event only exists on
193 * supported AVRs.
194 *
195 * \see Events.h for more information on this event.
196 */
197 RAISES_EVENT(USB_UIDChange);
198 #endif
199
200 /* Private Interface - For use in library only: */
201 #if !defined(__DOXYGEN__)
202 /* Macros: */
203 #define USB_INT_GET_EN_REG(a, b, c, d) a
204 #define USB_INT_GET_EN_MASK(a, b, c, d) b
205 #define USB_INT_GET_INT_REG(a, b, c, d) c
206 #define USB_INT_GET_INT_MASK(a, b, c, d) d
207
208 #define USB_INT_VBUS USBCON, (1 << VBUSTE) , USBINT, (1 << VBUSTI)
209 #define USB_INT_IDTI USBCON, (1 << IDTE) , USBINT, (1 << IDTI)
210 #define USB_INT_WAKEUP UDIEN , (1 << WAKEUPE), UDINT , (1 << WAKEUPI)
211 #define USB_INT_SUSPEND UDIEN , (1 << SUSPE) , UDINT , (1 << SUSPI)
212 #define USB_INT_EORSTI UDIEN , (1 << EORSTE) , UDINT , (1 << EORSTI)
213 #define USB_INT_DCONNI UHIEN , (1 << DCONNE) , UHINT , (1 << DCONNI)
214 #define USB_INT_DDISCI UHIEN , (1 << DDISCE) , UHINT , (1 << DDISCI)
215 #define USB_INT_BCERRI OTGIEN, (1 << BCERRE) , OTGINT, (1 << BCERRI)
216 #define USB_INT_VBERRI OTGIEN, (1 << VBERRE) , OTGINT, (1 << VBERRI)
217 #define USB_INT_SOFI UDIEN, (1 << SOFE) , UDINT , (1 << SOFI)
218 #define USB_INT_HSOFI UHIEN, (1 << HSOFE) , UHINT , (1 << HSOFI)
219 #define USB_INT_RSTI UHIEN , (1 << RSTE) , UHINT , (1 << RSTI)
220 #define USB_INT_SRPI OTGIEN, (1 << SRPE) , OTGINT, (1 << SRPI)
221
222 /* Function Prototypes: */
223 void USB_INT_ClearAllInterrupts(void);
224 void USB_INT_DisableAllInterrupts(void);
225 #endif
226
227 /* Disable C linkage for C++ Compilers: */
228 #if defined(__cplusplus)
229 }
230 #endif
231
232 #endif
233
234 /** @} */