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