1 /**
2 ******************************************************************************
3 * @file usbh_ioreq.c
4 * @author MCD Application Team
5 * @version V3.0.0
6 * @date 18-February-2014
7 * @brief This file handles the issuing of the USB transactions
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
12 *
13 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 * You may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at:
16 *
17 * http://www.st.com/software_license_agreement_liberty_v2
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *
25 ******************************************************************************
26 */
27 /* Includes ------------------------------------------------------------------*/
28
29 #include "usbh_ioreq.h"
30
31 /** @addtogroup USBH_LIB
32 * @{
33 */
34
35 /** @addtogroup USBH_LIB_CORE
36 * @{
37 */
38
39 /** @defgroup USBH_IOREQ
40 * @brief This file handles the standard protocol processing (USB v2.0)
41 * @{
42 */
43
44
45 /** @defgroup USBH_IOREQ_Private_Defines
46 * @{
47 */
48
49 /**
50 * @}
51 */
52
53
54 /** @defgroup USBH_IOREQ_Private_TypesDefinitions
55 * @{
56 */
57 /**
58 * @}
59 */
60
61
62
63 /** @defgroup USBH_IOREQ_Private_Macros
64 * @{
65 */
66 /**
67 * @}
68 */
69
70
71 /** @defgroup USBH_IOREQ_Private_Variables
72 * @{
73 */
74 /**
75 * @}
76 */
77 /** @defgroup USBH_IOREQ_Private_FunctionPrototypes
78 * @{
79 */
80
81 /**
82 * @}
83 */
84
85
86 /** @defgroup USBH_IOREQ_Private_Functions
87 * @{
88 */
89
90
91
92 /**
93 * @brief USBH_CtlSendSetup
94 * Sends the Setup Packet to the Device
95 * @param phost: Host Handle
96 * @param buff: Buffer pointer from which the Data will be send to Device
97 * @param pipe_num: Pipe Number
98 * @retval USBH Status
99 */
USBH_CtlSendSetup(USBH_HandleTypeDef * phost,uint8_t * buff,uint8_t pipe_num)100 USBH_StatusTypeDef USBH_CtlSendSetup (USBH_HandleTypeDef *phost,
101 uint8_t *buff,
102 uint8_t pipe_num)
103 {
104
105 USBH_LL_SubmitURB (phost, /* Driver handle */
106 pipe_num, /* Pipe index */
107 0, /* Direction : OUT */
108 USBH_EP_CONTROL, /* EP type */
109 USBH_PID_SETUP, /* Type setup */
110 buff, /* data buffer */
111 USBH_SETUP_PKT_SIZE, /* data length */
112 0);
113 return USBH_OK;
114 }
115
116
117 /**
118 * @brief USBH_CtlSendData
119 * Sends a data Packet to the Device
120 * @param phost: Host Handle
121 * @param buff: Buffer pointer from which the Data will be sent to Device
122 * @param length: Length of the data to be sent
123 * @param pipe_num: Pipe Number
124 * @retval USBH Status
125 */
USBH_CtlSendData(USBH_HandleTypeDef * phost,uint8_t * buff,uint16_t length,uint8_t pipe_num,uint8_t do_ping)126 USBH_StatusTypeDef USBH_CtlSendData (USBH_HandleTypeDef *phost,
127 uint8_t *buff,
128 uint16_t length,
129 uint8_t pipe_num,
130 uint8_t do_ping )
131 {
132 if(phost->device.speed != USBH_SPEED_HIGH)
133 {
134 do_ping = 0;
135 }
136
137 USBH_LL_SubmitURB (phost, /* Driver handle */
138 pipe_num, /* Pipe index */
139 0, /* Direction : OUT */
140 USBH_EP_CONTROL, /* EP type */
141 USBH_PID_DATA, /* Type Data */
142 buff, /* data buffer */
143 length, /* data length */
144 do_ping); /* do ping (HS Only)*/
145
146 return USBH_OK;
147 }
148
149
150 /**
151 * @brief USBH_CtlReceiveData
152 * Receives the Device Response to the Setup Packet
153 * @param phost: Host Handle
154 * @param buff: Buffer pointer in which the response needs to be copied
155 * @param length: Length of the data to be received
156 * @param pipe_num: Pipe Number
157 * @retval USBH Status.
158 */
USBH_CtlReceiveData(USBH_HandleTypeDef * phost,uint8_t * buff,uint16_t length,uint8_t pipe_num)159 USBH_StatusTypeDef USBH_CtlReceiveData(USBH_HandleTypeDef *phost,
160 uint8_t* buff,
161 uint16_t length,
162 uint8_t pipe_num)
163 {
164 USBH_LL_SubmitURB (phost, /* Driver handle */
165 pipe_num, /* Pipe index */
166 1, /* Direction : IN */
167 USBH_EP_CONTROL, /* EP type */
168 USBH_PID_DATA, /* Type Data */
169 buff, /* data buffer */
170 length, /* data length */
171 0);
172 return USBH_OK;
173
174 }
175
176
177 /**
178 * @brief USBH_BulkSendData
179 * Sends the Bulk Packet to the device
180 * @param phost: Host Handle
181 * @param buff: Buffer pointer from which the Data will be sent to Device
182 * @param length: Length of the data to be sent
183 * @param pipe_num: Pipe Number
184 * @retval USBH Status
185 */
USBH_BulkSendData(USBH_HandleTypeDef * phost,uint8_t * buff,uint16_t length,uint8_t pipe_num,uint8_t do_ping)186 USBH_StatusTypeDef USBH_BulkSendData (USBH_HandleTypeDef *phost,
187 uint8_t *buff,
188 uint16_t length,
189 uint8_t pipe_num,
190 uint8_t do_ping )
191 {
192 if(phost->device.speed != USBH_SPEED_HIGH)
193 {
194 do_ping = 0;
195 }
196
197 USBH_LL_SubmitURB (phost, /* Driver handle */
198 pipe_num, /* Pipe index */
199 0, /* Direction : IN */
200 USBH_EP_BULK, /* EP type */
201 USBH_PID_DATA, /* Type Data */
202 buff, /* data buffer */
203 length, /* data length */
204 do_ping); /* do ping (HS Only)*/
205 return USBH_OK;
206 }
207
208
209 /**
210 * @brief USBH_BulkReceiveData
211 * Receives IN bulk packet from device
212 * @param phost: Host Handle
213 * @param buff: Buffer pointer in which the received data packet to be copied
214 * @param length: Length of the data to be received
215 * @param pipe_num: Pipe Number
216 * @retval USBH Status.
217 */
USBH_BulkReceiveData(USBH_HandleTypeDef * phost,uint8_t * buff,uint16_t length,uint8_t pipe_num)218 USBH_StatusTypeDef USBH_BulkReceiveData(USBH_HandleTypeDef *phost,
219 uint8_t *buff,
220 uint16_t length,
221 uint8_t pipe_num)
222 {
223 USBH_LL_SubmitURB (phost, /* Driver handle */
224 pipe_num, /* Pipe index */
225 1, /* Direction : IN */
226 USBH_EP_BULK, /* EP type */
227 USBH_PID_DATA, /* Type Data */
228 buff, /* data buffer */
229 length, /* data length */
230 0);
231 return USBH_OK;
232 }
233
234
235 /**
236 * @brief USBH_InterruptReceiveData
237 * Receives the Device Response to the Interrupt IN token
238 * @param phost: Host Handle
239 * @param buff: Buffer pointer in which the response needs to be copied
240 * @param length: Length of the data to be received
241 * @param pipe_num: Pipe Number
242 * @retval USBH Status.
243 */
USBH_InterruptReceiveData(USBH_HandleTypeDef * phost,uint8_t * buff,uint8_t length,uint8_t pipe_num)244 USBH_StatusTypeDef USBH_InterruptReceiveData(USBH_HandleTypeDef *phost,
245 uint8_t *buff,
246 uint8_t length,
247 uint8_t pipe_num)
248 {
249 USBH_LL_SubmitURB (phost, /* Driver handle */
250 pipe_num, /* Pipe index */
251 1, /* Direction : IN */
252 USBH_EP_INTERRUPT, /* EP type */
253 USBH_PID_DATA, /* Type Data */
254 buff, /* data buffer */
255 length, /* data length */
256 0);
257
258 return USBH_OK;
259 }
260
261 /**
262 * @brief USBH_InterruptSendData
263 * Sends the data on Interrupt OUT Endpoint
264 * @param phost: Host Handle
265 * @param buff: Buffer pointer from where the data needs to be copied
266 * @param length: Length of the data to be sent
267 * @param pipe_num: Pipe Number
268 * @retval USBH Status.
269 */
USBH_InterruptSendData(USBH_HandleTypeDef * phost,uint8_t * buff,uint8_t length,uint8_t pipe_num)270 USBH_StatusTypeDef USBH_InterruptSendData(USBH_HandleTypeDef *phost,
271 uint8_t *buff,
272 uint8_t length,
273 uint8_t pipe_num)
274 {
275 USBH_LL_SubmitURB (phost, /* Driver handle */
276 pipe_num, /* Pipe index */
277 0, /* Direction : OUT */
278 USBH_EP_INTERRUPT, /* EP type */
279 USBH_PID_DATA, /* Type Data */
280 buff, /* data buffer */
281 length, /* data length */
282 0);
283
284 return USBH_OK;
285 }
286
287 /**
288 * @brief USBH_IsocReceiveData
289 * Receives the Device Response to the Isochronous IN token
290 * @param phost: Host Handle
291 * @param buff: Buffer pointer in which the response needs to be copied
292 * @param length: Length of the data to be received
293 * @param pipe_num: Pipe Number
294 * @retval USBH Status.
295 */
USBH_IsocReceiveData(USBH_HandleTypeDef * phost,uint8_t * buff,uint32_t length,uint8_t pipe_num)296 USBH_StatusTypeDef USBH_IsocReceiveData(USBH_HandleTypeDef *phost,
297 uint8_t *buff,
298 uint32_t length,
299 uint8_t pipe_num)
300 {
301 USBH_LL_SubmitURB (phost, /* Driver handle */
302 pipe_num, /* Pipe index */
303 1, /* Direction : IN */
304 USBH_EP_ISO, /* EP type */
305 USBH_PID_DATA, /* Type Data */
306 buff, /* data buffer */
307 length, /* data length */
308 0);
309
310
311 return USBH_OK;
312 }
313
314 /**
315 * @brief USBH_IsocSendData
316 * Sends the data on Isochronous OUT Endpoint
317 * @param phost: Host Handle
318 * @param buff: Buffer pointer from where the data needs to be copied
319 * @param length: Length of the data to be sent
320 * @param pipe_num: Pipe Number
321 * @retval USBH Status.
322 */
USBH_IsocSendData(USBH_HandleTypeDef * phost,uint8_t * buff,uint32_t length,uint8_t pipe_num)323 USBH_StatusTypeDef USBH_IsocSendData(USBH_HandleTypeDef *phost,
324 uint8_t *buff,
325 uint32_t length,
326 uint8_t pipe_num)
327 {
328 USBH_LL_SubmitURB (phost, /* Driver handle */
329 pipe_num, /* Pipe index */
330 0, /* Direction : OUT */
331 USBH_EP_ISO, /* EP type */
332 USBH_PID_DATA, /* Type Data */
333 buff, /* data buffer */
334 length, /* data length */
335 0);
336
337 return USBH_OK;
338 }
339 /**
340 * @}
341 */
342
343 /**
344 * @}
345 */
346
347 /**
348 * @}
349 */
350
351 /**
352 * @}
353 */
354
355 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
356
357
358
359