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