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 Kleber Silva

Committer:
krebyy
Date:
Thu Jun 29 20:20:49 2017 +0000
Revision:
3:9c7195d31602
Parent:
1:3a73d77c2cef
Update to TON Board V1.2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
krebyy 1:3a73d77c2cef 1 /**
krebyy 1:3a73d77c2cef 2 ******************************************************************************
krebyy 1:3a73d77c2cef 3 * @file usbd_core.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 all the USBD core functions.
krebyy 1:3a73d77c2cef 8 ******************************************************************************
krebyy 1:3a73d77c2cef 9 * @attention
krebyy 1:3a73d77c2cef 10 *
krebyy 1:3a73d77c2cef 11 * <h2><center>&copy; 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_core.h"
krebyy 1:3a73d77c2cef 30
krebyy 1:3a73d77c2cef 31 /** @addtogroup STM32_USBD_DEVICE_LIBRARY
krebyy 1:3a73d77c2cef 32 * @{
krebyy 1:3a73d77c2cef 33 */
krebyy 1:3a73d77c2cef 34
krebyy 1:3a73d77c2cef 35
krebyy 1:3a73d77c2cef 36 /** @defgroup USBD_CORE
krebyy 1:3a73d77c2cef 37 * @brief usbd core module
krebyy 1:3a73d77c2cef 38 * @{
krebyy 1:3a73d77c2cef 39 */
krebyy 1:3a73d77c2cef 40
krebyy 1:3a73d77c2cef 41 /** @defgroup USBD_CORE_Private_TypesDefinitions
krebyy 1:3a73d77c2cef 42 * @{
krebyy 1:3a73d77c2cef 43 */
krebyy 1:3a73d77c2cef 44 /**
krebyy 1:3a73d77c2cef 45 * @}
krebyy 1:3a73d77c2cef 46 */
krebyy 1:3a73d77c2cef 47
krebyy 1:3a73d77c2cef 48
krebyy 1:3a73d77c2cef 49 /** @defgroup USBD_CORE_Private_Defines
krebyy 1:3a73d77c2cef 50 * @{
krebyy 1:3a73d77c2cef 51 */
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 /** @defgroup USBD_CORE_Private_Macros
krebyy 1:3a73d77c2cef 59 * @{
krebyy 1:3a73d77c2cef 60 */
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_CORE_Private_FunctionPrototypes
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_CORE_Private_Variables
krebyy 1:3a73d77c2cef 77 * @{
krebyy 1:3a73d77c2cef 78 */
krebyy 1:3a73d77c2cef 79
krebyy 1:3a73d77c2cef 80 /**
krebyy 1:3a73d77c2cef 81 * @}
krebyy 1:3a73d77c2cef 82 */
krebyy 1:3a73d77c2cef 83
krebyy 1:3a73d77c2cef 84 /** @defgroup USBD_CORE_Private_Functions
krebyy 1:3a73d77c2cef 85 * @{
krebyy 1:3a73d77c2cef 86 */
krebyy 1:3a73d77c2cef 87
krebyy 1:3a73d77c2cef 88 /**
krebyy 1:3a73d77c2cef 89 * @brief USBD_Init
krebyy 1:3a73d77c2cef 90 * Initializes the device stack and load the class driver
krebyy 1:3a73d77c2cef 91 * @param pdev: device instance
krebyy 1:3a73d77c2cef 92 * @param pdesc: Descriptor structure address
krebyy 1:3a73d77c2cef 93 * @param id: Low level core index
krebyy 1:3a73d77c2cef 94 * @retval None
krebyy 1:3a73d77c2cef 95 */
krebyy 1:3a73d77c2cef 96 USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id)
krebyy 1:3a73d77c2cef 97 {
krebyy 1:3a73d77c2cef 98 /* Check whether the USB Host handle is valid */
krebyy 1:3a73d77c2cef 99 if(pdev == NULL)
krebyy 1:3a73d77c2cef 100 {
krebyy 1:3a73d77c2cef 101 USBD_ErrLog("Invalid Device handle");
krebyy 1:3a73d77c2cef 102 return USBD_FAIL;
krebyy 1:3a73d77c2cef 103 }
krebyy 1:3a73d77c2cef 104
krebyy 1:3a73d77c2cef 105 /* Unlink previous class*/
krebyy 1:3a73d77c2cef 106 if(pdev->pClass != NULL)
krebyy 1:3a73d77c2cef 107 {
krebyy 1:3a73d77c2cef 108 pdev->pClass = NULL;
krebyy 1:3a73d77c2cef 109 }
krebyy 1:3a73d77c2cef 110
krebyy 1:3a73d77c2cef 111 /* Assign USBD Descriptors */
krebyy 1:3a73d77c2cef 112 if(pdesc != NULL)
krebyy 1:3a73d77c2cef 113 {
krebyy 1:3a73d77c2cef 114 pdev->pDesc = pdesc;
krebyy 1:3a73d77c2cef 115 }
krebyy 1:3a73d77c2cef 116
krebyy 1:3a73d77c2cef 117 /* Set Device initial State */
krebyy 1:3a73d77c2cef 118 pdev->dev_state = USBD_STATE_DEFAULT;
krebyy 1:3a73d77c2cef 119 pdev->id = id;
krebyy 1:3a73d77c2cef 120 /* Initialize low level driver */
krebyy 1:3a73d77c2cef 121 USBD_LL_Init(pdev);
krebyy 1:3a73d77c2cef 122
krebyy 1:3a73d77c2cef 123 return USBD_OK;
krebyy 1:3a73d77c2cef 124 }
krebyy 1:3a73d77c2cef 125
krebyy 1:3a73d77c2cef 126 /**
krebyy 1:3a73d77c2cef 127 * @brief USBD_DeInit
krebyy 1:3a73d77c2cef 128 * Re-Initialize th device library
krebyy 1:3a73d77c2cef 129 * @param pdev: device instance
krebyy 1:3a73d77c2cef 130 * @retval status: status
krebyy 1:3a73d77c2cef 131 */
krebyy 1:3a73d77c2cef 132 USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev)
krebyy 1:3a73d77c2cef 133 {
krebyy 1:3a73d77c2cef 134 /* Set Default State */
krebyy 1:3a73d77c2cef 135 pdev->dev_state = USBD_STATE_DEFAULT;
krebyy 1:3a73d77c2cef 136
krebyy 1:3a73d77c2cef 137 /* Free Class Resources */
krebyy 1:3a73d77c2cef 138 pdev->pClass->DeInit(pdev, pdev->dev_config);
krebyy 1:3a73d77c2cef 139
krebyy 1:3a73d77c2cef 140 /* Stop the low level driver */
krebyy 1:3a73d77c2cef 141 USBD_LL_Stop(pdev);
krebyy 1:3a73d77c2cef 142
krebyy 1:3a73d77c2cef 143 /* Initialize low level driver */
krebyy 1:3a73d77c2cef 144 USBD_LL_DeInit(pdev);
krebyy 1:3a73d77c2cef 145
krebyy 1:3a73d77c2cef 146 return USBD_OK;
krebyy 1:3a73d77c2cef 147 }
krebyy 1:3a73d77c2cef 148
krebyy 1:3a73d77c2cef 149
krebyy 1:3a73d77c2cef 150 /**
krebyy 1:3a73d77c2cef 151 * @brief USBD_RegisterClass
krebyy 1:3a73d77c2cef 152 * Link class driver to Device Core.
krebyy 1:3a73d77c2cef 153 * @param pDevice : Device Handle
krebyy 1:3a73d77c2cef 154 * @param pclass: Class handle
krebyy 1:3a73d77c2cef 155 * @retval USBD Status
krebyy 1:3a73d77c2cef 156 */
krebyy 1:3a73d77c2cef 157 USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass)
krebyy 1:3a73d77c2cef 158 {
krebyy 1:3a73d77c2cef 159 USBD_StatusTypeDef status = USBD_OK;
krebyy 1:3a73d77c2cef 160 if(pclass != 0)
krebyy 1:3a73d77c2cef 161 {
krebyy 1:3a73d77c2cef 162 /* link the class to the USB Device handle */
krebyy 1:3a73d77c2cef 163 pdev->pClass = pclass;
krebyy 1:3a73d77c2cef 164 status = USBD_OK;
krebyy 1:3a73d77c2cef 165 }
krebyy 1:3a73d77c2cef 166 else
krebyy 1:3a73d77c2cef 167 {
krebyy 1:3a73d77c2cef 168 USBD_ErrLog("Invalid Class handle");
krebyy 1:3a73d77c2cef 169 status = USBD_FAIL;
krebyy 1:3a73d77c2cef 170 }
krebyy 1:3a73d77c2cef 171
krebyy 1:3a73d77c2cef 172 return status;
krebyy 1:3a73d77c2cef 173 }
krebyy 1:3a73d77c2cef 174
krebyy 1:3a73d77c2cef 175 /**
krebyy 1:3a73d77c2cef 176 * @brief USBD_Start
krebyy 1:3a73d77c2cef 177 * Start the USB Device Core.
krebyy 1:3a73d77c2cef 178 * @param pdev: Device Handle
krebyy 1:3a73d77c2cef 179 * @retval USBD Status
krebyy 1:3a73d77c2cef 180 */
krebyy 1:3a73d77c2cef 181 USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev)
krebyy 1:3a73d77c2cef 182 {
krebyy 1:3a73d77c2cef 183
krebyy 1:3a73d77c2cef 184 /* Start the low level driver */
krebyy 1:3a73d77c2cef 185 USBD_LL_Start(pdev);
krebyy 1:3a73d77c2cef 186
krebyy 1:3a73d77c2cef 187 return USBD_OK;
krebyy 1:3a73d77c2cef 188 }
krebyy 1:3a73d77c2cef 189
krebyy 1:3a73d77c2cef 190 /**
krebyy 1:3a73d77c2cef 191 * @brief USBD_Stop
krebyy 1:3a73d77c2cef 192 * Stop the USB Device Core.
krebyy 1:3a73d77c2cef 193 * @param pdev: Device Handle
krebyy 1:3a73d77c2cef 194 * @retval USBD Status
krebyy 1:3a73d77c2cef 195 */
krebyy 1:3a73d77c2cef 196 USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev)
krebyy 1:3a73d77c2cef 197 {
krebyy 1:3a73d77c2cef 198 /* Free Class Resources */
krebyy 1:3a73d77c2cef 199 pdev->pClass->DeInit(pdev, pdev->dev_config);
krebyy 1:3a73d77c2cef 200
krebyy 1:3a73d77c2cef 201 /* Stop the low level driver */
krebyy 1:3a73d77c2cef 202 USBD_LL_Stop(pdev);
krebyy 1:3a73d77c2cef 203
krebyy 1:3a73d77c2cef 204 return USBD_OK;
krebyy 1:3a73d77c2cef 205 }
krebyy 1:3a73d77c2cef 206
krebyy 1:3a73d77c2cef 207 /**
krebyy 1:3a73d77c2cef 208 * @brief USBD_RunTestMode
krebyy 1:3a73d77c2cef 209 * Launch test mode process
krebyy 1:3a73d77c2cef 210 * @param pdev: device instance
krebyy 1:3a73d77c2cef 211 * @retval status
krebyy 1:3a73d77c2cef 212 */
krebyy 1:3a73d77c2cef 213 USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev)
krebyy 1:3a73d77c2cef 214 {
krebyy 1:3a73d77c2cef 215 return USBD_OK;
krebyy 1:3a73d77c2cef 216 }
krebyy 1:3a73d77c2cef 217
krebyy 1:3a73d77c2cef 218
krebyy 1:3a73d77c2cef 219 /**
krebyy 1:3a73d77c2cef 220 * @brief USBD_SetClassConfig
krebyy 1:3a73d77c2cef 221 * Configure device and start the interface
krebyy 1:3a73d77c2cef 222 * @param pdev: device instance
krebyy 1:3a73d77c2cef 223 * @param cfgidx: configuration index
krebyy 1:3a73d77c2cef 224 * @retval status
krebyy 1:3a73d77c2cef 225 */
krebyy 1:3a73d77c2cef 226
krebyy 1:3a73d77c2cef 227 USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
krebyy 1:3a73d77c2cef 228 {
krebyy 1:3a73d77c2cef 229 USBD_StatusTypeDef ret = USBD_FAIL;
krebyy 1:3a73d77c2cef 230
krebyy 1:3a73d77c2cef 231 if(pdev->pClass != NULL)
krebyy 1:3a73d77c2cef 232 {
krebyy 1:3a73d77c2cef 233 /* Set configuration and Start the Class*/
krebyy 1:3a73d77c2cef 234 if(pdev->pClass->Init(pdev, cfgidx) == 0)
krebyy 1:3a73d77c2cef 235 {
krebyy 1:3a73d77c2cef 236 ret = USBD_OK;
krebyy 1:3a73d77c2cef 237 }
krebyy 1:3a73d77c2cef 238 }
krebyy 1:3a73d77c2cef 239 return ret;
krebyy 1:3a73d77c2cef 240 }
krebyy 1:3a73d77c2cef 241
krebyy 1:3a73d77c2cef 242 /**
krebyy 1:3a73d77c2cef 243 * @brief USBD_ClrClassConfig
krebyy 1:3a73d77c2cef 244 * Clear current configuration
krebyy 1:3a73d77c2cef 245 * @param pdev: device instance
krebyy 1:3a73d77c2cef 246 * @param cfgidx: configuration index
krebyy 1:3a73d77c2cef 247 * @retval status: USBD_StatusTypeDef
krebyy 1:3a73d77c2cef 248 */
krebyy 1:3a73d77c2cef 249 USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
krebyy 1:3a73d77c2cef 250 {
krebyy 1:3a73d77c2cef 251 /* Clear configuration and De-initialize the Class process*/
krebyy 1:3a73d77c2cef 252 pdev->pClass->DeInit(pdev, cfgidx);
krebyy 1:3a73d77c2cef 253 return USBD_OK;
krebyy 1:3a73d77c2cef 254 }
krebyy 1:3a73d77c2cef 255
krebyy 1:3a73d77c2cef 256
krebyy 1:3a73d77c2cef 257 /**
krebyy 1:3a73d77c2cef 258 * @brief USBD_SetupStage
krebyy 1:3a73d77c2cef 259 * Handle the setup stage
krebyy 1:3a73d77c2cef 260 * @param pdev: device instance
krebyy 1:3a73d77c2cef 261 * @retval status
krebyy 1:3a73d77c2cef 262 */
krebyy 1:3a73d77c2cef 263 USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup)
krebyy 1:3a73d77c2cef 264 {
krebyy 1:3a73d77c2cef 265
krebyy 1:3a73d77c2cef 266 USBD_ParseSetupRequest(&pdev->request, psetup);
krebyy 1:3a73d77c2cef 267
krebyy 1:3a73d77c2cef 268 pdev->ep0_state = USBD_EP0_SETUP;
krebyy 1:3a73d77c2cef 269 pdev->ep0_data_len = pdev->request.wLength;
krebyy 1:3a73d77c2cef 270
krebyy 1:3a73d77c2cef 271 switch (pdev->request.bmRequest & 0x1F)
krebyy 1:3a73d77c2cef 272 {
krebyy 1:3a73d77c2cef 273 case USB_REQ_RECIPIENT_DEVICE:
krebyy 1:3a73d77c2cef 274 USBD_StdDevReq (pdev, &pdev->request);
krebyy 1:3a73d77c2cef 275 break;
krebyy 1:3a73d77c2cef 276
krebyy 1:3a73d77c2cef 277 case USB_REQ_RECIPIENT_INTERFACE:
krebyy 1:3a73d77c2cef 278 USBD_StdItfReq(pdev, &pdev->request);
krebyy 1:3a73d77c2cef 279 break;
krebyy 1:3a73d77c2cef 280
krebyy 1:3a73d77c2cef 281 case USB_REQ_RECIPIENT_ENDPOINT:
krebyy 1:3a73d77c2cef 282 USBD_StdEPReq(pdev, &pdev->request);
krebyy 1:3a73d77c2cef 283 break;
krebyy 1:3a73d77c2cef 284
krebyy 1:3a73d77c2cef 285 default:
krebyy 1:3a73d77c2cef 286 USBD_LL_StallEP(pdev , pdev->request.bmRequest & 0x80);
krebyy 1:3a73d77c2cef 287 break;
krebyy 1:3a73d77c2cef 288 }
krebyy 1:3a73d77c2cef 289 return USBD_OK;
krebyy 1:3a73d77c2cef 290 }
krebyy 1:3a73d77c2cef 291
krebyy 1:3a73d77c2cef 292 /**
krebyy 1:3a73d77c2cef 293 * @brief USBD_DataOutStage
krebyy 1:3a73d77c2cef 294 * Handle data OUT stage
krebyy 1:3a73d77c2cef 295 * @param pdev: device instance
krebyy 1:3a73d77c2cef 296 * @param epnum: endpoint index
krebyy 1:3a73d77c2cef 297 * @retval status
krebyy 1:3a73d77c2cef 298 */
krebyy 1:3a73d77c2cef 299 USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata)
krebyy 1:3a73d77c2cef 300 {
krebyy 1:3a73d77c2cef 301 USBD_EndpointTypeDef *pep;
krebyy 1:3a73d77c2cef 302
krebyy 1:3a73d77c2cef 303 if(epnum == 0)
krebyy 1:3a73d77c2cef 304 {
krebyy 1:3a73d77c2cef 305 pep = &pdev->ep_out[0];
krebyy 1:3a73d77c2cef 306
krebyy 1:3a73d77c2cef 307 if ( pdev->ep0_state == USBD_EP0_DATA_OUT)
krebyy 1:3a73d77c2cef 308 {
krebyy 1:3a73d77c2cef 309 if(pep->rem_length > pep->maxpacket)
krebyy 1:3a73d77c2cef 310 {
krebyy 1:3a73d77c2cef 311 pep->rem_length -= pep->maxpacket;
krebyy 1:3a73d77c2cef 312
krebyy 1:3a73d77c2cef 313 USBD_CtlContinueRx (pdev,
krebyy 1:3a73d77c2cef 314 pdata,
krebyy 1:3a73d77c2cef 315 MIN(pep->rem_length ,pep->maxpacket));
krebyy 1:3a73d77c2cef 316 }
krebyy 1:3a73d77c2cef 317 else
krebyy 1:3a73d77c2cef 318 {
krebyy 1:3a73d77c2cef 319 if((pdev->pClass->EP0_RxReady != NULL)&&
krebyy 1:3a73d77c2cef 320 (pdev->dev_state == USBD_STATE_CONFIGURED))
krebyy 1:3a73d77c2cef 321 {
krebyy 1:3a73d77c2cef 322 pdev->pClass->EP0_RxReady(pdev);
krebyy 1:3a73d77c2cef 323 }
krebyy 1:3a73d77c2cef 324 USBD_CtlSendStatus(pdev);
krebyy 1:3a73d77c2cef 325 }
krebyy 1:3a73d77c2cef 326 }
krebyy 1:3a73d77c2cef 327 }
krebyy 1:3a73d77c2cef 328 else if((pdev->pClass->DataOut != NULL)&&
krebyy 1:3a73d77c2cef 329 (pdev->dev_state == USBD_STATE_CONFIGURED))
krebyy 1:3a73d77c2cef 330 {
krebyy 1:3a73d77c2cef 331 pdev->pClass->DataOut(pdev, epnum);
krebyy 1:3a73d77c2cef 332 }
krebyy 1:3a73d77c2cef 333 return USBD_OK;
krebyy 1:3a73d77c2cef 334 }
krebyy 1:3a73d77c2cef 335
krebyy 1:3a73d77c2cef 336 /**
krebyy 1:3a73d77c2cef 337 * @brief USBD_DataInStage
krebyy 1:3a73d77c2cef 338 * Handle data in stage
krebyy 1:3a73d77c2cef 339 * @param pdev: device instance
krebyy 1:3a73d77c2cef 340 * @param epnum: endpoint index
krebyy 1:3a73d77c2cef 341 * @retval status
krebyy 1:3a73d77c2cef 342 */
krebyy 1:3a73d77c2cef 343 USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev ,uint8_t epnum, uint8_t *pdata)
krebyy 1:3a73d77c2cef 344 {
krebyy 1:3a73d77c2cef 345 USBD_EndpointTypeDef *pep;
krebyy 1:3a73d77c2cef 346
krebyy 1:3a73d77c2cef 347 if(epnum == 0)
krebyy 1:3a73d77c2cef 348 {
krebyy 1:3a73d77c2cef 349 pep = &pdev->ep_in[0];
krebyy 1:3a73d77c2cef 350
krebyy 1:3a73d77c2cef 351 if ( pdev->ep0_state == USBD_EP0_DATA_IN)
krebyy 1:3a73d77c2cef 352 {
krebyy 1:3a73d77c2cef 353 if(pep->rem_length > pep->maxpacket)
krebyy 1:3a73d77c2cef 354 {
krebyy 1:3a73d77c2cef 355 pep->rem_length -= pep->maxpacket;
krebyy 1:3a73d77c2cef 356
krebyy 1:3a73d77c2cef 357 USBD_CtlContinueSendData (pdev,
krebyy 1:3a73d77c2cef 358 pdata,
krebyy 1:3a73d77c2cef 359 pep->rem_length);
krebyy 1:3a73d77c2cef 360 }
krebyy 1:3a73d77c2cef 361 else
krebyy 1:3a73d77c2cef 362 { /* last packet is MPS multiple, so send ZLP packet */
krebyy 1:3a73d77c2cef 363 if((pep->total_length % pep->maxpacket == 0) &&
krebyy 1:3a73d77c2cef 364 (pep->total_length >= pep->maxpacket) &&
krebyy 1:3a73d77c2cef 365 (pep->total_length < pdev->ep0_data_len ))
krebyy 1:3a73d77c2cef 366 {
krebyy 1:3a73d77c2cef 367
krebyy 1:3a73d77c2cef 368 USBD_CtlContinueSendData(pdev , NULL, 0);
krebyy 1:3a73d77c2cef 369 pdev->ep0_data_len = 0;
krebyy 1:3a73d77c2cef 370 }
krebyy 1:3a73d77c2cef 371 else
krebyy 1:3a73d77c2cef 372 {
krebyy 1:3a73d77c2cef 373 if((pdev->pClass->EP0_TxSent != NULL)&&
krebyy 1:3a73d77c2cef 374 (pdev->dev_state == USBD_STATE_CONFIGURED))
krebyy 1:3a73d77c2cef 375 {
krebyy 1:3a73d77c2cef 376 pdev->pClass->EP0_TxSent(pdev);
krebyy 1:3a73d77c2cef 377 }
krebyy 1:3a73d77c2cef 378 USBD_CtlReceiveStatus(pdev);
krebyy 1:3a73d77c2cef 379 }
krebyy 1:3a73d77c2cef 380 }
krebyy 1:3a73d77c2cef 381 }
krebyy 1:3a73d77c2cef 382 if (pdev->dev_test_mode == 1)
krebyy 1:3a73d77c2cef 383 {
krebyy 1:3a73d77c2cef 384 USBD_RunTestMode(pdev);
krebyy 1:3a73d77c2cef 385 pdev->dev_test_mode = 0;
krebyy 1:3a73d77c2cef 386 }
krebyy 1:3a73d77c2cef 387 }
krebyy 1:3a73d77c2cef 388 else if((pdev->pClass->DataIn != NULL)&&
krebyy 1:3a73d77c2cef 389 (pdev->dev_state == USBD_STATE_CONFIGURED))
krebyy 1:3a73d77c2cef 390 {
krebyy 1:3a73d77c2cef 391 pdev->pClass->DataIn(pdev, epnum);
krebyy 1:3a73d77c2cef 392 }
krebyy 1:3a73d77c2cef 393 return USBD_OK;
krebyy 1:3a73d77c2cef 394 }
krebyy 1:3a73d77c2cef 395
krebyy 1:3a73d77c2cef 396 /**
krebyy 1:3a73d77c2cef 397 * @brief USBD_LL_Reset
krebyy 1:3a73d77c2cef 398 * Handle Reset event
krebyy 1:3a73d77c2cef 399 * @param pdev: device instance
krebyy 1:3a73d77c2cef 400 * @retval status
krebyy 1:3a73d77c2cef 401 */
krebyy 1:3a73d77c2cef 402
krebyy 1:3a73d77c2cef 403 USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev)
krebyy 1:3a73d77c2cef 404 {
krebyy 1:3a73d77c2cef 405 /* Open EP0 OUT */
krebyy 1:3a73d77c2cef 406 USBD_LL_OpenEP(pdev,
krebyy 1:3a73d77c2cef 407 0x00,
krebyy 1:3a73d77c2cef 408 USBD_EP_TYPE_CTRL,
krebyy 1:3a73d77c2cef 409 USB_MAX_EP0_SIZE);
krebyy 1:3a73d77c2cef 410
krebyy 1:3a73d77c2cef 411 pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE;
krebyy 1:3a73d77c2cef 412
krebyy 1:3a73d77c2cef 413 /* Open EP0 IN */
krebyy 1:3a73d77c2cef 414 USBD_LL_OpenEP(pdev,
krebyy 1:3a73d77c2cef 415 0x80,
krebyy 1:3a73d77c2cef 416 USBD_EP_TYPE_CTRL,
krebyy 1:3a73d77c2cef 417 USB_MAX_EP0_SIZE);
krebyy 1:3a73d77c2cef 418
krebyy 1:3a73d77c2cef 419 pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE;
krebyy 1:3a73d77c2cef 420 /* Upon Reset call user call back */
krebyy 1:3a73d77c2cef 421 pdev->dev_state = USBD_STATE_DEFAULT;
krebyy 1:3a73d77c2cef 422
krebyy 1:3a73d77c2cef 423 if (pdev->pClassData)
krebyy 1:3a73d77c2cef 424 pdev->pClass->DeInit(pdev, pdev->dev_config);
krebyy 1:3a73d77c2cef 425
krebyy 1:3a73d77c2cef 426
krebyy 1:3a73d77c2cef 427 return USBD_OK;
krebyy 1:3a73d77c2cef 428 }
krebyy 1:3a73d77c2cef 429
krebyy 1:3a73d77c2cef 430
krebyy 1:3a73d77c2cef 431
krebyy 1:3a73d77c2cef 432
krebyy 1:3a73d77c2cef 433 /**
krebyy 1:3a73d77c2cef 434 * @brief USBD_LL_Reset
krebyy 1:3a73d77c2cef 435 * Handle Reset event
krebyy 1:3a73d77c2cef 436 * @param pdev: device instance
krebyy 1:3a73d77c2cef 437 * @retval status
krebyy 1:3a73d77c2cef 438 */
krebyy 1:3a73d77c2cef 439 USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed)
krebyy 1:3a73d77c2cef 440 {
krebyy 1:3a73d77c2cef 441 pdev->dev_speed = speed;
krebyy 1:3a73d77c2cef 442 return USBD_OK;
krebyy 1:3a73d77c2cef 443 }
krebyy 1:3a73d77c2cef 444
krebyy 1:3a73d77c2cef 445 /**
krebyy 1:3a73d77c2cef 446 * @brief USBD_Suspend
krebyy 1:3a73d77c2cef 447 * Handle Suspend event
krebyy 1:3a73d77c2cef 448 * @param pdev: device instance
krebyy 1:3a73d77c2cef 449 * @retval status
krebyy 1:3a73d77c2cef 450 */
krebyy 1:3a73d77c2cef 451
krebyy 1:3a73d77c2cef 452 USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev)
krebyy 1:3a73d77c2cef 453 {
krebyy 1:3a73d77c2cef 454 pdev->dev_old_state = pdev->dev_state;
krebyy 1:3a73d77c2cef 455 pdev->dev_state = USBD_STATE_SUSPENDED;
krebyy 1:3a73d77c2cef 456 return USBD_OK;
krebyy 1:3a73d77c2cef 457 }
krebyy 1:3a73d77c2cef 458
krebyy 1:3a73d77c2cef 459 /**
krebyy 1:3a73d77c2cef 460 * @brief USBD_Resume
krebyy 1:3a73d77c2cef 461 * Handle Resume event
krebyy 1:3a73d77c2cef 462 * @param pdev: device instance
krebyy 1:3a73d77c2cef 463 * @retval status
krebyy 1:3a73d77c2cef 464 */
krebyy 1:3a73d77c2cef 465
krebyy 1:3a73d77c2cef 466 USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev)
krebyy 1:3a73d77c2cef 467 {
krebyy 1:3a73d77c2cef 468 pdev->dev_state = pdev->dev_old_state;
krebyy 1:3a73d77c2cef 469 return USBD_OK;
krebyy 1:3a73d77c2cef 470 }
krebyy 1:3a73d77c2cef 471
krebyy 1:3a73d77c2cef 472 /**
krebyy 1:3a73d77c2cef 473 * @brief USBD_SOF
krebyy 1:3a73d77c2cef 474 * Handle SOF event
krebyy 1:3a73d77c2cef 475 * @param pdev: device instance
krebyy 1:3a73d77c2cef 476 * @retval status
krebyy 1:3a73d77c2cef 477 */
krebyy 1:3a73d77c2cef 478
krebyy 1:3a73d77c2cef 479 USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev)
krebyy 1:3a73d77c2cef 480 {
krebyy 1:3a73d77c2cef 481 if(pdev->dev_state == USBD_STATE_CONFIGURED)
krebyy 1:3a73d77c2cef 482 {
krebyy 1:3a73d77c2cef 483 if(pdev->pClass->SOF != NULL)
krebyy 1:3a73d77c2cef 484 {
krebyy 1:3a73d77c2cef 485 pdev->pClass->SOF(pdev);
krebyy 1:3a73d77c2cef 486 }
krebyy 1:3a73d77c2cef 487 }
krebyy 1:3a73d77c2cef 488 return USBD_OK;
krebyy 1:3a73d77c2cef 489 }
krebyy 1:3a73d77c2cef 490
krebyy 1:3a73d77c2cef 491 /**
krebyy 1:3a73d77c2cef 492 * @brief USBD_IsoINIncomplete
krebyy 1:3a73d77c2cef 493 * Handle iso in incomplete event
krebyy 1:3a73d77c2cef 494 * @param pdev: device instance
krebyy 1:3a73d77c2cef 495 * @retval status
krebyy 1:3a73d77c2cef 496 */
krebyy 1:3a73d77c2cef 497 USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
krebyy 1:3a73d77c2cef 498 {
krebyy 1:3a73d77c2cef 499 return USBD_OK;
krebyy 1:3a73d77c2cef 500 }
krebyy 1:3a73d77c2cef 501
krebyy 1:3a73d77c2cef 502 /**
krebyy 1:3a73d77c2cef 503 * @brief USBD_IsoOUTIncomplete
krebyy 1:3a73d77c2cef 504 * Handle iso out incomplete event
krebyy 1:3a73d77c2cef 505 * @param pdev: device instance
krebyy 1:3a73d77c2cef 506 * @retval status
krebyy 1:3a73d77c2cef 507 */
krebyy 1:3a73d77c2cef 508 USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
krebyy 1:3a73d77c2cef 509 {
krebyy 1:3a73d77c2cef 510 return USBD_OK;
krebyy 1:3a73d77c2cef 511 }
krebyy 1:3a73d77c2cef 512
krebyy 1:3a73d77c2cef 513 /**
krebyy 1:3a73d77c2cef 514 * @brief USBD_DevConnected
krebyy 1:3a73d77c2cef 515 * Handle device connection event
krebyy 1:3a73d77c2cef 516 * @param pdev: device instance
krebyy 1:3a73d77c2cef 517 * @retval status
krebyy 1:3a73d77c2cef 518 */
krebyy 1:3a73d77c2cef 519 USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev)
krebyy 1:3a73d77c2cef 520 {
krebyy 1:3a73d77c2cef 521 return USBD_OK;
krebyy 1:3a73d77c2cef 522 }
krebyy 1:3a73d77c2cef 523
krebyy 1:3a73d77c2cef 524 /**
krebyy 1:3a73d77c2cef 525 * @brief USBD_DevDisconnected
krebyy 1:3a73d77c2cef 526 * Handle device disconnection event
krebyy 1:3a73d77c2cef 527 * @param pdev: device instance
krebyy 1:3a73d77c2cef 528 * @retval status
krebyy 1:3a73d77c2cef 529 */
krebyy 1:3a73d77c2cef 530 USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev)
krebyy 1:3a73d77c2cef 531 {
krebyy 1:3a73d77c2cef 532 /* Free Class Resources */
krebyy 1:3a73d77c2cef 533 pdev->dev_state = USBD_STATE_DEFAULT;
krebyy 1:3a73d77c2cef 534 pdev->pClass->DeInit(pdev, pdev->dev_config);
krebyy 1:3a73d77c2cef 535
krebyy 1:3a73d77c2cef 536 return USBD_OK;
krebyy 1:3a73d77c2cef 537 }
krebyy 1:3a73d77c2cef 538 /**
krebyy 1:3a73d77c2cef 539 * @}
krebyy 1:3a73d77c2cef 540 */
krebyy 1:3a73d77c2cef 541
krebyy 1:3a73d77c2cef 542
krebyy 1:3a73d77c2cef 543 /**
krebyy 1:3a73d77c2cef 544 * @}
krebyy 1:3a73d77c2cef 545 */
krebyy 1:3a73d77c2cef 546
krebyy 1:3a73d77c2cef 547
krebyy 1:3a73d77c2cef 548 /**
krebyy 1:3a73d77c2cef 549 * @}
krebyy 1:3a73d77c2cef 550 */
krebyy 1:3a73d77c2cef 551
krebyy 1:3a73d77c2cef 552 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
krebyy 1:3a73d77c2cef 553