/* * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. * Copyright 2016 NXP * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, this list * of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, this * list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * o Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _USB_HOST_H_ #define _USB_HOST_H_ #include #include #include /******************************************************************************* * Definitions ******************************************************************************/ struct _usb_host_transfer; /* for cross reference */ /*! * @addtogroup usb_host_drv * @{ */ /*! @brief USB host class handle type define */ typedef void *usb_host_class_handle; /*! @brief USB host controller handle type define */ typedef void *usb_host_controller_handle; /*! @brief USB host configuration handle type define */ typedef void *usb_host_configuration_handle; /*! @brief USB host interface handle type define */ typedef void *usb_host_interface_handle; /*! @brief USB host pipe handle type define */ typedef void *usb_host_pipe_handle; /*! @brief Event codes for device attach/detach */ typedef enum _usb_host_event { kUSB_HostEventAttach = 1U, /*!< Device is attached */ kUSB_HostEventDetach, /*!< Device is detached */ kUSB_HostEventEnumerationDone, /*!< Device's enumeration is done and the device is supported */ kUSB_HostEventNotSupported, /*!< Device's enumeration is done and the device is not supported */ #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U)) kUSB_HostEventNotSuspended, /*!< Suspend failed */ kUSB_HostEventSuspended, /*!< Suspend successful */ kUSB_HostEventNotResumed, /*!< Resume failed */ kUSB_HostEventDetectResume, /*!< Detect resume signal */ kUSB_HostEventResumed, /*!< Resume successful */ kUSB_HostEventL1Sleeped, /*!< L1 Sleep successful,state transition was successful (ACK) */ kUSB_HostEventL1SleepNYET, /*!< Device was unable to enter the L1 state at this time (NYET) */ kUSB_HostEventL1SleepNotSupport, /*!< Device does not support the L1 state (STALL) */ kUSB_HostEventL1SleepError, /*!< Device failed to respond or an error occurred */ kUSB_HostEventL1NotResumed, /*!< Resume failed */ kUSB_HostEventL1DetectResume, /*!< Detect resume signal */ kUSB_HostEventL1Resumed, /*!< Resume successful */ #endif } usb_host_event_t; /*! @brief USB host device information code */ typedef enum _usb_host_dev_info { kUSB_HostGetDeviceAddress = 1U, /*!< Device's address */ kUSB_HostGetDeviceHubNumber, /*!< Device's first hub address */ kUSB_HostGetDevicePortNumber, /*!< Device's first hub port number */ kUSB_HostGetDeviceSpeed, /*!< Device's speed */ kUSB_HostGetDeviceHSHubNumber, /*!< Device's first high-speed hub address */ kUSB_HostGetDeviceHSHubPort, /*!< Device's first high-speed hub number */ kUSB_HostGetDeviceLevel, /*!< Device's hub level */ kUSB_HostGetHostHandle, /*!< Device's host handle */ kUSB_HostGetDeviceControlPipe, /*!< Device's control pipe handle */ kUSB_HostGetDevicePID, /*!< Device's PID */ kUSB_HostGetDeviceVID, /*!< Device's VID */ kUSB_HostGetHubThinkTime, /*!< Device's hub total think time */ kUSB_HostGetDeviceConfigIndex, /*!< Device's running zero-based config index */ kUSB_HostGetConfigurationDes, /*!< Device's configuration descriptor pointer */ kUSB_HostGetConfigurationLength, /*!< Device's configuration descriptor pointer */ } usb_host_dev_info_t; /*! * @brief Host callback function typedef. * * This callback function is used to notify application device attach/detach event. * This callback pointer is passed when initializing the host. * * @param deviceHandle The device handle, which indicates the attached device. * @param configurationHandle The configuration handle contains the attached device's configuration information. * @param event_code The callback event code; See the enumeration host_event_t. * * @return A USB error code or kStatus_USB_Success. * @retval kStatus_USB_Success Application handles the attached device successfully. * @retval kStatus_USB_NotSupported Application don't support the attached device. * @retval kStatus_USB_Error Application handles the attached device falsely. */ typedef usb_status_t (*host_callback_t)(usb_device_handle deviceHandle, usb_host_configuration_handle configurationHandle, uint32_t eventCode); /*! * @brief Transfer callback function typedef. * * This callback function is used to notify the upper layer the result of the transfer. * This callback pointer is passed when calling the send/receive APIs. * * @param param The parameter pointer, which is passed when calling the send/receive APIs. * @param data The data buffer pointer. * @param data_len The result data length. * @param status A USB error code or kStatus_USB_Success. */ typedef void (*transfer_callback_t)(void *param, uint8_t *data, uint32_t dataLen, usb_status_t status); /*! * @brief Host stack inner transfer callback function typedef. * * This callback function is used to notify the upper layer the result of a transfer. * This callback pointer is passed when initializing the structure usb_host_transfer_t. * * @param param The parameter pointer, which is passed when calling the send/receive APIs. * @param transfer The transfer information; See the structure usb_host_transfer_t. * @param status A USB error code or kStatus_USB_Success. */ typedef void (*host_inner_transfer_callback_t)(void *param, struct _usb_host_transfer *transfer, usb_status_t status); /*! @brief USB host endpoint information structure */ typedef struct _usb_host_ep { usb_descriptor_endpoint_t *epDesc; /*!< Endpoint descriptor pointer*/ uint8_t *epExtension; /*!< Endpoint extended descriptor pointer*/ uint16_t epExtensionLength; /*!< Extended descriptor length*/ } usb_host_ep_t; /*! @brief USB host interface information structure */ typedef struct _usb_host_interface { usb_host_ep_t epList[USB_HOST_CONFIG_INTERFACE_MAX_EP]; /*!< Endpoint array*/ usb_descriptor_interface_t *interfaceDesc; /*!< Interface descriptor pointer*/ uint8_t *interfaceExtension; /*!< Interface extended descriptor pointer*/ uint16_t interfaceExtensionLength; /*!< Extended descriptor length*/ uint8_t interfaceIndex; /*!< The interface index*/ uint8_t alternateSettingNumber; /*!< The interface alternate setting value*/ uint8_t epCount; /*!< Interface's endpoint number*/ } usb_host_interface_t; /*! @brief USB host configuration information structure */ typedef struct _usb_host_configuration { usb_host_interface_t interfaceList[USB_HOST_CONFIG_CONFIGURATION_MAX_INTERFACE]; /*!< Interface array*/ usb_descriptor_configuration_t *configurationDesc; /*!< Configuration descriptor pointer*/ uint8_t *configurationExtension; /*!< Configuration extended descriptor pointer*/ uint16_t configurationExtensionLength; /*!< Extended descriptor length*/ uint8_t interfaceCount; /*!< The configuration's interface number*/ } usb_host_configuration_t; /*! @brief USB host pipe common structure */ typedef struct _usb_host_pipe { struct _usb_host_pipe *next; /*!< Link the idle pipes*/ usb_device_handle deviceHandle; /*!< This pipe's device's handle*/ uint16_t currentCount; /*!< For KHCI transfer*/ uint16_t nakCount; /*!< Maximum NAK count*/ uint16_t maxPacketSize; /*!< Maximum packet size*/ uint16_t interval; /*!< FS/LS: frame unit; HS: micro-frame unit*/ uint8_t open; /*!< 0 - closed, 1 - open*/ uint8_t nextdata01; /*!< Data toggle*/ uint8_t endpointAddress; /*!< Endpoint address*/ uint8_t direction; /*!< Pipe direction*/ uint8_t pipeType; /*!< Pipe type, for example USB_ENDPOINT_BULK*/ uint8_t numberPerUframe; /*!< Transaction number per micro-frame*/ } usb_host_pipe_t; /*! @brief USB host transfer structure */ typedef struct _usb_host_transfer { struct _usb_host_transfer *next; /*!< The next transfer structure*/ uint8_t *transferBuffer; /*!< Transfer data buffer*/ uint32_t transferLength; /*!< Transfer data length*/ uint32_t transferSofar; /*!< Length transferred so far*/ host_inner_transfer_callback_t callbackFn; /*!< Transfer callback function*/ void *callbackParam; /*!< Transfer callback parameter*/ usb_host_pipe_t *transferPipe; /*!< Transfer pipe pointer*/ usb_setup_struct_t *setupPacket; /*!< Set up packet buffer*/ uint8_t direction; /*!< Transfer direction; it's values are USB_OUT or USB_IN*/ uint8_t setupStatus; /*!< Set up the transfer status*/ union { uint32_t unitHead; /*!< xTD head for this transfer*/ int32_t transferResult; /*!< KHCI transfer result */ } union1; union { uint32_t unitTail; /*! 0U)) /*! * @brief Send a bus or device suspend request. * * This function is used to send a bus or device suspend request. * * @param[in] hostHandle The host handle. * @param[in] deviceHandle The device handle. * * @retval kStatus_USB_Success Request successfully. * @retval kStatus_USB_InvalidHandle The hostHandle is a NULL pointer. Or the controller handle is invalid. * @retval kStatus_USB_Error There is no idle transfer. * Or, the deviceHandle is invalid. * Or, the request is invalid. */ extern usb_status_t USB_HostSuspendDeviceResquest(usb_host_handle hostHandle, usb_device_handle deviceHandle); /*! * @brief Send a bus or device resume request. * * This function is used to send a bus or device resume request. * * @param[in] hostHandle The host handle. * @param[in] deviceHandle The device handle. * * @retval kStatus_USB_Success Request successfully. * @retval kStatus_USB_InvalidHandle The hostHandle is a NULL pointer. Or the controller handle is invalid. * @retval kStatus_USB_Error There is no idle transfer. * Or, the deviceHandle is invalid. * Or, the request is invalid. */ extern usb_status_t USB_HostResumeDeviceResquest(usb_host_handle hostHandle, usb_device_handle deviceHandle); #if ((defined(USB_HOST_CONFIG_LPM_L1)) && (USB_HOST_CONFIG_LPM_L1 > 0U)) /*! * @brief Send a bus or device suspend request. * * This function is used to send a bus or device suspend request. * * @param[in] hostHandle The host handle. * @param[in] deviceHandle The device handle. *@param[in] sleeptype Bus suspend or single device suspend. * * @retval kStatus_USB_Success Request successfully. * @retval kStatus_USB_InvalidHandle The hostHandle is a NULL pointer. Or the controller handle is invalid. * @retval kStatus_USB_Error There is no idle transfer. * Or, the deviceHandle is invalid. * Or, the request is invalid. */ extern usb_status_t USB_HostL1SleepDeviceResquest(usb_host_handle hostHandle, usb_device_handle deviceHandle, uint8_t sleeptype); /*! * @brief Send a bus or device resume request. * * This function is used to send a bus or device resume request. * * @param[in] hostHandle The host handle. * @param[in] deviceHandle The device handle. * *@param[in] sleeptype Bus suspend or single device suspend. * * @retval kStatus_USB_Success Request successfully. * @retval kStatus_USB_InvalidHandle The hostHandle is a NULL pointer. Or the controller handle is invalid. * @retval kStatus_USB_Error There is no idle transfer. * Or, the deviceHandle is invalid. * Or, the request is invalid. */ extern usb_status_t USB_HostL1ResumeDeviceResquest(usb_host_handle hostHandle, usb_device_handle deviceHandle, uint8_t sleepType); /*! * @brief Update the lpm param. * * The function is used to configuure the lpm token. * * @param[in] hostHandle The host handle. * @param[in] lpmParam HIRD vaule and whether enable remotewakeup. * */ extern usb_status_t USB_HostL1SleepDeviceResquestConfig(usb_host_handle hostHandle, uint8_t *lpmParam); #endif /*! * @brief Update the hardware tick. * * The function is used to update the hardware tick. * * @param[in] hostHandle The host handle. * @param[in] tick Current hardware tick(uint is ms). * */ extern usb_status_t USB_HostUpdateHwTick(usb_host_handle hostHandle, uint64_t tick); #endif /*! @}*/ #ifdef __cplusplus } #endif /*! @}*/ #endif /* _USB_HOST_H_ */