Template_Endpoint_Control_R.c 1.21 KB
Newer Older
1
uint8_t TEMPLATE_FUNC_NAME (void* const Buffer,
2
                            uint16_t Length)
3
4
{
	uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
5

6
7
	if (!(Length))
	  Endpoint_ClearOUT();
8

9
10
	while (Length)
	{
11
		uint8_t USB_DeviceState_LCL = USB_DeviceState;
12

13
		if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
14
		  return ENDPOINT_RWCSTREAM_DeviceDisconnected;
15
		else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
16
		  return ENDPOINT_RWCSTREAM_BusSuspended;
17
18
		else if (Endpoint_IsSETUPReceived())
		  return ENDPOINT_RWCSTREAM_HostAborted;
19

20
21
22
23
24
		if (Endpoint_IsOUTReceived())
		{
			while (Length && Endpoint_BytesInEndpoint())
			{
				TEMPLATE_TRANSFER_BYTE(DataStream);
25
				TEMPLATE_BUFFER_MOVE(DataStream, 1);
26
27
				Length--;
			}
28

29
			Endpoint_ClearOUT();
30
		}
31
	}
32

33
34
	while (!(Endpoint_IsINReady()))
	{
35
36
37
		uint8_t USB_DeviceState_LCL = USB_DeviceState;

		if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
38
		  return ENDPOINT_RWCSTREAM_DeviceDisconnected;
39
		else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
40
41
		  return ENDPOINT_RWCSTREAM_BusSuspended;
	}
42

43
44
45
46
47
	return ENDPOINT_RWCSTREAM_NoError;
}


#undef TEMPLATE_BUFFER_OFFSET
48
#undef TEMPLATE_BUFFER_MOVE
49
#undef TEMPLATE_FUNC_NAME
50
#undef TEMPLATE_TRANSFER_BYTE