3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
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.
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
31 #ifndef __USBINTERRUPT_H__
32 #define __USBINTERRUPT_H__
38 #include "../../../Common/Common.h"
39 #include "../LowLevel/LowLevel.h"
43 /* Enable C linkage for C++ Compilers: */
44 #if defined(__cplusplus)
48 /* Public Interface - May be used in end-application: */
49 /* Throwable Events: */
50 /** This module raises the USB Connected interrupt when the AVR is attached to a host while in device
53 * \note For the smaller USB AVRs (AT90USBXX2) with limited USB controllers, VBUS is not available to the USB controller.
54 * this means that the current connection state is derived from the bus suspension and wake up events by default,
55 * which is not always accurate (host may suspend the bus while still connected). If the actual connection state
56 * needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by
57 * passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection
58 * and disconnection events may be manually fired by \ref RAISE_EVENT(), and the USB_IsConnected global changed manually.
60 RAISES_EVENT(USB_Connect
);
62 /** This module raises the USB Disconnected interrupt when the AVR is removed from a host while in
65 * \note For the smaller USB AVRs (AT90USBXX2) with limited USB controllers, VBUS is not available to the USB controller.
66 * this means that the current connection state is derived from the bus suspension and wake up events by default,
67 * which is not always accurate (host may suspend the bus while still connected). If the actual connection state
68 * needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by
69 * passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection
70 * and disconnection events may be manually fired by \ref RAISE_EVENT(), and the USB_IsConnected global changed manually.
72 RAISES_EVENT(USB_Disconnect
);
74 #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) || defined(__DOXYGEN__)
75 /** This module raises the VBUS Change event when the current VBUS status (present or not present) has
78 * \note Not all USB AVR models support VBUS interrupts; this event only exists on supported AVRs.
80 * \see \ref Group_Events for more information on this event.
82 RAISES_EVENT(USB_VBUSChange
);
84 /** This module raises the VBUS Connect event when the VBUS line is powered.
86 * \note Not all USB AVR models support VBUS interrupts; this event only exists on supported AVRs.
88 * \see \ref Group_Events for more information on this event.
90 RAISES_EVENT(USB_VBUSConnect
);
92 /** This module raises the VBUS Disconnect event when power is removed from the VBUS line.
94 * \note Not all USB AVR models support VBUS interrupts; this event only exists on supported AVRs.
96 * \see \ref Group_Events for more information on this event.
98 RAISES_EVENT(USB_VBUSDisconnect
);
101 #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)
102 /** This module raises the Suspended event when the host suspends the USB interface of the AVR
103 * whilst running in device mode.
105 * \see \ref Group_Events for more information on this event.
107 RAISES_EVENT(USB_Suspend
);
109 /** This module raises the Wake Up event when the host resumes the USB interface of the AVR
110 * whilst running in device mode.
112 * \see \ref Group_Events for more information on this event.
114 RAISES_EVENT(USB_WakeUp
);
116 /** This module raises the USB Reset event when the host resets the USB interface of the AVR
117 * whilst running in device mode.
119 * \see \ref Group_Events for more information on this event.
121 RAISES_EVENT(USB_Reset
);
124 #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__)
125 /** This module raises the Host Error event when the VBUS line voltage dips below the minimum threshold
126 * while running in host mode.
128 * \note Not all USB AVR models support host mode; this event only exists on supported AVRs.
130 * \see \ref Group_Events for more information on this event.
132 RAISES_EVENT(USB_HostError
);
134 /** This module raises the Device Unattached event when an attached device is removed from the AVR whilst
135 * running in host mode.
137 * \note Not all USB AVR models support host mode; this event only exists on supported AVRs.
139 * \see \ref Group_Events for more information on this event.
141 RAISES_EVENT(USB_DeviceUnattached
);
144 #if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__)
145 /** This module raises the UID Change event when the UID line changes in value on dual-role devices.
147 * \note Not all USB AVR models support host mode and thus the UID pin; this event only exists on
150 * \see \ref Group_Events for more information on this event.
152 RAISES_EVENT(USB_UIDChange
);
155 /* Private Interface - For use in library only: */
156 #if !defined(__DOXYGEN__)
158 #define USB_INT_Enable(int) MACROS{ USB_INT_GET_EN_REG(int) |= USB_INT_GET_EN_MASK(int); }MACROE
159 #define USB_INT_Disable(int) MACROS{ USB_INT_GET_EN_REG(int) &= ~(USB_INT_GET_EN_MASK(int)); }MACROE
160 #define USB_INT_Clear(int) MACROS{ USB_INT_GET_INT_REG(int) &= ~(USB_INT_GET_INT_MASK(int)); }MACROE
161 #define USB_INT_IsEnabled(int) ((USB_INT_GET_EN_REG(int) & USB_INT_GET_EN_MASK(int)) ? true : false)
162 #define USB_INT_HasOccurred(int) ((USB_INT_GET_INT_REG(int) & USB_INT_GET_INT_MASK(int)) ? true : false)
164 #define USB_INT_GET_EN_REG(a, b, c, d) a
165 #define USB_INT_GET_EN_MASK(a, b, c, d) b
166 #define USB_INT_GET_INT_REG(a, b, c, d) c
167 #define USB_INT_GET_INT_MASK(a, b, c, d) d
169 #define USB_INT_VBUS USBCON, (1 << VBUSTE) , USBINT, (1 << VBUSTI)
170 #define USB_INT_IDTI USBCON, (1 << IDTE) , USBINT, (1 << IDTI)
171 #define USB_INT_WAKEUP UDIEN , (1 << WAKEUPE), UDINT , (1 << WAKEUPI)
172 #define USB_INT_SUSPEND UDIEN , (1 << SUSPE) , UDINT , (1 << SUSPI)
173 #define USB_INT_EORSTI UDIEN , (1 << EORSTE) , UDINT , (1 << EORSTI)
174 #define USB_INT_DCONNI UHIEN , (1 << DCONNE) , UHINT , (1 << DCONNI)
175 #define USB_INT_DDISCI UHIEN , (1 << DDISCE) , UHINT , (1 << DDISCI)
176 #define USB_INT_BCERRI OTGIEN, (1 << BCERRE) , OTGINT, (1 << BCERRI)
177 #define USB_INT_VBERRI OTGIEN, (1 << VBERRE) , OTGINT, (1 << VBERRI)
178 #define USB_INT_SOFI UDIEN, (1 << SOFE) , UDINT , (1 << SOFI)
179 #define USB_INT_HSOFI UHIEN, (1 << HSOFE) , UHINT , (1 << HSOFI)
180 #define USB_INT_RSTI UHIEN , (1 << RSTE) , UHINT , (1 << RSTI)
181 #define USB_INT_SRPI OTGIEN, (1 << SRPE) , OTGINT, (1 << SRPI)
182 #define USB_INT_ENDPOINT_SETUP UEIENX, (1 << RXSTPE) , UEINTX, (1 << RXSTPI)
184 /* Function Prototypes: */
185 void USB_INT_ClearAllInterrupts(void);
186 void USB_INT_DisableAllInterrupts(void);
189 /* Disable C linkage for C++ Compilers: */
190 #if defined(__cplusplus)