3      Copyright (C) Dean Camera, 2015. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2015  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  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. 
  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 
  32  *  \brief USB Controller Interrupt definitions for the AVR8 microcontrollers. 
  34  *  This file contains definitions required for the correct handling of low level USB service routine interrupts 
  35  *  from the USB controller. 
  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. 
  41 #ifndef __USBINTERRUPT_AVR8_H__ 
  42 #define __USBINTERRUPT_AVR8_H__ 
  45                 #include "../../../../Common/Common.h" 
  47         /* Enable C linkage for C++ Compilers: */ 
  48                 #if defined(__cplusplus) 
  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. 
  57         /* Private Interface - For use in library only: */ 
  58         #if !defined(__DOXYGEN__) 
  62                                 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)) 
  65                                 #if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__)) 
  68                                 #if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)) 
  75                                 #if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__)) 
  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
) 
  92                                         #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) 
  94                                                 USBCON 
|= (1 << VBUSTE
); 
  97                                         #if defined(USB_CAN_BE_BOTH) 
  99                                                 USBCON 
|= (1 << IDTE
); 
 102                                         #if defined(USB_CAN_BE_DEVICE) 
 103                                         case USB_INT_WAKEUPI
: 
 104                                                 UDIEN  
|= (1 << WAKEUPE
); 
 107                                                 UDIEN  
|= (1 << SUSPE
); 
 110                                                 UDIEN  
|= (1 << EORSTE
); 
 113                                                 UDIEN  
|= (1 << SOFE
); 
 116                                                 UEIENX 
|= (1 << RXSTPE
); 
 119                                         #if defined(USB_CAN_BE_HOST) 
 121                                                 UHIEN  
|= (1 << HSOFE
); 
 124                                                 UHIEN  
|= (1 << DCONNE
); 
 127                                                 UHIEN  
|= (1 << DDISCE
); 
 130                                                 UHIEN  
|= (1 << RSTE
); 
 133                                                 OTGIEN 
|= (1 << BCERRE
); 
 136                                                 OTGIEN 
|= (1 << VBERRE
); 
 139                                                 OTGIEN 
|= (1 << SRPE
); 
 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
) 
 152                                         #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) 
 154                                                 USBCON 
&= ~(1 << VBUSTE
); 
 157                                         #if defined(USB_CAN_BE_BOTH) 
 159                                                 USBCON 
&= ~(1 << IDTE
); 
 162                                         #if defined(USB_CAN_BE_DEVICE) 
 163                                         case USB_INT_WAKEUPI
: 
 164                                                 UDIEN  
&= ~(1 << WAKEUPE
); 
 167                                                 UDIEN  
&= ~(1 << SUSPE
); 
 170                                                 UDIEN  
&= ~(1 << EORSTE
); 
 173                                                 UDIEN  
&= ~(1 << SOFE
); 
 176                                                 UEIENX 
&= ~(1 << RXSTPE
); 
 179                                         #if defined(USB_CAN_BE_HOST) 
 181                                                 UHIEN  
&= ~(1 << HSOFE
); 
 184                                                 UHIEN  
&= ~(1 << DCONNE
); 
 187                                                 UHIEN  
&= ~(1 << DDISCE
); 
 190                                                 UHIEN  
&= ~(1 << RSTE
); 
 193                                                 OTGIEN 
&= ~(1 << BCERRE
); 
 196                                                 OTGIEN 
&= ~(1 << VBERRE
); 
 199                                                 OTGIEN 
&= ~(1 << SRPE
); 
 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
) 
 212                                         #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) 
 214                                                 USBINT 
&= ~(1 << VBUSTI
); 
 217                                         #if defined(USB_CAN_BE_BOTH) 
 219                                                 USBINT 
&= ~(1 << IDTI
); 
 222                                         #if defined(USB_CAN_BE_DEVICE) 
 223                                         case USB_INT_WAKEUPI
: 
 224                                                 UDINT  
&= ~(1 << WAKEUPI
); 
 227                                                 UDINT  
&= ~(1 << SUSPI
); 
 230                                                 UDINT  
&= ~(1 << EORSTI
); 
 233                                                 UDINT  
&= ~(1 << SOFI
); 
 236                                                 UEINTX 
&= ~(1 << RXSTPI
); 
 239                                         #if defined(USB_CAN_BE_HOST) 
 241                                                 UHINT  
&= ~(1 << HSOFI
); 
 244                                                 UHINT  
&= ~(1 << DCONNI
); 
 247                                                 UHINT  
&= ~(1 << DDISCI
); 
 250                                                 UHINT  
&= ~(1 << RSTI
); 
 253                                                 OTGINT 
&= ~(1 << BCERRI
); 
 256                                                 OTGINT 
&= ~(1 << VBERRI
); 
 259                                                 OTGINT 
&= ~(1 << SRPI
); 
 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
) 
 272                                         #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) 
 274                                                 return (USBCON 
& (1 << VBUSTE
)); 
 276                                         #if defined(USB_CAN_BE_BOTH) 
 278                                                 return (USBCON 
& (1 << IDTE
)); 
 280                                         #if defined(USB_CAN_BE_DEVICE) 
 281                                         case USB_INT_WAKEUPI
: 
 282                                                 return (UDIEN  
& (1 << WAKEUPE
)); 
 284                                                 return (UDIEN  
& (1 << SUSPE
)); 
 286                                                 return (UDIEN  
& (1 << EORSTE
)); 
 288                                                 return (UDIEN  
& (1 << SOFE
)); 
 290                                                 return (UEIENX 
& (1 << RXSTPE
)); 
 292                                         #if defined(USB_CAN_BE_HOST) 
 294                                                 return (UHIEN  
& (1 << HSOFE
)); 
 296                                                 return (UHIEN  
& (1 << DCONNE
)); 
 298                                                 return (UHIEN  
& (1 << DDISCE
)); 
 300                                                 return (UHIEN  
& (1 << RSTE
)); 
 302                                                 return (OTGIEN 
& (1 << BCERRE
)); 
 304                                                 return (OTGIEN 
& (1 << VBERRE
)); 
 306                                                 return (OTGIEN 
& (1 << SRPE
)); 
 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
) 
 318                                         #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) 
 320                                                 return (USBINT 
& (1 << VBUSTI
)); 
 322                                         #if defined(USB_CAN_BE_BOTH) 
 324                                                 return (USBINT 
& (1 << IDTI
)); 
 326                                         #if defined(USB_CAN_BE_DEVICE) 
 327                                         case USB_INT_WAKEUPI
: 
 328                                                 return (UDINT  
& (1 << WAKEUPI
)); 
 330                                                 return (UDINT  
& (1 << SUSPI
)); 
 332                                                 return (UDINT  
& (1 << EORSTI
)); 
 334                                                 return (UDINT  
& (1 << SOFI
)); 
 336                                                 return (UEINTX 
& (1 << RXSTPI
)); 
 338                                         #if defined(USB_CAN_BE_HOST) 
 340                                                 return (UHINT  
& (1 << HSOFI
)); 
 342                                                 return (UHINT  
& (1 << DCONNI
)); 
 344                                                 return (UHINT  
& (1 << DDISCI
)); 
 346                                                 return (UHINT  
& (1 << RSTI
)); 
 348                                                 return (OTGINT 
& (1 << BCERRI
)); 
 350                                                 return (OTGINT 
& (1 << VBERRI
)); 
 352                                                 return (OTGINT 
& (1 << SRPI
)); 
 360                         #include "../USBMode.h" 
 361                         #include "../Events.h" 
 362                         #include "../USBController.h" 
 364                 /* Function Prototypes: */ 
 365                         void USB_INT_ClearAllInterrupts(void); 
 366                         void USB_INT_DisableAllInterrupts(void); 
 369         /* Disable C linkage for C++ Compilers: */ 
 370                 #if defined(__cplusplus)