Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

USBInterrupt_AVR8.h 10KB

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