Subversion Repositories LedShow

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 9
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    usbd_req.c
3
  * @file    usbd_req.c
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @version V2.4.2
-
 
6
  * @date    11-December-2015
-
 
7
  * @brief   This file provides the standard USB requests following chapter 9.
5
  * @brief   This file provides the standard USB requests following chapter 9.
8
  ******************************************************************************
6
  ******************************************************************************
9
  * @attention
7
  * @attention
10
  *
8
  *
11
  * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
9
  * <h2><center>&copy; Copyright (c) 2015 STMicroelectronics.
-
 
10
  * All rights reserved.</center></h2>
12
  *
11
  *
13
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
12
  * This software component is licensed by ST under Ultimate Liberty license
14
  * You may not use this file except in compliance with the License.
13
  * SLA0044, the "License"; You may not use this file except in compliance with
15
  * You may obtain a copy of the License at:
14
  * the License. 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.
15
  *                      www.st.com/SLA0044
24
  *
16
  *
25
  ******************************************************************************
17
  ******************************************************************************
26
  */
18
  */
27
 
19
 
28
/* Includes ------------------------------------------------------------------*/
20
/* Includes ------------------------------------------------------------------*/
29
#include "usbd_ctlreq.h"
21
#include "usbd_ctlreq.h"
30
#include "usbd_ioreq.h"
22
#include "usbd_ioreq.h"
31
 
23
 
Line 33... Line 25...
33
/** @addtogroup STM32_USBD_STATE_DEVICE_LIBRARY
25
/** @addtogroup STM32_USBD_STATE_DEVICE_LIBRARY
34
  * @{
26
  * @{
35
  */
27
  */
36
 
28
 
37
 
29
 
38
/** @defgroup USBD_REQ
30
/** @defgroup USBD_REQ
39
  * @brief USB standard requests module
31
  * @brief USB standard requests module
40
  * @{
32
  * @{
41
  */
33
  */
42
 
34
 
43
/** @defgroup USBD_REQ_Private_TypesDefinitions
35
/** @defgroup USBD_REQ_Private_TypesDefinitions
44
  * @{
36
  * @{
45
  */
37
  */
-
 
38
 
46
/**
39
/**
47
  * @}
40
  * @}
48
  */
41
  */
49
 
42
 
50
 
43
 
51
/** @defgroup USBD_REQ_Private_Defines
44
/** @defgroup USBD_REQ_Private_Defines
52
  * @{
45
  * @{
53
  */
46
  */
54
 
47
 
55
/**
48
/**
56
  * @}
49
  * @}
57
  */
50
  */
58
 
51
 
59
 
52
 
60
/** @defgroup USBD_REQ_Private_Macros
53
/** @defgroup USBD_REQ_Private_Macros
61
  * @{
54
  * @{
62
  */
55
  */
-
 
56
 
63
/**
57
/**
64
  * @}
58
  * @}
65
  */
59
  */
66
 
60
 
67
 
61
 
68
/** @defgroup USBD_REQ_Private_Variables
62
/** @defgroup USBD_REQ_Private_Variables
69
  * @{
63
  * @{
70
  */
64
  */
-
 
65
 
71
/**
66
/**
72
  * @}
67
  * @}
73
  */
68
  */
74
 
69
 
75
 
70
 
76
/** @defgroup USBD_REQ_Private_FunctionPrototypes
71
/** @defgroup USBD_REQ_Private_FunctionPrototypes
77
  * @{
72
  * @{
78
  */
73
  */
79
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev ,
74
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev,
80
                               USBD_SetupReqTypedef *req);
75
                               USBD_SetupReqTypedef *req);
81
 
76
 
82
static void USBD_SetAddress(USBD_HandleTypeDef *pdev ,
77
static void USBD_SetAddress(USBD_HandleTypeDef *pdev,
83
                            USBD_SetupReqTypedef *req);
78
                            USBD_SetupReqTypedef *req);
84
 
79
 
85
static void USBD_SetConfig(USBD_HandleTypeDef *pdev ,
80
static void USBD_SetConfig(USBD_HandleTypeDef *pdev,
86
                           USBD_SetupReqTypedef *req);
81
                           USBD_SetupReqTypedef *req);
87
 
82
 
88
static void USBD_GetConfig(USBD_HandleTypeDef *pdev ,
83
static void USBD_GetConfig(USBD_HandleTypeDef *pdev,
89
                           USBD_SetupReqTypedef *req);
84
                           USBD_SetupReqTypedef *req);
90
 
85
 
91
static void USBD_GetStatus(USBD_HandleTypeDef *pdev ,
86
static void USBD_GetStatus(USBD_HandleTypeDef *pdev,
92
                           USBD_SetupReqTypedef *req);
87
                           USBD_SetupReqTypedef *req);
93
 
88
 
94
static void USBD_SetFeature(USBD_HandleTypeDef *pdev ,
89
static void USBD_SetFeature(USBD_HandleTypeDef *pdev,
95
                            USBD_SetupReqTypedef *req);
90
                            USBD_SetupReqTypedef *req);
96
 
91
 
97
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev ,
92
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev,
98
                            USBD_SetupReqTypedef *req);
93
                            USBD_SetupReqTypedef *req);
99
 
94
 
100
static uint8_t USBD_GetLen(uint8_t *buf);
95
static uint8_t USBD_GetLen(uint8_t *buf);
101
 
96
 
102
/**
97
/**
103
  * @}
98
  * @}
104
  */
99
  */
105
 
100
 
106
 
101
 
107
/** @defgroup USBD_REQ_Private_Functions
102
/** @defgroup USBD_REQ_Private_Functions
108
  * @{
103
  * @{
109
  */
104
  */
110
 
105
 
111
 
106
 
112
/**
107
/**
113
* @brief  USBD_StdDevReq
108
* @brief  USBD_StdDevReq
114
*         Handle standard usb device requests
109
*         Handle standard usb device requests
115
* @param  pdev: device instance
110
* @param  pdev: device instance
116
* @param  req: usb request
111
* @param  req: usb request
117
* @retval status
112
* @retval status
118
*/
113
*/
119
USBD_StatusTypeDef  USBD_StdDevReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef  *req)
114
USBD_StatusTypeDef  USBD_StdDevReq(USBD_HandleTypeDef *pdev,
-
 
115
                                   USBD_SetupReqTypedef *req)
120
{
116
{
121
  USBD_StatusTypeDef ret = USBD_OK;  
117
  USBD_StatusTypeDef ret = USBD_OK;
122
 
118
 
123
  switch (req->bRequest)
119
  switch (req->bmRequest & USB_REQ_TYPE_MASK)
124
  {
120
  {
-
 
121
    case USB_REQ_TYPE_CLASS:
125
  case USB_REQ_GET_DESCRIPTOR:
122
    case USB_REQ_TYPE_VENDOR:
-
 
123
      pdev->pClass->Setup(pdev, req);
-
 
124
      break;
-
 
125
 
-
 
126
    case USB_REQ_TYPE_STANDARD:
-
 
127
      switch (req->bRequest)
126
   
128
      {
-
 
129
        case USB_REQ_GET_DESCRIPTOR:
127
    USBD_GetDescriptor (pdev, req) ;
130
          USBD_GetDescriptor(pdev, req);
128
    break;
131
          break;
129
   
132
 
130
  case USB_REQ_SET_ADDRESS:                      
133
        case USB_REQ_SET_ADDRESS:
131
    USBD_SetAddress(pdev, req);
134
          USBD_SetAddress(pdev, req);
132
    break;
135
          break;
133
   
136
 
134
  case USB_REQ_SET_CONFIGURATION:                    
137
        case USB_REQ_SET_CONFIGURATION:
135
    USBD_SetConfig (pdev , req);
138
          USBD_SetConfig(pdev, req);
136
    break;
139
          break;
137
   
140
 
138
  case USB_REQ_GET_CONFIGURATION:                
141
        case USB_REQ_GET_CONFIGURATION:
139
    USBD_GetConfig (pdev , req);
142
          USBD_GetConfig(pdev, req);
140
    break;
143
          break;
141
   
144
 
142
  case USB_REQ_GET_STATUS:                                  
145
        case USB_REQ_GET_STATUS:
143
    USBD_GetStatus (pdev , req);
146
          USBD_GetStatus(pdev, req);
144
    break;
147
          break;
145
   
-
 
146
   
148
 
147
  case USB_REQ_SET_FEATURE:  
149
        case USB_REQ_SET_FEATURE:
148
    USBD_SetFeature (pdev , req);    
150
          USBD_SetFeature(pdev, req);
149
    break;
151
          break;
150
   
152
 
151
  case USB_REQ_CLEAR_FEATURE:                                  
153
        case USB_REQ_CLEAR_FEATURE:
152
    USBD_ClrFeature (pdev , req);
154
          USBD_ClrFeature(pdev, req);
-
 
155
          break;
-
 
156
 
-
 
157
        default:
-
 
158
          USBD_CtlError(pdev, req);
153
    break;
159
          break;
154
   
160
      }
-
 
161
      break;
-
 
162
 
155
  default:  
163
    default:
156
    USBD_CtlError(pdev , req);
164
      USBD_CtlError(pdev, req);
157
    break;
165
      break;
158
  }
166
  }
159
 
167
 
160
  return ret;
168
  return ret;
161
}
169
}
162
 
170
 
163
/**
171
/**
164
* @brief  USBD_StdItfReq
172
* @brief  USBD_StdItfReq
165
*         Handle standard usb interface requests
173
*         Handle standard usb interface requests
166
* @param  pdev: device instance
174
* @param  pdev: device instance
167
* @param  req: usb request
175
* @param  req: usb request
168
* @retval status
176
* @retval status
169
*/
177
*/
170
USBD_StatusTypeDef  USBD_StdItfReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef  *req)
178
USBD_StatusTypeDef  USBD_StdItfReq(USBD_HandleTypeDef *pdev,
-
 
179
                                   USBD_SetupReqTypedef  *req)
171
{
180
{
172
  USBD_StatusTypeDef ret = USBD_OK;
181
  USBD_StatusTypeDef ret = USBD_OK;
-
 
182
 
-
 
183
  switch (req->bmRequest & USB_REQ_TYPE_MASK)
173
 
184
  {
-
 
185
    case USB_REQ_TYPE_CLASS:
-
 
186
    case USB_REQ_TYPE_VENDOR:
-
 
187
    case USB_REQ_TYPE_STANDARD:
174
  switch (pdev->dev_state)
188
      switch (pdev->dev_state)
175
  {
189
      {
-
 
190
        case USBD_STATE_DEFAULT:
-
 
191
        case USBD_STATE_ADDRESSED:
176
  case USBD_STATE_CONFIGURED:
192
        case USBD_STATE_CONFIGURED:
177
   
193
 
178
    if (LOBYTE(req->wIndex) <= USBD_MAX_NUM_INTERFACES)
194
          if (LOBYTE(req->wIndex) <= USBD_MAX_NUM_INTERFACES)
179
    {
195
          {
180
      pdev->pClass->Setup (pdev, req);
196
            ret = (USBD_StatusTypeDef)pdev->pClass->Setup(pdev, req);
181
     
197
 
182
      if((req->wLength == 0)&& (ret == USBD_OK))
198
            if ((req->wLength == 0U) && (ret == USBD_OK))
183
      {
199
            {
184
         USBD_CtlSendStatus(pdev);
200
              USBD_CtlSendStatus(pdev);
185
      }
201
            }
186
    }
202
          }
-
 
203
          else
187
    else
204
          {
188
    {                                              
205
            USBD_CtlError(pdev, req);
-
 
206
          }
-
 
207
          break;
-
 
208
 
-
 
209
        default:
189
       USBD_CtlError(pdev , req);
210
          USBD_CtlError(pdev, req);
-
 
211
          break;
190
    }
212
      }
191
    break;
213
      break;
192
   
214
 
193
  default:
215
    default:
194
     USBD_CtlError(pdev , req);
216
      USBD_CtlError(pdev, req);
195
    break;
217
      break;
196
  }
218
  }
-
 
219
 
197
  return USBD_OK;
220
  return USBD_OK;
198
}
221
}
199
 
222
 
200
/**
223
/**
201
* @brief  USBD_StdEPReq
224
* @brief  USBD_StdEPReq
202
*         Handle standard usb endpoint requests
225
*         Handle standard usb endpoint requests
203
* @param  pdev: device instance
226
* @param  pdev: device instance
204
* @param  req: usb request
227
* @param  req: usb request
205
* @retval status
228
* @retval status
206
*/
229
*/
207
USBD_StatusTypeDef  USBD_StdEPReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef  *req)
230
USBD_StatusTypeDef  USBD_StdEPReq(USBD_HandleTypeDef *pdev,
-
 
231
                                  USBD_SetupReqTypedef  *req)
208
{
232
{
209
 
233
  USBD_EndpointTypeDef *pep;
210
  uint8_t   ep_addr;
234
  uint8_t   ep_addr;
211
  USBD_StatusTypeDef ret = USBD_OK;
235
  USBD_StatusTypeDef ret = USBD_OK;
212
  USBD_EndpointTypeDef   *pep;
-
 
213
  ep_addr  = LOBYTE(req->wIndex);  
236
  ep_addr  = LOBYTE(req->wIndex);
-
 
237
 
-
 
238
  switch (req->bmRequest & USB_REQ_TYPE_MASK)
214
 
239
  {
-
 
240
    case USB_REQ_TYPE_CLASS:
-
 
241
    case USB_REQ_TYPE_VENDOR:
-
 
242
      pdev->pClass->Setup(pdev, req);
-
 
243
      break;
-
 
244
 
-
 
245
    case USB_REQ_TYPE_STANDARD:
215
  /* Check if it is a class request */
246
      /* Check if it is a class request */
216
  if ((req->bmRequest & 0x60) == 0x20)
247
      if ((req->bmRequest & 0x60U) == 0x20U)
217
  {
248
      {
218
    pdev->pClass->Setup (pdev, req);
249
        ret = (USBD_StatusTypeDef)pdev->pClass->Setup(pdev, req);
219
   
250
 
220
    return USBD_OK;
251
        return ret;
221
  }
252
      }
222
 
253
 
223
  switch (req->bRequest)
254
      switch (req->bRequest)
224
  {
-
 
225
   
255
      {
226
  case USB_REQ_SET_FEATURE :
256
        case USB_REQ_SET_FEATURE:
227
   
-
 
228
    switch (pdev->dev_state)
257
          switch (pdev->dev_state)
229
    {
258
          {
230
    case USBD_STATE_ADDRESSED:          
259
            case USBD_STATE_ADDRESSED:
231
      if ((ep_addr != 0x00) && (ep_addr != 0x80))
260
              if ((ep_addr != 0x00U) && (ep_addr != 0x80U))
232
      {
261
              {
233
        USBD_LL_StallEP(pdev , ep_addr);
262
                USBD_LL_StallEP(pdev, ep_addr);
-
 
263
                USBD_LL_StallEP(pdev, 0x80U);
234
      }
264
              }
-
 
265
              else
235
      break;   
266
              {
-
 
267
                USBD_CtlError(pdev, req);
236
     
268
              }
-
 
269
              break;
-
 
270
 
237
    case USBD_STATE_CONFIGURED:  
271
            case USBD_STATE_CONFIGURED:
238
      if (req->wValue == USB_FEATURE_EP_HALT)
272
              if (req->wValue == USB_FEATURE_EP_HALT)
239
      {
273
              {
-
 
274
                if ((ep_addr != 0x00U) &&
240
        if ((ep_addr != 0x00) && (ep_addr != 0x80))
275
                    (ep_addr != 0x80U) && (req->wLength == 0x00U))
241
        {
276
                {
242
          USBD_LL_StallEP(pdev , ep_addr);
277
                  USBD_LL_StallEP(pdev, ep_addr);
-
 
278
                }
243
         
279
              }
-
 
280
              USBD_CtlSendStatus(pdev);
-
 
281
 
-
 
282
              break;
-
 
283
 
-
 
284
            default:
-
 
285
              USBD_CtlError(pdev, req);
-
 
286
              break;
244
        }
287
          }
-
 
288
          break;
-
 
289
 
-
 
290
        case USB_REQ_CLEAR_FEATURE:
-
 
291
 
-
 
292
          switch (pdev->dev_state)
245
      }
293
          {
-
 
294
            case USBD_STATE_ADDRESSED:
-
 
295
              if ((ep_addr != 0x00U) && (ep_addr != 0x80U))
-
 
296
              {
-
 
297
                USBD_LL_StallEP(pdev, ep_addr);
246
      pdev->pClass->Setup (pdev, req);  
298
                USBD_LL_StallEP(pdev, 0x80U);
-
 
299
              }
-
 
300
              else
-
 
301
              {
247
      USBD_CtlSendStatus(pdev);
302
                USBD_CtlError(pdev, req);
248
     
303
              }
249
      break;
304
              break;
-
 
305
 
-
 
306
            case USBD_STATE_CONFIGURED:
-
 
307
              if (req->wValue == USB_FEATURE_EP_HALT)
250
     
308
              {
-
 
309
                if ((ep_addr & 0x7FU) != 0x00U)
-
 
310
                {
-
 
311
                  USBD_LL_ClearStallEP(pdev, ep_addr);
251
    default:                        
312
                }
-
 
313
                USBD_CtlSendStatus(pdev);
-
 
314
              }
-
 
315
              break;
-
 
316
 
-
 
317
            default:
252
      USBD_CtlError(pdev , req);
318
              USBD_CtlError(pdev, req);
253
      break;    
319
              break;
254
    }
320
          }
255
    break;
321
          break;
256
   
322
 
257
  case USB_REQ_CLEAR_FEATURE :
323
        case USB_REQ_GET_STATUS:
258
   
-
 
259
    switch (pdev->dev_state)
324
          switch (pdev->dev_state)
260
    {
325
          {
261
    case USBD_STATE_ADDRESSED:          
326
            case USBD_STATE_ADDRESSED:
262
      if ((ep_addr != 0x00) && (ep_addr != 0x80))
327
              if ((ep_addr != 0x00U) && (ep_addr != 0x80U))
263
      {
328
              {
264
        USBD_LL_StallEP(pdev , ep_addr);
329
                USBD_CtlError(pdev, req);
-
 
330
                break;
265
      }
331
              }
-
 
332
              pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU] : \
-
 
333
                    &pdev->ep_out[ep_addr & 0x7FU];
-
 
334
 
-
 
335
              pep->status = 0x0000U;
-
 
336
 
-
 
337
              USBD_CtlSendData(pdev, (uint8_t *)(void *)&pep->status, 2U);
266
      break;   
338
              break;
267
     
339
 
268
    case USBD_STATE_CONFIGURED:  
340
            case USBD_STATE_CONFIGURED:
-
 
341
              if ((ep_addr & 0x80U) == 0x80U)
-
 
342
              {
-
 
343
                if (pdev->ep_in[ep_addr & 0xFU].is_used == 0U)
-
 
344
                {
269
      if (req->wValue == USB_FEATURE_EP_HALT)
345
                  USBD_CtlError(pdev, req);
-
 
346
                  break;
-
 
347
                }
-
 
348
              }
-
 
349
              else
270
      {
350
              {
-
 
351
                if (pdev->ep_out[ep_addr & 0xFU].is_used == 0U)
-
 
352
                {
-
 
353
                  USBD_CtlError(pdev, req);
-
 
354
                  break;
-
 
355
                }
-
 
356
              }
-
 
357
 
-
 
358
              pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU] : \
-
 
359
                    &pdev->ep_out[ep_addr & 0x7FU];
-
 
360
 
271
        if ((ep_addr & 0x7F) != 0x00)
361
              if ((ep_addr == 0x00U) || (ep_addr == 0x80U))
-
 
362
              {
-
 
363
                pep->status = 0x0000U;
272
        {        
364
              }
273
          USBD_LL_ClearStallEP(pdev , ep_addr);
365
              else if (USBD_LL_IsStallEP(pdev, ep_addr))
-
 
366
              {
-
 
367
                pep->status = 0x0001U;
-
 
368
              }
-
 
369
              else
-
 
370
              {
-
 
371
                pep->status = 0x0000U;
-
 
372
              }
-
 
373
 
-
 
374
              USBD_CtlSendData(pdev, (uint8_t *)(void *)&pep->status, 2U);
-
 
375
              break;
-
 
376
 
-
 
377
            default:
274
          pdev->pClass->Setup (pdev, req);
378
              USBD_CtlError(pdev, req);
-
 
379
              break;
275
        }
380
          }
-
 
381
          break;
-
 
382
 
-
 
383
        default:
276
        USBD_CtlSendStatus(pdev);
384
          USBD_CtlError(pdev, req);
-
 
385
          break;
277
      }
386
      }
278
      break;
387
      break;
279
     
-
 
280
    default:                        
-
 
281
      USBD_CtlError(pdev , req);
-
 
282
      break;    
-
 
283
    }
-
 
284
    break;
-
 
285
   
388
 
286
  case USB_REQ_GET_STATUS:                  
-
 
287
    switch (pdev->dev_state)
-
 
288
    {
-
 
289
    case USBD_STATE_ADDRESSED:          
-
 
290
      if ((ep_addr & 0x7F) != 0x00)
-
 
291
      {
-
 
292
        USBD_LL_StallEP(pdev , ep_addr);
-
 
293
      }
-
 
294
      break;   
-
 
295
     
-
 
296
    case USBD_STATE_CONFIGURED:
-
 
297
      pep = ((ep_addr & 0x80) == 0x80) ? &pdev->ep_in[ep_addr & 0x7F]:\
-
 
298
                                         &pdev->ep_out[ep_addr & 0x7F];
-
 
299
      if(USBD_LL_IsStallEP(pdev, ep_addr))
-
 
300
      {
-
 
301
        pep->status = 0x0001;    
-
 
302
      }
-
 
303
      else
389
    default:
304
      {
-
 
305
        pep->status = 0x0000;  
-
 
306
      }
-
 
307
     
-
 
308
      USBD_CtlSendData (pdev,
-
 
309
                        (uint8_t *)&pep->status,
-
 
310
                        2);
-
 
311
      break;
-
 
312
     
-
 
313
    default:                        
-
 
314
      USBD_CtlError(pdev , req);
390
      USBD_CtlError(pdev, req);
315
      break;
391
      break;
316
    }
-
 
317
    break;
-
 
318
   
-
 
319
  default:
-
 
320
    break;
-
 
321
  }
392
  }
-
 
393
 
322
  return ret;
394
  return ret;
323
}
395
}
-
 
396
 
-
 
397
 
324
/**
398
/**
325
* @brief  USBD_GetDescriptor
399
* @brief  USBD_GetDescriptor
326
*         Handle Get Descriptor requests
400
*         Handle Get Descriptor requests
327
* @param  pdev: device instance
401
* @param  pdev: device instance
328
* @param  req: usb request
402
* @param  req: usb request
329
* @retval status
403
* @retval status
330
*/
404
*/
331
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev ,
405
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev,
332
                               USBD_SetupReqTypedef *req)
406
                               USBD_SetupReqTypedef *req)
333
{
407
{
334
  uint16_t len;
408
  uint16_t len = 0U;
335
  uint8_t *pbuf;
409
  uint8_t *pbuf = NULL;
-
 
410
  uint8_t err = 0U;
336
 
411
 
337
   
-
 
338
  switch (req->wValue >> 8)
412
  switch (req->wValue >> 8)
339
  {
413
  {
340
#if (USBD_LPM_ENABLED == 1)
414
#if (USBD_LPM_ENABLED == 1U)
341
  case USB_DESC_TYPE_BOS:
415
    case USB_DESC_TYPE_BOS:
342
    pbuf = pdev->pDesc->GetBOSDescriptor(pdev->dev_speed, &len);
416
      if (pdev->pDesc->GetBOSDescriptor != NULL)
343
    break;
417
      {
344
#endif    
-
 
345
  case USB_DESC_TYPE_DEVICE:
-
 
346
    pbuf = pdev->pDesc->GetDeviceDescriptor(pdev->dev_speed, &len);
418
        pbuf = pdev->pDesc->GetBOSDescriptor(pdev->dev_speed, &len);
347
    break;
-
 
348
   
-
 
349
  case USB_DESC_TYPE_CONFIGURATION:    
-
 
350
    if(pdev->dev_speed == USBD_SPEED_HIGH )  
-
 
351
    {
-
 
352
      pbuf   = (uint8_t *)pdev->pClass->GetHSConfigDescriptor(&len);
-
 
353
      pbuf[1] = USB_DESC_TYPE_CONFIGURATION;
-
 
354
    }
419
      }
355
    else
420
      else
356
    {
421
      {
357
      pbuf   = (uint8_t *)pdev->pClass->GetFSConfigDescriptor(&len);
-
 
358
      pbuf[1] = USB_DESC_TYPE_CONFIGURATION;
422
        USBD_CtlError(pdev, req);
359
    }
-
 
360
    break;
423
        err++;
361
   
-
 
362
  case USB_DESC_TYPE_STRING:
-
 
363
    switch ((uint8_t)(req->wValue))
-
 
364
    {
424
      }
365
    case USBD_IDX_LANGID_STR:
-
 
366
     pbuf = pdev->pDesc->GetLangIDStrDescriptor(pdev->dev_speed, &len);        
-
 
367
      break;
425
      break;
368
     
-
 
369
    case USBD_IDX_MFC_STR:
-
 
370
      pbuf = pdev->pDesc->GetManufacturerStrDescriptor(pdev->dev_speed, &len);
-
 
371
      break;
-
 
372
     
426
#endif
373
    case USBD_IDX_PRODUCT_STR:
-
 
374
      pbuf = pdev->pDesc->GetProductStrDescriptor(pdev->dev_speed, &len);
-
 
375
      break;
-
 
376
     
-
 
377
    case USBD_IDX_SERIAL_STR:
-
 
378
      pbuf = pdev->pDesc->GetSerialStrDescriptor(pdev->dev_speed, &len);
-
 
379
      break;
-
 
380
     
-
 
381
    case USBD_IDX_CONFIG_STR:
-
 
382
      pbuf = pdev->pDesc->GetConfigurationStrDescriptor(pdev->dev_speed, &len);
-
 
383
      break;
-
 
384
     
-
 
385
    case USBD_IDX_INTERFACE_STR:
427
    case USB_DESC_TYPE_DEVICE:
386
      pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev->dev_speed, &len);
428
      pbuf = pdev->pDesc->GetDeviceDescriptor(pdev->dev_speed, &len);
387
      break;
429
      break;
-
 
430
 
-
 
431
    case USB_DESC_TYPE_CONFIGURATION:
-
 
432
      if (pdev->dev_speed == USBD_SPEED_HIGH)
388
     
433
      {
-
 
434
        pbuf = pdev->pClass->GetHSConfigDescriptor(&len);
-
 
435
        pbuf[1] = USB_DESC_TYPE_CONFIGURATION;
-
 
436
      }
389
    default:
437
      else
390
#if (USBD_SUPPORT_USER_STRING == 1)
438
      {
391
      pbuf = pdev->pClass->GetUsrStrDescriptor(pdev, (req->wValue) , &len);
439
        pbuf = pdev->pClass->GetFSConfigDescriptor(&len);
-
 
440
        pbuf[1] = USB_DESC_TYPE_CONFIGURATION;
-
 
441
      }
392
      break;
442
      break;
393
#else      
-
 
394
       USBD_CtlError(pdev , req);
-
 
395
      return;
-
 
396
#endif   
-
 
397
    }
-
 
398
    break;
-
 
399
  case USB_DESC_TYPE_DEVICE_QUALIFIER:                  
-
 
400
 
443
 
401
    if(pdev->dev_speed == USBD_SPEED_HIGH  )  
444
    case USB_DESC_TYPE_STRING:
-
 
445
      switch ((uint8_t)(req->wValue))
402
    {
446
      {
-
 
447
        case USBD_IDX_LANGID_STR:
-
 
448
          if (pdev->pDesc->GetLangIDStrDescriptor != NULL)
-
 
449
          {
-
 
450
            pbuf = pdev->pDesc->GetLangIDStrDescriptor(pdev->dev_speed, &len);
-
 
451
          }
-
 
452
          else
-
 
453
          {
-
 
454
            USBD_CtlError(pdev, req);
-
 
455
            err++;
-
 
456
          }
-
 
457
          break;
-
 
458
 
-
 
459
        case USBD_IDX_MFC_STR:
-
 
460
          if (pdev->pDesc->GetManufacturerStrDescriptor != NULL)
-
 
461
          {
-
 
462
            pbuf = pdev->pDesc->GetManufacturerStrDescriptor(pdev->dev_speed, &len);
-
 
463
          }
-
 
464
          else
-
 
465
          {
-
 
466
            USBD_CtlError(pdev, req);
-
 
467
            err++;
-
 
468
          }
-
 
469
          break;
-
 
470
 
-
 
471
        case USBD_IDX_PRODUCT_STR:
-
 
472
          if (pdev->pDesc->GetProductStrDescriptor != NULL)
-
 
473
          {
-
 
474
            pbuf = pdev->pDesc->GetProductStrDescriptor(pdev->dev_speed, &len);
-
 
475
          }
-
 
476
          else
-
 
477
          {
-
 
478
            USBD_CtlError(pdev, req);
-
 
479
            err++;
-
 
480
          }
-
 
481
          break;
-
 
482
 
-
 
483
        case USBD_IDX_SERIAL_STR:
403
      pbuf   = (uint8_t *)pdev->pClass->GetDeviceQualifierDescriptor(&len);
484
          if (pdev->pDesc->GetSerialStrDescriptor != NULL)
-
 
485
          {
-
 
486
            pbuf = pdev->pDesc->GetSerialStrDescriptor(pdev->dev_speed, &len);
-
 
487
          }
-
 
488
          else
-
 
489
          {
-
 
490
            USBD_CtlError(pdev, req);
-
 
491
            err++;
-
 
492
          }
-
 
493
          break;
-
 
494
 
-
 
495
        case USBD_IDX_CONFIG_STR:
-
 
496
          if (pdev->pDesc->GetConfigurationStrDescriptor != NULL)
-
 
497
          {
-
 
498
            pbuf = pdev->pDesc->GetConfigurationStrDescriptor(pdev->dev_speed, &len);
-
 
499
          }
-
 
500
          else
-
 
501
          {
-
 
502
            USBD_CtlError(pdev, req);
-
 
503
            err++;
-
 
504
          }
-
 
505
          break;
-
 
506
 
-
 
507
        case USBD_IDX_INTERFACE_STR:
-
 
508
          if (pdev->pDesc->GetInterfaceStrDescriptor != NULL)
-
 
509
          {
-
 
510
            pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev->dev_speed, &len);
-
 
511
          }
-
 
512
          else
-
 
513
          {
-
 
514
            USBD_CtlError(pdev, req);
-
 
515
            err++;
-
 
516
          }
-
 
517
          break;
-
 
518
 
-
 
519
        default:
-
 
520
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
-
 
521
          if (pdev->pClass->GetUsrStrDescriptor != NULL)
-
 
522
          {
-
 
523
            pbuf = pdev->pClass->GetUsrStrDescriptor(pdev, (req->wValue), &len);
-
 
524
          }
-
 
525
          else
-
 
526
          {
-
 
527
            USBD_CtlError(pdev, req);
-
 
528
            err++;
-
 
529
          }
-
 
530
          break;
-
 
531
#else
-
 
532
          USBD_CtlError(pdev, req);
-
 
533
          err++;
-
 
534
#endif
-
 
535
      }
404
      break;
536
      break;
405
    }
-
 
406
    else
-
 
407
    {
-
 
408
      USBD_CtlError(pdev , req);
-
 
409
      return;
-
 
410
    }
-
 
411
 
537
 
-
 
538
    case USB_DESC_TYPE_DEVICE_QUALIFIER:
-
 
539
      if (pdev->dev_speed == USBD_SPEED_HIGH)
-
 
540
      {
-
 
541
        pbuf = pdev->pClass->GetDeviceQualifierDescriptor(&len);
-
 
542
      }
-
 
543
      else
-
 
544
      {
-
 
545
        USBD_CtlError(pdev, req);
-
 
546
        err++;
-
 
547
      }
-
 
548
      break;
-
 
549
 
412
  case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION:
550
    case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION:
413
    if(pdev->dev_speed == USBD_SPEED_HIGH  )  
551
      if (pdev->dev_speed == USBD_SPEED_HIGH)
414
    {
552
      {
415
      pbuf   = (uint8_t *)pdev->pClass->GetOtherSpeedConfigDescriptor(&len);
553
        pbuf = pdev->pClass->GetOtherSpeedConfigDescriptor(&len);
416
      pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION;
554
        pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION;
-
 
555
      }
417
      break;
556
      else
418
    }
557
      {
-
 
558
        USBD_CtlError(pdev, req);
419
    else
559
        err++;
420
    {
560
      }
-
 
561
      break;
-
 
562
 
-
 
563
    default:
421
      USBD_CtlError(pdev , req);
564
      USBD_CtlError(pdev, req);
-
 
565
      err++;
422
      return;
566
      break;
423
    }
567
  }
424
 
568
 
425
  default:
569
  if (err != 0U)
426
     USBD_CtlError(pdev , req);
570
  {
427
    return;
571
    return;
428
  }
572
  }
429
 
573
  else
430
  if((len != 0)&& (req->wLength != 0))
-
 
431
  {
574
  {
-
 
575
    if ((len != 0U) && (req->wLength != 0U))
432
   
576
    {
433
    len = MIN(len , req->wLength);
577
      len = MIN(len, req->wLength);
-
 
578
      (void)USBD_CtlSendData(pdev, pbuf, len);
434
   
579
    }
-
 
580
 
435
    USBD_CtlSendData (pdev,
581
    if (req->wLength == 0U)
436
                      pbuf,
582
    {
437
                      len);
583
      (void)USBD_CtlSendStatus(pdev);
-
 
584
    }
438
  }
585
  }
439
 
-
 
440
}
586
}
441
 
587
 
442
/**
588
/**
443
* @brief  USBD_SetAddress
589
* @brief  USBD_SetAddress
444
*         Set device address
590
*         Set device address
445
* @param  pdev: device instance
591
* @param  pdev: device instance
446
* @param  req: usb request
592
* @param  req: usb request
447
* @retval status
593
* @retval status
448
*/
594
*/
449
static void USBD_SetAddress(USBD_HandleTypeDef *pdev ,
595
static void USBD_SetAddress(USBD_HandleTypeDef *pdev,
450
                            USBD_SetupReqTypedef *req)
596
                            USBD_SetupReqTypedef *req)
451
{
597
{
452
  uint8_t  dev_addr;
598
  uint8_t  dev_addr;
453
 
599
 
454
  if ((req->wIndex == 0) && (req->wLength == 0))
600
  if ((req->wIndex == 0U) && (req->wLength == 0U) && (req->wValue < 128U))
455
  {
601
  {
456
    dev_addr = (uint8_t)(req->wValue) & 0x7F;    
602
    dev_addr = (uint8_t)(req->wValue) & 0x7FU;
457
   
603
 
458
    if (pdev->dev_state == USBD_STATE_CONFIGURED)
604
    if (pdev->dev_state == USBD_STATE_CONFIGURED)
459
    {
605
    {
460
      USBD_CtlError(pdev , req);
606
      USBD_CtlError(pdev, req);
461
    }
607
    }
462
    else
608
    else
463
    {
609
    {
464
      pdev->dev_address = dev_addr;
610
      pdev->dev_address = dev_addr;
465
      USBD_LL_SetUSBAddress(pdev, dev_addr);              
611
      USBD_LL_SetUSBAddress(pdev, dev_addr);
466
      USBD_CtlSendStatus(pdev);                        
612
      USBD_CtlSendStatus(pdev);
467
     
613
 
468
      if (dev_addr != 0)
614
      if (dev_addr != 0U)
469
      {
-
 
470
        pdev->dev_state  = USBD_STATE_ADDRESSED;
-
 
471
      }
-
 
472
      else
-
 
473
      {
615
      {
-
 
616
        pdev->dev_state = USBD_STATE_ADDRESSED;
-
 
617
      }
-
 
618
      else
-
 
619
      {
474
        pdev->dev_state  = USBD_STATE_DEFAULT;
620
        pdev->dev_state = USBD_STATE_DEFAULT;
475
      }
621
      }
476
    }
622
    }
477
  }
623
  }
478
  else
624
  else
479
  {
625
  {
480
     USBD_CtlError(pdev , req);                        
626
    USBD_CtlError(pdev, req);
481
  }
627
  }
482
}
628
}
483
 
629
 
484
/**
630
/**
485
* @brief  USBD_SetConfig
631
* @brief  USBD_SetConfig
486
*         Handle Set device configuration request
632
*         Handle Set device configuration request
487
* @param  pdev: device instance
633
* @param  pdev: device instance
488
* @param  req: usb request
634
* @param  req: usb request
489
* @retval status
635
* @retval status
490
*/
636
*/
491
static void USBD_SetConfig(USBD_HandleTypeDef *pdev ,
637
static void USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
492
                           USBD_SetupReqTypedef *req)
-
 
493
{
638
{
494
 
-
 
495
  static uint8_t  cfgidx;
639
  static uint8_t cfgidx;
496
 
640
 
497
  cfgidx = (uint8_t)(req->wValue);                
641
  cfgidx = (uint8_t)(req->wValue);
498
 
642
 
499
  if (cfgidx > USBD_MAX_NUM_CONFIGURATION )
643
  if (cfgidx > USBD_MAX_NUM_CONFIGURATION)
500
  {            
-
 
501
     USBD_CtlError(pdev , req);                              
-
 
502
  }
-
 
503
  else
-
 
504
  {
644
  {
-
 
645
    USBD_CtlError(pdev, req);
-
 
646
  }
-
 
647
  else
-
 
648
  {
505
    switch (pdev->dev_state)
649
    switch (pdev->dev_state)
506
    {
650
    {
507
    case USBD_STATE_ADDRESSED:
651
      case USBD_STATE_ADDRESSED:
508
      if (cfgidx)
652
        if (cfgidx)
509
      {                                                                                                                                                                                                
-
 
510
        pdev->dev_config = cfgidx;
-
 
511
        pdev->dev_state = USBD_STATE_CONFIGURED;
-
 
512
        if(USBD_SetClassConfig(pdev , cfgidx) == USBD_FAIL)
-
 
513
        {
653
        {
-
 
654
          pdev->dev_config = cfgidx;
-
 
655
          pdev->dev_state = USBD_STATE_CONFIGURED;
-
 
656
          if (USBD_SetClassConfig(pdev, cfgidx) == USBD_FAIL)
-
 
657
          {
514
          USBD_CtlError(pdev , req);  
658
            USBD_CtlError(pdev, req);
515
          return;
659
            return;
-
 
660
          }
-
 
661
          USBD_CtlSendStatus(pdev);
516
        }
662
        }
517
        USBD_CtlSendStatus(pdev);
-
 
518
      }
-
 
519
      else
663
        else
520
      {
-
 
521
         USBD_CtlSendStatus(pdev);
-
 
522
      }
-
 
523
      break;
-
 
524
     
-
 
525
    case USBD_STATE_CONFIGURED:
-
 
526
      if (cfgidx == 0)
-
 
527
      {                          
-
 
528
        pdev->dev_state = USBD_STATE_ADDRESSED;
-
 
529
        pdev->dev_config = cfgidx;          
-
 
530
        USBD_ClrClassConfig(pdev , cfgidx);
-
 
531
        USBD_CtlSendStatus(pdev);
-
 
532
       
-
 
533
      }
-
 
534
      else  if (cfgidx != pdev->dev_config)
-
 
535
      {
-
 
536
        /* Clear old configuration */
-
 
537
        USBD_ClrClassConfig(pdev , pdev->dev_config);
-
 
538
       
-
 
539
        /* set new configuration */
-
 
540
        pdev->dev_config = cfgidx;
-
 
541
        if(USBD_SetClassConfig(pdev , cfgidx) == USBD_FAIL)
-
 
542
        {
664
        {
543
          USBD_CtlError(pdev , req);  
665
          USBD_CtlSendStatus(pdev);
544
          return;
-
 
545
        }
666
        }
-
 
667
        break;
-
 
668
 
-
 
669
      case USBD_STATE_CONFIGURED:
-
 
670
        if (cfgidx == 0U)
-
 
671
        {
-
 
672
          pdev->dev_state = USBD_STATE_ADDRESSED;
-
 
673
          pdev->dev_config = cfgidx;
-
 
674
          USBD_ClrClassConfig(pdev, cfgidx);
546
        USBD_CtlSendStatus(pdev);
675
          USBD_CtlSendStatus(pdev);
547
      }
676
        }
-
 
677
        else if (cfgidx != pdev->dev_config)
548
      else
678
        {
-
 
679
          /* Clear old configuration */
-
 
680
          USBD_ClrClassConfig(pdev, (uint8_t)pdev->dev_config);
-
 
681
 
-
 
682
          /* set new configuration */
-
 
683
          pdev->dev_config = cfgidx;
-
 
684
          if (USBD_SetClassConfig(pdev, cfgidx) == USBD_FAIL)
549
      {
685
          {
-
 
686
            USBD_CtlError(pdev, req);
-
 
687
            return;
-
 
688
          }
550
        USBD_CtlSendStatus(pdev);
689
          USBD_CtlSendStatus(pdev);
551
      }
690
        }
552
      break;
691
        else
-
 
692
        {
-
 
693
          USBD_CtlSendStatus(pdev);
553
     
694
        }
-
 
695
        break;
-
 
696
 
554
    default:                                   
697
      default:
555
       USBD_CtlError(pdev , req);                    
698
        USBD_CtlError(pdev, req);
-
 
699
        USBD_ClrClassConfig(pdev, cfgidx);
556
      break;
700
        break;
557
    }
701
    }
558
  }
702
  }
559
}
703
}
560
 
704
 
561
/**
705
/**
Line 563... Line 707...
563
*         Handle Get device configuration request
707
*         Handle Get device configuration request
564
* @param  pdev: device instance
708
* @param  pdev: device instance
565
* @param  req: usb request
709
* @param  req: usb request
566
* @retval status
710
* @retval status
567
*/
711
*/
568
static void USBD_GetConfig(USBD_HandleTypeDef *pdev ,
712
static void USBD_GetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
569
                           USBD_SetupReqTypedef *req)
-
 
570
{
713
{
571
 
-
 
572
  if (req->wLength != 1)
714
  if (req->wLength != 1U)
573
  {                  
715
  {
574
     USBD_CtlError(pdev , req);
716
    USBD_CtlError(pdev, req);
575
  }
717
  }
576
  else
718
  else
577
  {
719
  {
578
    switch (pdev->dev_state )  
720
    switch (pdev->dev_state)
579
    {
721
    {
-
 
722
      case USBD_STATE_DEFAULT:
580
    case USBD_STATE_ADDRESSED:                    
723
      case USBD_STATE_ADDRESSED:
581
      pdev->dev_default_config = 0;
724
        pdev->dev_default_config = 0U;
582
      USBD_CtlSendData (pdev,
-
 
583
                        (uint8_t *)&pdev->dev_default_config,
725
        USBD_CtlSendData(pdev, (uint8_t *)(void *)&pdev->dev_default_config, 1U);
584
                        1);
-
 
585
      break;
726
        break;
586
     
727
 
587
    case USBD_STATE_CONFIGURED:  
728
      case USBD_STATE_CONFIGURED:
588
     
-
 
589
      USBD_CtlSendData (pdev,
-
 
590
                        (uint8_t *)&pdev->dev_config,
729
        USBD_CtlSendData(pdev, (uint8_t *)(void *)&pdev->dev_config, 1U);
591
                        1);
-
 
592
      break;
730
        break;
593
     
731
 
594
    default:
732
      default:
595
       USBD_CtlError(pdev , req);
733
        USBD_CtlError(pdev, req);
596
      break;
734
        break;
597
    }
735
    }
598
  }
736
  }
599
}
737
}
600
 
738
 
601
/**
739
/**
Line 603... Line 741...
603
*         Handle Get Status request
741
*         Handle Get Status request
604
* @param  pdev: device instance
742
* @param  pdev: device instance
605
* @param  req: usb request
743
* @param  req: usb request
606
* @retval status
744
* @retval status
607
*/
745
*/
608
static void USBD_GetStatus(USBD_HandleTypeDef *pdev ,
746
static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
609
                           USBD_SetupReqTypedef *req)
-
 
610
{
747
{
611
 
-
 
612
   
-
 
613
  switch (pdev->dev_state)
748
  switch (pdev->dev_state)
614
  {
749
  {
-
 
750
    case USBD_STATE_DEFAULT:
615
  case USBD_STATE_ADDRESSED:
751
    case USBD_STATE_ADDRESSED:
616
  case USBD_STATE_CONFIGURED:
752
    case USBD_STATE_CONFIGURED:
-
 
753
      if (req->wLength != 0x2U)
-
 
754
      {
-
 
755
        USBD_CtlError(pdev, req);
-
 
756
        break;
617
   
757
      }
-
 
758
 
618
#if ( USBD_SELF_POWERED == 1)
759
#if (USBD_SELF_POWERED == 1U)
619
    pdev->dev_config_status = USB_CONFIG_SELF_POWERED;                                  
760
      pdev->dev_config_status = USB_CONFIG_SELF_POWERED;
620
#else
761
#else
621
    pdev->dev_config_status = 0;                                  
762
      pdev->dev_config_status = 0U;
622
#endif
763
#endif
623
                     
-
 
-
 
764
 
624
    if (pdev->dev_remote_wakeup)
765
      if (pdev->dev_remote_wakeup)
625
    {
766
      {
626
       pdev->dev_config_status |= USB_CONFIG_REMOTE_WAKEUP;                                
767
        pdev->dev_config_status |= USB_CONFIG_REMOTE_WAKEUP;
627
    }
768
      }
628
   
769
 
629
    USBD_CtlSendData (pdev,
-
 
630
                      (uint8_t *)& pdev->dev_config_status,
770
      USBD_CtlSendData(pdev, (uint8_t *)(void *)&pdev->dev_config_status, 2U);
631
                      2);
-
 
632
    break;
771
      break;
633
   
772
 
634
  default :
773
    default:
635
    USBD_CtlError(pdev , req);                        
774
      USBD_CtlError(pdev, req);
636
    break;
775
      break;
637
  }
776
  }
638
}
777
}
639
 
778
 
640
 
779
 
641
/**
780
/**
Line 643... Line 782...
643
*         Handle Set device feature request
782
*         Handle Set device feature request
644
* @param  pdev: device instance
783
* @param  pdev: device instance
645
* @param  req: usb request
784
* @param  req: usb request
646
* @retval status
785
* @retval status
647
*/
786
*/
648
static void USBD_SetFeature(USBD_HandleTypeDef *pdev ,
787
static void USBD_SetFeature(USBD_HandleTypeDef *pdev,
649
                            USBD_SetupReqTypedef *req)
788
                            USBD_SetupReqTypedef *req)
650
{
789
{
651
 
-
 
652
  if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
790
  if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
653
  {
791
  {
654
    pdev->dev_remote_wakeup = 1;  
792
    pdev->dev_remote_wakeup = 1U;
655
    pdev->pClass->Setup (pdev, req);  
-
 
656
    USBD_CtlSendStatus(pdev);
793
    USBD_CtlSendStatus(pdev);
657
  }
794
  }
658
 
-
 
659
}
795
}
660
 
796
 
661
 
797
 
662
/**
798
/**
663
* @brief  USBD_ClrFeature
799
* @brief  USBD_ClrFeature
664
*         Handle clear device feature request
800
*         Handle clear device feature request
665
* @param  pdev: device instance
801
* @param  pdev: device instance
666
* @param  req: usb request
802
* @param  req: usb request
667
* @retval status
803
* @retval status
668
*/
804
*/
669
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev ,
805
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev,
670
                            USBD_SetupReqTypedef *req)
806
                            USBD_SetupReqTypedef *req)
671
{
807
{
672
  switch (pdev->dev_state)
808
  switch (pdev->dev_state)
673
  {
809
  {
-
 
810
    case USBD_STATE_DEFAULT:
674
  case USBD_STATE_ADDRESSED:
811
    case USBD_STATE_ADDRESSED:
675
  case USBD_STATE_CONFIGURED:
812
    case USBD_STATE_CONFIGURED:
676
    if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
813
      if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
677
    {
814
      {
678
      pdev->dev_remote_wakeup = 0;
815
        pdev->dev_remote_wakeup = 0U;
679
      pdev->pClass->Setup (pdev, req);  
-
 
680
      USBD_CtlSendStatus(pdev);
816
        USBD_CtlSendStatus(pdev);
681
    }
817
      }
682
    break;
818
      break;
683
   
819
 
684
  default :
820
    default:
685
     USBD_CtlError(pdev , req);
821
      USBD_CtlError(pdev, req);
686
    break;
822
      break;
687
  }
823
  }
688
}
824
}
689
 
825
 
690
/**
826
/**
691
* @brief  USBD_ParseSetupRequest
827
* @brief  USBD_ParseSetupRequest
692
*         Copy buffer into setup structure
828
*         Copy buffer into setup structure
693
* @param  pdev: device instance
829
* @param  pdev: device instance
694
* @param  req: usb request
830
* @param  req: usb request
695
* @retval None
831
* @retval None
696
*/
832
*/
697
 
833
 
698
void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata)
834
void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata)
699
{
835
{
700
  req->bmRequest     = *(uint8_t *)  (pdata);
836
  req->bmRequest = *(uint8_t *)(pdata);
701
  req->bRequest      = *(uint8_t *)  (pdata +  1);
837
  req->bRequest = *(uint8_t *)(pdata + 1U);
702
  req->wValue        = SWAPBYTE      (pdata +  2);
838
  req->wValue = SWAPBYTE(pdata + 2U);
703
  req->wIndex        = SWAPBYTE      (pdata +  4);
839
  req->wIndex = SWAPBYTE(pdata + 4U);
704
  req->wLength       = SWAPBYTE      (pdata +  6);
840
  req->wLength = SWAPBYTE(pdata + 6U);
705
 
841
 
706
}
842
}
707
 
843
 
708
/**
844
/**
709
* @brief  USBD_CtlError
845
* @brief  USBD_CtlError
710
*         Handle USB low level Error
846
*         Handle USB low level Error
711
* @param  pdev: device instance
847
* @param  pdev: device instance
712
* @param  req: usb request
848
* @param  req: usb request
713
* @retval None
849
* @retval None
714
*/
850
*/
715
 
851
 
716
void USBD_CtlError( USBD_HandleTypeDef *pdev ,
852
void USBD_CtlError(USBD_HandleTypeDef *pdev,
717
                            USBD_SetupReqTypedef *req)
853
                   USBD_SetupReqTypedef *req)
718
{
854
{
719
  USBD_LL_StallEP(pdev , 0x80);
855
  USBD_LL_StallEP(pdev, 0x80U);
720
  USBD_LL_StallEP(pdev , 0);
856
  USBD_LL_StallEP(pdev, 0U);
721
}
857
}
722
 
858
 
723
 
859
 
724
/**
860
/**
725
  * @brief  USBD_GetString
861
  * @brief  USBD_GetString
Line 729... Line 865...
729
  * @param  len : descriptor length
865
  * @param  len : descriptor length
730
  * @retval None
866
  * @retval None
731
  */
867
  */
732
void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len)
868
void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len)
733
{
869
{
734
  uint8_t idx = 0;
870
  uint8_t idx = 0U;
735
 
871
 
736
  if (desc != NULL)
872
  if (desc != NULL)
737
  {
873
  {
738
    *len =  USBD_GetLen(desc) * 2 + 2;    
874
    *len = (uint16_t)USBD_GetLen(desc) * 2U + 2U;
739
    unicode[idx++] = *len;
875
    unicode[idx++] = *(uint8_t *)(void *)len;
740
    unicode[idx++] =  USB_DESC_TYPE_STRING;
876
    unicode[idx++] = USB_DESC_TYPE_STRING;
741
   
877
 
742
    while (*desc != '\0')
878
    while (*desc != '\0')
743
    {
879
    {
744
      unicode[idx++] = *desc++;
880
      unicode[idx++] = *desc++;
745
      unicode[idx++] =  0x00;
881
      unicode[idx++] =  0U;
746
    }
882
    }
747
  }
883
  }
748
}
884
}
749
 
885
 
750
/**
886
/**
751
  * @brief  USBD_GetLen
887
  * @brief  USBD_GetLen
752
  *         return the string length
888
  *         return the string length
753
   * @param  buf : pointer to the ascii string buffer
889
   * @param  buf : pointer to the ascii string buffer
754
  * @retval string length
890
  * @retval string length
755
  */
891
  */
756
static uint8_t USBD_GetLen(uint8_t *buf)
892
static uint8_t USBD_GetLen(uint8_t *buf)
757
{
893
{
758
    uint8_t  len = 0;
894
  uint8_t  len = 0U;
759
 
895
 
760
    while (*buf != '\0')
896
  while (*buf != '\0')
761
    {
897
  {
762
        len++;
898
    len++;
763
        buf++;
899
    buf++;
764
    }
900
  }
765
 
901
 
766
    return len;
902
  return len;
767
}
903
}
768
/**
904
/**
769
  * @}
905
  * @}
770
  */
906
  */
771
 
907
 
772
 
908
 
773
/**
909
/**
774
  * @}
910
  * @}
775
  */
911
  */
776
 
912
 
777
 
913
 
778
/**
914
/**
779
  * @}
915
  * @}
780
  */
916
  */
781
 
917
 
782
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
918
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/