]> git.gir.st - tmk_keyboard.git/blob - protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/AVR8/USBInterrupt_AVR8.h
Squashed 'tmk_core/' changes from caca2c0..dc0e46e
[tmk_keyboard.git] / protocol / lufa / LUFA-git / LUFA / Drivers / USB / Core / AVR8 / USBInterrupt_AVR8.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2014.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2014 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 disclaims 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 Controller Interrupt definitions for the AVR8 microcontrollers.
33 *
34 * This file contains definitions required for the correct handling of low level USB service routine interrupts
35 * from the USB controller.
36 *
37 * \note This file should not be included directly. It is automatically included as needed by the USB driver
38 * dispatch header located in LUFA/Drivers/USB/USB.h.
39 */
40
41 #ifndef __USBINTERRUPT_AVR8_H__
42 #define __USBINTERRUPT_AVR8_H__
43
44 /* Includes: */
45 #include "../../../../Common/Common.h"
46
47 /* Enable C linkage for C++ Compilers: */
48 #if defined(__cplusplus)
49 extern "C" {
50 #endif
51
52 /* Preprocessor Checks: */
53 #if !defined(__INCLUDE_FROM_USB_DRIVER)
54 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
55 #endif
56
57 /* Private Interface - For use in library only: */
58 #if !defined(__DOXYGEN__)
59 /* Enums: */
60 enum USB_Interrupts_t
61 {
62 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__))
63 USB_INT_VBUSTI = 0,
64 #endif
65 #if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__))
66 USB_INT_IDTI = 1,
67 #endif
68 #if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__))
69 USB_INT_WAKEUPI = 2,
70 USB_INT_SUSPI = 3,
71 USB_INT_EORSTI = 4,
72 USB_INT_SOFI = 5,
73 USB_INT_RXSTPI = 6,
74 #endif
75 #if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__))
76 USB_INT_HSOFI = 7,
77 USB_INT_DCONNI = 8,
78 USB_INT_DDISCI = 9,
79 USB_INT_RSTI = 10,
80 USB_INT_BCERRI = 11,
81 USB_INT_VBERRI = 12,
82 USB_INT_SRPI = 13,
83 #endif
84 };
85
86 /* Inline Functions: */
87 static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
88 static inline void USB_INT_Enable(const uint8_t Interrupt)
89 {
90 switch (Interrupt)
91 {
92 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
93 case USB_INT_VBUSTI:
94 USBCON |= (1 << VBUSTE);
95 break;
96 #endif
97 #if defined(USB_CAN_BE_BOTH)
98 case USB_INT_IDTI:
99 USBCON |= (1 << IDTE);
100 break;
101 #endif
102 #if defined(USB_CAN_BE_DEVICE)
103 case USB_INT_WAKEUPI:
104 UDIEN |= (1 << WAKEUPE);
105 break;
106 case USB_INT_SUSPI:
107 UDIEN |= (1 << SUSPE);
108 break;
109 case USB_INT_EORSTI:
110 UDIEN |= (1 << EORSTE);
111 break;
112 case USB_INT_SOFI:
113 UDIEN |= (1 << SOFE);
114 break;
115 case USB_INT_RXSTPI:
116 UEIENX |= (1 << RXSTPE);
117 break;
118 #endif
119 #if defined(USB_CAN_BE_HOST)
120 case USB_INT_HSOFI:
121 UHIEN |= (1 << HSOFE);
122 break;
123 case USB_INT_DCONNI:
124 UHIEN |= (1 << DCONNE);
125 break;
126 case USB_INT_DDISCI:
127 UHIEN |= (1 << DDISCE);
128 break;
129 case USB_INT_RSTI:
130 UHIEN |= (1 << RSTE);
131 break;
132 case USB_INT_BCERRI:
133 OTGIEN |= (1 << BCERRE);
134 break;
135 case USB_INT_VBERRI:
136 OTGIEN |= (1 << VBERRE);
137 break;
138 case USB_INT_SRPI:
139 OTGIEN |= (1 << SRPE);
140 break;
141 #endif
142 default:
143 break;
144 }
145 }
146
147 static inline void USB_INT_Disable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
148 static inline void USB_INT_Disable(const uint8_t Interrupt)
149 {
150 switch (Interrupt)
151 {
152 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
153 case USB_INT_VBUSTI:
154 USBCON &= ~(1 << VBUSTE);
155 break;
156 #endif
157 #if defined(USB_CAN_BE_BOTH)
158 case USB_INT_IDTI:
159 USBCON &= ~(1 << IDTE);
160 break;
161 #endif
162 #if defined(USB_CAN_BE_DEVICE)
163 case USB_INT_WAKEUPI:
164 UDIEN &= ~(1 << WAKEUPE);
165 break;
166 case USB_INT_SUSPI:
167 UDIEN &= ~(1 << SUSPE);
168 break;
169 case USB_INT_EORSTI:
170 UDIEN &= ~(1 << EORSTE);
171 break;
172 case USB_INT_SOFI:
173 UDIEN &= ~(1 << SOFE);
174 break;
175 case USB_INT_RXSTPI:
176 UEIENX &= ~(1 << RXSTPE);
177 break;
178 #endif
179 #if defined(USB_CAN_BE_HOST)
180 case USB_INT_HSOFI:
181 UHIEN &= ~(1 << HSOFE);
182 break;
183 case USB_INT_DCONNI:
184 UHIEN &= ~(1 << DCONNE);
185 break;
186 case USB_INT_DDISCI:
187 UHIEN &= ~(1 << DDISCE);
188 break;
189 case USB_INT_RSTI:
190 UHIEN &= ~(1 << RSTE);
191 break;
192 case USB_INT_BCERRI:
193 OTGIEN &= ~(1 << BCERRE);
194 break;
195 case USB_INT_VBERRI:
196 OTGIEN &= ~(1 << VBERRE);
197 break;
198 case USB_INT_SRPI:
199 OTGIEN &= ~(1 << SRPE);
200 break;
201 #endif
202 default:
203 break;
204 }
205 }
206
207 static inline void USB_INT_Clear(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
208 static inline void USB_INT_Clear(const uint8_t Interrupt)
209 {
210 switch (Interrupt)
211 {
212 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
213 case USB_INT_VBUSTI:
214 USBINT &= ~(1 << VBUSTI);
215 break;
216 #endif
217 #if defined(USB_CAN_BE_BOTH)
218 case USB_INT_IDTI:
219 USBINT &= ~(1 << IDTI);
220 break;
221 #endif
222 #if defined(USB_CAN_BE_DEVICE)
223 case USB_INT_WAKEUPI:
224 UDINT &= ~(1 << WAKEUPI);
225 break;
226 case USB_INT_SUSPI:
227 UDINT &= ~(1 << SUSPI);
228 break;
229 case USB_INT_EORSTI:
230 UDINT &= ~(1 << EORSTI);
231 break;
232 case USB_INT_SOFI:
233 UDINT &= ~(1 << SOFI);
234 break;
235 case USB_INT_RXSTPI:
236 UEINTX &= ~(1 << RXSTPI);
237 break;
238 #endif
239 #if defined(USB_CAN_BE_HOST)
240 case USB_INT_HSOFI:
241 UHINT &= ~(1 << HSOFI);
242 break;
243 case USB_INT_DCONNI:
244 UHINT &= ~(1 << DCONNI);
245 break;
246 case USB_INT_DDISCI:
247 UHINT &= ~(1 << DDISCI);
248 break;
249 case USB_INT_RSTI:
250 UHINT &= ~(1 << RSTI);
251 break;
252 case USB_INT_BCERRI:
253 OTGINT &= ~(1 << BCERRI);
254 break;
255 case USB_INT_VBERRI:
256 OTGINT &= ~(1 << VBERRI);
257 break;
258 case USB_INT_SRPI:
259 OTGINT &= ~(1 << SRPI);
260 break;
261 #endif
262 default:
263 break;
264 }
265 }
266
267 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
268 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt)
269 {
270 switch (Interrupt)
271 {
272 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
273 case USB_INT_VBUSTI:
274 return (USBCON & (1 << VBUSTE));
275 #endif
276 #if defined(USB_CAN_BE_BOTH)
277 case USB_INT_IDTI:
278 return (USBCON & (1 << IDTE));
279 #endif
280 #if defined(USB_CAN_BE_DEVICE)
281 case USB_INT_WAKEUPI:
282 return (UDIEN & (1 << WAKEUPE));
283 case USB_INT_SUSPI:
284 return (UDIEN & (1 << SUSPE));
285 case USB_INT_EORSTI:
286 return (UDIEN & (1 << EORSTE));
287 case USB_INT_SOFI:
288 return (UDIEN & (1 << SOFE));
289 case USB_INT_RXSTPI:
290 return (UEIENX & (1 << RXSTPE));
291 #endif
292 #if defined(USB_CAN_BE_HOST)
293 case USB_INT_HSOFI:
294 return (UHIEN & (1 << HSOFE));
295 case USB_INT_DCONNI:
296 return (UHIEN & (1 << DCONNE));
297 case USB_INT_DDISCI:
298 return (UHIEN & (1 << DDISCE));
299 case USB_INT_RSTI:
300 return (UHIEN & (1 << RSTE));
301 case USB_INT_BCERRI:
302 return (OTGIEN & (1 << BCERRE));
303 case USB_INT_VBERRI:
304 return (OTGIEN & (1 << VBERRE));
305 case USB_INT_SRPI:
306 return (OTGIEN & (1 << SRPE));
307 #endif
308 default:
309 return false;
310 }
311 }
312
313 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
314 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt)
315 {
316 switch (Interrupt)
317 {
318 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
319 case USB_INT_VBUSTI:
320 return (USBINT & (1 << VBUSTI));
321 #endif
322 #if defined(USB_CAN_BE_BOTH)
323 case USB_INT_IDTI:
324 return (USBINT & (1 << IDTI));
325 #endif
326 #if defined(USB_CAN_BE_DEVICE)
327 case USB_INT_WAKEUPI:
328 return (UDINT & (1 << WAKEUPI));
329 case USB_INT_SUSPI:
330 return (UDINT & (1 << SUSPI));
331 case USB_INT_EORSTI:
332 return (UDINT & (1 << EORSTI));
333 case USB_INT_SOFI:
334 return (UDINT & (1 << SOFI));
335 case USB_INT_RXSTPI:
336 return (UEINTX & (1 << RXSTPI));
337 #endif
338 #if defined(USB_CAN_BE_HOST)
339 case USB_INT_HSOFI:
340 return (UHINT & (1 << HSOFI));
341 case USB_INT_DCONNI:
342 return (UHINT & (1 << DCONNI));
343 case USB_INT_DDISCI:
344 return (UHINT & (1 << DDISCI));
345 case USB_INT_RSTI:
346 return (UHINT & (1 << RSTI));
347 case USB_INT_BCERRI:
348 return (OTGINT & (1 << BCERRI));
349 case USB_INT_VBERRI:
350 return (OTGINT & (1 << VBERRI));
351 case USB_INT_SRPI:
352 return (OTGINT & (1 << SRPI));
353 #endif
354 default:
355 return false;
356 }
357 }
358
359 /* Includes: */
360 #include "../USBMode.h"
361 #include "../Events.h"
362 #include "../USBController.h"
363
364 /* Function Prototypes: */
365 void USB_INT_ClearAllInterrupts(void);
366 void USB_INT_DisableAllInterrupts(void);
367 #endif
368
369 /* Disable C linkage for C++ Compilers: */
370 #if defined(__cplusplus)
371 }
372 #endif
373
374 #endif
375
Imprint / Impressum