1 /* 2 * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. 3 * Copyright 2016 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef __USB_DEVICE_H__ 10 #define __USB_DEVICE_H__ 11 12 #include "usb.h" 13 14 /*! 15 * @addtogroup usb_device_driver 16 * @{ 17 */ 18 19 /******************************************************************************* 20 * Definitions 21 ******************************************************************************/ 22 23 /*! @brief Defines Get/Set status Types */ 24 typedef enum _usb_device_status 25 { 26 kUSB_DeviceStatusTestMode = 1U, /*!< Test mode */ 27 kUSB_DeviceStatusSpeed, /*!< Current speed */ 28 kUSB_DeviceStatusOtg, /*!< OTG status */ 29 kUSB_DeviceStatusDevice, /*!< Device status */ 30 kUSB_DeviceStatusEndpoint, /*!< Endpoint state usb_device_endpoint_status_t */ 31 kUSB_DeviceStatusDeviceState, /*!< Device state */ 32 kUSB_DeviceStatusAddress, /*!< Device address */ 33 kUSB_DeviceStatusSynchFrame, /*!< Current frame */ 34 kUSB_DeviceStatusBus, /*!< Bus status */ 35 kUSB_DeviceStatusBusSuspend, /*!< Bus suspend */ 36 kUSB_DeviceStatusBusSleep, /*!< Bus suspend */ 37 kUSB_DeviceStatusBusResume, /*!< Bus resume */ 38 kUSB_DeviceStatusRemoteWakeup, /*!< Remote wakeup state */ 39 kUSB_DeviceStatusBusSleepResume, /*!< Bus resume */ 40 #if defined(USB_DEVICE_CONFIG_GET_SOF_COUNT) && (USB_DEVICE_CONFIG_GET_SOF_COUNT > 0U) 41 kUSB_DeviceStatusGetCurrentFrameCount, /*!< Get current frame count */ 42 #endif 43 } usb_device_status_t; 44 45 /*! @brief Defines USB 2.0 device state */ 46 typedef enum _usb_device_state 47 { 48 kUSB_DeviceStateConfigured = 0U, /*!< Device state, Configured*/ 49 kUSB_DeviceStateAddress, /*!< Device state, Address*/ 50 kUSB_DeviceStateDefault, /*!< Device state, Default*/ 51 kUSB_DeviceStateAddressing, /*!< Device state, Address setting*/ 52 kUSB_DeviceStateTestMode, /*!< Device state, Test mode*/ 53 } usb_device_state_t; 54 55 /*! @brief Defines endpoint state */ 56 typedef enum _usb_endpoint_status 57 { 58 kUSB_DeviceEndpointStateIdle = 0U, /*!< Endpoint state, idle*/ 59 kUSB_DeviceEndpointStateStalled, /*!< Endpoint state, stalled*/ 60 } usb_device_endpoint_status_t; 61 62 /*! @brief Control endpoint index */ 63 #define USB_CONTROL_ENDPOINT (0U) 64 /*! @brief Control endpoint maxPacketSize */ 65 #define USB_CONTROL_MAX_PACKET_SIZE (64U) 66 67 #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0U) 68 #if (USB_CONTROL_MAX_PACKET_SIZE != (64U)) 69 #error For high speed, USB_CONTROL_MAX_PACKET_SIZE must be 64!!! 70 #endif 71 #endif 72 73 /*! @brief The setup packet size of USB control transfer. */ 74 #define USB_SETUP_PACKET_SIZE (8U) 75 /*! @brief USB endpoint mask */ 76 #define USB_ENDPOINT_NUMBER_MASK (0x0FU) 77 78 /*! @brief uninitialized value */ 79 #define USB_UNINITIALIZED_VAL_32 (0xFFFFFFFFU) 80 81 /*! @brief the endpoint callback length of cancelled transfer */ 82 #define USB_CANCELLED_TRANSFER_LENGTH (0xFFFFFFFFU) 83 84 /*! @brief invalid tranfer buffer addresss */ 85 #define USB_INVALID_TRANSFER_BUFFER (0xFFFFFFFEU) 86 87 #if defined(USB_DEVICE_CONFIG_GET_SOF_COUNT) && (USB_DEVICE_CONFIG_GET_SOF_COUNT > 0U) 88 /* USB device IP3511 max frame count */ 89 #define USB_DEVICE_IP3511_MAX_FRAME_COUNT (0x000007FFU) 90 /* USB device EHCI max frame count */ 91 #define USB_DEVICE_EHCI_MAX_FRAME_COUNT (0x00003FFFU) 92 /* USB device EHCI max frame count */ 93 #define USB_DEVICE_KHCI_MAX_FRAME_COUNT (0x000007FFU) 94 95 /*! @brief usb device controller max frame count */ 96 #if ((defined(USB_DEVICE_CONFIG_KHCI)) && (USB_DEVICE_CONFIG_KHCI > 0U)) 97 #define USB_DEVICE_MAX_FRAME_COUNT (USB_DEVICE_KHCI_MAX_FRAME_COUNT) 98 #elif (((defined(USB_DEVICE_CONFIG_LPCIP3511FS)) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)) || \ 99 ((defined(USB_DEVICE_CONFIG_LPCIP3511HS)) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U))) 100 #define USB_DEVICE_MAX_FRAME_COUNT (USB_DEVICE_IP3511_MAX_FRAME_COUNT) 101 #elif ((defined(USB_DEVICE_CONFIG_EHCI)) && (USB_DEVICE_CONFIG_EHCI > 0U)) 102 #define USB_DEVICE_MAX_FRAME_COUNT (USB_DEVICE_EHCI_MAX_FRAME_COUNT) 103 #endif 104 #endif 105 106 /*! @brief Available common EVENT types in device callback */ 107 typedef enum _usb_device_event 108 { 109 kUSB_DeviceEventBusReset = 1U, /*!< USB bus reset signal detected */ 110 kUSB_DeviceEventSuspend, /*!< USB bus suspend signal detected */ 111 kUSB_DeviceEventResume, /*!< USB bus resume signal detected. The resume signal is driven by itself or a host */ 112 kUSB_DeviceEventSleeped, /*!< USB bus LPM suspend signal detected */ 113 kUSB_DeviceEventLPMResume, /*!< USB bus LPM resume signal detected. The resume signal is driven by itself or a host 114 */ 115 kUSB_DeviceEventError, /*!< An error is happened in the bus. */ 116 kUSB_DeviceEventDetach, /*!< USB device is disconnected from a host. */ 117 kUSB_DeviceEventAttach, /*!< USB device is connected to a host. */ 118 kUSB_DeviceEventSetConfiguration, /*!< Set configuration. */ 119 kUSB_DeviceEventSetInterface, /*!< Set interface. */ 120 121 kUSB_DeviceEventGetDeviceDescriptor, /*!< Get device descriptor. */ 122 kUSB_DeviceEventGetConfigurationDescriptor, /*!< Get configuration descriptor. */ 123 kUSB_DeviceEventGetStringDescriptor, /*!< Get string descriptor. */ 124 kUSB_DeviceEventGetHidDescriptor, /*!< Get HID descriptor. */ 125 kUSB_DeviceEventGetHidReportDescriptor, /*!< Get HID report descriptor. */ 126 kUSB_DeviceEventGetHidPhysicalDescriptor, /*!< Get HID physical descriptor. */ 127 kUSB_DeviceEventGetBOSDescriptor, /*!< Get configuration descriptor. */ 128 kUSB_DeviceEventGetDeviceQualifierDescriptor, /*!< Get device qualifier descriptor. */ 129 kUSB_DeviceEventVendorRequest, /*!< Vendor request. */ 130 kUSB_DeviceEventSetRemoteWakeup, /*!< Enable or disable remote wakeup function. */ 131 kUSB_DeviceEventGetConfiguration, /*!< Get current configuration index */ 132 kUSB_DeviceEventGetInterface, /*!< Get current interface alternate setting value */ 133 kUSB_DeviceEventSetBHNPEnable, 134 #if (defined(USB_DEVICE_CONFIG_CHARGER_DETECT) && (USB_DEVICE_CONFIG_CHARGER_DETECT > 0U)) 135 kUSB_DeviceEventDcdDetectionfinished, /*!< The DCD detection finished */ 136 #endif 137 } usb_device_event_t; 138 139 /*! @brief Endpoint callback message structure */ 140 typedef struct _usb_device_endpoint_callback_message_struct 141 { 142 uint8_t *buffer; /*!< Transferred buffer */ 143 uint32_t length; /*!< Transferred data length */ 144 uint8_t isSetup; /*!< Is in a setup phase */ 145 } usb_device_endpoint_callback_message_struct_t; 146 147 /*! 148 * @brief Endpoint callback function typedef. 149 * 150 * This callback function is used to notify the upper layer what the transfer result is. 151 * This callback pointer is passed when a specified endpoint is initialized by calling API #USB_DeviceInitEndpoint. 152 * 153 * @param handle The device handle. It equals to the value returned from #USB_DeviceInit. 154 * @param message The result of a transfer, which includes transfer buffer, transfer length, and whether is in a 155 * setup phase. 156 * phase for control pipe. 157 * @param callbackParam The parameter for this callback. It is same with 158 * usb_device_endpoint_callback_struct_t::callbackParam. 159 * 160 * @return A USB error code or kStatus_USB_Success. 161 */ 162 typedef usb_status_t (*usb_device_endpoint_callback_t)(usb_device_handle handle, 163 usb_device_endpoint_callback_message_struct_t *message, 164 void *callbackParam); 165 166 /*! 167 * @brief Device callback function typedef. 168 * 169 * This callback function is used to notify the upper layer that the device status has changed. 170 * This callback pointer is passed by calling API #USB_DeviceInit. 171 * 172 * @param handle The device handle. It equals the value returned from #USB_DeviceInit. 173 * @param callbackEvent The callback event type. See enumeration #usb_device_event_t. 174 * @param eventParam The event parameter for this callback. The parameter type is determined by the callback event. 175 * 176 * @return A USB error code or kStatus_USB_Success. 177 */ 178 typedef usb_status_t (*usb_device_callback_t)(usb_device_handle handle, uint32_t callbackEvent, void *eventParam); 179 180 /*! @brief Endpoint callback structure */ 181 typedef struct _usb_device_endpoint_callback_struct 182 { 183 usb_device_endpoint_callback_t callbackFn; /*!< Endpoint callback function*/ 184 void *callbackParam; /*!< Parameter for callback function*/ 185 uint8_t isBusy; 186 } usb_device_endpoint_callback_struct_t; 187 188 /*! @brief Endpoint initialization structure */ 189 typedef struct _usb_device_endpoint_init_struct 190 { 191 uint16_t maxPacketSize; /*!< Endpoint maximum packet size */ 192 uint8_t endpointAddress; /*!< Endpoint address*/ 193 uint8_t transferType; /*!< Endpoint transfer type*/ 194 uint8_t zlt; /*!< ZLT flag*/ 195 uint8_t interval; /*!< Endpoint interval*/ 196 } usb_device_endpoint_init_struct_t; 197 198 /*! @brief Endpoint status structure */ 199 typedef struct _usb_device_endpoint_status_struct 200 { 201 uint8_t endpointAddress; /*!< Endpoint address */ 202 uint16_t endpointStatus; /*!< Endpoint status : idle or stalled */ 203 } usb_device_endpoint_status_struct_t; 204 205 #if defined(__cplusplus) 206 extern "C" { 207 #endif /* __cplusplus*/ 208 209 /*! 210 * @name USB device APIs 211 * @{ 212 */ 213 214 /******************************************************************************* 215 * API 216 ******************************************************************************/ 217 218 /*! 219 * @brief Initializes the USB device stack. 220 * 221 * This function initializes the USB device module specified by the controllerId. 222 * 223 * @param[in] controllerId The controller ID of the USB IP. See the enumeration #usb_controller_index_t. 224 * @param[in] deviceCallback Function pointer of the device callback. 225 * @param[out] handle It is an out parameter used to return the pointer of the device handle to the caller. 226 * 227 * @retval kStatus_USB_Success The device is initialized successfully. 228 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. 229 * @retval kStatus_USB_Busy Cannot allocate a device handle. 230 * @retval kStatus_USB_ControllerNotFound Cannot find the controller according to the controller id. 231 * @retval kStatus_USB_InvalidControllerInterface The controller driver interfaces is invalid. There is an empty 232 * interface entity. 233 * @retval kStatus_USB_Error The macro USB_DEVICE_CONFIG_ENDPOINTS is more than the IP's endpoint number. 234 * Or, the device has been initialized. 235 * Or, the mutex or message queue is created failed. 236 */ 237 extern usb_status_t USB_DeviceInit(uint8_t controllerId, 238 usb_device_callback_t deviceCallback, 239 usb_device_handle *handle); 240 241 /*! 242 * @brief Enables the device functionality. 243 * 244 * The function enables the device functionality, so that the device can be recognized by the host when the device 245 * detects that it has been connected to a host. 246 * 247 * @param[in] handle The device handle got from #USB_DeviceInit. 248 * 249 * @retval kStatus_USB_Success The device is run successfully. 250 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 251 * @retval kStatus_USB_InvalidHandle The device handle is a NULL pointer. Or the controller handle is invalid. 252 * 253 */ 254 extern usb_status_t USB_DeviceRun(usb_device_handle handle); 255 256 /*! 257 * @brief Disables the device functionality. 258 * 259 * The function disables the device functionality. After this function called, even if the device is detached to the 260 * host, 261 * it can't work. 262 * 263 * @param[in] handle The device handle received from #USB_DeviceInit. 264 * 265 * @retval kStatus_USB_Success The device is stopped successfully. 266 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 267 * @retval kStatus_USB_InvalidHandle The device handle is a NULL pointer or the controller handle is invalid. 268 */ 269 extern usb_status_t USB_DeviceStop(usb_device_handle handle); 270 271 /*! 272 * @brief De-initializes the device controller. 273 * 274 * The function de-initializes the device controller specified by the handle. 275 * 276 * @param[in] handle The device handle got from #USB_DeviceInit. 277 * 278 * @retval kStatus_USB_Success The device is stopped successfully. 279 * @retval kStatus_USB_InvalidHandle The device handle is a NULL pointer or the controller handle is invalid. 280 */ 281 extern usb_status_t USB_DeviceDeinit(usb_device_handle handle); 282 283 /*! 284 * @brief Sends data through a specified endpoint. 285 * 286 * The function is used to send data through a specified endpoint. 287 * 288 * @param[in] handle The device handle got from #USB_DeviceInit. 289 * @param[in] endpointAddress Endpoint index. 290 * @param[in] buffer The memory address to hold the data need to be sent. The function is not reentrant. 291 * @param[in] length The data length need to be sent. 292 * 293 * @retval kStatus_USB_Success The send request is sent successfully. 294 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid. 295 * @retval kStatus_USB_Busy Cannot allocate DTDS for current transfer in EHCI driver. 296 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 297 * @retval kStatus_USB_Error The device is doing reset. 298 * 299 * @note The return value indicates whether the sending request is successful or not. The transfer done is notified by 300 * the 301 * corresponding callback function. 302 * Currently, only one transfer request can be supported for one specific endpoint. 303 * If there is a specific requirement to support multiple transfer requests for one specific endpoint, the application 304 * should implement a queue on the application level. 305 * The subsequent transfer can begin only when the previous transfer is done (get notification through the endpoint 306 * callback). 307 */ 308 extern usb_status_t USB_DeviceSendRequest(usb_device_handle handle, 309 uint8_t endpointAddress, 310 uint8_t *buffer, 311 uint32_t length); 312 313 /*! 314 * @brief Receives data through a specified endpoint. 315 * 316 * The function is used to receive data through a specified endpoint. The function is not reentrant. 317 * 318 * @param[in] handle The device handle got from #USB_DeviceInit. 319 * @param[in] endpointAddress Endpoint index. 320 * @param[in] buffer The memory address to save the received data. 321 * @param[in] length The data length want to be received. 322 * 323 * @retval kStatus_USB_Success The receive request is sent successfully. 324 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid. 325 * @retval kStatus_USB_Busy Cannot allocate DTDS for current transfer in EHCI driver. 326 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 327 * @retval kStatus_USB_Error The device is doing reset. 328 * 329 * @note The return value indicates whether the receiving request is successful or not. The transfer done is notified by 330 * the 331 * corresponding callback function. 332 * Currently, only one transfer request can be supported for one specific endpoint. 333 * If there is a specific requirement to support multiple transfer requests for one specific endpoint, the application 334 * should implement a queue on the application level. 335 * The subsequent transfer can begin only when the previous transfer is done (get notification through the endpoint 336 * callback). 337 */ 338 extern usb_status_t USB_DeviceRecvRequest(usb_device_handle handle, 339 uint8_t endpointAddress, 340 uint8_t *buffer, 341 uint32_t length); 342 343 /*! 344 * @brief Cancels the pending transfer in a specified endpoint. 345 * 346 * The function is used to cancel the pending transfer in a specified endpoint. 347 * 348 * @param[in] handle The device handle got from #USB_DeviceInit. 349 * @param[in] endpointAddress Endpoint address, bit7 is the direction of endpoint, 1U - IN, and 0U - OUT. 350 * 351 * @retval kStatus_USB_Success The transfer is cancelled. 352 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer or the controller handle is invalid. 353 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 354 */ 355 extern usb_status_t USB_DeviceCancel(usb_device_handle handle, uint8_t endpointAddress); 356 357 /*! 358 * @brief Initializes a specified endpoint. 359 * 360 * The function is used to initialize a specified endpoint. The corresponding endpoint callback is also initialized. 361 * 362 * @param[in] handle The device handle received from #USB_DeviceInit. 363 * @param[in] epInit Endpoint initialization structure. See the structure usb_device_endpoint_init_struct_t. 364 * @param[in] epCallback Endpoint callback structure. See the structure 365 * usb_device_endpoint_callback_struct_t. 366 * 367 * @retval kStatus_USB_Success The endpoint is initialized successfully. 368 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid. 369 * @retval kStatus_USB_InvalidParameter The epInit or epCallback is NULL pointer. Or the endpoint number is 370 * more than USB_DEVICE_CONFIG_ENDPOINTS. 371 * @retval kStatus_USB_Busy The endpoint is busy in EHCI driver. 372 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 373 */ 374 extern usb_status_t USB_DeviceInitEndpoint(usb_device_handle handle, 375 usb_device_endpoint_init_struct_t *epInit, 376 usb_device_endpoint_callback_struct_t *epCallback); 377 378 /*! 379 * @brief Deinitializes a specified endpoint. 380 * 381 * The function is used to deinitializes a specified endpoint. 382 * 383 * @param[in] handle The device handle got from #USB_DeviceInit. 384 * @param[in] endpointAddress Endpoint address, bit7 is the direction of endpoint, 1U - IN, and 0U - OUT. 385 * 386 * @retval kStatus_USB_Success The endpoint is de-initialized successfully. 387 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid. 388 * @retval kStatus_USB_InvalidParameter The endpoint number is more than USB_DEVICE_CONFIG_ENDPOINTS. 389 * @retval kStatus_USB_Busy The endpoint is busy in EHCI driver. 390 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 391 */ 392 extern usb_status_t USB_DeviceDeinitEndpoint(usb_device_handle handle, uint8_t endpointAddress); 393 394 /*! 395 * @brief Stalls a specified endpoint. 396 * 397 * The function is used to stall a specified endpoint. 398 * 399 * @param[in] handle The device handle received from #USB_DeviceInit. 400 * @param[in] endpointAddress Endpoint address, bit7 is the direction of endpoint, 1U - IN, and 0U - OUT. 401 * 402 * @retval kStatus_USB_Success The endpoint is stalled successfully. 403 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid. 404 * @retval kStatus_USB_InvalidParameter The endpoint number is more than USB_DEVICE_CONFIG_ENDPOINTS. 405 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 406 */ 407 extern usb_status_t USB_DeviceStallEndpoint(usb_device_handle handle, uint8_t endpointAddress); 408 409 /*! 410 * @brief Un-stall a specified endpoint. 411 * 412 * The function is used to unstall a specified endpoint. 413 * 414 * @param[in] handle The device handle received from #USB_DeviceInit. 415 * @param[in] endpointAddress Endpoint address, bit7 is the direction of endpoint, 1U - IN, and 0U - OUT. 416 * 417 * @retval kStatus_USB_Success The endpoint is un-stalled successfully. 418 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid. 419 * @retval kStatus_USB_InvalidParameter The endpoint number is more than USB_DEVICE_CONFIG_ENDPOINTS. 420 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 421 */ 422 extern usb_status_t USB_DeviceUnstallEndpoint(usb_device_handle handle, uint8_t endpointAddress); 423 424 /*! 425 * @brief Gets the status of the selected item. 426 * 427 * The function is used to get the status of the selected item. 428 * 429 * @param[in] handle The device handle got from #USB_DeviceInit. 430 * @param[in] type The selected item. See the structure #usb_device_status_t. 431 * @param[out] param The parameter type is determined by the selected item. 432 * 433 * @retval kStatus_USB_Success Get status successfully. 434 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid. 435 * @retval kStatus_USB_InvalidParameter The parameter is NULL pointer. 436 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 437 * @retval kStatus_USB_Error Unsupported type. 438 */ 439 extern usb_status_t USB_DeviceGetStatus(usb_device_handle handle, usb_device_status_t type, void *param); 440 441 /*! 442 * @brief Sets the status of the selected item. 443 * 444 * The function is used to set the status of the selected item. 445 * 446 * @param[in] handle The device handle got from #USB_DeviceInit. 447 * @param[in] type The selected item. See the structure #usb_device_status_t. 448 * @param[in] param The parameter type is determined by the selected item. 449 * 450 * @retval kStatus_USB_Success Set status successfully. 451 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid. 452 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 453 * @retval kStatus_USB_Error Unsupported type or the parameter is NULL pointer. 454 */ 455 extern usb_status_t USB_DeviceSetStatus(usb_device_handle handle, usb_device_status_t type, void *param); 456 457 #if (defined(USB_DEVICE_CONFIG_CHARGER_DETECT) && (USB_DEVICE_CONFIG_CHARGER_DETECT > 0U)) 458 /*! 459 * @brief Enable the device dcd module. 460 * 461 * The function enable the device dcd module. 462 * 463 * @param[in] handle The device handle got from #USB_DeviceInit. 464 * 465 * @retval kStatus_USB_Success The device could run. 466 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 467 * @retval kStatus_USB_InvalidHandle The device handle is a NULL pointer. Or the controller handle is invalid. 468 * 469 */ 470 extern usb_status_t USB_DeviceDcdEnable(usb_device_handle handle); 471 472 /*! 473 * @brief Disable the device dcd module. 474 * 475 * The function disable the device dcd module. 476 * 477 * @param[in] handle The device handle got from #USB_DeviceInit. 478 * 479 * @retval kStatus_USB_Success The dcd is reset and stopped. 480 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 481 * @retval kStatus_USB_InvalidHandle The device handle is a NULL pointer or the controller handle is invalid. 482 * 483 */ 484 extern usb_status_t USB_DeviceDcdDisable(usb_device_handle handle); 485 #endif 486 487 #if ((defined(USB_DEVICE_CONFIG_USE_TASK)) && (USB_DEVICE_CONFIG_USE_TASK > 0U)) 488 /*! 489 * @brief Device task function. 490 * 491 * The function is used to handle the controller message. 492 * This function should not be called in the application directly. 493 * 494 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 495 */ 496 extern void USB_DeviceTaskFunction(void *deviceHandle); 497 #endif 498 499 #if ((defined(USB_DEVICE_CONFIG_KHCI)) && (USB_DEVICE_CONFIG_KHCI > 0U)) 500 #if ((defined(USB_DEVICE_CONFIG_USE_TASK)) && (USB_DEVICE_CONFIG_USE_TASK > 0U)) 501 /*! 502 * @brief Device KHCI task function. 503 * 504 * The function is used to handle the KHCI controller message. 505 * In the bare metal environment, this function should be called periodically in the main function. 506 * In the RTOS environment, this function should be used as a function entry to create a task. 507 * 508 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 509 */ 510 #define USB_DeviceKhciTaskFunction(deviceHandle) USB_DeviceTaskFunction(deviceHandle) 511 #endif 512 #endif 513 514 #if ((defined(USB_DEVICE_CONFIG_EHCI)) && (USB_DEVICE_CONFIG_EHCI > 0U)) 515 #if ((defined(USB_DEVICE_CONFIG_USE_TASK)) && (USB_DEVICE_CONFIG_USE_TASK > 0U)) 516 /*! 517 * @brief Device EHCI task function. 518 * 519 * The function is used to handle the EHCI controller message. 520 * In the bare metal environment, this function should be called periodically in the main function. 521 * In the RTOS environment, this function should be used as a function entry to create a task. 522 * 523 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 524 */ 525 #define USB_DeviceEhciTaskFunction(deviceHandle) USB_DeviceTaskFunction(deviceHandle) 526 #endif 527 #if (defined(USB_DEVICE_CONFIG_CHARGER_DETECT) && (USB_DEVICE_CONFIG_CHARGER_DETECT > 0U)) 528 #if (defined(FSL_FEATURE_SOC_USBHSDCD_COUNT) && (FSL_FEATURE_SOC_USBHSDCD_COUNT > 0U)) 529 /*! 530 * @brief Device ehci DCD ISR function. 531 * 532 * The function is the ehci DCD interrupt service routine. 533 * 534 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 535 */ 536 extern void USB_DeviceEhciIsrHSDCDFunction(void *deviceHandle); 537 #endif 538 #endif 539 #endif 540 541 #if (((defined(USB_DEVICE_CONFIG_LPCIP3511FS)) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)) || \ 542 ((defined(USB_DEVICE_CONFIG_LPCIP3511HS)) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U))) 543 #if ((defined(USB_DEVICE_CONFIG_USE_TASK)) && (USB_DEVICE_CONFIG_USE_TASK > 0U)) 544 /*! 545 * @brief Device LPC ip3511 controller task function. 546 * 547 * The function is used to handle the LPC ip3511 controller message. 548 * In the bare metal environment, this function should be called periodically in the main function. 549 * In the RTOS environment, this function should be used as a function entry to create a task. 550 * 551 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 552 */ 553 #define USB_DeviceLpcIp3511TaskFunction(deviceHandle) USB_DeviceTaskFunction(deviceHandle) 554 #endif 555 #if (defined(USB_DEVICE_CONFIG_CHARGER_DETECT) && (USB_DEVICE_CONFIG_CHARGER_DETECT > 0U)) 556 #if (defined(FSL_FEATURE_SOC_USBHSDCD_COUNT) && (FSL_FEATURE_SOC_USBHSDCD_COUNT > 0U)) 557 /*! 558 * @brief Device IP3511 DCD ISR function. 559 * 560 * The function is the IP3511 DCD interrupt service routine. 561 * 562 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 563 */ 564 extern void USB_DeviceLpcIp3511IsrDCDFunction(void *deviceHandle); 565 #endif 566 #endif 567 #endif 568 569 #if ((defined(USB_DEVICE_CONFIG_KHCI)) && (USB_DEVICE_CONFIG_KHCI > 0U)) 570 /*! 571 * @brief Device KHCI ISR function. 572 * 573 * The function is the KHCI interrupt service routine. 574 * 575 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 576 */ 577 extern void USB_DeviceKhciIsrFunction(void *deviceHandle); 578 #if (defined(USB_DEVICE_CONFIG_CHARGER_DETECT) && (USB_DEVICE_CONFIG_CHARGER_DETECT > 0U)) 579 #if (defined(FSL_FEATURE_SOC_USBDCD_COUNT) && (FSL_FEATURE_SOC_USBDCD_COUNT > 0U)) 580 #if 0U /* it is not implemented yet */ 581 /*! 582 * @brief Device KHCI DCD ISR function. 583 * 584 * The function is the KHCI DCD interrupt service routine. 585 * 586 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 587 */ 588 extern void USB_DeviceDcdIsrFunction(void *deviceHandle); 589 #endif 590 #endif 591 #endif 592 #endif 593 594 #if ((defined(USB_DEVICE_CONFIG_EHCI)) && (USB_DEVICE_CONFIG_EHCI > 0U)) 595 /*! 596 * @brief Device EHCI ISR function. 597 * 598 * The function is the EHCI interrupt service routine. 599 * 600 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 601 */ 602 extern void USB_DeviceEhciIsrFunction(void *deviceHandle); 603 #endif 604 605 #if (((defined(USB_DEVICE_CONFIG_LPCIP3511FS)) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)) || \ 606 ((defined(USB_DEVICE_CONFIG_LPCIP3511HS)) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U))) 607 /*! 608 * @brief Device LPC USB ISR function. 609 * 610 * The function is the LPC USB interrupt service routine. 611 * 612 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 613 */ 614 extern void USB_DeviceLpcIp3511IsrFunction(void *deviceHandle); 615 #endif 616 617 #if (((defined(USB_DEVICE_CONFIG_DWC3)) && (USB_DEVICE_CONFIG_DWC3 > 0U)) || \ 618 ((defined(USB_DEVICE_CONFIG_DWC3)) && (USB_DEVICE_CONFIG_DWC3 > 0U))) 619 /*! 620 * @brief Device USB DWC3 ISR function. 621 * 622 * The function is the USB interrupt service routine. 623 * 624 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 625 */ 626 extern void USB_DeviceDwc3IsrFunction(void *deviceHandle); 627 #endif 628 629 /*! 630 * @brief Gets the device stack version function. 631 * 632 * The function is used to get the device stack version. 633 * 634 * @param[out] version The version structure pointer to keep the device stack version. 635 * 636 */ 637 extern void USB_DeviceGetVersion(uint32_t *version); 638 639 #if ((defined(USB_DEVICE_CONFIG_REMOTE_WAKEUP)) && (USB_DEVICE_CONFIG_REMOTE_WAKEUP > 0U)) || \ 640 (((defined(USB_DEVICE_CONFIG_CHARGER_DETECT) && (USB_DEVICE_CONFIG_CHARGER_DETECT > 0U)) && \ 641 (defined(FSL_FEATURE_SOC_USB_ANALOG_COUNT) && (FSL_FEATURE_SOC_USB_ANALOG_COUNT > 0U)))) 642 /*! 643 * @brief Update the hardware tick. 644 * 645 * The function is used to update the hardware tick. 646 * 647 * @param[in] handle The device handle got from #USB_DeviceInit. 648 * @param[in] tick Current hardware tick(uint is ms). 649 * 650 */ 651 extern usb_status_t USB_DeviceUpdateHwTick(usb_device_handle handle, uint64_t tick); 652 #endif 653 654 /*! @}*/ 655 656 #if defined(__cplusplus) 657 } 658 #endif /* __cplusplus*/ 659 660 /*! @}*/ 661 662 #endif /* __USB_DEVICE_H__ */ 663