IOTON boards API using mbed SDK - http://ioton.cc/plataforma-ton
Dependents: ton-bot_teste ton-bot_seguidor_linha ton-bot_seguidor_parede
Fork of IOTON-API by
usbd_ctlreq.c@1:3a73d77c2cef, 2017-06-29 (annotated)
- Committer:
- krebyy
- Date:
- Thu Jun 29 20:11:00 2017 +0000
- Revision:
- 1:3a73d77c2cef
Update to TON Board V1.2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
krebyy | 1:3a73d77c2cef | 1 | /** |
krebyy | 1:3a73d77c2cef | 2 | ****************************************************************************** |
krebyy | 1:3a73d77c2cef | 3 | * @file usbd_req.c |
krebyy | 1:3a73d77c2cef | 4 | * @author MCD Application Team |
krebyy | 1:3a73d77c2cef | 5 | * @version V2.3.0 |
krebyy | 1:3a73d77c2cef | 6 | * @date 04-November-2014 |
krebyy | 1:3a73d77c2cef | 7 | * @brief This file provides the standard USB requests following chapter 9. |
krebyy | 1:3a73d77c2cef | 8 | ****************************************************************************** |
krebyy | 1:3a73d77c2cef | 9 | * @attention |
krebyy | 1:3a73d77c2cef | 10 | * |
krebyy | 1:3a73d77c2cef | 11 | * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> |
krebyy | 1:3a73d77c2cef | 12 | * |
krebyy | 1:3a73d77c2cef | 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
krebyy | 1:3a73d77c2cef | 14 | * You may not use this file except in compliance with the License. |
krebyy | 1:3a73d77c2cef | 15 | * You may obtain a copy of the License at: |
krebyy | 1:3a73d77c2cef | 16 | * |
krebyy | 1:3a73d77c2cef | 17 | * http://www.st.com/software_license_agreement_liberty_v2 |
krebyy | 1:3a73d77c2cef | 18 | * |
krebyy | 1:3a73d77c2cef | 19 | * Unless required by applicable law or agreed to in writing, software |
krebyy | 1:3a73d77c2cef | 20 | * distributed under the License is distributed on an "AS IS" BASIS, |
krebyy | 1:3a73d77c2cef | 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
krebyy | 1:3a73d77c2cef | 22 | * See the License for the specific language governing permissions and |
krebyy | 1:3a73d77c2cef | 23 | * limitations under the License. |
krebyy | 1:3a73d77c2cef | 24 | * |
krebyy | 1:3a73d77c2cef | 25 | ****************************************************************************** |
krebyy | 1:3a73d77c2cef | 26 | */ |
krebyy | 1:3a73d77c2cef | 27 | |
krebyy | 1:3a73d77c2cef | 28 | /* Includes ------------------------------------------------------------------*/ |
krebyy | 1:3a73d77c2cef | 29 | #include "usbd_ctlreq.h" |
krebyy | 1:3a73d77c2cef | 30 | #include "usbd_ioreq.h" |
krebyy | 1:3a73d77c2cef | 31 | |
krebyy | 1:3a73d77c2cef | 32 | |
krebyy | 1:3a73d77c2cef | 33 | /** @addtogroup STM32_USBD_STATE_DEVICE_LIBRARY |
krebyy | 1:3a73d77c2cef | 34 | * @{ |
krebyy | 1:3a73d77c2cef | 35 | */ |
krebyy | 1:3a73d77c2cef | 36 | |
krebyy | 1:3a73d77c2cef | 37 | |
krebyy | 1:3a73d77c2cef | 38 | /** @defgroup USBD_REQ |
krebyy | 1:3a73d77c2cef | 39 | * @brief USB standard requests module |
krebyy | 1:3a73d77c2cef | 40 | * @{ |
krebyy | 1:3a73d77c2cef | 41 | */ |
krebyy | 1:3a73d77c2cef | 42 | |
krebyy | 1:3a73d77c2cef | 43 | /** @defgroup USBD_REQ_Private_TypesDefinitions |
krebyy | 1:3a73d77c2cef | 44 | * @{ |
krebyy | 1:3a73d77c2cef | 45 | */ |
krebyy | 1:3a73d77c2cef | 46 | /** |
krebyy | 1:3a73d77c2cef | 47 | * @} |
krebyy | 1:3a73d77c2cef | 48 | */ |
krebyy | 1:3a73d77c2cef | 49 | |
krebyy | 1:3a73d77c2cef | 50 | |
krebyy | 1:3a73d77c2cef | 51 | /** @defgroup USBD_REQ_Private_Defines |
krebyy | 1:3a73d77c2cef | 52 | * @{ |
krebyy | 1:3a73d77c2cef | 53 | */ |
krebyy | 1:3a73d77c2cef | 54 | |
krebyy | 1:3a73d77c2cef | 55 | /** |
krebyy | 1:3a73d77c2cef | 56 | * @} |
krebyy | 1:3a73d77c2cef | 57 | */ |
krebyy | 1:3a73d77c2cef | 58 | |
krebyy | 1:3a73d77c2cef | 59 | |
krebyy | 1:3a73d77c2cef | 60 | /** @defgroup USBD_REQ_Private_Macros |
krebyy | 1:3a73d77c2cef | 61 | * @{ |
krebyy | 1:3a73d77c2cef | 62 | */ |
krebyy | 1:3a73d77c2cef | 63 | /** |
krebyy | 1:3a73d77c2cef | 64 | * @} |
krebyy | 1:3a73d77c2cef | 65 | */ |
krebyy | 1:3a73d77c2cef | 66 | |
krebyy | 1:3a73d77c2cef | 67 | |
krebyy | 1:3a73d77c2cef | 68 | /** @defgroup USBD_REQ_Private_Variables |
krebyy | 1:3a73d77c2cef | 69 | * @{ |
krebyy | 1:3a73d77c2cef | 70 | */ |
krebyy | 1:3a73d77c2cef | 71 | /** |
krebyy | 1:3a73d77c2cef | 72 | * @} |
krebyy | 1:3a73d77c2cef | 73 | */ |
krebyy | 1:3a73d77c2cef | 74 | |
krebyy | 1:3a73d77c2cef | 75 | |
krebyy | 1:3a73d77c2cef | 76 | /** @defgroup USBD_REQ_Private_FunctionPrototypes |
krebyy | 1:3a73d77c2cef | 77 | * @{ |
krebyy | 1:3a73d77c2cef | 78 | */ |
krebyy | 1:3a73d77c2cef | 79 | static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev , |
krebyy | 1:3a73d77c2cef | 80 | USBD_SetupReqTypedef *req); |
krebyy | 1:3a73d77c2cef | 81 | |
krebyy | 1:3a73d77c2cef | 82 | static void USBD_SetAddress(USBD_HandleTypeDef *pdev , |
krebyy | 1:3a73d77c2cef | 83 | USBD_SetupReqTypedef *req); |
krebyy | 1:3a73d77c2cef | 84 | |
krebyy | 1:3a73d77c2cef | 85 | static void USBD_SetConfig(USBD_HandleTypeDef *pdev , |
krebyy | 1:3a73d77c2cef | 86 | USBD_SetupReqTypedef *req); |
krebyy | 1:3a73d77c2cef | 87 | |
krebyy | 1:3a73d77c2cef | 88 | static void USBD_GetConfig(USBD_HandleTypeDef *pdev , |
krebyy | 1:3a73d77c2cef | 89 | USBD_SetupReqTypedef *req); |
krebyy | 1:3a73d77c2cef | 90 | |
krebyy | 1:3a73d77c2cef | 91 | static void USBD_GetStatus(USBD_HandleTypeDef *pdev , |
krebyy | 1:3a73d77c2cef | 92 | USBD_SetupReqTypedef *req); |
krebyy | 1:3a73d77c2cef | 93 | |
krebyy | 1:3a73d77c2cef | 94 | static void USBD_SetFeature(USBD_HandleTypeDef *pdev , |
krebyy | 1:3a73d77c2cef | 95 | USBD_SetupReqTypedef *req); |
krebyy | 1:3a73d77c2cef | 96 | |
krebyy | 1:3a73d77c2cef | 97 | static void USBD_ClrFeature(USBD_HandleTypeDef *pdev , |
krebyy | 1:3a73d77c2cef | 98 | USBD_SetupReqTypedef *req); |
krebyy | 1:3a73d77c2cef | 99 | |
krebyy | 1:3a73d77c2cef | 100 | static uint8_t USBD_GetLen(uint8_t *buf); |
krebyy | 1:3a73d77c2cef | 101 | |
krebyy | 1:3a73d77c2cef | 102 | /** |
krebyy | 1:3a73d77c2cef | 103 | * @} |
krebyy | 1:3a73d77c2cef | 104 | */ |
krebyy | 1:3a73d77c2cef | 105 | |
krebyy | 1:3a73d77c2cef | 106 | |
krebyy | 1:3a73d77c2cef | 107 | /** @defgroup USBD_REQ_Private_Functions |
krebyy | 1:3a73d77c2cef | 108 | * @{ |
krebyy | 1:3a73d77c2cef | 109 | */ |
krebyy | 1:3a73d77c2cef | 110 | |
krebyy | 1:3a73d77c2cef | 111 | |
krebyy | 1:3a73d77c2cef | 112 | /** |
krebyy | 1:3a73d77c2cef | 113 | * @brief USBD_StdDevReq |
krebyy | 1:3a73d77c2cef | 114 | * Handle standard usb device requests |
krebyy | 1:3a73d77c2cef | 115 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 116 | * @param req: usb request |
krebyy | 1:3a73d77c2cef | 117 | * @retval status |
krebyy | 1:3a73d77c2cef | 118 | */ |
krebyy | 1:3a73d77c2cef | 119 | USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) |
krebyy | 1:3a73d77c2cef | 120 | { |
krebyy | 1:3a73d77c2cef | 121 | USBD_StatusTypeDef ret = USBD_OK; |
krebyy | 1:3a73d77c2cef | 122 | |
krebyy | 1:3a73d77c2cef | 123 | switch (req->bRequest) |
krebyy | 1:3a73d77c2cef | 124 | { |
krebyy | 1:3a73d77c2cef | 125 | case USB_REQ_GET_DESCRIPTOR: |
krebyy | 1:3a73d77c2cef | 126 | |
krebyy | 1:3a73d77c2cef | 127 | USBD_GetDescriptor (pdev, req) ; |
krebyy | 1:3a73d77c2cef | 128 | break; |
krebyy | 1:3a73d77c2cef | 129 | |
krebyy | 1:3a73d77c2cef | 130 | case USB_REQ_SET_ADDRESS: |
krebyy | 1:3a73d77c2cef | 131 | USBD_SetAddress(pdev, req); |
krebyy | 1:3a73d77c2cef | 132 | break; |
krebyy | 1:3a73d77c2cef | 133 | |
krebyy | 1:3a73d77c2cef | 134 | case USB_REQ_SET_CONFIGURATION: |
krebyy | 1:3a73d77c2cef | 135 | USBD_SetConfig (pdev , req); |
krebyy | 1:3a73d77c2cef | 136 | break; |
krebyy | 1:3a73d77c2cef | 137 | |
krebyy | 1:3a73d77c2cef | 138 | case USB_REQ_GET_CONFIGURATION: |
krebyy | 1:3a73d77c2cef | 139 | USBD_GetConfig (pdev , req); |
krebyy | 1:3a73d77c2cef | 140 | break; |
krebyy | 1:3a73d77c2cef | 141 | |
krebyy | 1:3a73d77c2cef | 142 | case USB_REQ_GET_STATUS: |
krebyy | 1:3a73d77c2cef | 143 | USBD_GetStatus (pdev , req); |
krebyy | 1:3a73d77c2cef | 144 | break; |
krebyy | 1:3a73d77c2cef | 145 | |
krebyy | 1:3a73d77c2cef | 146 | |
krebyy | 1:3a73d77c2cef | 147 | case USB_REQ_SET_FEATURE: |
krebyy | 1:3a73d77c2cef | 148 | USBD_SetFeature (pdev , req); |
krebyy | 1:3a73d77c2cef | 149 | break; |
krebyy | 1:3a73d77c2cef | 150 | |
krebyy | 1:3a73d77c2cef | 151 | case USB_REQ_CLEAR_FEATURE: |
krebyy | 1:3a73d77c2cef | 152 | USBD_ClrFeature (pdev , req); |
krebyy | 1:3a73d77c2cef | 153 | break; |
krebyy | 1:3a73d77c2cef | 154 | |
krebyy | 1:3a73d77c2cef | 155 | default: |
krebyy | 1:3a73d77c2cef | 156 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 157 | break; |
krebyy | 1:3a73d77c2cef | 158 | } |
krebyy | 1:3a73d77c2cef | 159 | |
krebyy | 1:3a73d77c2cef | 160 | return ret; |
krebyy | 1:3a73d77c2cef | 161 | } |
krebyy | 1:3a73d77c2cef | 162 | |
krebyy | 1:3a73d77c2cef | 163 | /** |
krebyy | 1:3a73d77c2cef | 164 | * @brief USBD_StdItfReq |
krebyy | 1:3a73d77c2cef | 165 | * Handle standard usb interface requests |
krebyy | 1:3a73d77c2cef | 166 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 167 | * @param req: usb request |
krebyy | 1:3a73d77c2cef | 168 | * @retval status |
krebyy | 1:3a73d77c2cef | 169 | */ |
krebyy | 1:3a73d77c2cef | 170 | USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) |
krebyy | 1:3a73d77c2cef | 171 | { |
krebyy | 1:3a73d77c2cef | 172 | USBD_StatusTypeDef ret = USBD_OK; |
krebyy | 1:3a73d77c2cef | 173 | |
krebyy | 1:3a73d77c2cef | 174 | switch (pdev->dev_state) |
krebyy | 1:3a73d77c2cef | 175 | { |
krebyy | 1:3a73d77c2cef | 176 | case USBD_STATE_CONFIGURED: |
krebyy | 1:3a73d77c2cef | 177 | |
krebyy | 1:3a73d77c2cef | 178 | if (LOBYTE(req->wIndex) <= USBD_MAX_NUM_INTERFACES) |
krebyy | 1:3a73d77c2cef | 179 | { |
krebyy | 1:3a73d77c2cef | 180 | pdev->pClass->Setup (pdev, req); |
krebyy | 1:3a73d77c2cef | 181 | |
krebyy | 1:3a73d77c2cef | 182 | if((req->wLength == 0)&& (ret == USBD_OK)) |
krebyy | 1:3a73d77c2cef | 183 | { |
krebyy | 1:3a73d77c2cef | 184 | USBD_CtlSendStatus(pdev); |
krebyy | 1:3a73d77c2cef | 185 | } |
krebyy | 1:3a73d77c2cef | 186 | } |
krebyy | 1:3a73d77c2cef | 187 | else |
krebyy | 1:3a73d77c2cef | 188 | { |
krebyy | 1:3a73d77c2cef | 189 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 190 | } |
krebyy | 1:3a73d77c2cef | 191 | break; |
krebyy | 1:3a73d77c2cef | 192 | |
krebyy | 1:3a73d77c2cef | 193 | default: |
krebyy | 1:3a73d77c2cef | 194 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 195 | break; |
krebyy | 1:3a73d77c2cef | 196 | } |
krebyy | 1:3a73d77c2cef | 197 | return USBD_OK; |
krebyy | 1:3a73d77c2cef | 198 | } |
krebyy | 1:3a73d77c2cef | 199 | |
krebyy | 1:3a73d77c2cef | 200 | /** |
krebyy | 1:3a73d77c2cef | 201 | * @brief USBD_StdEPReq |
krebyy | 1:3a73d77c2cef | 202 | * Handle standard usb endpoint requests |
krebyy | 1:3a73d77c2cef | 203 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 204 | * @param req: usb request |
krebyy | 1:3a73d77c2cef | 205 | * @retval status |
krebyy | 1:3a73d77c2cef | 206 | */ |
krebyy | 1:3a73d77c2cef | 207 | USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) |
krebyy | 1:3a73d77c2cef | 208 | { |
krebyy | 1:3a73d77c2cef | 209 | |
krebyy | 1:3a73d77c2cef | 210 | uint8_t ep_addr; |
krebyy | 1:3a73d77c2cef | 211 | USBD_StatusTypeDef ret = USBD_OK; |
krebyy | 1:3a73d77c2cef | 212 | USBD_EndpointTypeDef *pep; |
krebyy | 1:3a73d77c2cef | 213 | ep_addr = LOBYTE(req->wIndex); |
krebyy | 1:3a73d77c2cef | 214 | |
krebyy | 1:3a73d77c2cef | 215 | switch (req->bRequest) |
krebyy | 1:3a73d77c2cef | 216 | { |
krebyy | 1:3a73d77c2cef | 217 | |
krebyy | 1:3a73d77c2cef | 218 | case USB_REQ_SET_FEATURE : |
krebyy | 1:3a73d77c2cef | 219 | |
krebyy | 1:3a73d77c2cef | 220 | switch (pdev->dev_state) |
krebyy | 1:3a73d77c2cef | 221 | { |
krebyy | 1:3a73d77c2cef | 222 | case USBD_STATE_ADDRESSED: |
krebyy | 1:3a73d77c2cef | 223 | if ((ep_addr != 0x00) && (ep_addr != 0x80)) |
krebyy | 1:3a73d77c2cef | 224 | { |
krebyy | 1:3a73d77c2cef | 225 | USBD_LL_StallEP(pdev , ep_addr); |
krebyy | 1:3a73d77c2cef | 226 | } |
krebyy | 1:3a73d77c2cef | 227 | break; |
krebyy | 1:3a73d77c2cef | 228 | |
krebyy | 1:3a73d77c2cef | 229 | case USBD_STATE_CONFIGURED: |
krebyy | 1:3a73d77c2cef | 230 | if (req->wValue == USB_FEATURE_EP_HALT) |
krebyy | 1:3a73d77c2cef | 231 | { |
krebyy | 1:3a73d77c2cef | 232 | if ((ep_addr != 0x00) && (ep_addr != 0x80)) |
krebyy | 1:3a73d77c2cef | 233 | { |
krebyy | 1:3a73d77c2cef | 234 | USBD_LL_StallEP(pdev , ep_addr); |
krebyy | 1:3a73d77c2cef | 235 | |
krebyy | 1:3a73d77c2cef | 236 | } |
krebyy | 1:3a73d77c2cef | 237 | } |
krebyy | 1:3a73d77c2cef | 238 | pdev->pClass->Setup (pdev, req); |
krebyy | 1:3a73d77c2cef | 239 | USBD_CtlSendStatus(pdev); |
krebyy | 1:3a73d77c2cef | 240 | |
krebyy | 1:3a73d77c2cef | 241 | break; |
krebyy | 1:3a73d77c2cef | 242 | |
krebyy | 1:3a73d77c2cef | 243 | default: |
krebyy | 1:3a73d77c2cef | 244 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 245 | break; |
krebyy | 1:3a73d77c2cef | 246 | } |
krebyy | 1:3a73d77c2cef | 247 | break; |
krebyy | 1:3a73d77c2cef | 248 | |
krebyy | 1:3a73d77c2cef | 249 | case USB_REQ_CLEAR_FEATURE : |
krebyy | 1:3a73d77c2cef | 250 | |
krebyy | 1:3a73d77c2cef | 251 | switch (pdev->dev_state) |
krebyy | 1:3a73d77c2cef | 252 | { |
krebyy | 1:3a73d77c2cef | 253 | case USBD_STATE_ADDRESSED: |
krebyy | 1:3a73d77c2cef | 254 | if ((ep_addr != 0x00) && (ep_addr != 0x80)) |
krebyy | 1:3a73d77c2cef | 255 | { |
krebyy | 1:3a73d77c2cef | 256 | USBD_LL_StallEP(pdev , ep_addr); |
krebyy | 1:3a73d77c2cef | 257 | } |
krebyy | 1:3a73d77c2cef | 258 | break; |
krebyy | 1:3a73d77c2cef | 259 | |
krebyy | 1:3a73d77c2cef | 260 | case USBD_STATE_CONFIGURED: |
krebyy | 1:3a73d77c2cef | 261 | if (req->wValue == USB_FEATURE_EP_HALT) |
krebyy | 1:3a73d77c2cef | 262 | { |
krebyy | 1:3a73d77c2cef | 263 | if ((ep_addr & 0x7F) != 0x00) |
krebyy | 1:3a73d77c2cef | 264 | { |
krebyy | 1:3a73d77c2cef | 265 | USBD_LL_ClearStallEP(pdev , ep_addr); |
krebyy | 1:3a73d77c2cef | 266 | pdev->pClass->Setup (pdev, req); |
krebyy | 1:3a73d77c2cef | 267 | } |
krebyy | 1:3a73d77c2cef | 268 | USBD_CtlSendStatus(pdev); |
krebyy | 1:3a73d77c2cef | 269 | } |
krebyy | 1:3a73d77c2cef | 270 | break; |
krebyy | 1:3a73d77c2cef | 271 | |
krebyy | 1:3a73d77c2cef | 272 | default: |
krebyy | 1:3a73d77c2cef | 273 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 274 | break; |
krebyy | 1:3a73d77c2cef | 275 | } |
krebyy | 1:3a73d77c2cef | 276 | break; |
krebyy | 1:3a73d77c2cef | 277 | |
krebyy | 1:3a73d77c2cef | 278 | case USB_REQ_GET_STATUS: |
krebyy | 1:3a73d77c2cef | 279 | switch (pdev->dev_state) |
krebyy | 1:3a73d77c2cef | 280 | { |
krebyy | 1:3a73d77c2cef | 281 | case USBD_STATE_ADDRESSED: |
krebyy | 1:3a73d77c2cef | 282 | if ((ep_addr & 0x7F) != 0x00) |
krebyy | 1:3a73d77c2cef | 283 | { |
krebyy | 1:3a73d77c2cef | 284 | USBD_LL_StallEP(pdev , ep_addr); |
krebyy | 1:3a73d77c2cef | 285 | } |
krebyy | 1:3a73d77c2cef | 286 | break; |
krebyy | 1:3a73d77c2cef | 287 | |
krebyy | 1:3a73d77c2cef | 288 | case USBD_STATE_CONFIGURED: |
krebyy | 1:3a73d77c2cef | 289 | pep = ((ep_addr & 0x80) == 0x80) ? &pdev->ep_in[ep_addr & 0x7F]:\ |
krebyy | 1:3a73d77c2cef | 290 | &pdev->ep_out[ep_addr & 0x7F]; |
krebyy | 1:3a73d77c2cef | 291 | if(USBD_LL_IsStallEP(pdev, ep_addr)) |
krebyy | 1:3a73d77c2cef | 292 | { |
krebyy | 1:3a73d77c2cef | 293 | pep->status = 0x0001; |
krebyy | 1:3a73d77c2cef | 294 | } |
krebyy | 1:3a73d77c2cef | 295 | else |
krebyy | 1:3a73d77c2cef | 296 | { |
krebyy | 1:3a73d77c2cef | 297 | pep->status = 0x0000; |
krebyy | 1:3a73d77c2cef | 298 | } |
krebyy | 1:3a73d77c2cef | 299 | |
krebyy | 1:3a73d77c2cef | 300 | USBD_CtlSendData (pdev, |
krebyy | 1:3a73d77c2cef | 301 | (uint8_t *)&pep->status, |
krebyy | 1:3a73d77c2cef | 302 | 2); |
krebyy | 1:3a73d77c2cef | 303 | break; |
krebyy | 1:3a73d77c2cef | 304 | |
krebyy | 1:3a73d77c2cef | 305 | default: |
krebyy | 1:3a73d77c2cef | 306 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 307 | break; |
krebyy | 1:3a73d77c2cef | 308 | } |
krebyy | 1:3a73d77c2cef | 309 | break; |
krebyy | 1:3a73d77c2cef | 310 | |
krebyy | 1:3a73d77c2cef | 311 | default: |
krebyy | 1:3a73d77c2cef | 312 | break; |
krebyy | 1:3a73d77c2cef | 313 | } |
krebyy | 1:3a73d77c2cef | 314 | return ret; |
krebyy | 1:3a73d77c2cef | 315 | } |
krebyy | 1:3a73d77c2cef | 316 | /** |
krebyy | 1:3a73d77c2cef | 317 | * @brief USBD_GetDescriptor |
krebyy | 1:3a73d77c2cef | 318 | * Handle Get Descriptor requests |
krebyy | 1:3a73d77c2cef | 319 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 320 | * @param req: usb request |
krebyy | 1:3a73d77c2cef | 321 | * @retval status |
krebyy | 1:3a73d77c2cef | 322 | */ |
krebyy | 1:3a73d77c2cef | 323 | static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev , |
krebyy | 1:3a73d77c2cef | 324 | USBD_SetupReqTypedef *req) |
krebyy | 1:3a73d77c2cef | 325 | { |
krebyy | 1:3a73d77c2cef | 326 | uint16_t len; |
krebyy | 1:3a73d77c2cef | 327 | uint8_t *pbuf; |
krebyy | 1:3a73d77c2cef | 328 | |
krebyy | 1:3a73d77c2cef | 329 | |
krebyy | 1:3a73d77c2cef | 330 | switch (req->wValue >> 8) |
krebyy | 1:3a73d77c2cef | 331 | { |
krebyy | 1:3a73d77c2cef | 332 | case USB_DESC_TYPE_DEVICE: |
krebyy | 1:3a73d77c2cef | 333 | pbuf = pdev->pDesc->GetDeviceDescriptor(pdev->dev_speed, &len); |
krebyy | 1:3a73d77c2cef | 334 | break; |
krebyy | 1:3a73d77c2cef | 335 | |
krebyy | 1:3a73d77c2cef | 336 | case USB_DESC_TYPE_CONFIGURATION: |
krebyy | 1:3a73d77c2cef | 337 | if(pdev->dev_speed == USBD_SPEED_HIGH ) |
krebyy | 1:3a73d77c2cef | 338 | { |
krebyy | 1:3a73d77c2cef | 339 | pbuf = (uint8_t *)pdev->pClass->GetHSConfigDescriptor(&len); |
krebyy | 1:3a73d77c2cef | 340 | pbuf[1] = USB_DESC_TYPE_CONFIGURATION; |
krebyy | 1:3a73d77c2cef | 341 | } |
krebyy | 1:3a73d77c2cef | 342 | else |
krebyy | 1:3a73d77c2cef | 343 | { |
krebyy | 1:3a73d77c2cef | 344 | pbuf = (uint8_t *)pdev->pClass->GetFSConfigDescriptor(&len); |
krebyy | 1:3a73d77c2cef | 345 | pbuf[1] = USB_DESC_TYPE_CONFIGURATION; |
krebyy | 1:3a73d77c2cef | 346 | } |
krebyy | 1:3a73d77c2cef | 347 | break; |
krebyy | 1:3a73d77c2cef | 348 | |
krebyy | 1:3a73d77c2cef | 349 | case USB_DESC_TYPE_STRING: |
krebyy | 1:3a73d77c2cef | 350 | switch ((uint8_t)(req->wValue)) |
krebyy | 1:3a73d77c2cef | 351 | { |
krebyy | 1:3a73d77c2cef | 352 | case USBD_IDX_LANGID_STR: |
krebyy | 1:3a73d77c2cef | 353 | pbuf = pdev->pDesc->GetLangIDStrDescriptor(pdev->dev_speed, &len); |
krebyy | 1:3a73d77c2cef | 354 | break; |
krebyy | 1:3a73d77c2cef | 355 | |
krebyy | 1:3a73d77c2cef | 356 | case USBD_IDX_MFC_STR: |
krebyy | 1:3a73d77c2cef | 357 | pbuf = pdev->pDesc->GetManufacturerStrDescriptor(pdev->dev_speed, &len); |
krebyy | 1:3a73d77c2cef | 358 | break; |
krebyy | 1:3a73d77c2cef | 359 | |
krebyy | 1:3a73d77c2cef | 360 | case USBD_IDX_PRODUCT_STR: |
krebyy | 1:3a73d77c2cef | 361 | pbuf = pdev->pDesc->GetProductStrDescriptor(pdev->dev_speed, &len); |
krebyy | 1:3a73d77c2cef | 362 | break; |
krebyy | 1:3a73d77c2cef | 363 | |
krebyy | 1:3a73d77c2cef | 364 | case USBD_IDX_SERIAL_STR: |
krebyy | 1:3a73d77c2cef | 365 | pbuf = pdev->pDesc->GetSerialStrDescriptor(pdev->dev_speed, &len); |
krebyy | 1:3a73d77c2cef | 366 | break; |
krebyy | 1:3a73d77c2cef | 367 | |
krebyy | 1:3a73d77c2cef | 368 | case USBD_IDX_CONFIG_STR: |
krebyy | 1:3a73d77c2cef | 369 | pbuf = pdev->pDesc->GetConfigurationStrDescriptor(pdev->dev_speed, &len); |
krebyy | 1:3a73d77c2cef | 370 | break; |
krebyy | 1:3a73d77c2cef | 371 | |
krebyy | 1:3a73d77c2cef | 372 | case USBD_IDX_INTERFACE_STR: |
krebyy | 1:3a73d77c2cef | 373 | pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev->dev_speed, &len); |
krebyy | 1:3a73d77c2cef | 374 | break; |
krebyy | 1:3a73d77c2cef | 375 | |
krebyy | 1:3a73d77c2cef | 376 | default: |
krebyy | 1:3a73d77c2cef | 377 | #if (USBD_SUPPORT_USER_STRING == 1) |
krebyy | 1:3a73d77c2cef | 378 | pbuf = pdev->pClass->GetUsrStrDescriptor(pdev, (req->wValue) , &len); |
krebyy | 1:3a73d77c2cef | 379 | break; |
krebyy | 1:3a73d77c2cef | 380 | #else |
krebyy | 1:3a73d77c2cef | 381 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 382 | return; |
krebyy | 1:3a73d77c2cef | 383 | #endif |
krebyy | 1:3a73d77c2cef | 384 | } |
krebyy | 1:3a73d77c2cef | 385 | break; |
krebyy | 1:3a73d77c2cef | 386 | case USB_DESC_TYPE_DEVICE_QUALIFIER: |
krebyy | 1:3a73d77c2cef | 387 | |
krebyy | 1:3a73d77c2cef | 388 | if(pdev->dev_speed == USBD_SPEED_HIGH ) |
krebyy | 1:3a73d77c2cef | 389 | { |
krebyy | 1:3a73d77c2cef | 390 | pbuf = (uint8_t *)pdev->pClass->GetDeviceQualifierDescriptor(&len); |
krebyy | 1:3a73d77c2cef | 391 | break; |
krebyy | 1:3a73d77c2cef | 392 | } |
krebyy | 1:3a73d77c2cef | 393 | else |
krebyy | 1:3a73d77c2cef | 394 | { |
krebyy | 1:3a73d77c2cef | 395 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 396 | return; |
krebyy | 1:3a73d77c2cef | 397 | } |
krebyy | 1:3a73d77c2cef | 398 | |
krebyy | 1:3a73d77c2cef | 399 | case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION: |
krebyy | 1:3a73d77c2cef | 400 | if(pdev->dev_speed == USBD_SPEED_HIGH ) |
krebyy | 1:3a73d77c2cef | 401 | { |
krebyy | 1:3a73d77c2cef | 402 | pbuf = (uint8_t *)pdev->pClass->GetOtherSpeedConfigDescriptor(&len); |
krebyy | 1:3a73d77c2cef | 403 | pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION; |
krebyy | 1:3a73d77c2cef | 404 | break; |
krebyy | 1:3a73d77c2cef | 405 | } |
krebyy | 1:3a73d77c2cef | 406 | else |
krebyy | 1:3a73d77c2cef | 407 | { |
krebyy | 1:3a73d77c2cef | 408 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 409 | return; |
krebyy | 1:3a73d77c2cef | 410 | } |
krebyy | 1:3a73d77c2cef | 411 | |
krebyy | 1:3a73d77c2cef | 412 | default: |
krebyy | 1:3a73d77c2cef | 413 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 414 | return; |
krebyy | 1:3a73d77c2cef | 415 | } |
krebyy | 1:3a73d77c2cef | 416 | |
krebyy | 1:3a73d77c2cef | 417 | if((len != 0)&& (req->wLength != 0)) |
krebyy | 1:3a73d77c2cef | 418 | { |
krebyy | 1:3a73d77c2cef | 419 | |
krebyy | 1:3a73d77c2cef | 420 | len = MIN(len , req->wLength); |
krebyy | 1:3a73d77c2cef | 421 | |
krebyy | 1:3a73d77c2cef | 422 | USBD_CtlSendData (pdev, |
krebyy | 1:3a73d77c2cef | 423 | pbuf, |
krebyy | 1:3a73d77c2cef | 424 | len); |
krebyy | 1:3a73d77c2cef | 425 | } |
krebyy | 1:3a73d77c2cef | 426 | |
krebyy | 1:3a73d77c2cef | 427 | } |
krebyy | 1:3a73d77c2cef | 428 | |
krebyy | 1:3a73d77c2cef | 429 | /** |
krebyy | 1:3a73d77c2cef | 430 | * @brief USBD_SetAddress |
krebyy | 1:3a73d77c2cef | 431 | * Set device address |
krebyy | 1:3a73d77c2cef | 432 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 433 | * @param req: usb request |
krebyy | 1:3a73d77c2cef | 434 | * @retval status |
krebyy | 1:3a73d77c2cef | 435 | */ |
krebyy | 1:3a73d77c2cef | 436 | static void USBD_SetAddress(USBD_HandleTypeDef *pdev , |
krebyy | 1:3a73d77c2cef | 437 | USBD_SetupReqTypedef *req) |
krebyy | 1:3a73d77c2cef | 438 | { |
krebyy | 1:3a73d77c2cef | 439 | uint8_t dev_addr; |
krebyy | 1:3a73d77c2cef | 440 | |
krebyy | 1:3a73d77c2cef | 441 | if ((req->wIndex == 0) && (req->wLength == 0)) |
krebyy | 1:3a73d77c2cef | 442 | { |
krebyy | 1:3a73d77c2cef | 443 | dev_addr = (uint8_t)(req->wValue) & 0x7F; |
krebyy | 1:3a73d77c2cef | 444 | |
krebyy | 1:3a73d77c2cef | 445 | if (pdev->dev_state == USBD_STATE_CONFIGURED) |
krebyy | 1:3a73d77c2cef | 446 | { |
krebyy | 1:3a73d77c2cef | 447 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 448 | } |
krebyy | 1:3a73d77c2cef | 449 | else |
krebyy | 1:3a73d77c2cef | 450 | { |
krebyy | 1:3a73d77c2cef | 451 | pdev->dev_address = dev_addr; |
krebyy | 1:3a73d77c2cef | 452 | USBD_LL_SetUSBAddress(pdev, dev_addr); |
krebyy | 1:3a73d77c2cef | 453 | USBD_CtlSendStatus(pdev); |
krebyy | 1:3a73d77c2cef | 454 | |
krebyy | 1:3a73d77c2cef | 455 | if (dev_addr != 0) |
krebyy | 1:3a73d77c2cef | 456 | { |
krebyy | 1:3a73d77c2cef | 457 | pdev->dev_state = USBD_STATE_ADDRESSED; |
krebyy | 1:3a73d77c2cef | 458 | } |
krebyy | 1:3a73d77c2cef | 459 | else |
krebyy | 1:3a73d77c2cef | 460 | { |
krebyy | 1:3a73d77c2cef | 461 | pdev->dev_state = USBD_STATE_DEFAULT; |
krebyy | 1:3a73d77c2cef | 462 | } |
krebyy | 1:3a73d77c2cef | 463 | } |
krebyy | 1:3a73d77c2cef | 464 | } |
krebyy | 1:3a73d77c2cef | 465 | else |
krebyy | 1:3a73d77c2cef | 466 | { |
krebyy | 1:3a73d77c2cef | 467 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 468 | } |
krebyy | 1:3a73d77c2cef | 469 | } |
krebyy | 1:3a73d77c2cef | 470 | |
krebyy | 1:3a73d77c2cef | 471 | /** |
krebyy | 1:3a73d77c2cef | 472 | * @brief USBD_SetConfig |
krebyy | 1:3a73d77c2cef | 473 | * Handle Set device configuration request |
krebyy | 1:3a73d77c2cef | 474 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 475 | * @param req: usb request |
krebyy | 1:3a73d77c2cef | 476 | * @retval status |
krebyy | 1:3a73d77c2cef | 477 | */ |
krebyy | 1:3a73d77c2cef | 478 | static void USBD_SetConfig(USBD_HandleTypeDef *pdev , |
krebyy | 1:3a73d77c2cef | 479 | USBD_SetupReqTypedef *req) |
krebyy | 1:3a73d77c2cef | 480 | { |
krebyy | 1:3a73d77c2cef | 481 | |
krebyy | 1:3a73d77c2cef | 482 | static uint8_t cfgidx; |
krebyy | 1:3a73d77c2cef | 483 | |
krebyy | 1:3a73d77c2cef | 484 | cfgidx = (uint8_t)(req->wValue); |
krebyy | 1:3a73d77c2cef | 485 | |
krebyy | 1:3a73d77c2cef | 486 | if (cfgidx > USBD_MAX_NUM_CONFIGURATION ) |
krebyy | 1:3a73d77c2cef | 487 | { |
krebyy | 1:3a73d77c2cef | 488 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 489 | } |
krebyy | 1:3a73d77c2cef | 490 | else |
krebyy | 1:3a73d77c2cef | 491 | { |
krebyy | 1:3a73d77c2cef | 492 | switch (pdev->dev_state) |
krebyy | 1:3a73d77c2cef | 493 | { |
krebyy | 1:3a73d77c2cef | 494 | case USBD_STATE_ADDRESSED: |
krebyy | 1:3a73d77c2cef | 495 | if (cfgidx) |
krebyy | 1:3a73d77c2cef | 496 | { |
krebyy | 1:3a73d77c2cef | 497 | pdev->dev_config = cfgidx; |
krebyy | 1:3a73d77c2cef | 498 | pdev->dev_state = USBD_STATE_CONFIGURED; |
krebyy | 1:3a73d77c2cef | 499 | if(USBD_SetClassConfig(pdev , cfgidx) == USBD_FAIL) |
krebyy | 1:3a73d77c2cef | 500 | { |
krebyy | 1:3a73d77c2cef | 501 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 502 | return; |
krebyy | 1:3a73d77c2cef | 503 | } |
krebyy | 1:3a73d77c2cef | 504 | USBD_CtlSendStatus(pdev); |
krebyy | 1:3a73d77c2cef | 505 | } |
krebyy | 1:3a73d77c2cef | 506 | else |
krebyy | 1:3a73d77c2cef | 507 | { |
krebyy | 1:3a73d77c2cef | 508 | USBD_CtlSendStatus(pdev); |
krebyy | 1:3a73d77c2cef | 509 | } |
krebyy | 1:3a73d77c2cef | 510 | break; |
krebyy | 1:3a73d77c2cef | 511 | |
krebyy | 1:3a73d77c2cef | 512 | case USBD_STATE_CONFIGURED: |
krebyy | 1:3a73d77c2cef | 513 | if (cfgidx == 0) |
krebyy | 1:3a73d77c2cef | 514 | { |
krebyy | 1:3a73d77c2cef | 515 | pdev->dev_state = USBD_STATE_ADDRESSED; |
krebyy | 1:3a73d77c2cef | 516 | pdev->dev_config = cfgidx; |
krebyy | 1:3a73d77c2cef | 517 | USBD_ClrClassConfig(pdev , cfgidx); |
krebyy | 1:3a73d77c2cef | 518 | USBD_CtlSendStatus(pdev); |
krebyy | 1:3a73d77c2cef | 519 | |
krebyy | 1:3a73d77c2cef | 520 | } |
krebyy | 1:3a73d77c2cef | 521 | else if (cfgidx != pdev->dev_config) |
krebyy | 1:3a73d77c2cef | 522 | { |
krebyy | 1:3a73d77c2cef | 523 | /* Clear old configuration */ |
krebyy | 1:3a73d77c2cef | 524 | USBD_ClrClassConfig(pdev , pdev->dev_config); |
krebyy | 1:3a73d77c2cef | 525 | |
krebyy | 1:3a73d77c2cef | 526 | /* set new configuration */ |
krebyy | 1:3a73d77c2cef | 527 | pdev->dev_config = cfgidx; |
krebyy | 1:3a73d77c2cef | 528 | if(USBD_SetClassConfig(pdev , cfgidx) == USBD_FAIL) |
krebyy | 1:3a73d77c2cef | 529 | { |
krebyy | 1:3a73d77c2cef | 530 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 531 | return; |
krebyy | 1:3a73d77c2cef | 532 | } |
krebyy | 1:3a73d77c2cef | 533 | USBD_CtlSendStatus(pdev); |
krebyy | 1:3a73d77c2cef | 534 | } |
krebyy | 1:3a73d77c2cef | 535 | else |
krebyy | 1:3a73d77c2cef | 536 | { |
krebyy | 1:3a73d77c2cef | 537 | USBD_CtlSendStatus(pdev); |
krebyy | 1:3a73d77c2cef | 538 | } |
krebyy | 1:3a73d77c2cef | 539 | break; |
krebyy | 1:3a73d77c2cef | 540 | |
krebyy | 1:3a73d77c2cef | 541 | default: |
krebyy | 1:3a73d77c2cef | 542 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 543 | break; |
krebyy | 1:3a73d77c2cef | 544 | } |
krebyy | 1:3a73d77c2cef | 545 | } |
krebyy | 1:3a73d77c2cef | 546 | } |
krebyy | 1:3a73d77c2cef | 547 | |
krebyy | 1:3a73d77c2cef | 548 | /** |
krebyy | 1:3a73d77c2cef | 549 | * @brief USBD_GetConfig |
krebyy | 1:3a73d77c2cef | 550 | * Handle Get device configuration request |
krebyy | 1:3a73d77c2cef | 551 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 552 | * @param req: usb request |
krebyy | 1:3a73d77c2cef | 553 | * @retval status |
krebyy | 1:3a73d77c2cef | 554 | */ |
krebyy | 1:3a73d77c2cef | 555 | static void USBD_GetConfig(USBD_HandleTypeDef *pdev , |
krebyy | 1:3a73d77c2cef | 556 | USBD_SetupReqTypedef *req) |
krebyy | 1:3a73d77c2cef | 557 | { |
krebyy | 1:3a73d77c2cef | 558 | |
krebyy | 1:3a73d77c2cef | 559 | if (req->wLength != 1) |
krebyy | 1:3a73d77c2cef | 560 | { |
krebyy | 1:3a73d77c2cef | 561 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 562 | } |
krebyy | 1:3a73d77c2cef | 563 | else |
krebyy | 1:3a73d77c2cef | 564 | { |
krebyy | 1:3a73d77c2cef | 565 | switch (pdev->dev_state ) |
krebyy | 1:3a73d77c2cef | 566 | { |
krebyy | 1:3a73d77c2cef | 567 | case USBD_STATE_ADDRESSED: |
krebyy | 1:3a73d77c2cef | 568 | pdev->dev_default_config = 0; |
krebyy | 1:3a73d77c2cef | 569 | USBD_CtlSendData (pdev, |
krebyy | 1:3a73d77c2cef | 570 | (uint8_t *)&pdev->dev_default_config, |
krebyy | 1:3a73d77c2cef | 571 | 1); |
krebyy | 1:3a73d77c2cef | 572 | break; |
krebyy | 1:3a73d77c2cef | 573 | |
krebyy | 1:3a73d77c2cef | 574 | case USBD_STATE_CONFIGURED: |
krebyy | 1:3a73d77c2cef | 575 | |
krebyy | 1:3a73d77c2cef | 576 | USBD_CtlSendData (pdev, |
krebyy | 1:3a73d77c2cef | 577 | (uint8_t *)&pdev->dev_config, |
krebyy | 1:3a73d77c2cef | 578 | 1); |
krebyy | 1:3a73d77c2cef | 579 | break; |
krebyy | 1:3a73d77c2cef | 580 | |
krebyy | 1:3a73d77c2cef | 581 | default: |
krebyy | 1:3a73d77c2cef | 582 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 583 | break; |
krebyy | 1:3a73d77c2cef | 584 | } |
krebyy | 1:3a73d77c2cef | 585 | } |
krebyy | 1:3a73d77c2cef | 586 | } |
krebyy | 1:3a73d77c2cef | 587 | |
krebyy | 1:3a73d77c2cef | 588 | /** |
krebyy | 1:3a73d77c2cef | 589 | * @brief USBD_GetStatus |
krebyy | 1:3a73d77c2cef | 590 | * Handle Get Status request |
krebyy | 1:3a73d77c2cef | 591 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 592 | * @param req: usb request |
krebyy | 1:3a73d77c2cef | 593 | * @retval status |
krebyy | 1:3a73d77c2cef | 594 | */ |
krebyy | 1:3a73d77c2cef | 595 | static void USBD_GetStatus(USBD_HandleTypeDef *pdev , |
krebyy | 1:3a73d77c2cef | 596 | USBD_SetupReqTypedef *req) |
krebyy | 1:3a73d77c2cef | 597 | { |
krebyy | 1:3a73d77c2cef | 598 | |
krebyy | 1:3a73d77c2cef | 599 | |
krebyy | 1:3a73d77c2cef | 600 | switch (pdev->dev_state) |
krebyy | 1:3a73d77c2cef | 601 | { |
krebyy | 1:3a73d77c2cef | 602 | case USBD_STATE_ADDRESSED: |
krebyy | 1:3a73d77c2cef | 603 | case USBD_STATE_CONFIGURED: |
krebyy | 1:3a73d77c2cef | 604 | |
krebyy | 1:3a73d77c2cef | 605 | #if ( USBD_SELF_POWERED == 1) |
krebyy | 1:3a73d77c2cef | 606 | pdev->dev_config_status = USB_CONFIG_SELF_POWERED; |
krebyy | 1:3a73d77c2cef | 607 | #else |
krebyy | 1:3a73d77c2cef | 608 | pdev->dev_config_status = 0; |
krebyy | 1:3a73d77c2cef | 609 | #endif |
krebyy | 1:3a73d77c2cef | 610 | |
krebyy | 1:3a73d77c2cef | 611 | if (pdev->dev_remote_wakeup) |
krebyy | 1:3a73d77c2cef | 612 | { |
krebyy | 1:3a73d77c2cef | 613 | pdev->dev_config_status |= USB_CONFIG_REMOTE_WAKEUP; |
krebyy | 1:3a73d77c2cef | 614 | } |
krebyy | 1:3a73d77c2cef | 615 | |
krebyy | 1:3a73d77c2cef | 616 | USBD_CtlSendData (pdev, |
krebyy | 1:3a73d77c2cef | 617 | (uint8_t *)& pdev->dev_config_status, |
krebyy | 1:3a73d77c2cef | 618 | 2); |
krebyy | 1:3a73d77c2cef | 619 | break; |
krebyy | 1:3a73d77c2cef | 620 | |
krebyy | 1:3a73d77c2cef | 621 | default : |
krebyy | 1:3a73d77c2cef | 622 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 623 | break; |
krebyy | 1:3a73d77c2cef | 624 | } |
krebyy | 1:3a73d77c2cef | 625 | } |
krebyy | 1:3a73d77c2cef | 626 | |
krebyy | 1:3a73d77c2cef | 627 | |
krebyy | 1:3a73d77c2cef | 628 | /** |
krebyy | 1:3a73d77c2cef | 629 | * @brief USBD_SetFeature |
krebyy | 1:3a73d77c2cef | 630 | * Handle Set device feature request |
krebyy | 1:3a73d77c2cef | 631 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 632 | * @param req: usb request |
krebyy | 1:3a73d77c2cef | 633 | * @retval status |
krebyy | 1:3a73d77c2cef | 634 | */ |
krebyy | 1:3a73d77c2cef | 635 | static void USBD_SetFeature(USBD_HandleTypeDef *pdev , |
krebyy | 1:3a73d77c2cef | 636 | USBD_SetupReqTypedef *req) |
krebyy | 1:3a73d77c2cef | 637 | { |
krebyy | 1:3a73d77c2cef | 638 | |
krebyy | 1:3a73d77c2cef | 639 | if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) |
krebyy | 1:3a73d77c2cef | 640 | { |
krebyy | 1:3a73d77c2cef | 641 | pdev->dev_remote_wakeup = 1; |
krebyy | 1:3a73d77c2cef | 642 | pdev->pClass->Setup (pdev, req); |
krebyy | 1:3a73d77c2cef | 643 | USBD_CtlSendStatus(pdev); |
krebyy | 1:3a73d77c2cef | 644 | } |
krebyy | 1:3a73d77c2cef | 645 | |
krebyy | 1:3a73d77c2cef | 646 | } |
krebyy | 1:3a73d77c2cef | 647 | |
krebyy | 1:3a73d77c2cef | 648 | |
krebyy | 1:3a73d77c2cef | 649 | /** |
krebyy | 1:3a73d77c2cef | 650 | * @brief USBD_ClrFeature |
krebyy | 1:3a73d77c2cef | 651 | * Handle clear device feature request |
krebyy | 1:3a73d77c2cef | 652 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 653 | * @param req: usb request |
krebyy | 1:3a73d77c2cef | 654 | * @retval status |
krebyy | 1:3a73d77c2cef | 655 | */ |
krebyy | 1:3a73d77c2cef | 656 | static void USBD_ClrFeature(USBD_HandleTypeDef *pdev , |
krebyy | 1:3a73d77c2cef | 657 | USBD_SetupReqTypedef *req) |
krebyy | 1:3a73d77c2cef | 658 | { |
krebyy | 1:3a73d77c2cef | 659 | switch (pdev->dev_state) |
krebyy | 1:3a73d77c2cef | 660 | { |
krebyy | 1:3a73d77c2cef | 661 | case USBD_STATE_ADDRESSED: |
krebyy | 1:3a73d77c2cef | 662 | case USBD_STATE_CONFIGURED: |
krebyy | 1:3a73d77c2cef | 663 | if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) |
krebyy | 1:3a73d77c2cef | 664 | { |
krebyy | 1:3a73d77c2cef | 665 | pdev->dev_remote_wakeup = 0; |
krebyy | 1:3a73d77c2cef | 666 | pdev->pClass->Setup (pdev, req); |
krebyy | 1:3a73d77c2cef | 667 | USBD_CtlSendStatus(pdev); |
krebyy | 1:3a73d77c2cef | 668 | } |
krebyy | 1:3a73d77c2cef | 669 | break; |
krebyy | 1:3a73d77c2cef | 670 | |
krebyy | 1:3a73d77c2cef | 671 | default : |
krebyy | 1:3a73d77c2cef | 672 | USBD_CtlError(pdev , req); |
krebyy | 1:3a73d77c2cef | 673 | break; |
krebyy | 1:3a73d77c2cef | 674 | } |
krebyy | 1:3a73d77c2cef | 675 | } |
krebyy | 1:3a73d77c2cef | 676 | |
krebyy | 1:3a73d77c2cef | 677 | /** |
krebyy | 1:3a73d77c2cef | 678 | * @brief USBD_ParseSetupRequest |
krebyy | 1:3a73d77c2cef | 679 | * Copy buffer into setup structure |
krebyy | 1:3a73d77c2cef | 680 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 681 | * @param req: usb request |
krebyy | 1:3a73d77c2cef | 682 | * @retval None |
krebyy | 1:3a73d77c2cef | 683 | */ |
krebyy | 1:3a73d77c2cef | 684 | |
krebyy | 1:3a73d77c2cef | 685 | void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata) |
krebyy | 1:3a73d77c2cef | 686 | { |
krebyy | 1:3a73d77c2cef | 687 | req->bmRequest = *(uint8_t *) (pdata); |
krebyy | 1:3a73d77c2cef | 688 | req->bRequest = *(uint8_t *) (pdata + 1); |
krebyy | 1:3a73d77c2cef | 689 | req->wValue = SWAPBYTE (pdata + 2); |
krebyy | 1:3a73d77c2cef | 690 | req->wIndex = SWAPBYTE (pdata + 4); |
krebyy | 1:3a73d77c2cef | 691 | req->wLength = SWAPBYTE (pdata + 6); |
krebyy | 1:3a73d77c2cef | 692 | |
krebyy | 1:3a73d77c2cef | 693 | } |
krebyy | 1:3a73d77c2cef | 694 | |
krebyy | 1:3a73d77c2cef | 695 | /** |
krebyy | 1:3a73d77c2cef | 696 | * @brief USBD_CtlError |
krebyy | 1:3a73d77c2cef | 697 | * Handle USB low level Error |
krebyy | 1:3a73d77c2cef | 698 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 699 | * @param req: usb request |
krebyy | 1:3a73d77c2cef | 700 | * @retval None |
krebyy | 1:3a73d77c2cef | 701 | */ |
krebyy | 1:3a73d77c2cef | 702 | |
krebyy | 1:3a73d77c2cef | 703 | void USBD_CtlError( USBD_HandleTypeDef *pdev , |
krebyy | 1:3a73d77c2cef | 704 | USBD_SetupReqTypedef *req) |
krebyy | 1:3a73d77c2cef | 705 | { |
krebyy | 1:3a73d77c2cef | 706 | USBD_LL_StallEP(pdev , 0x80); |
krebyy | 1:3a73d77c2cef | 707 | USBD_LL_StallEP(pdev , 0); |
krebyy | 1:3a73d77c2cef | 708 | } |
krebyy | 1:3a73d77c2cef | 709 | |
krebyy | 1:3a73d77c2cef | 710 | |
krebyy | 1:3a73d77c2cef | 711 | /** |
krebyy | 1:3a73d77c2cef | 712 | * @brief USBD_GetString |
krebyy | 1:3a73d77c2cef | 713 | * Convert Ascii string into unicode one |
krebyy | 1:3a73d77c2cef | 714 | * @param desc : descriptor buffer |
krebyy | 1:3a73d77c2cef | 715 | * @param unicode : Formatted string buffer (unicode) |
krebyy | 1:3a73d77c2cef | 716 | * @param len : descriptor length |
krebyy | 1:3a73d77c2cef | 717 | * @retval None |
krebyy | 1:3a73d77c2cef | 718 | */ |
krebyy | 1:3a73d77c2cef | 719 | void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len) |
krebyy | 1:3a73d77c2cef | 720 | { |
krebyy | 1:3a73d77c2cef | 721 | uint8_t idx = 0; |
krebyy | 1:3a73d77c2cef | 722 | |
krebyy | 1:3a73d77c2cef | 723 | if (desc != NULL) |
krebyy | 1:3a73d77c2cef | 724 | { |
krebyy | 1:3a73d77c2cef | 725 | *len = USBD_GetLen(desc) * 2 + 2; |
krebyy | 1:3a73d77c2cef | 726 | unicode[idx++] = *len; |
krebyy | 1:3a73d77c2cef | 727 | unicode[idx++] = USB_DESC_TYPE_STRING; |
krebyy | 1:3a73d77c2cef | 728 | |
krebyy | 1:3a73d77c2cef | 729 | while (*desc != '\0') |
krebyy | 1:3a73d77c2cef | 730 | { |
krebyy | 1:3a73d77c2cef | 731 | unicode[idx++] = *desc++; |
krebyy | 1:3a73d77c2cef | 732 | unicode[idx++] = 0x00; |
krebyy | 1:3a73d77c2cef | 733 | } |
krebyy | 1:3a73d77c2cef | 734 | } |
krebyy | 1:3a73d77c2cef | 735 | } |
krebyy | 1:3a73d77c2cef | 736 | |
krebyy | 1:3a73d77c2cef | 737 | /** |
krebyy | 1:3a73d77c2cef | 738 | * @brief USBD_GetLen |
krebyy | 1:3a73d77c2cef | 739 | * return the string length |
krebyy | 1:3a73d77c2cef | 740 | * @param buf : pointer to the ascii string buffer |
krebyy | 1:3a73d77c2cef | 741 | * @retval string length |
krebyy | 1:3a73d77c2cef | 742 | */ |
krebyy | 1:3a73d77c2cef | 743 | static uint8_t USBD_GetLen(uint8_t *buf) |
krebyy | 1:3a73d77c2cef | 744 | { |
krebyy | 1:3a73d77c2cef | 745 | uint8_t len = 0; |
krebyy | 1:3a73d77c2cef | 746 | |
krebyy | 1:3a73d77c2cef | 747 | while (*buf != '\0') |
krebyy | 1:3a73d77c2cef | 748 | { |
krebyy | 1:3a73d77c2cef | 749 | len++; |
krebyy | 1:3a73d77c2cef | 750 | buf++; |
krebyy | 1:3a73d77c2cef | 751 | } |
krebyy | 1:3a73d77c2cef | 752 | |
krebyy | 1:3a73d77c2cef | 753 | return len; |
krebyy | 1:3a73d77c2cef | 754 | } |
krebyy | 1:3a73d77c2cef | 755 | /** |
krebyy | 1:3a73d77c2cef | 756 | * @} |
krebyy | 1:3a73d77c2cef | 757 | */ |
krebyy | 1:3a73d77c2cef | 758 | |
krebyy | 1:3a73d77c2cef | 759 | |
krebyy | 1:3a73d77c2cef | 760 | /** |
krebyy | 1:3a73d77c2cef | 761 | * @} |
krebyy | 1:3a73d77c2cef | 762 | */ |
krebyy | 1:3a73d77c2cef | 763 | |
krebyy | 1:3a73d77c2cef | 764 | |
krebyy | 1:3a73d77c2cef | 765 | /** |
krebyy | 1:3a73d77c2cef | 766 | * @} |
krebyy | 1:3a73d77c2cef | 767 | */ |
krebyy | 1:3a73d77c2cef | 768 | |
krebyy | 1:3a73d77c2cef | 769 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |