]> git.donarmstrong.com Git - qmk_firmware.git/blob - protocol/lufa/LUFA-120730/LUFA/Drivers/USB/Core/UC3/Template/Template_Endpoint_Control_R.c
Change TOP_DIR to TMK_DIR in makefiles
[qmk_firmware.git] / protocol / lufa / LUFA-120730 / LUFA / Drivers / USB / Core / UC3 / Template / Template_Endpoint_Control_R.c
1 /*\r
2              LUFA Library\r
3      Copyright (C) Dean Camera, 2012.\r
4 \r
5   dean [at] fourwalledcubicle [dot] com\r
6            www.lufa-lib.org\r
7 */\r
8 \r
9 /*\r
10   Copyright 2012  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
11 \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
20 \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
28   this software.\r
29 */\r
30 \r
31 #if defined(TEMPLATE_FUNC_NAME)\r
32 \r
33 // cppcheck-suppress unusedFunction\r
34 uint8_t TEMPLATE_FUNC_NAME (void* const Buffer,\r
35                             uint16_t Length)\r
36 {\r
37         uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));\r
38 \r
39         if (!(Length))\r
40           Endpoint_ClearOUT();\r
41 \r
42         while (Length)\r
43         {\r
44                 uint8_t USB_DeviceState_LCL = USB_DeviceState;\r
45 \r
46                 if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)\r
47                   return ENDPOINT_RWCSTREAM_DeviceDisconnected;\r
48                 else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)\r
49                   return ENDPOINT_RWCSTREAM_BusSuspended;\r
50                 else if (Endpoint_IsSETUPReceived())\r
51                   return ENDPOINT_RWCSTREAM_HostAborted;\r
52 \r
53                 if (Endpoint_IsOUTReceived())\r
54                 {\r
55                         while (Length && Endpoint_BytesInEndpoint())\r
56                         {\r
57                                 TEMPLATE_TRANSFER_BYTE(DataStream);\r
58                                 TEMPLATE_BUFFER_MOVE(DataStream, 1);\r
59                                 Length--;\r
60                         }\r
61 \r
62                         Endpoint_ClearOUT();\r
63                 }\r
64         }\r
65 \r
66         while (!(Endpoint_IsINReady()))\r
67         {\r
68                 uint8_t USB_DeviceState_LCL = USB_DeviceState;\r
69 \r
70                 if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)\r
71                   return ENDPOINT_RWCSTREAM_DeviceDisconnected;\r
72                 else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)\r
73                   return ENDPOINT_RWCSTREAM_BusSuspended;\r
74         }\r
75 \r
76         return ENDPOINT_RWCSTREAM_NoError;\r
77 }\r
78 \r
79 #undef TEMPLATE_BUFFER_OFFSET\r
80 #undef TEMPLATE_BUFFER_MOVE\r
81 #undef TEMPLATE_FUNC_NAME\r
82 #undef TEMPLATE_TRANSFER_BYTE\r
83 \r
84 #endif\r
85 \r