]> git.gir.st - tmk_keyboard.git/blob - protocol/lufa/LUFA-120730/LUFA/Drivers/USB/Core/UC3/Template/Template_Endpoint_Control_W.c
Squashed 'tmk_core/' content from commit 05caacc
[tmk_keyboard.git] / protocol / lufa / LUFA-120730 / LUFA / Drivers / USB / Core / UC3 / Template / Template_Endpoint_Control_W.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2012.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2012 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 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
28 this software.
29 */
30
31 #if defined(TEMPLATE_FUNC_NAME)
32
33 // cppcheck-suppress unusedFunction
34 uint8_t TEMPLATE_FUNC_NAME (const void* const Buffer,
35 uint16_t Length)
36 {
37 uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
38 bool LastPacketFull = false;
39
40 if (Length > USB_ControlRequest.wLength)
41 Length = USB_ControlRequest.wLength;
42 else if (!(Length))
43 Endpoint_ClearIN();
44
45 while (Length || LastPacketFull)
46 {
47 uint8_t USB_DeviceState_LCL = USB_DeviceState;
48
49 if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
50 return ENDPOINT_RWCSTREAM_DeviceDisconnected;
51 else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
52 return ENDPOINT_RWCSTREAM_BusSuspended;
53 else if (Endpoint_IsSETUPReceived())
54 return ENDPOINT_RWCSTREAM_HostAborted;
55 else if (Endpoint_IsOUTReceived())
56 break;
57
58 if (Endpoint_IsINReady())
59 {
60 uint16_t BytesInEndpoint = Endpoint_BytesInEndpoint();
61
62 while (Length && (BytesInEndpoint < USB_Device_ControlEndpointSize))
63 {
64 TEMPLATE_TRANSFER_BYTE(DataStream);
65 TEMPLATE_BUFFER_MOVE(DataStream, 1);
66 Length--;
67 BytesInEndpoint++;
68 }
69
70 LastPacketFull = (BytesInEndpoint == USB_Device_ControlEndpointSize);
71 Endpoint_ClearIN();
72 }
73 }
74
75 while (!(Endpoint_IsOUTReceived()))
76 {
77 uint8_t USB_DeviceState_LCL = USB_DeviceState;
78
79 if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
80 return ENDPOINT_RWCSTREAM_DeviceDisconnected;
81 else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
82 return ENDPOINT_RWCSTREAM_BusSuspended;
83 }
84
85 return ENDPOINT_RWCSTREAM_NoError;
86 }
87
88 #undef TEMPLATE_BUFFER_OFFSET
89 #undef TEMPLATE_BUFFER_MOVE
90 #undef TEMPLATE_FUNC_NAME
91 #undef TEMPLATE_TRANSFER_BYTE
92
93 #endif
94
Imprint / Impressum