3 Copyright (C) Dean Camera, 2010.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2010 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 #define __INCLUDE_FROM_USB_DRIVER
32 #include "../HighLevel/USBMode.h"
34 #if defined(USB_CAN_BE_DEVICE)
38 #if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
39 uint8_t USB_ControlEndpointSize
= ENDPOINT_CONTROLEP_DEFAULT_SIZE
;
42 bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number
,
43 const uint8_t UECFG0XData
,
44 const uint8_t UECFG1XData
)
46 uint8_t UECFG0XTemp
[ENDPOINT_TOTAL_ENDPOINTS
];
47 uint8_t UECFG1XTemp
[ENDPOINT_TOTAL_ENDPOINTS
];
49 for (uint8_t EPNum
= 0; EPNum
< ENDPOINT_TOTAL_ENDPOINTS
; EPNum
++)
51 Endpoint_SelectEndpoint(EPNum
);
52 UECFG0XTemp
[EPNum
] = UECFG0X
;
53 UECFG1XTemp
[EPNum
] = UECFG1X
;
56 UECFG0XTemp
[Number
] = UECFG0XData
;
57 UECFG1XTemp
[Number
] = UECFG1XData
;
59 for (uint8_t EPNum
= 1; EPNum
< ENDPOINT_TOTAL_ENDPOINTS
; EPNum
++)
61 Endpoint_SelectEndpoint(EPNum
);
65 Endpoint_DisableEndpoint();
68 for (uint8_t EPNum
= 0; EPNum
< ENDPOINT_TOTAL_ENDPOINTS
; EPNum
++)
70 if (!(UECFG1XTemp
[EPNum
] & (1 << ALLOC
)))
73 Endpoint_SelectEndpoint(EPNum
);
74 Endpoint_EnableEndpoint();
76 UECFG0X
= UECFG0XTemp
[EPNum
];
77 UECFG1X
= UECFG1XTemp
[EPNum
];
79 if (!(Endpoint_IsConfigured()))
83 Endpoint_SelectEndpoint(Number
);
87 void Endpoint_ClearEndpoints(void)
91 for (uint8_t EPNum
= 0; EPNum
< ENDPOINT_TOTAL_ENDPOINTS
; EPNum
++)
93 Endpoint_SelectEndpoint(EPNum
);
97 Endpoint_DisableEndpoint();
101 void Endpoint_ClearStatusStage(void)
103 if (USB_ControlRequest
.bmRequestType
& REQDIR_DEVICETOHOST
)
105 while (!(Endpoint_IsOUTReceived()))
107 if (USB_DeviceState
== DEVICE_STATE_Unattached
)
115 while (!(Endpoint_IsINReady()))
117 if (USB_DeviceState
== DEVICE_STATE_Unattached
)
125 #if !defined(CONTROL_ONLY_DEVICE)
126 uint8_t Endpoint_WaitUntilReady(void)
128 #if (USB_STREAM_TIMEOUT_MS < 0xFF)
129 uint8_t TimeoutMSRem
= USB_STREAM_TIMEOUT_MS
;
131 uint16_t TimeoutMSRem
= USB_STREAM_TIMEOUT_MS
;
136 if (Endpoint_GetEndpointDirection() == ENDPOINT_DIR_IN
)
138 if (Endpoint_IsINReady())
139 return ENDPOINT_READYWAIT_NoError
;
143 if (Endpoint_IsOUTReceived())
144 return ENDPOINT_READYWAIT_NoError
;
147 if (USB_DeviceState
== DEVICE_STATE_Unattached
)
148 return ENDPOINT_READYWAIT_DeviceDisconnected
;
149 else if (USB_DeviceState
== DEVICE_STATE_Suspended
)
150 return ENDPOINT_READYWAIT_BusSuspended
;
151 else if (Endpoint_IsStalled())
152 return ENDPOINT_READYWAIT_EndpointStalled
;
154 if (USB_INT_HasOccurred(USB_INT_SOFI
))
156 USB_INT_Clear(USB_INT_SOFI
);
158 if (!(TimeoutMSRem
--))
159 return ENDPOINT_READYWAIT_Timeout
;