Merge pull request #93 from zyp/master
[fw/stlink] / example / stm32f4 / STM32_USB_Device_Library / Core / src / usbd_ioreq.c
1 /**
2   ******************************************************************************
3   * @file    usbd_ioreq.c
4   * @author  MCD Application Team
5   * @version V1.0.0
6   * @date    22-July-2011
7   * @brief   This file provides the IO requests APIs for control endpoints.
8   ******************************************************************************
9   * @attention
10   *
11   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17   *
18   * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
19   ******************************************************************************
20   */ 
21
22 /* Includes ------------------------------------------------------------------*/
23 #include "usbd_ioreq.h"
24 /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
25   * @{
26   */
27
28
29 /** @defgroup USBD_IOREQ 
30   * @brief control I/O requests module
31   * @{
32   */ 
33
34 /** @defgroup USBD_IOREQ_Private_TypesDefinitions
35   * @{
36   */ 
37 /**
38   * @}
39   */ 
40
41
42 /** @defgroup USBD_IOREQ_Private_Defines
43   * @{
44   */ 
45
46 /**
47   * @}
48   */ 
49
50
51 /** @defgroup USBD_IOREQ_Private_Macros
52   * @{
53   */ 
54 /**
55   * @}
56   */ 
57
58
59 /** @defgroup USBD_IOREQ_Private_Variables
60   * @{
61   */ 
62
63 /**
64   * @}
65   */ 
66
67
68 /** @defgroup USBD_IOREQ_Private_FunctionPrototypes
69   * @{
70   */ 
71 /**
72   * @}
73   */ 
74
75
76 /** @defgroup USBD_IOREQ_Private_Functions
77   * @{
78   */ 
79
80 /**
81 * @brief  USBD_CtlSendData
82 *         send data on the ctl pipe
83 * @param  pdev: device instance
84 * @param  buff: pointer to data buffer
85 * @param  len: length of data to be sent
86 * @retval status
87 */
88 USBD_Status  USBD_CtlSendData (USB_OTG_CORE_HANDLE  *pdev, 
89                                uint8_t *pbuf,
90                                uint16_t len)
91 {
92   USBD_Status ret = USBD_OK;
93   
94   pdev->dev.in_ep[0].total_data_len = len;
95   pdev->dev.in_ep[0].rem_data_len   = len;
96   pdev->dev.device_state = USB_OTG_EP0_DATA_IN;
97
98   DCD_EP_Tx (pdev, 0, pbuf, len);
99  
100   return ret;
101 }
102
103 /**
104 * @brief  USBD_CtlContinueSendData
105 *         continue sending data on the ctl pipe
106 * @param  pdev: device instance
107 * @param  buff: pointer to data buffer
108 * @param  len: length of data to be sent
109 * @retval status
110 */
111 USBD_Status  USBD_CtlContinueSendData (USB_OTG_CORE_HANDLE  *pdev, 
112                                        uint8_t *pbuf,
113                                        uint16_t len)
114 {
115   USBD_Status ret = USBD_OK;
116   
117   DCD_EP_Tx (pdev, 0, pbuf, len);
118   
119   
120   return ret;
121 }
122
123 /**
124 * @brief  USBD_CtlPrepareRx
125 *         receive data on the ctl pipe
126 * @param  pdev: USB OTG device instance
127 * @param  buff: pointer to data buffer
128 * @param  len: length of data to be received
129 * @retval status
130 */
131 USBD_Status  USBD_CtlPrepareRx (USB_OTG_CORE_HANDLE  *pdev,
132                                   uint8_t *pbuf,                                  
133                                   uint16_t len)
134 {
135   USBD_Status ret = USBD_OK;
136   
137   pdev->dev.out_ep[0].total_data_len = len;
138   pdev->dev.out_ep[0].rem_data_len   = len;
139   pdev->dev.device_state = USB_OTG_EP0_DATA_OUT;
140   
141   DCD_EP_PrepareRx (pdev,
142                     0,
143                     pbuf,
144                     len);
145   
146
147   return ret;
148 }
149
150 /**
151 * @brief  USBD_CtlContinueRx
152 *         continue receive data on the ctl pipe
153 * @param  pdev: USB OTG device instance
154 * @param  buff: pointer to data buffer
155 * @param  len: length of data to be received
156 * @retval status
157 */
158 USBD_Status  USBD_CtlContinueRx (USB_OTG_CORE_HANDLE  *pdev, 
159                                           uint8_t *pbuf,                                          
160                                           uint16_t len)
161 {
162   USBD_Status ret = USBD_OK;
163   
164   DCD_EP_PrepareRx (pdev,
165                     0,                     
166                     pbuf,                         
167                     len);
168   return ret;
169 }
170 /**
171 * @brief  USBD_CtlSendStatus
172 *         send zero lzngth packet on the ctl pipe
173 * @param  pdev: USB OTG device instance
174 * @retval status
175 */
176 USBD_Status  USBD_CtlSendStatus (USB_OTG_CORE_HANDLE  *pdev)
177 {
178   USBD_Status ret = USBD_OK;
179   pdev->dev.device_state = USB_OTG_EP0_STATUS_IN;
180   DCD_EP_Tx (pdev,
181              0,
182              NULL, 
183              0); 
184   
185   USB_OTG_EP0_OutStart(pdev);  
186   
187   return ret;
188 }
189
190 /**
191 * @brief  USBD_CtlReceiveStatus
192 *         receive zero lzngth packet on the ctl pipe
193 * @param  pdev: USB OTG device instance
194 * @retval status
195 */
196 USBD_Status  USBD_CtlReceiveStatus (USB_OTG_CORE_HANDLE  *pdev)
197 {
198   USBD_Status ret = USBD_OK;
199   pdev->dev.device_state = USB_OTG_EP0_STATUS_OUT;  
200   DCD_EP_PrepareRx ( pdev,
201                     0,
202                     NULL,
203                     0);  
204
205   USB_OTG_EP0_OutStart(pdev);
206   
207   return ret;
208 }
209
210
211 /**
212 * @brief  USBD_GetRxCount
213 *         returns the received data length
214 * @param  pdev: USB OTG device instance
215 *         epnum: endpoint index
216 * @retval Rx Data blength
217 */
218 uint16_t  USBD_GetRxCount (USB_OTG_CORE_HANDLE  *pdev , uint8_t epnum)
219 {
220   return pdev->dev.out_ep[epnum].xfer_count;
221 }
222
223 /**
224   * @}
225   */ 
226
227
228 /**
229   * @}
230   */ 
231
232
233 /**
234   * @}
235   */ 
236
237 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/