3 Copyright (C) Dean Camera, 2012.
\r
5 dean [at] fourwalledcubicle [dot] com
\r
10 Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
\r
12 Permission to use, copy, modify, distribute, and sell this
\r
13 software and its documentation for any purpose is hereby granted
\r
14 without fee, provided that the above copyright notice appear in
\r
15 all copies and that both that the copyright notice and this
\r
16 permission notice and warranty disclaimer appear in supporting
\r
17 documentation, and that the name of the author not be used in
\r
18 advertising or publicity pertaining to distribution of the
\r
19 software without specific, written prior permission.
\r
21 The author disclaim all warranties with regard to this
\r
22 software, including all implied warranties of merchantability
\r
23 and fitness. In no event shall the author be liable for any
\r
24 special, indirect or consequential damages or any damages
\r
25 whatsoever resulting from loss of use, data or profits, whether
\r
26 in an action of contract, negligence or other tortious action,
\r
27 arising out of or in connection with the use or performance of
\r
31 #include "../../../../Common/Common.h"
\r
32 #if (ARCH == ARCH_AVR8)
\r
34 #define __INCLUDE_FROM_USB_DRIVER
\r
35 #include "../USBMode.h"
\r
37 #if defined(USB_CAN_BE_DEVICE)
\r
39 #include "../Endpoint.h"
\r
41 #if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
\r
42 uint8_t USB_Device_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE;
\r
45 bool Endpoint_ConfigureEndpointTable(const USB_Endpoint_Table_t* const Table,
\r
46 const uint8_t Entries)
\r
48 for (uint8_t i = 0; i < Entries; i++)
\r
50 if (!(Table[i].Address))
\r
53 if (!(Endpoint_ConfigureEndpoint(Table[i].Address, Table[i].Type, Table[i].Size, Table[i].Banks)))
\r
60 bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
\r
61 const uint8_t UECFG0XData,
\r
62 const uint8_t UECFG1XData)
\r
64 #if defined(CONTROL_ONLY_DEVICE) || defined(ORDERED_EP_CONFIG)
\r
65 Endpoint_SelectEndpoint(Number);
\r
66 Endpoint_EnableEndpoint();
\r
69 UECFG0X = UECFG0XData;
\r
70 UECFG1X = UECFG1XData;
\r
72 return Endpoint_IsConfigured();
\r
74 for (uint8_t EPNum = Number; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++)
\r
76 uint8_t UECFG0XTemp;
\r
77 uint8_t UECFG1XTemp;
\r
80 Endpoint_SelectEndpoint(EPNum);
\r
82 if (EPNum == Number)
\r
84 UECFG0XTemp = UECFG0XData;
\r
85 UECFG1XTemp = UECFG1XData;
\r
90 UECFG0XTemp = UECFG0X;
\r
91 UECFG1XTemp = UECFG1X;
\r
92 UEIENXTemp = UEIENX;
\r
95 if (!(UECFG1XTemp & (1 << ALLOC)))
\r
98 Endpoint_DisableEndpoint();
\r
99 UECFG1X &= ~(1 << ALLOC);
\r
101 Endpoint_EnableEndpoint();
\r
102 UECFG0X = UECFG0XTemp;
\r
103 UECFG1X = UECFG1XTemp;
\r
104 UEIENX = UEIENXTemp;
\r
106 if (!(Endpoint_IsConfigured()))
\r
110 Endpoint_SelectEndpoint(Number);
\r
115 void Endpoint_ClearEndpoints(void)
\r
119 for (uint8_t EPNum = 0; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++)
\r
121 Endpoint_SelectEndpoint(EPNum);
\r
125 Endpoint_DisableEndpoint();
\r
129 void Endpoint_ClearStatusStage(void)
\r
131 if (USB_ControlRequest.bmRequestType & REQDIR_DEVICETOHOST)
\r
133 while (!(Endpoint_IsOUTReceived()))
\r
135 if (USB_DeviceState == DEVICE_STATE_Unattached)
\r
139 Endpoint_ClearOUT();
\r
143 while (!(Endpoint_IsINReady()))
\r
145 if (USB_DeviceState == DEVICE_STATE_Unattached)
\r
149 Endpoint_ClearIN();
\r
153 #if !defined(CONTROL_ONLY_DEVICE)
\r
154 uint8_t Endpoint_WaitUntilReady(void)
\r
156 #if (USB_STREAM_TIMEOUT_MS < 0xFF)
\r
157 uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
\r
159 uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
\r
162 uint16_t PreviousFrameNumber = USB_Device_GetFrameNumber();
\r
166 if (Endpoint_GetEndpointDirection() == ENDPOINT_DIR_IN)
\r
168 if (Endpoint_IsINReady())
\r
169 return ENDPOINT_READYWAIT_NoError;
\r
173 if (Endpoint_IsOUTReceived())
\r
174 return ENDPOINT_READYWAIT_NoError;
\r
177 uint8_t USB_DeviceState_LCL = USB_DeviceState;
\r
179 if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
\r
180 return ENDPOINT_READYWAIT_DeviceDisconnected;
\r
181 else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
\r
182 return ENDPOINT_READYWAIT_BusSuspended;
\r
183 else if (Endpoint_IsStalled())
\r
184 return ENDPOINT_READYWAIT_EndpointStalled;
\r
186 uint16_t CurrentFrameNumber = USB_Device_GetFrameNumber();
\r
188 if (CurrentFrameNumber != PreviousFrameNumber)
\r
190 PreviousFrameNumber = CurrentFrameNumber;
\r
192 if (!(TimeoutMSRem--))
\r
193 return ENDPOINT_READYWAIT_Timeout;
\r