3 Copyright (C) Dean Camera, 2011.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
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.
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
31 #define __INCLUDE_FROM_USB_DRIVER
34 #if defined(USB_CAN_BE_HOST)
36 #include "PipeStream.h"
38 uint8_t Pipe_Discard_Stream(uint16_t Length
43 Pipe_SetPipeToken(PIPE_TOKEN_IN
);
45 if ((ErrorCode
= Pipe_WaitUntilReady()))
50 if (!(Pipe_IsReadWriteAllowed()))
54 #if !defined(NO_STREAM_CALLBACKS)
55 if ((Callback
!= NULL
) && (Callback() == STREAMCALLBACK_Abort
))
56 return PIPE_RWSTREAM_CallbackAborted
;
59 if ((ErrorCode
= Pipe_WaitUntilReady()))
69 return PIPE_RWSTREAM_NoError
;
72 /* The following abuses the C preprocessor in order to copy-past common code with slight alterations,
73 * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */
75 #define TEMPLATE_FUNC_NAME Pipe_Write_Stream_LE
76 #define TEMPLATE_BUFFER_TYPE const void*
77 #define TEMPLATE_TOKEN PIPE_TOKEN_OUT
78 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
79 #define TEMPLATE_BUFFER_OFFSET(Length) 0
80 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(*((uint8_t*)BufferPtr++))
81 #include "Template/Template_Pipe_RW.c"
83 #define TEMPLATE_FUNC_NAME Pipe_Write_PStream_LE
84 #define TEMPLATE_BUFFER_TYPE const void*
85 #define TEMPLATE_TOKEN PIPE_TOKEN_OUT
86 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
87 #define TEMPLATE_BUFFER_OFFSET(Length) 0
88 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++))
89 #include "Template/Template_Pipe_RW.c"
91 #define TEMPLATE_FUNC_NAME Pipe_Write_EStream_LE
92 #define TEMPLATE_BUFFER_TYPE const void*
93 #define TEMPLATE_TOKEN PIPE_TOKEN_OUT
94 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
95 #define TEMPLATE_BUFFER_OFFSET(Length) 0
96 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++))
97 #include "Template/Template_Pipe_RW.c"
99 #define TEMPLATE_FUNC_NAME Pipe_Write_Stream_BE
100 #define TEMPLATE_BUFFER_TYPE const void*
101 #define TEMPLATE_TOKEN PIPE_TOKEN_OUT
102 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
103 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
104 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(*((uint8_t*)BufferPtr--))
105 #include "Template/Template_Pipe_RW.c"
107 #define TEMPLATE_FUNC_NAME Pipe_Write_PStream_BE
108 #define TEMPLATE_BUFFER_TYPE const void*
109 #define TEMPLATE_TOKEN PIPE_TOKEN_OUT
110 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
111 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
112 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--))
113 #include "Template/Template_Pipe_RW.c"
115 #define TEMPLATE_FUNC_NAME Pipe_Write_EStream_BE
116 #define TEMPLATE_BUFFER_TYPE const void*
117 #define TEMPLATE_TOKEN PIPE_TOKEN_OUT
118 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
119 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
120 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--))
121 #include "Template/Template_Pipe_RW.c"
123 #define TEMPLATE_FUNC_NAME Pipe_Read_Stream_LE
124 #define TEMPLATE_BUFFER_TYPE void*
125 #define TEMPLATE_TOKEN PIPE_TOKEN_IN
126 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
127 #define TEMPLATE_BUFFER_OFFSET(Length) 0
128 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Pipe_Read_Byte()
129 #include "Template/Template_Pipe_RW.c"
131 #define TEMPLATE_FUNC_NAME Pipe_Read_EStream_LE
132 #define TEMPLATE_BUFFER_TYPE void*
133 #define TEMPLATE_TOKEN PIPE_TOKEN_IN
134 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
135 #define TEMPLATE_BUFFER_OFFSET(Length) 0
136 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr++, Pipe_Read_Byte())
137 #include "Template/Template_Pipe_RW.c"
139 #define TEMPLATE_FUNC_NAME Pipe_Read_Stream_BE
140 #define TEMPLATE_BUFFER_TYPE void*
141 #define TEMPLATE_TOKEN PIPE_TOKEN_IN
142 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
143 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
144 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Pipe_Read_Byte()
145 #include "Template/Template_Pipe_RW.c"
147 #define TEMPLATE_FUNC_NAME Pipe_Read_EStream_BE
148 #define TEMPLATE_BUFFER_TYPE void*
149 #define TEMPLATE_TOKEN PIPE_TOKEN_IN
150 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
151 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
152 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr--, Pipe_Read_Byte())
153 #include "Template/Template_Pipe_RW.c"