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:11:00 2017 +0000
Revision:
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 umart_lite_plus_teste/src/usbd_conf.c
krebyy 1:3a73d77c2cef 4 * @author MCD Application Team
krebyy 1:3a73d77c2cef 5 * @version V1.2.0
krebyy 1:3a73d77c2cef 6 * @date 26-December-2014
krebyy 1:3a73d77c2cef 7 * @brief This file implements the USB Device library callbacks and MSP
krebyy 1:3a73d77c2cef 8 ******************************************************************************
krebyy 1:3a73d77c2cef 9 * @attention
krebyy 1:3a73d77c2cef 10 *
krebyy 1:3a73d77c2cef 11 * <h2><center>&copy; COPYRIGHT(c) 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 * @remark
krebyy 1:3a73d77c2cef 27 * Funções HAL_PCD_MspInit, HAL_PCD_MspDeInit e USBD_LL_Init modificadas por
krebyy 1:3a73d77c2cef 28 * Kleber Lima da Silva (kleber.ufu@hotmail.com) em 26-Abril-2015
krebyy 1:3a73d77c2cef 29 *
krebyy 1:3a73d77c2cef 30 */
krebyy 1:3a73d77c2cef 31
krebyy 1:3a73d77c2cef 32 /* Includes ------------------------------------------------------------------*/
krebyy 1:3a73d77c2cef 33 #include "stm32f4xx_hal.h"
krebyy 1:3a73d77c2cef 34 #include "usbd_core.h"
krebyy 1:3a73d77c2cef 35
krebyy 1:3a73d77c2cef 36
krebyy 1:3a73d77c2cef 37 /* Private typedef -----------------------------------------------------------*/
krebyy 1:3a73d77c2cef 38 /* Private define ------------------------------------------------------------*/
krebyy 1:3a73d77c2cef 39 /* Private macro -------------------------------------------------------------*/
krebyy 1:3a73d77c2cef 40 /* Private variables ---------------------------------------------------------*/
krebyy 1:3a73d77c2cef 41 PCD_HandleTypeDef hpcd;
krebyy 1:3a73d77c2cef 42
krebyy 1:3a73d77c2cef 43 /* Private function prototypes -----------------------------------------------*/
krebyy 1:3a73d77c2cef 44 /* Private functions ---------------------------------------------------------*/
krebyy 1:3a73d77c2cef 45
krebyy 1:3a73d77c2cef 46 /*******************************************************************************
krebyy 1:3a73d77c2cef 47 PCD BSP Routines
krebyy 1:3a73d77c2cef 48 *******************************************************************************/
krebyy 1:3a73d77c2cef 49 /**
krebyy 1:3a73d77c2cef 50 * @brief Initializes the PCD MSP.
krebyy 1:3a73d77c2cef 51 * @param hpcd: PCD handle
krebyy 1:3a73d77c2cef 52 * @retval None
krebyy 1:3a73d77c2cef 53 */
krebyy 1:3a73d77c2cef 54 void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
krebyy 1:3a73d77c2cef 55 {
krebyy 1:3a73d77c2cef 56 GPIO_InitTypeDef GPIO_InitStruct;
krebyy 1:3a73d77c2cef 57
krebyy 1:3a73d77c2cef 58 if(hpcd->Instance == USB_OTG_FS)
krebyy 1:3a73d77c2cef 59 {
krebyy 1:3a73d77c2cef 60 /* Configure USB FS GPIOs */
krebyy 1:3a73d77c2cef 61
krebyy 1:3a73d77c2cef 62 __GPIOA_CLK_ENABLE();
krebyy 1:3a73d77c2cef 63
krebyy 1:3a73d77c2cef 64 /* Configure DM DP Pins */
krebyy 1:3a73d77c2cef 65 GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
krebyy 1:3a73d77c2cef 66 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
krebyy 1:3a73d77c2cef 67 GPIO_InitStruct.Pull = GPIO_NOPULL;
krebyy 1:3a73d77c2cef 68 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
krebyy 1:3a73d77c2cef 69 GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
krebyy 1:3a73d77c2cef 70 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
krebyy 1:3a73d77c2cef 71
krebyy 1:3a73d77c2cef 72 /* Configure VBUS Pin */
krebyy 1:3a73d77c2cef 73 /*GPIO_InitStruct.Pin = GPIO_PIN_9;
krebyy 1:3a73d77c2cef 74 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
krebyy 1:3a73d77c2cef 75 GPIO_InitStruct.Pull = GPIO_NOPULL;
krebyy 1:3a73d77c2cef 76 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);*/
krebyy 1:3a73d77c2cef 77
krebyy 1:3a73d77c2cef 78 /* Configure ID pin */
krebyy 1:3a73d77c2cef 79 /*GPIO_InitStruct.Pin = GPIO_PIN_10;
krebyy 1:3a73d77c2cef 80 GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
krebyy 1:3a73d77c2cef 81 GPIO_InitStruct.Pull = GPIO_PULLUP;
krebyy 1:3a73d77c2cef 82 GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
krebyy 1:3a73d77c2cef 83 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);*/
krebyy 1:3a73d77c2cef 84
krebyy 1:3a73d77c2cef 85 /* Enable USB FS Clocks */
krebyy 1:3a73d77c2cef 86 __USB_OTG_FS_CLK_ENABLE();
krebyy 1:3a73d77c2cef 87
krebyy 1:3a73d77c2cef 88 /* Set USBFS Interrupt priority */
krebyy 1:3a73d77c2cef 89 HAL_NVIC_SetPriority(OTG_FS_IRQn, 6, 0);
krebyy 1:3a73d77c2cef 90
krebyy 1:3a73d77c2cef 91 /* Enable USBFS Interrupt */
krebyy 1:3a73d77c2cef 92 HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
krebyy 1:3a73d77c2cef 93 }
krebyy 1:3a73d77c2cef 94 }
krebyy 1:3a73d77c2cef 95 /**
krebyy 1:3a73d77c2cef 96 * @brief DeInitializes the PCD MSP.
krebyy 1:3a73d77c2cef 97 * @param hpcd: PCD handle
krebyy 1:3a73d77c2cef 98 * @retval None
krebyy 1:3a73d77c2cef 99 */
krebyy 1:3a73d77c2cef 100 void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd)
krebyy 1:3a73d77c2cef 101 {
krebyy 1:3a73d77c2cef 102 if(hpcd->Instance == USB_OTG_FS)
krebyy 1:3a73d77c2cef 103 {
krebyy 1:3a73d77c2cef 104 /* Disable USB FS Clocks */
krebyy 1:3a73d77c2cef 105 __USB_OTG_FS_CLK_DISABLE();
krebyy 1:3a73d77c2cef 106 __SYSCFG_CLK_DISABLE();
krebyy 1:3a73d77c2cef 107 }
krebyy 1:3a73d77c2cef 108 }
krebyy 1:3a73d77c2cef 109
krebyy 1:3a73d77c2cef 110 /*******************************************************************************
krebyy 1:3a73d77c2cef 111 LL Driver Callbacks (PCD -> USB Device Library)
krebyy 1:3a73d77c2cef 112 *******************************************************************************/
krebyy 1:3a73d77c2cef 113
krebyy 1:3a73d77c2cef 114
krebyy 1:3a73d77c2cef 115 /**
krebyy 1:3a73d77c2cef 116 * @brief Setup stage callback.
krebyy 1:3a73d77c2cef 117 * @param hpcd: PCD handle
krebyy 1:3a73d77c2cef 118 * @retval None
krebyy 1:3a73d77c2cef 119 */
krebyy 1:3a73d77c2cef 120 void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
krebyy 1:3a73d77c2cef 121 {
krebyy 1:3a73d77c2cef 122 USBD_LL_SetupStage(hpcd->pData, (uint8_t *)hpcd->Setup);
krebyy 1:3a73d77c2cef 123 }
krebyy 1:3a73d77c2cef 124
krebyy 1:3a73d77c2cef 125 /**
krebyy 1:3a73d77c2cef 126 * @brief Data Out stage callback.
krebyy 1:3a73d77c2cef 127 * @param hpcd: PCD handle
krebyy 1:3a73d77c2cef 128 * @param epnum: Endpoint Number
krebyy 1:3a73d77c2cef 129 * @retval None
krebyy 1:3a73d77c2cef 130 */
krebyy 1:3a73d77c2cef 131 void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
krebyy 1:3a73d77c2cef 132 {
krebyy 1:3a73d77c2cef 133 USBD_LL_DataOutStage(hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff);
krebyy 1:3a73d77c2cef 134 }
krebyy 1:3a73d77c2cef 135
krebyy 1:3a73d77c2cef 136 /**
krebyy 1:3a73d77c2cef 137 * @brief Data In stage callback.
krebyy 1:3a73d77c2cef 138 * @param hpcd: PCD handle
krebyy 1:3a73d77c2cef 139 * @param epnum: Endpoint Number
krebyy 1:3a73d77c2cef 140 * @retval None
krebyy 1:3a73d77c2cef 141 */
krebyy 1:3a73d77c2cef 142 void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
krebyy 1:3a73d77c2cef 143 {
krebyy 1:3a73d77c2cef 144 USBD_LL_DataInStage(hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff);
krebyy 1:3a73d77c2cef 145 }
krebyy 1:3a73d77c2cef 146
krebyy 1:3a73d77c2cef 147 /**
krebyy 1:3a73d77c2cef 148 * @brief SOF callback.
krebyy 1:3a73d77c2cef 149 * @param hpcd: PCD handle
krebyy 1:3a73d77c2cef 150 * @retval None
krebyy 1:3a73d77c2cef 151 */
krebyy 1:3a73d77c2cef 152 void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
krebyy 1:3a73d77c2cef 153 {
krebyy 1:3a73d77c2cef 154 USBD_LL_SOF(hpcd->pData);
krebyy 1:3a73d77c2cef 155 }
krebyy 1:3a73d77c2cef 156
krebyy 1:3a73d77c2cef 157 /**
krebyy 1:3a73d77c2cef 158 * @brief Reset callback.
krebyy 1:3a73d77c2cef 159 * @param hpcd: PCD handle
krebyy 1:3a73d77c2cef 160 * @retval None
krebyy 1:3a73d77c2cef 161 */
krebyy 1:3a73d77c2cef 162 void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
krebyy 1:3a73d77c2cef 163 {
krebyy 1:3a73d77c2cef 164 USBD_SpeedTypeDef speed = USBD_SPEED_FULL;
krebyy 1:3a73d77c2cef 165
krebyy 1:3a73d77c2cef 166 /* Set USB Current Speed */
krebyy 1:3a73d77c2cef 167 switch(hpcd->Init.speed)
krebyy 1:3a73d77c2cef 168 {
krebyy 1:3a73d77c2cef 169 case PCD_SPEED_HIGH:
krebyy 1:3a73d77c2cef 170 speed = USBD_SPEED_HIGH;
krebyy 1:3a73d77c2cef 171 break;
krebyy 1:3a73d77c2cef 172
krebyy 1:3a73d77c2cef 173 case PCD_SPEED_FULL:
krebyy 1:3a73d77c2cef 174 speed = USBD_SPEED_FULL;
krebyy 1:3a73d77c2cef 175 break;
krebyy 1:3a73d77c2cef 176
krebyy 1:3a73d77c2cef 177 default:
krebyy 1:3a73d77c2cef 178 speed = USBD_SPEED_FULL;
krebyy 1:3a73d77c2cef 179 break;
krebyy 1:3a73d77c2cef 180 }
krebyy 1:3a73d77c2cef 181 USBD_LL_SetSpeed(hpcd->pData, speed);
krebyy 1:3a73d77c2cef 182
krebyy 1:3a73d77c2cef 183 /* Reset Device */
krebyy 1:3a73d77c2cef 184 USBD_LL_Reset(hpcd->pData);
krebyy 1:3a73d77c2cef 185 }
krebyy 1:3a73d77c2cef 186
krebyy 1:3a73d77c2cef 187 /**
krebyy 1:3a73d77c2cef 188 * @brief Suspend callback.
krebyy 1:3a73d77c2cef 189 * @param hpcd: PCD handle
krebyy 1:3a73d77c2cef 190 * @retval None
krebyy 1:3a73d77c2cef 191 */
krebyy 1:3a73d77c2cef 192 void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
krebyy 1:3a73d77c2cef 193 {
krebyy 1:3a73d77c2cef 194 USBD_LL_Suspend(hpcd->pData);
krebyy 1:3a73d77c2cef 195 }
krebyy 1:3a73d77c2cef 196
krebyy 1:3a73d77c2cef 197 /**
krebyy 1:3a73d77c2cef 198 * @brief Resume callback.
krebyy 1:3a73d77c2cef 199 * @param hpcd: PCD handle
krebyy 1:3a73d77c2cef 200 * @retval None
krebyy 1:3a73d77c2cef 201 */
krebyy 1:3a73d77c2cef 202 void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
krebyy 1:3a73d77c2cef 203 {
krebyy 1:3a73d77c2cef 204 USBD_LL_Resume(hpcd->pData);
krebyy 1:3a73d77c2cef 205 }
krebyy 1:3a73d77c2cef 206
krebyy 1:3a73d77c2cef 207 /**
krebyy 1:3a73d77c2cef 208 * @brief ISOC Out Incomplete callback.
krebyy 1:3a73d77c2cef 209 * @param hpcd: PCD handle
krebyy 1:3a73d77c2cef 210 * @param epnum: Endpoint Number
krebyy 1:3a73d77c2cef 211 * @retval None
krebyy 1:3a73d77c2cef 212 */
krebyy 1:3a73d77c2cef 213 void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
krebyy 1:3a73d77c2cef 214 {
krebyy 1:3a73d77c2cef 215 USBD_LL_IsoOUTIncomplete(hpcd->pData, epnum);
krebyy 1:3a73d77c2cef 216 }
krebyy 1:3a73d77c2cef 217
krebyy 1:3a73d77c2cef 218 /**
krebyy 1:3a73d77c2cef 219 * @brief ISOC In Incomplete callback.
krebyy 1:3a73d77c2cef 220 * @param hpcd: PCD handle
krebyy 1:3a73d77c2cef 221 * @param epnum: Endpoint Number
krebyy 1:3a73d77c2cef 222 * @retval None
krebyy 1:3a73d77c2cef 223 */
krebyy 1:3a73d77c2cef 224 void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
krebyy 1:3a73d77c2cef 225 {
krebyy 1:3a73d77c2cef 226 USBD_LL_IsoINIncomplete(hpcd->pData, epnum);
krebyy 1:3a73d77c2cef 227 }
krebyy 1:3a73d77c2cef 228
krebyy 1:3a73d77c2cef 229 /**
krebyy 1:3a73d77c2cef 230 * @brief Connect callback.
krebyy 1:3a73d77c2cef 231 * @param hpcd: PCD handle
krebyy 1:3a73d77c2cef 232 * @retval None
krebyy 1:3a73d77c2cef 233 */
krebyy 1:3a73d77c2cef 234 void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
krebyy 1:3a73d77c2cef 235 {
krebyy 1:3a73d77c2cef 236 USBD_LL_DevConnected(hpcd->pData);
krebyy 1:3a73d77c2cef 237 }
krebyy 1:3a73d77c2cef 238
krebyy 1:3a73d77c2cef 239 /**
krebyy 1:3a73d77c2cef 240 * @brief Disconnect callback.
krebyy 1:3a73d77c2cef 241 * @param hpcd: PCD handle
krebyy 1:3a73d77c2cef 242 * @retval None
krebyy 1:3a73d77c2cef 243 */
krebyy 1:3a73d77c2cef 244 void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
krebyy 1:3a73d77c2cef 245 {
krebyy 1:3a73d77c2cef 246 USBD_LL_DevDisconnected(hpcd->pData);
krebyy 1:3a73d77c2cef 247 }
krebyy 1:3a73d77c2cef 248
krebyy 1:3a73d77c2cef 249 /*******************************************************************************
krebyy 1:3a73d77c2cef 250 LL Driver Interface (USB Device Library --> PCD)
krebyy 1:3a73d77c2cef 251 *******************************************************************************/
krebyy 1:3a73d77c2cef 252 /**
krebyy 1:3a73d77c2cef 253 * @brief Initializes the Low Level portion of the Device driver.
krebyy 1:3a73d77c2cef 254 * @param pdev: Device handle
krebyy 1:3a73d77c2cef 255 * @retval USBD Status
krebyy 1:3a73d77c2cef 256 */
krebyy 1:3a73d77c2cef 257 USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev)
krebyy 1:3a73d77c2cef 258 {
krebyy 1:3a73d77c2cef 259 /* Change Systick prioity */
krebyy 1:3a73d77c2cef 260 NVIC_SetPriority (SysTick_IRQn, 0);
krebyy 1:3a73d77c2cef 261
krebyy 1:3a73d77c2cef 262 /*Set LL Driver parameters */
krebyy 1:3a73d77c2cef 263 hpcd.Instance = USB_OTG_FS;
krebyy 1:3a73d77c2cef 264 hpcd.Init.dev_endpoints = 4;
krebyy 1:3a73d77c2cef 265 hpcd.Init.use_dedicated_ep1 = 0;
krebyy 1:3a73d77c2cef 266 hpcd.Init.ep0_mps = 0x40;
krebyy 1:3a73d77c2cef 267 hpcd.Init.dma_enable = 0;
krebyy 1:3a73d77c2cef 268 hpcd.Init.low_power_enable = 0;
krebyy 1:3a73d77c2cef 269 hpcd.Init.phy_itface = PCD_PHY_EMBEDDED;
krebyy 1:3a73d77c2cef 270 hpcd.Init.Sof_enable = 0;
krebyy 1:3a73d77c2cef 271 hpcd.Init.speed = PCD_SPEED_FULL;
krebyy 1:3a73d77c2cef 272 hpcd.Init.vbus_sensing_enable = 1;
krebyy 1:3a73d77c2cef 273 /* Link The driver to the stack */
krebyy 1:3a73d77c2cef 274 hpcd.pData = pdev;
krebyy 1:3a73d77c2cef 275 pdev->pData = &hpcd;
krebyy 1:3a73d77c2cef 276 /*Initialize LL Driver */
krebyy 1:3a73d77c2cef 277 HAL_PCD_Init(&hpcd);
krebyy 1:3a73d77c2cef 278
krebyy 1:3a73d77c2cef 279 HAL_PCDEx_SetRxFiFo(&hpcd, 0x80);
krebyy 1:3a73d77c2cef 280 HAL_PCDEx_SetTxFiFo(&hpcd, 0, 0x40);
krebyy 1:3a73d77c2cef 281 HAL_PCDEx_SetTxFiFo(&hpcd, 1, 0x80);
krebyy 1:3a73d77c2cef 282
krebyy 1:3a73d77c2cef 283 return USBD_OK;
krebyy 1:3a73d77c2cef 284 }
krebyy 1:3a73d77c2cef 285
krebyy 1:3a73d77c2cef 286 /**
krebyy 1:3a73d77c2cef 287 * @brief De-Initializes the Low Level portion of the Device driver.
krebyy 1:3a73d77c2cef 288 * @param pdev: Device handle
krebyy 1:3a73d77c2cef 289 * @retval USBD Status
krebyy 1:3a73d77c2cef 290 */
krebyy 1:3a73d77c2cef 291 USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
krebyy 1:3a73d77c2cef 292 {
krebyy 1:3a73d77c2cef 293 HAL_PCD_DeInit(pdev->pData);
krebyy 1:3a73d77c2cef 294 return USBD_OK;
krebyy 1:3a73d77c2cef 295 }
krebyy 1:3a73d77c2cef 296
krebyy 1:3a73d77c2cef 297 /**
krebyy 1:3a73d77c2cef 298 * @brief Starts the Low Level portion of the Device driver.
krebyy 1:3a73d77c2cef 299 * @param pdev: Device handle
krebyy 1:3a73d77c2cef 300 * @retval USBD Status
krebyy 1:3a73d77c2cef 301 */
krebyy 1:3a73d77c2cef 302 USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
krebyy 1:3a73d77c2cef 303 {
krebyy 1:3a73d77c2cef 304 HAL_PCD_Start(pdev->pData);
krebyy 1:3a73d77c2cef 305 return USBD_OK;
krebyy 1:3a73d77c2cef 306 }
krebyy 1:3a73d77c2cef 307
krebyy 1:3a73d77c2cef 308 /**
krebyy 1:3a73d77c2cef 309 * @brief Stops the Low Level portion of the Device driver.
krebyy 1:3a73d77c2cef 310 * @param pdev: Device handle
krebyy 1:3a73d77c2cef 311 * @retval USBD Status
krebyy 1:3a73d77c2cef 312 */
krebyy 1:3a73d77c2cef 313 USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
krebyy 1:3a73d77c2cef 314 {
krebyy 1:3a73d77c2cef 315 HAL_PCD_Stop(pdev->pData);
krebyy 1:3a73d77c2cef 316 return USBD_OK;
krebyy 1:3a73d77c2cef 317 }
krebyy 1:3a73d77c2cef 318
krebyy 1:3a73d77c2cef 319 /**
krebyy 1:3a73d77c2cef 320 * @brief Opens an endpoint of the Low Level Driver.
krebyy 1:3a73d77c2cef 321 * @param pdev: Device handle
krebyy 1:3a73d77c2cef 322 * @param ep_addr: Endpoint Number
krebyy 1:3a73d77c2cef 323 * @param ep_type: Endpoint Type
krebyy 1:3a73d77c2cef 324 * @param ep_mps: Endpoint Max Packet Size
krebyy 1:3a73d77c2cef 325 * @retval USBD Status
krebyy 1:3a73d77c2cef 326 */
krebyy 1:3a73d77c2cef 327 USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev,
krebyy 1:3a73d77c2cef 328 uint8_t ep_addr,
krebyy 1:3a73d77c2cef 329 uint8_t ep_type,
krebyy 1:3a73d77c2cef 330 uint16_t ep_mps)
krebyy 1:3a73d77c2cef 331 {
krebyy 1:3a73d77c2cef 332 HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type);
krebyy 1:3a73d77c2cef 333 return USBD_OK;
krebyy 1:3a73d77c2cef 334 }
krebyy 1:3a73d77c2cef 335
krebyy 1:3a73d77c2cef 336 /**
krebyy 1:3a73d77c2cef 337 * @brief Closes an endpoint of the Low Level Driver.
krebyy 1:3a73d77c2cef 338 * @param pdev: Device handle
krebyy 1:3a73d77c2cef 339 * @param ep_addr: Endpoint Number
krebyy 1:3a73d77c2cef 340 * @retval USBD Status
krebyy 1:3a73d77c2cef 341 */
krebyy 1:3a73d77c2cef 342 USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
krebyy 1:3a73d77c2cef 343 {
krebyy 1:3a73d77c2cef 344 HAL_PCD_EP_Close(pdev->pData, ep_addr);
krebyy 1:3a73d77c2cef 345 return USBD_OK;
krebyy 1:3a73d77c2cef 346 }
krebyy 1:3a73d77c2cef 347
krebyy 1:3a73d77c2cef 348 /**
krebyy 1:3a73d77c2cef 349 * @brief Flushes an endpoint of the Low Level Driver.
krebyy 1:3a73d77c2cef 350 * @param pdev: Device handle
krebyy 1:3a73d77c2cef 351 * @param ep_addr: Endpoint Number
krebyy 1:3a73d77c2cef 352 * @retval USBD Status
krebyy 1:3a73d77c2cef 353 */
krebyy 1:3a73d77c2cef 354 USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
krebyy 1:3a73d77c2cef 355 {
krebyy 1:3a73d77c2cef 356 HAL_PCD_EP_Flush(pdev->pData, ep_addr);
krebyy 1:3a73d77c2cef 357 return USBD_OK;
krebyy 1:3a73d77c2cef 358 }
krebyy 1:3a73d77c2cef 359
krebyy 1:3a73d77c2cef 360 /**
krebyy 1:3a73d77c2cef 361 * @brief Sets a Stall condition on an endpoint of the Low Level Driver.
krebyy 1:3a73d77c2cef 362 * @param pdev: Device handle
krebyy 1:3a73d77c2cef 363 * @param ep_addr: Endpoint Number
krebyy 1:3a73d77c2cef 364 * @retval USBD Status
krebyy 1:3a73d77c2cef 365 */
krebyy 1:3a73d77c2cef 366 USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
krebyy 1:3a73d77c2cef 367 {
krebyy 1:3a73d77c2cef 368 HAL_PCD_EP_SetStall(pdev->pData, ep_addr);
krebyy 1:3a73d77c2cef 369 return USBD_OK;
krebyy 1:3a73d77c2cef 370 }
krebyy 1:3a73d77c2cef 371
krebyy 1:3a73d77c2cef 372 /**
krebyy 1:3a73d77c2cef 373 * @brief Clears a Stall condition on an endpoint of the Low Level Driver.
krebyy 1:3a73d77c2cef 374 * @param pdev: Device handle
krebyy 1:3a73d77c2cef 375 * @param ep_addr: Endpoint Number
krebyy 1:3a73d77c2cef 376 * @retval USBD Status
krebyy 1:3a73d77c2cef 377 */
krebyy 1:3a73d77c2cef 378 USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
krebyy 1:3a73d77c2cef 379 {
krebyy 1:3a73d77c2cef 380 HAL_PCD_EP_ClrStall(pdev->pData, ep_addr);
krebyy 1:3a73d77c2cef 381 return USBD_OK;
krebyy 1:3a73d77c2cef 382 }
krebyy 1:3a73d77c2cef 383
krebyy 1:3a73d77c2cef 384 /**
krebyy 1:3a73d77c2cef 385 * @brief Returns Stall condition.
krebyy 1:3a73d77c2cef 386 * @param pdev: Device handle
krebyy 1:3a73d77c2cef 387 * @param ep_addr: Endpoint Number
krebyy 1:3a73d77c2cef 388 * @retval Stall (1: yes, 0: No)
krebyy 1:3a73d77c2cef 389 */
krebyy 1:3a73d77c2cef 390 uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
krebyy 1:3a73d77c2cef 391 {
krebyy 1:3a73d77c2cef 392 PCD_HandleTypeDef *hpcd = pdev->pData;
krebyy 1:3a73d77c2cef 393
krebyy 1:3a73d77c2cef 394 if((ep_addr & 0x80) == 0x80)
krebyy 1:3a73d77c2cef 395 {
krebyy 1:3a73d77c2cef 396 return hpcd->IN_ep[ep_addr & 0x7F].is_stall;
krebyy 1:3a73d77c2cef 397 }
krebyy 1:3a73d77c2cef 398 else
krebyy 1:3a73d77c2cef 399 {
krebyy 1:3a73d77c2cef 400 return hpcd->OUT_ep[ep_addr & 0x7F].is_stall;
krebyy 1:3a73d77c2cef 401 }
krebyy 1:3a73d77c2cef 402 }
krebyy 1:3a73d77c2cef 403
krebyy 1:3a73d77c2cef 404 /**
krebyy 1:3a73d77c2cef 405 * @brief Assigns an USB address to the device
krebyy 1:3a73d77c2cef 406 * @param pdev: Device handle
krebyy 1:3a73d77c2cef 407 * @param dev_addr: USB address
krebyy 1:3a73d77c2cef 408 * @retval USBD Status
krebyy 1:3a73d77c2cef 409 */
krebyy 1:3a73d77c2cef 410 USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr)
krebyy 1:3a73d77c2cef 411 {
krebyy 1:3a73d77c2cef 412 HAL_PCD_SetAddress(pdev->pData, dev_addr);
krebyy 1:3a73d77c2cef 413 return USBD_OK;
krebyy 1:3a73d77c2cef 414 }
krebyy 1:3a73d77c2cef 415
krebyy 1:3a73d77c2cef 416 /**
krebyy 1:3a73d77c2cef 417 * @brief Transmits data over an endpoint
krebyy 1:3a73d77c2cef 418 * @param pdev: Device handle
krebyy 1:3a73d77c2cef 419 * @param ep_addr: Endpoint Number
krebyy 1:3a73d77c2cef 420 * @param pbuf: Pointer to data to be sent
krebyy 1:3a73d77c2cef 421 * @param size: Data size
krebyy 1:3a73d77c2cef 422 * @retval USBD Status
krebyy 1:3a73d77c2cef 423 */
krebyy 1:3a73d77c2cef 424 USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev,
krebyy 1:3a73d77c2cef 425 uint8_t ep_addr,
krebyy 1:3a73d77c2cef 426 uint8_t *pbuf,
krebyy 1:3a73d77c2cef 427 uint16_t size)
krebyy 1:3a73d77c2cef 428 {
krebyy 1:3a73d77c2cef 429 HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size);
krebyy 1:3a73d77c2cef 430 return USBD_OK;
krebyy 1:3a73d77c2cef 431 }
krebyy 1:3a73d77c2cef 432
krebyy 1:3a73d77c2cef 433 /**
krebyy 1:3a73d77c2cef 434 * @brief Prepares an endpoint for reception
krebyy 1:3a73d77c2cef 435 * @param pdev: Device handle
krebyy 1:3a73d77c2cef 436 * @param ep_addr: Endpoint Number
krebyy 1:3a73d77c2cef 437 * @param pbuf:pointer to data to be received
krebyy 1:3a73d77c2cef 438 * @param size: data size
krebyy 1:3a73d77c2cef 439 * @retval USBD Status
krebyy 1:3a73d77c2cef 440 */
krebyy 1:3a73d77c2cef 441 USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
krebyy 1:3a73d77c2cef 442 uint8_t ep_addr,
krebyy 1:3a73d77c2cef 443 uint8_t *pbuf,
krebyy 1:3a73d77c2cef 444 uint16_t size)
krebyy 1:3a73d77c2cef 445 {
krebyy 1:3a73d77c2cef 446 HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size);
krebyy 1:3a73d77c2cef 447 return USBD_OK;
krebyy 1:3a73d77c2cef 448 }
krebyy 1:3a73d77c2cef 449
krebyy 1:3a73d77c2cef 450 /**
krebyy 1:3a73d77c2cef 451 * @brief Returns the last transfered packet size.
krebyy 1:3a73d77c2cef 452 * @param pdev: Device handle
krebyy 1:3a73d77c2cef 453 * @param ep_addr: Endpoint Number
krebyy 1:3a73d77c2cef 454 * @retval Recived Data Size
krebyy 1:3a73d77c2cef 455 */
krebyy 1:3a73d77c2cef 456 uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
krebyy 1:3a73d77c2cef 457 {
krebyy 1:3a73d77c2cef 458 return HAL_PCD_EP_GetRxCount(pdev->pData, ep_addr);
krebyy 1:3a73d77c2cef 459 }
krebyy 1:3a73d77c2cef 460
krebyy 1:3a73d77c2cef 461 /**
krebyy 1:3a73d77c2cef 462 * @brief Delay routine for the USB Device Library
krebyy 1:3a73d77c2cef 463 * @param Delay: Delay in ms
krebyy 1:3a73d77c2cef 464 * @retval None
krebyy 1:3a73d77c2cef 465 */
krebyy 1:3a73d77c2cef 466 void USBD_LL_Delay(uint32_t Delay)
krebyy 1:3a73d77c2cef 467 {
krebyy 1:3a73d77c2cef 468 HAL_Delay(Delay);
krebyy 1:3a73d77c2cef 469 }
krebyy 1:3a73d77c2cef 470
krebyy 1:3a73d77c2cef 471 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/