Statistics
| Branch: | Tag: | Revision:

root / LUFA / Drivers / USB / Core / UC3 / Template / Template_Endpoint_Control_R.c @ 978b99e5

History | View | Annotate | Download (2.48 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
#if defined(TEMPLATE_FUNC_NAME)
32

    
33
uint8_t TEMPLATE_FUNC_NAME (void* const Buffer,
34
                            uint16_t Length)
35
{
36
        uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
37

    
38
        if (!(Length))
39
          Endpoint_ClearOUT();
40

    
41
        while (Length)
42
        {
43
                uint8_t USB_DeviceState_LCL = USB_DeviceState;
44

    
45
                if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
46
                  return ENDPOINT_RWCSTREAM_DeviceDisconnected;
47
                else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
48
                  return ENDPOINT_RWCSTREAM_BusSuspended;
49
                else if (Endpoint_IsSETUPReceived())
50
                  return ENDPOINT_RWCSTREAM_HostAborted;
51

    
52
                if (Endpoint_IsOUTReceived())
53
                {
54
                        while (Length && Endpoint_BytesInEndpoint())
55
                        {
56
                                TEMPLATE_TRANSFER_BYTE(DataStream);
57
                                TEMPLATE_BUFFER_MOVE(DataStream, 1);
58
                                Length--;
59
                        }
60

    
61
                        Endpoint_ClearOUT();
62
                }
63
        }
64

    
65
        while (!(Endpoint_IsINReady()))
66
        {
67
                uint8_t USB_DeviceState_LCL = USB_DeviceState;
68

    
69
                if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
70
                  return ENDPOINT_RWCSTREAM_DeviceDisconnected;
71
                else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
72
                  return ENDPOINT_RWCSTREAM_BusSuspended;
73
        }
74

    
75
        return ENDPOINT_RWCSTREAM_NoError;
76
}
77

    
78
#undef TEMPLATE_BUFFER_OFFSET
79
#undef TEMPLATE_BUFFER_MOVE
80
#undef TEMPLATE_FUNC_NAME
81
#undef TEMPLATE_TRANSFER_BYTE
82

    
83
#endif