1 uint8_t TEMPLATE_FUNC_NAME (const void* Buffer
, uint16_t Length
)
3 uint8_t* DataStream
= ((uint8_t*)Buffer
+ TEMPLATE_BUFFER_OFFSET(Length
));
4 bool LastPacketFull
= false;
6 if (Length
> USB_ControlRequest
.wLength
)
7 Length
= USB_ControlRequest
.wLength
;
11 while (Length
|| LastPacketFull
)
13 if (Endpoint_IsSETUPReceived())
14 return ENDPOINT_RWCSTREAM_HostAborted
;
16 if (Endpoint_IsOUTReceived())
19 if (USB_DeviceState
== DEVICE_STATE_Unattached
)
20 return ENDPOINT_RWCSTREAM_DeviceDisconnected
;
21 else if (USB_DeviceState
== DEVICE_STATE_Suspended
)
22 return ENDPOINT_RWCSTREAM_BusSuspended
;
24 if (Endpoint_IsINReady())
26 uint8_t BytesInEndpoint
= Endpoint_BytesInEndpoint();
28 while (Length
&& (BytesInEndpoint
< USB_ControlEndpointSize
))
30 TEMPLATE_TRANSFER_BYTE(DataStream
);
35 LastPacketFull
= (BytesInEndpoint
== USB_ControlEndpointSize
);
40 while (!(Endpoint_IsOUTReceived()))
42 if (USB_DeviceState
== DEVICE_STATE_Unattached
)
43 return ENDPOINT_RWCSTREAM_DeviceDisconnected
;
44 else if (USB_DeviceState
== DEVICE_STATE_Suspended
)
45 return ENDPOINT_RWCSTREAM_BusSuspended
;
48 return ENDPOINT_RWCSTREAM_NoError
;
51 #undef TEMPLATE_BUFFER_OFFSET
52 #undef TEMPLATE_FUNC_NAME
53 #undef TEMPLATE_TRANSFER_BYTE