3 Copyright (C) Dean Camera, 2018.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2018 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
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_Addressed
: 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 USB_Device_ControlEndpointSize
, 1);
126 #if defined(INTERRUPT_CONTROL_ENDPOINT)
127 USB_INT_Enable(USB_INT_RXSTPI
);
130 EVENT_USB_Device_Reset();
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
))
138 USB_INT_Clear(USB_INT_HSOFI
);
140 EVENT_USB_Host_StartOfFrame();
144 if (USB_INT_HasOccurred(USB_INT_DDISCI
) && USB_INT_IsEnabled(USB_INT_DDISCI
))
146 USB_INT_Clear(USB_INT_DDISCI
);
147 USB_INT_Clear(USB_INT_DCONNI
);
148 USB_INT_Disable(USB_INT_DDISCI
);
150 EVENT_USB_Host_DeviceUnattached();
152 USB_ResetInterface();
155 if (USB_INT_HasOccurred(USB_INT_VBERRI
) && USB_INT_IsEnabled(USB_INT_VBERRI
))
157 USB_INT_Clear(USB_INT_VBERRI
);
159 USB_Host_VBUS_Manual_Off();
160 USB_Host_VBUS_Auto_Off();
162 EVENT_USB_Host_HostError(HOST_ERROR_VBusVoltageDip
);
163 EVENT_USB_Host_DeviceUnattached();
165 USB_HostState
= HOST_STATE_Unattached
;
168 if (USB_INT_HasOccurred(USB_INT_DCONNI
) && USB_INT_IsEnabled(USB_INT_DCONNI
))
170 USB_INT_Clear(USB_INT_DCONNI
);
171 USB_INT_Disable(USB_INT_DCONNI
);
173 EVENT_USB_Host_DeviceAttached();
175 USB_INT_Enable(USB_INT_DDISCI
);
177 USB_HostState
= HOST_STATE_Powered
;
180 if (USB_INT_HasOccurred(USB_INT_BCERRI
) && USB_INT_IsEnabled(USB_INT_BCERRI
))
182 USB_INT_Clear(USB_INT_BCERRI
);
184 EVENT_USB_Host_DeviceEnumerationFailed(HOST_ENUMERROR_NoDeviceDetected
, 0);
185 EVENT_USB_Host_DeviceUnattached();
187 USB_ResetInterface();
191 #if defined(USB_CAN_BE_BOTH)
192 if (USB_INT_HasOccurred(USB_INT_IDTI
) && USB_INT_IsEnabled(USB_INT_IDTI
))
194 USB_INT_Clear(USB_INT_IDTI
);
196 if (USB_DeviceState
!= DEVICE_STATE_Unattached
)
197 EVENT_USB_Device_Disconnect();
199 if (USB_HostState
!= HOST_STATE_Unattached
)
200 EVENT_USB_Host_DeviceUnattached();
202 USB_CurrentMode
= USB_GetUSBModeFromUID();
203 USB_ResetInterface();
205 EVENT_USB_UIDChange();
210 #if defined(INTERRUPT_CONTROL_ENDPOINT) && defined(USB_CAN_BE_DEVICE)
213 uint8_t PrevSelectedEndpoint
= Endpoint_GetCurrentEndpoint();
215 Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP
);
216 USB_INT_Disable(USB_INT_RXSTPI
);
218 GlobalInterruptEnable();
220 USB_Device_ProcessControlRequest();
222 Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP
);
223 USB_INT_Enable(USB_INT_RXSTPI
);
224 Endpoint_SelectEndpoint(PrevSelectedEndpoint
);