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_SOF_NOTIFICATIONS) && (USB_DEVICE_CONFIG_SOF_NOTIFICATIONS > 0U)) 135 kUSB_DeviceEventSOF, /*!< Start of Frame received */ 136 #endif 137 #if (defined(USB_DEVICE_CONFIG_CHARGER_DETECT) && (USB_DEVICE_CONFIG_CHARGER_DETECT > 0U)) 138 kUSB_DeviceEventDcdDetectionfinished, /*!< The DCD detection finished */ 139 #endif 140 } usb_device_event_t; 141 142 /*! @brief Endpoint callback message structure */ 143 typedef struct _usb_device_endpoint_callback_message_struct 144 { 145 uint8_t *buffer; /*!< Transferred buffer */ 146 uint32_t length; /*!< Transferred data length */ 147 uint8_t isSetup; /*!< Is in a setup phase */ 148 } usb_device_endpoint_callback_message_struct_t; 149 150 /*! 151 * @brief Endpoint callback function typedef. 152 * 153 * This callback function is used to notify the upper layer what the transfer result is. 154 * This callback pointer is passed when a specified endpoint is initialized by calling API #USB_DeviceInitEndpoint. 155 * 156 * @param handle The device handle. It equals to the value returned from #USB_DeviceInit. 157 * @param message The result of a transfer, which includes transfer buffer, transfer length, and whether is in a 158 * setup phase. 159 * phase for control pipe. 160 * @param callbackParam The parameter for this callback. It is same with 161 * usb_device_endpoint_callback_struct_t::callbackParam. 162 * 163 * @return A USB error code or kStatus_USB_Success. 164 */ 165 typedef usb_status_t (*usb_device_endpoint_callback_t)(usb_device_handle handle, 166 usb_device_endpoint_callback_message_struct_t *message, 167 void *callbackParam); 168 169 /*! 170 * @brief Device callback function typedef. 171 * 172 * This callback function is used to notify the upper layer that the device status has changed. 173 * This callback pointer is passed by calling API #USB_DeviceInit. 174 * 175 * @param handle The device handle. It equals the value returned from #USB_DeviceInit. 176 * @param callbackEvent The callback event type. See enumeration #usb_device_event_t. 177 * @param eventParam The event parameter for this callback. The parameter type is determined by the callback event. 178 * 179 * @return A USB error code or kStatus_USB_Success. 180 */ 181 typedef usb_status_t (*usb_device_callback_t)(usb_device_handle handle, uint32_t callbackEvent, void *eventParam); 182 183 /*! @brief Endpoint callback structure */ 184 typedef struct _usb_device_endpoint_callback_struct 185 { 186 usb_device_endpoint_callback_t callbackFn; /*!< Endpoint callback function*/ 187 void *callbackParam; /*!< Parameter for callback function*/ 188 uint8_t isBusy; 189 } usb_device_endpoint_callback_struct_t; 190 191 /*! @brief Endpoint initialization structure */ 192 typedef struct _usb_device_endpoint_init_struct 193 { 194 uint16_t maxPacketSize; /*!< Endpoint maximum packet size */ 195 uint8_t endpointAddress; /*!< Endpoint address*/ 196 uint8_t transferType; /*!< Endpoint transfer type*/ 197 uint8_t zlt; /*!< ZLT flag*/ 198 uint8_t interval; /*!< Endpoint interval*/ 199 } usb_device_endpoint_init_struct_t; 200 201 /*! @brief Endpoint status structure */ 202 typedef struct _usb_device_endpoint_status_struct 203 { 204 uint8_t endpointAddress; /*!< Endpoint address */ 205 uint16_t endpointStatus; /*!< Endpoint status : idle or stalled */ 206 } usb_device_endpoint_status_struct_t; 207 208 #if defined(__cplusplus) 209 extern "C" { 210 #endif /* __cplusplus*/ 211 212 /*! 213 * @name USB device APIs 214 * @{ 215 */ 216 217 /******************************************************************************* 218 * API 219 ******************************************************************************/ 220 221 /*! 222 * @brief Initializes the USB device stack. 223 * 224 * This function initializes the USB device module specified by the controllerId. 225 * 226 * @param[in] controllerId The controller ID of the USB IP. See the enumeration #usb_controller_index_t. 227 * @param[in] deviceCallback Function pointer of the device callback. 228 * @param[out] handle It is an out parameter used to return the pointer of the device handle to the caller. 229 * 230 * @retval kStatus_USB_Success The device is initialized successfully. 231 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. 232 * @retval kStatus_USB_Busy Cannot allocate a device handle. 233 * @retval kStatus_USB_ControllerNotFound Cannot find the controller according to the controller id. 234 * @retval kStatus_USB_InvalidControllerInterface The controller driver interfaces is invalid. There is an empty 235 * interface entity. 236 * @retval kStatus_USB_Error The macro USB_DEVICE_CONFIG_ENDPOINTS is more than the IP's endpoint number. 237 * Or, the device has been initialized. 238 * Or, the mutex or message queue is created failed. 239 */ 240 extern usb_status_t USB_DeviceInit(uint8_t controllerId, 241 usb_device_callback_t deviceCallback, 242 usb_device_handle *handle); 243 244 /*! 245 * @brief Enables the device functionality. 246 * 247 * The function enables the device functionality, so that the device can be recognized by the host when the device 248 * detects that it has been connected to a host. 249 * 250 * @param[in] handle The device handle got from #USB_DeviceInit. 251 * 252 * @retval kStatus_USB_Success The device is run successfully. 253 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 254 * @retval kStatus_USB_InvalidHandle The device handle is a NULL pointer. Or the controller handle is invalid. 255 * 256 */ 257 extern usb_status_t USB_DeviceRun(usb_device_handle handle); 258 259 /*! 260 * @brief Disables the device functionality. 261 * 262 * The function disables the device functionality. After this function called, even if the device is detached to the 263 * host, 264 * it can't work. 265 * 266 * @param[in] handle The device handle received from #USB_DeviceInit. 267 * 268 * @retval kStatus_USB_Success The device is stopped successfully. 269 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 270 * @retval kStatus_USB_InvalidHandle The device handle is a NULL pointer or the controller handle is invalid. 271 */ 272 extern usb_status_t USB_DeviceStop(usb_device_handle handle); 273 274 /*! 275 * @brief De-initializes the device controller. 276 * 277 * The function de-initializes the device controller specified by the handle. 278 * 279 * @param[in] handle The device handle got from #USB_DeviceInit. 280 * 281 * @retval kStatus_USB_Success The device is stopped successfully. 282 * @retval kStatus_USB_InvalidHandle The device handle is a NULL pointer or the controller handle is invalid. 283 */ 284 extern usb_status_t USB_DeviceDeinit(usb_device_handle handle); 285 286 /*! 287 * @brief Sends data through a specified endpoint. 288 * 289 * The function is used to send data through a specified endpoint. 290 * 291 * @param[in] handle The device handle got from #USB_DeviceInit. 292 * @param[in] endpointAddress Endpoint index. 293 * @param[in] buffer The memory address to hold the data need to be sent. The function is not reentrant. 294 * @param[in] length The data length need to be sent. 295 * 296 * @retval kStatus_USB_Success The send request is sent successfully. 297 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid. 298 * @retval kStatus_USB_Busy Cannot allocate DTDS for current transfer in EHCI driver. 299 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 300 * @retval kStatus_USB_Error The device is doing reset. 301 * 302 * @note The return value indicates whether the sending request is successful or not. The transfer done is notified by 303 * the 304 * corresponding callback function. 305 * Currently, only one transfer request can be supported for one specific endpoint. 306 * If there is a specific requirement to support multiple transfer requests for one specific endpoint, the application 307 * should implement a queue on the application level. 308 * The subsequent transfer can begin only when the previous transfer is done (get notification through the endpoint 309 * callback). 310 */ 311 extern usb_status_t USB_DeviceSendRequest(usb_device_handle handle, 312 uint8_t endpointAddress, 313 uint8_t *buffer, 314 uint32_t length); 315 316 /*! 317 * @brief Receives data through a specified endpoint. 318 * 319 * The function is used to receive data through a specified endpoint. The function is not reentrant. 320 * 321 * @param[in] handle The device handle got from #USB_DeviceInit. 322 * @param[in] endpointAddress Endpoint index. 323 * @param[in] buffer The memory address to save the received data. 324 * @param[in] length The data length want to be received. 325 * 326 * @retval kStatus_USB_Success The receive request is sent successfully. 327 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid. 328 * @retval kStatus_USB_Busy Cannot allocate DTDS for current transfer in EHCI driver. 329 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 330 * @retval kStatus_USB_Error The device is doing reset. 331 * 332 * @note The return value indicates whether the receiving request is successful or not. The transfer done is notified by 333 * the 334 * corresponding callback function. 335 * Currently, only one transfer request can be supported for one specific endpoint. 336 * If there is a specific requirement to support multiple transfer requests for one specific endpoint, the application 337 * should implement a queue on the application level. 338 * The subsequent transfer can begin only when the previous transfer is done (get notification through the endpoint 339 * callback). 340 */ 341 extern usb_status_t USB_DeviceRecvRequest(usb_device_handle handle, 342 uint8_t endpointAddress, 343 uint8_t *buffer, 344 uint32_t length); 345 346 /*! 347 * @brief Cancels the pending transfer in a specified endpoint. 348 * 349 * The function is used to cancel the pending transfer in a specified endpoint. 350 * 351 * @param[in] handle The device handle got from #USB_DeviceInit. 352 * @param[in] endpointAddress Endpoint address, bit7 is the direction of endpoint, 1U - IN, and 0U - OUT. 353 * 354 * @retval kStatus_USB_Success The transfer is cancelled. 355 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer or the controller handle is invalid. 356 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 357 */ 358 extern usb_status_t USB_DeviceCancel(usb_device_handle handle, uint8_t endpointAddress); 359 360 /*! 361 * @brief Initializes a specified endpoint. 362 * 363 * The function is used to initialize a specified endpoint. The corresponding endpoint callback is also initialized. 364 * 365 * @param[in] handle The device handle received from #USB_DeviceInit. 366 * @param[in] epInit Endpoint initialization structure. See the structure usb_device_endpoint_init_struct_t. 367 * @param[in] epCallback Endpoint callback structure. See the structure 368 * usb_device_endpoint_callback_struct_t. 369 * 370 * @retval kStatus_USB_Success The endpoint is initialized successfully. 371 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid. 372 * @retval kStatus_USB_InvalidParameter The epInit or epCallback is NULL pointer. Or the endpoint number is 373 * more than USB_DEVICE_CONFIG_ENDPOINTS. 374 * @retval kStatus_USB_Busy The endpoint is busy in EHCI driver. 375 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 376 */ 377 extern usb_status_t USB_DeviceInitEndpoint(usb_device_handle handle, 378 usb_device_endpoint_init_struct_t *epInit, 379 usb_device_endpoint_callback_struct_t *epCallback); 380 381 /*! 382 * @brief Deinitializes a specified endpoint. 383 * 384 * The function is used to deinitializes a specified endpoint. 385 * 386 * @param[in] handle The device handle got from #USB_DeviceInit. 387 * @param[in] endpointAddress Endpoint address, bit7 is the direction of endpoint, 1U - IN, and 0U - OUT. 388 * 389 * @retval kStatus_USB_Success The endpoint is de-initialized successfully. 390 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid. 391 * @retval kStatus_USB_InvalidParameter The endpoint number is more than USB_DEVICE_CONFIG_ENDPOINTS. 392 * @retval kStatus_USB_Busy The endpoint is busy in EHCI driver. 393 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 394 */ 395 extern usb_status_t USB_DeviceDeinitEndpoint(usb_device_handle handle, uint8_t endpointAddress); 396 397 /*! 398 * @brief Stalls a specified endpoint. 399 * 400 * The function is used to stall a specified endpoint. 401 * 402 * @param[in] handle The device handle received from #USB_DeviceInit. 403 * @param[in] endpointAddress Endpoint address, bit7 is the direction of endpoint, 1U - IN, and 0U - OUT. 404 * 405 * @retval kStatus_USB_Success The endpoint is stalled successfully. 406 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid. 407 * @retval kStatus_USB_InvalidParameter The endpoint number is more than USB_DEVICE_CONFIG_ENDPOINTS. 408 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 409 */ 410 extern usb_status_t USB_DeviceStallEndpoint(usb_device_handle handle, uint8_t endpointAddress); 411 412 /*! 413 * @brief Un-stall a specified endpoint. 414 * 415 * The function is used to unstall a specified endpoint. 416 * 417 * @param[in] handle The device handle received from #USB_DeviceInit. 418 * @param[in] endpointAddress Endpoint address, bit7 is the direction of endpoint, 1U - IN, and 0U - OUT. 419 * 420 * @retval kStatus_USB_Success The endpoint is un-stalled successfully. 421 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid. 422 * @retval kStatus_USB_InvalidParameter The endpoint number is more than USB_DEVICE_CONFIG_ENDPOINTS. 423 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 424 */ 425 extern usb_status_t USB_DeviceUnstallEndpoint(usb_device_handle handle, uint8_t endpointAddress); 426 427 /*! 428 * @brief Gets the status of the selected item. 429 * 430 * The function is used to get the status of the selected item. 431 * 432 * @param[in] handle The device handle got from #USB_DeviceInit. 433 * @param[in] type The selected item. See the structure #usb_device_status_t. 434 * @param[out] param The parameter type is determined by the selected item. 435 * 436 * @retval kStatus_USB_Success Get status successfully. 437 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid. 438 * @retval kStatus_USB_InvalidParameter The parameter is NULL pointer. 439 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 440 * @retval kStatus_USB_Error Unsupported type. 441 */ 442 extern usb_status_t USB_DeviceGetStatus(usb_device_handle handle, usb_device_status_t type, void *param); 443 444 /*! 445 * @brief Sets the status of the selected item. 446 * 447 * The function is used to set the status of the selected item. 448 * 449 * @param[in] handle The device handle got from #USB_DeviceInit. 450 * @param[in] type The selected item. See the structure #usb_device_status_t. 451 * @param[in] param The parameter type is determined by the selected item. 452 * 453 * @retval kStatus_USB_Success Set status successfully. 454 * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid. 455 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 456 * @retval kStatus_USB_Error Unsupported type or the parameter is NULL pointer. 457 */ 458 extern usb_status_t USB_DeviceSetStatus(usb_device_handle handle, usb_device_status_t type, void *param); 459 460 #if (defined(USB_DEVICE_CONFIG_CHARGER_DETECT) && (USB_DEVICE_CONFIG_CHARGER_DETECT > 0U)) 461 /*! 462 * @brief Enable the device dcd module. 463 * 464 * The function enable the device dcd module. 465 * 466 * @param[in] handle The device handle got from #USB_DeviceInit. 467 * 468 * @retval kStatus_USB_Success The device could run. 469 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 470 * @retval kStatus_USB_InvalidHandle The device handle is a NULL pointer. Or the controller handle is invalid. 471 * 472 */ 473 extern usb_status_t USB_DeviceDcdEnable(usb_device_handle handle); 474 475 /*! 476 * @brief Disable the device dcd module. 477 * 478 * The function disable the device dcd module. 479 * 480 * @param[in] handle The device handle got from #USB_DeviceInit. 481 * 482 * @retval kStatus_USB_Success The dcd is reset and stopped. 483 * @retval kStatus_USB_ControllerNotFound Cannot find the controller. 484 * @retval kStatus_USB_InvalidHandle The device handle is a NULL pointer or the controller handle is invalid. 485 * 486 */ 487 extern usb_status_t USB_DeviceDcdDisable(usb_device_handle handle); 488 #endif 489 490 #if ((defined(USB_DEVICE_CONFIG_USE_TASK)) && (USB_DEVICE_CONFIG_USE_TASK > 0U)) 491 /*! 492 * @brief Device task function. 493 * 494 * The function is used to handle the controller message. 495 * This function should not be called in the application directly. 496 * 497 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 498 */ 499 extern void USB_DeviceTaskFunction(void *deviceHandle); 500 #endif 501 502 #if ((defined(USB_DEVICE_CONFIG_KHCI)) && (USB_DEVICE_CONFIG_KHCI > 0U)) 503 #if ((defined(USB_DEVICE_CONFIG_USE_TASK)) && (USB_DEVICE_CONFIG_USE_TASK > 0U)) 504 /*! 505 * @brief Device KHCI task function. 506 * 507 * The function is used to handle the KHCI controller message. 508 * In the bare metal environment, this function should be called periodically in the main function. 509 * In the RTOS environment, this function should be used as a function entry to create a task. 510 * 511 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 512 */ 513 #define USB_DeviceKhciTaskFunction(deviceHandle) USB_DeviceTaskFunction(deviceHandle) 514 #endif 515 #endif 516 517 #if ((defined(USB_DEVICE_CONFIG_EHCI)) && (USB_DEVICE_CONFIG_EHCI > 0U)) 518 #if ((defined(USB_DEVICE_CONFIG_USE_TASK)) && (USB_DEVICE_CONFIG_USE_TASK > 0U)) 519 /*! 520 * @brief Device EHCI task function. 521 * 522 * The function is used to handle the EHCI controller message. 523 * In the bare metal environment, this function should be called periodically in the main function. 524 * In the RTOS environment, this function should be used as a function entry to create a task. 525 * 526 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 527 */ 528 #define USB_DeviceEhciTaskFunction(deviceHandle) USB_DeviceTaskFunction(deviceHandle) 529 #endif 530 #if (defined(USB_DEVICE_CONFIG_CHARGER_DETECT) && (USB_DEVICE_CONFIG_CHARGER_DETECT > 0U)) 531 #if (defined(FSL_FEATURE_SOC_USBHSDCD_COUNT) && (FSL_FEATURE_SOC_USBHSDCD_COUNT > 0U)) 532 /*! 533 * @brief Device ehci DCD ISR function. 534 * 535 * The function is the ehci DCD interrupt service routine. 536 * 537 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 538 */ 539 extern void USB_DeviceEhciIsrHSDCDFunction(void *deviceHandle); 540 #endif 541 #endif 542 #endif 543 544 #if (((defined(USB_DEVICE_CONFIG_LPCIP3511FS)) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)) || \ 545 ((defined(USB_DEVICE_CONFIG_LPCIP3511HS)) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U))) 546 #if ((defined(USB_DEVICE_CONFIG_USE_TASK)) && (USB_DEVICE_CONFIG_USE_TASK > 0U)) 547 /*! 548 * @brief Device LPC ip3511 controller task function. 549 * 550 * The function is used to handle the LPC ip3511 controller message. 551 * In the bare metal environment, this function should be called periodically in the main function. 552 * In the RTOS environment, this function should be used as a function entry to create a task. 553 * 554 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 555 */ 556 #define USB_DeviceLpcIp3511TaskFunction(deviceHandle) USB_DeviceTaskFunction(deviceHandle) 557 #endif 558 #if (defined(USB_DEVICE_CONFIG_CHARGER_DETECT) && (USB_DEVICE_CONFIG_CHARGER_DETECT > 0U)) 559 #if (defined(FSL_FEATURE_SOC_USBHSDCD_COUNT) && (FSL_FEATURE_SOC_USBHSDCD_COUNT > 0U)) 560 /*! 561 * @brief Device IP3511 DCD ISR function. 562 * 563 * The function is the IP3511 DCD interrupt service routine. 564 * 565 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 566 */ 567 extern void USB_DeviceLpcIp3511IsrDCDFunction(void *deviceHandle); 568 #endif 569 #endif 570 #endif 571 572 #if ((defined(USB_DEVICE_CONFIG_KHCI)) && (USB_DEVICE_CONFIG_KHCI > 0U)) 573 /*! 574 * @brief Device KHCI ISR function. 575 * 576 * The function is the KHCI interrupt service routine. 577 * 578 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 579 */ 580 extern void USB_DeviceKhciIsrFunction(void *deviceHandle); 581 #if (defined(USB_DEVICE_CONFIG_CHARGER_DETECT) && (USB_DEVICE_CONFIG_CHARGER_DETECT > 0U)) 582 #if (defined(FSL_FEATURE_SOC_USBDCD_COUNT) && (FSL_FEATURE_SOC_USBDCD_COUNT > 0U)) 583 #if 0U /* it is not implemented yet */ 584 /*! 585 * @brief Device KHCI DCD ISR function. 586 * 587 * The function is the KHCI DCD interrupt service routine. 588 * 589 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 590 */ 591 extern void USB_DeviceDcdIsrFunction(void *deviceHandle); 592 #endif 593 #endif 594 #endif 595 #endif 596 597 #if ((defined(USB_DEVICE_CONFIG_EHCI)) && (USB_DEVICE_CONFIG_EHCI > 0U)) 598 /*! 599 * @brief Device EHCI ISR function. 600 * 601 * The function is the EHCI interrupt service routine. 602 * 603 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 604 */ 605 extern void USB_DeviceEhciIsrFunction(void *deviceHandle); 606 #endif 607 608 #if (((defined(USB_DEVICE_CONFIG_LPCIP3511FS)) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)) || \ 609 ((defined(USB_DEVICE_CONFIG_LPCIP3511HS)) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U))) 610 /*! 611 * @brief Device LPC USB ISR function. 612 * 613 * The function is the LPC USB interrupt service routine. 614 * 615 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 616 */ 617 extern void USB_DeviceLpcIp3511IsrFunction(void *deviceHandle); 618 #endif 619 620 #if (((defined(USB_DEVICE_CONFIG_DWC3)) && (USB_DEVICE_CONFIG_DWC3 > 0U)) || \ 621 ((defined(USB_DEVICE_CONFIG_DWC3)) && (USB_DEVICE_CONFIG_DWC3 > 0U))) 622 /*! 623 * @brief Device USB DWC3 ISR function. 624 * 625 * The function is the USB interrupt service routine. 626 * 627 * @param[in] deviceHandle The device handle got from #USB_DeviceInit. 628 */ 629 extern void USB_DeviceDwc3IsrFunction(void *deviceHandle); 630 #endif 631 632 /*! 633 * @brief Gets the device stack version function. 634 * 635 * The function is used to get the device stack version. 636 * 637 * @param[out] version The version structure pointer to keep the device stack version. 638 * 639 */ 640 extern void USB_DeviceGetVersion(uint32_t *version); 641 642 #if ((defined(USB_DEVICE_CONFIG_REMOTE_WAKEUP)) && (USB_DEVICE_CONFIG_REMOTE_WAKEUP > 0U)) || \ 643 (((defined(USB_DEVICE_CONFIG_CHARGER_DETECT) && (USB_DEVICE_CONFIG_CHARGER_DETECT > 0U)) && \ 644 (defined(FSL_FEATURE_SOC_USB_ANALOG_COUNT) && (FSL_FEATURE_SOC_USB_ANALOG_COUNT > 0U)))) 645 /*! 646 * @brief Update the hardware tick. 647 * 648 * The function is used to update the hardware tick. 649 * 650 * @param[in] handle The device handle got from #USB_DeviceInit. 651 * @param[in] tick Current hardware tick(uint is ms). 652 * 653 */ 654 extern usb_status_t USB_DeviceUpdateHwTick(usb_device_handle handle, uint64_t tick); 655 #endif 656 657 /*! @}*/ 658 659 #if defined(__cplusplus) 660 } 661 #endif /* __cplusplus*/ 662 663 /*! @}*/ 664 665 #endif /* __USB_DEVICE_H__ */ 666