3 Copyright (C) Dean Camera, 2012.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2012 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 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 #include "../../../../Common/Common.h"
32 #if (ARCH == ARCH_UC3)
34 #define __INCLUDE_FROM_USB_DRIVER
35 #include "../USBInterrupt.h"
37 void USB_INT_DisableAllInterrupts(void)
39 AVR32_USBB
.USBCON
.vbuste
= false;
40 AVR32_USBB
.USBCON
.idte
= false;
42 AVR32_USBB
.uhinteclr
= -1;
43 AVR32_USBB
.udinteclr
= -1;
46 void USB_INT_ClearAllInterrupts(void)
48 AVR32_USBB
.USBSTACLR
.vbustic
= true;
49 AVR32_USBB
.USBSTACLR
.idtic
= true;
51 AVR32_USBB
.uhintclr
= -1;
52 AVR32_USBB
.udintclr
= -1;
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
))
61 USB_INT_Clear(USB_INT_SOFI
);
63 EVENT_USB_Device_StartOfFrame();
67 if (USB_INT_HasOccurred(USB_INT_VBUSTI
) && USB_INT_IsEnabled(USB_INT_VBUSTI
))
69 USB_INT_Clear(USB_INT_VBUSTI
);
71 if (USB_VBUS_GetStatus())
73 USB_DeviceState
= DEVICE_STATE_Powered
;
74 EVENT_USB_Device_Connect();
78 USB_DeviceState
= DEVICE_STATE_Unattached
;
79 EVENT_USB_Device_Disconnect();
83 if (USB_INT_HasOccurred(USB_INT_SUSPI
) && USB_INT_IsEnabled(USB_INT_SUSPI
))
85 USB_INT_Disable(USB_INT_SUSPI
);
86 USB_INT_Enable(USB_INT_WAKEUPI
);
90 USB_DeviceState
= DEVICE_STATE_Suspended
;
91 EVENT_USB_Device_Suspend();
94 if (USB_INT_HasOccurred(USB_INT_WAKEUPI
) && USB_INT_IsEnabled(USB_INT_WAKEUPI
))
98 USB_INT_Clear(USB_INT_WAKEUPI
);
100 USB_INT_Disable(USB_INT_WAKEUPI
);
101 USB_INT_Enable(USB_INT_SUSPI
);
103 if (USB_Device_ConfigurationNumber
)
104 USB_DeviceState
= DEVICE_STATE_Configured
;
106 USB_DeviceState
= (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured
: DEVICE_STATE_Powered
;
108 EVENT_USB_Device_WakeUp();
111 if (USB_INT_HasOccurred(USB_INT_EORSTI
) && USB_INT_IsEnabled(USB_INT_EORSTI
))
113 USB_INT_Clear(USB_INT_EORSTI
);
115 USB_DeviceState
= DEVICE_STATE_Default
;
116 USB_Device_ConfigurationNumber
= 0;
118 USB_INT_Clear(USB_INT_SUSPI
);
119 USB_INT_Disable(USB_INT_SUSPI
);
120 USB_INT_Enable(USB_INT_WAKEUPI
);
122 USB_Device_SetDeviceAddress(0);
123 Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP
, EP_TYPE_CONTROL
,
124 ENDPOINT_DIR_OUT
, USB_Device_ControlEndpointSize
,
125 ENDPOINT_BANK_SINGLE
);
127 #if defined(INTERRUPT_CONTROL_ENDPOINT)
128 USB_INT_Enable(USB_INT_RXSTPI
);
131 EVENT_USB_Device_Reset();
135 #if defined(USB_CAN_BE_HOST)
136 #if !defined(NO_SOF_EVENTS)
137 if (USB_INT_HasOccurred(USB_INT_HSOFI
) && USB_INT_IsEnabled(USB_INT_HSOFI
))
139 USB_INT_Clear(USB_INT_HSOFI
);
141 EVENT_USB_Host_StartOfFrame();
145 if (USB_INT_HasOccurred(USB_INT_DDISCI
) && USB_INT_IsEnabled(USB_INT_DDISCI
))
147 USB_INT_Clear(USB_INT_DDISCI
);
148 USB_INT_Clear(USB_INT_DCONNI
);
149 USB_INT_Disable(USB_INT_DDISCI
);
151 EVENT_USB_Host_DeviceUnattached();
153 USB_ResetInterface();
156 if (USB_INT_HasOccurred(USB_INT_VBERRI
) && USB_INT_IsEnabled(USB_INT_VBERRI
))
158 USB_INT_Clear(USB_INT_VBERRI
);
160 USB_Host_VBUS_Manual_Off();
161 USB_Host_VBUS_Auto_Off();
163 EVENT_USB_Host_HostError(HOST_ERROR_VBusVoltageDip
);
164 EVENT_USB_Host_DeviceUnattached();
166 USB_HostState
= HOST_STATE_Unattached
;
169 if (USB_INT_HasOccurred(USB_INT_DCONNI
) && USB_INT_IsEnabled(USB_INT_DCONNI
))
171 USB_INT_Clear(USB_INT_DCONNI
);
172 USB_INT_Disable(USB_INT_DCONNI
);
174 EVENT_USB_Host_DeviceAttached();
176 USB_INT_Enable(USB_INT_DDISCI
);
178 USB_HostState
= HOST_STATE_Powered
;
181 if (USB_INT_HasOccurred(USB_INT_BCERRI
) && USB_INT_IsEnabled(USB_INT_BCERRI
))
183 USB_INT_Clear(USB_INT_BCERRI
);
185 EVENT_USB_Host_DeviceEnumerationFailed(HOST_ENUMERROR_NoDeviceDetected
, 0);
186 EVENT_USB_Host_DeviceUnattached();
188 USB_ResetInterface();
192 #if defined(USB_CAN_BE_BOTH)
193 if (USB_INT_HasOccurred(USB_INT_IDTI
) && USB_INT_IsEnabled(USB_INT_IDTI
))
195 USB_INT_Clear(USB_INT_IDTI
);
197 if (USB_DeviceState
!= DEVICE_STATE_Unattached
)
198 EVENT_USB_Device_Disconnect();
200 if (USB_HostState
!= HOST_STATE_Unattached
)
201 EVENT_USB_Host_DeviceUnattached();
203 USB_CurrentMode
= USB_GetUSBModeFromUID();
204 USB_ResetInterface();
206 EVENT_USB_UIDChange();
211 #if defined(INTERRUPT_CONTROL_ENDPOINT) && defined(USB_CAN_BE_DEVICE)
214 uint8_t PrevSelectedEndpoint
= Endpoint_GetCurrentEndpoint();
216 Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP
);
217 USB_INT_Disable(USB_INT_RXSTPI
);
219 GlobalInterruptEnable();
221 USB_Device_ProcessControlRequest();
223 Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP
);
224 USB_INT_Enable(USB_INT_RXSTPI
);
225 Endpoint_SelectEndpoint(PrevSelectedEndpoint
);