Statistics
| Branch: | Tag: | Revision:

root / LUFA / Drivers / USB / Core / USBTask.c @ 978b99e5

History | View | Annotate | Download (2.44 KB)

1
/*
2
             LUFA Library
3
     Copyright (C) Dean Camera, 2011.
4

5
  dean [at] fourwalledcubicle [dot] com
6
           www.lufa-lib.org
7
*/
8

    
9
/*
10
  Copyright 2011  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
                else if (USB_CurrentMode == USB_MODE_Host)
56
                  USB_HostTask();
57
        #endif
58
}
59

    
60
#if defined(USB_CAN_BE_DEVICE)
61
static void USB_DeviceTask(void)
62
{
63
        if (USB_DeviceState != DEVICE_STATE_Unattached)
64
        {
65
                uint8_t PrevEndpoint = Endpoint_GetCurrentEndpoint();
66

    
67
                Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
68

    
69
                if (Endpoint_IsSETUPReceived())
70
                  USB_Device_ProcessControlRequest();
71

    
72
                Endpoint_SelectEndpoint(PrevEndpoint);
73
        }
74
}
75
#endif
76

    
77
#if defined(USB_CAN_BE_HOST)
78
static void USB_HostTask(void)
79
{
80
        uint8_t PrevPipe = Pipe_GetCurrentPipe();
81

    
82
        Pipe_SelectPipe(PIPE_CONTROLPIPE);
83

    
84
        USB_Host_ProcessNextHostState();
85

    
86
        Pipe_SelectPipe(PrevPipe);
87
}
88
#endif
89