]> git.gir.st - tmk_keyboard.git/blob - protocol/lufa/LUFA-120730/LUFA/Drivers/USB/Core/USBTask.c
Change TOP_DIR to TMK_DIR in makefiles
[tmk_keyboard.git] / protocol / lufa / LUFA-120730 / LUFA / Drivers / USB / Core / USBTask.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 #define __INCLUDE_FROM_USBTASK_C
32 #define __INCLUDE_FROM_USB_DRIVER
33 #include "USBTask.h"
34
35 volatile bool USB_IsInitialized;
36 USB_Request_Header_t USB_ControlRequest;
37
38 #if defined(USB_CAN_BE_HOST) && !defined(HOST_STATE_AS_GPIOR)
39 volatile uint8_t USB_HostState;
40 #endif
41
42 #if defined(USB_CAN_BE_DEVICE) && !defined(DEVICE_STATE_AS_GPIOR)
43 volatile uint8_t USB_DeviceState;
44 #endif
45
46 void USB_USBTask(void)
47 {
48 #if defined(USB_HOST_ONLY)
49 USB_HostTask();
50 #elif defined(USB_DEVICE_ONLY)
51 USB_DeviceTask();
52 #else
53 if (USB_CurrentMode == USB_MODE_Device)
54 USB_DeviceTask();
55 #if defined(USB_CAN_BE_HOST)
56 else if (USB_CurrentMode == USB_MODE_Host)
57 USB_HostTask();
58 #endif
59 #endif
60 }
61
62 #if defined(USB_CAN_BE_DEVICE)
63 static void USB_DeviceTask(void)
64 {
65 if (USB_DeviceState != DEVICE_STATE_Unattached)
66 {
67 uint8_t PrevEndpoint = Endpoint_GetCurrentEndpoint();
68
69 Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
70
71 if (Endpoint_IsSETUPReceived())
72 USB_Device_ProcessControlRequest();
73
74 Endpoint_SelectEndpoint(PrevEndpoint);
75 }
76 }
77 #endif
78
79 #if defined(USB_CAN_BE_HOST)
80 static void USB_HostTask(void)
81 {
82 uint8_t PrevPipe = Pipe_GetCurrentPipe();
83
84 Pipe_SelectPipe(PIPE_CONTROLPIPE);
85
86 USB_Host_ProcessNextHostState();
87
88 Pipe_SelectPipe(PrevPipe);
89 }
90 #endif
91
Imprint / Impressum