]> git.gir.st - tmk_keyboard.git/blob - protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c
Squashed 'tmk_core/' changes from caca2c0..dc0e46e
[tmk_keyboard.git] / protocol / lufa / LUFA-git / LUFA / Drivers / USB / Core / UC3 / USBInterrupt_UC3.c
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 #include "../../../../Common/Common.h"
32 #if (ARCH == ARCH_UC3)
33
34 #define __INCLUDE_FROM_USB_DRIVER
35 #include "../USBInterrupt.h"
36
37 void USB_INT_DisableAllInterrupts(void)
38 {
39 AVR32_USBB.USBCON.vbuste = false;
40 AVR32_USBB.USBCON.idte = false;
41
42 AVR32_USBB.uhinteclr = -1;
43 AVR32_USBB.udinteclr = -1;
44 }
45
46 void USB_INT_ClearAllInterrupts(void)
47 {
48 AVR32_USBB.USBSTACLR.vbustic = true;
49 AVR32_USBB.USBSTACLR.idtic = true;
50
51 AVR32_USBB.uhintclr = -1;
52 AVR32_USBB.udintclr = -1;
53 }
54
55 ISR(USB_GEN_vect)
56 {
57 #if defined(USB_CAN_BE_DEVICE)
58 #if !defined(NO_SOF_EVENTS)
59 if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI))
60 {
61 USB_INT_Clear(USB_INT_SOFI);
62
63 EVENT_USB_Device_StartOfFrame();
64 }
65 #endif
66
67 if (USB_INT_HasOccurred(USB_INT_VBUSTI) && USB_INT_IsEnabled(USB_INT_VBUSTI))
68 {
69 USB_INT_Clear(USB_INT_VBUSTI);
70
71 if (USB_VBUS_GetStatus())
72 {
73 USB_DeviceState = DEVICE_STATE_Powered;
74 EVENT_USB_Device_Connect();
75 }
76 else
77 {
78 USB_DeviceState = DEVICE_STATE_Unattached;
79 EVENT_USB_Device_Disconnect();
80 }
81 }
82
83 if (USB_INT_HasOccurred(USB_INT_SUSPI) && USB_INT_IsEnabled(USB_INT_SUSPI))
84 {
85 USB_INT_Disable(USB_INT_SUSPI);
86 USB_INT_Enable(USB_INT_WAKEUPI);
87
88 USB_CLK_Freeze();
89
90 USB_DeviceState = DEVICE_STATE_Suspended;
91 EVENT_USB_Device_Suspend();
92 }
93
94 if (USB_INT_HasOccurred(USB_INT_WAKEUPI) && USB_INT_IsEnabled(USB_INT_WAKEUPI))
95 {
96 USB_CLK_Unfreeze();
97
98 USB_INT_Clear(USB_INT_WAKEUPI);
99
100 USB_INT_Disable(USB_INT_WAKEUPI);
101 USB_INT_Enable(USB_INT_SUSPI);
102
103 if (USB_Device_ConfigurationNumber)
104 USB_DeviceState = DEVICE_STATE_Configured;
105 else
106 USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Addressed : DEVICE_STATE_Powered;
107
108 EVENT_USB_Device_WakeUp();
109 }
110
111 if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI))
112 {
113 USB_INT_Clear(USB_INT_EORSTI);
114
115 USB_DeviceState = DEVICE_STATE_Default;
116 USB_Device_ConfigurationNumber = 0;
117
118 USB_INT_Clear(USB_INT_SUSPI);
119 USB_INT_Disable(USB_INT_SUSPI);
120 USB_INT_Enable(USB_INT_WAKEUPI);
121
122 USB_Device_SetDeviceAddress(0);
123 Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
124 USB_Device_ControlEndpointSize, 1);
125
126 #if defined(INTERRUPT_CONTROL_ENDPOINT)
127 USB_INT_Enable(USB_INT_RXSTPI);
128 #endif
129
130 EVENT_USB_Device_Reset();
131 }
132 #endif
133
134 #if defined(USB_CAN_BE_HOST)
135 #if !defined(NO_SOF_EVENTS)
136 if (USB_INT_HasOccurred(USB_INT_HSOFI) && USB_INT_IsEnabled(USB_INT_HSOFI))
137 {
138 USB_INT_Clear(USB_INT_HSOFI);
139
140 EVENT_USB_Host_StartOfFrame();
141 }
142 #endif
143
144 if (USB_INT_HasOccurred(USB_INT_DDISCI) && USB_INT_IsEnabled(USB_INT_DDISCI))
145 {
146 USB_INT_Clear(USB_INT_DDISCI);
147 USB_INT_Clear(USB_INT_DCONNI);
148 USB_INT_Disable(USB_INT_DDISCI);
149
150 EVENT_USB_Host_DeviceUnattached();
151
152 USB_ResetInterface();
153 }
154
155 if (USB_INT_HasOccurred(USB_INT_VBERRI) && USB_INT_IsEnabled(USB_INT_VBERRI))
156 {
157 USB_INT_Clear(USB_INT_VBERRI);
158
159 USB_Host_VBUS_Manual_Off();
160 USB_Host_VBUS_Auto_Off();
161
162 EVENT_USB_Host_HostError(HOST_ERROR_VBusVoltageDip);
163 EVENT_USB_Host_DeviceUnattached();
164
165 USB_HostState = HOST_STATE_Unattached;
166 }
167
168 if (USB_INT_HasOccurred(USB_INT_DCONNI) && USB_INT_IsEnabled(USB_INT_DCONNI))
169 {
170 USB_INT_Clear(USB_INT_DCONNI);
171 USB_INT_Disable(USB_INT_DCONNI);
172
173 EVENT_USB_Host_DeviceAttached();
174
175 USB_INT_Enable(USB_INT_DDISCI);
176
177 USB_HostState = HOST_STATE_Powered;
178 }
179
180 if (USB_INT_HasOccurred(USB_INT_BCERRI) && USB_INT_IsEnabled(USB_INT_BCERRI))
181 {
182 USB_INT_Clear(USB_INT_BCERRI);
183
184 EVENT_USB_Host_DeviceEnumerationFailed(HOST_ENUMERROR_NoDeviceDetected, 0);
185 EVENT_USB_Host_DeviceUnattached();
186
187 USB_ResetInterface();
188 }
189 #endif
190
191 #if defined(USB_CAN_BE_BOTH)
192 if (USB_INT_HasOccurred(USB_INT_IDTI) && USB_INT_IsEnabled(USB_INT_IDTI))
193 {
194 USB_INT_Clear(USB_INT_IDTI);
195
196 if (USB_DeviceState != DEVICE_STATE_Unattached)
197 EVENT_USB_Device_Disconnect();
198
199 if (USB_HostState != HOST_STATE_Unattached)
200 EVENT_USB_Host_DeviceUnattached();
201
202 USB_CurrentMode = USB_GetUSBModeFromUID();
203 USB_ResetInterface();
204
205 EVENT_USB_UIDChange();
206 }
207 #endif
208 }
209
210 #if defined(INTERRUPT_CONTROL_ENDPOINT) && defined(USB_CAN_BE_DEVICE)
211 ISR(USB_COM_vect)
212 {
213 uint8_t PrevSelectedEndpoint = Endpoint_GetCurrentEndpoint();
214
215 Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
216 USB_INT_Disable(USB_INT_RXSTPI);
217
218 GlobalInterruptEnable();
219
220 USB_Device_ProcessControlRequest();
221
222 Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
223 USB_INT_Enable(USB_INT_RXSTPI);
224 Endpoint_SelectEndpoint(PrevSelectedEndpoint);
225 }
226 #endif
227
228 #endif
Imprint / Impressum