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 __USB_DEVICE_DCI_H__ 32 #define __USB_DEVICE_DCI_H__ 33 34 /*! 35 * @addtogroup usb_device_controller_driver 36 * @{ 37 */ 38 39 /******************************************************************************* 40 * Definitions 41 ******************************************************************************/ 42 43 /*! @brief Macro to define controller handle */ 44 #define usb_device_controller_handle usb_device_handle 45 46 /*! @brief Available notify types for device notification */ 47 typedef enum _usb_device_notification 48 { 49 kUSB_DeviceNotifyBusReset = 0x10U, /*!< Reset signal detected */ 50 kUSB_DeviceNotifySuspend, /*!< Suspend signal detected */ 51 kUSB_DeviceNotifyResume, /*!< Resume signal detected */ 52 kUSB_DeviceNotifyLPMSleep, /*!< LPM signal detected */ 53 kUSB_DeviceNotifyLPMResume, /*!< Resume signal detected */ 54 kUSB_DeviceNotifyError, /*!< Errors happened in bus */ 55 kUSB_DeviceNotifyDetach, /*!< Device disconnected from a host */ 56 kUSB_DeviceNotifyAttach, /*!< Device connected to a host */ 57 #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U)) 58 kUSB_DeviceNotifyDcdTimeOut, /*!< Device charger detection timeout */ 59 kUSB_DeviceNotifyDcdUnknownPortType, /*!< Device charger detection unknown port type */ 60 kUSB_DeviceNotifySDPDetected, /*!< The SDP facility is detected */ 61 kUSB_DeviceNotifyChargingPortDetected, /*!< The charging port is detected */ 62 kUSB_DeviceNotifyChargingHostDetected, /*!< The CDP facility is detected */ 63 kUSB_DeviceNotifyDedicatedChargerDetected, /*!< The DCP facility is detected */ 64 #endif 65 } usb_device_notification_t; 66 67 /*! @brief Device notification message structure */ 68 typedef struct _usb_device_callback_message_struct 69 { 70 uint8_t *buffer; /*!< Transferred buffer */ 71 uint32_t length; /*!< Transferred data length */ 72 uint8_t code; /*!< Notification code */ 73 uint8_t isSetup; /*!< Is in a setup phase */ 74 } usb_device_callback_message_struct_t; 75 76 /*! @brief Control type for controller */ 77 typedef enum _usb_device_control_type 78 { 79 kUSB_DeviceControlRun = 0U, /*!< Enable the device functionality */ 80 kUSB_DeviceControlStop, /*!< Disable the device functionality */ 81 kUSB_DeviceControlEndpointInit, /*!< Initialize a specified endpoint */ 82 kUSB_DeviceControlEndpointDeinit, /*!< De-initialize a specified endpoint */ 83 kUSB_DeviceControlEndpointStall, /*!< Stall a specified endpoint */ 84 kUSB_DeviceControlEndpointUnstall, /*!< Unstall a specified endpoint */ 85 kUSB_DeviceControlGetDeviceStatus, /*!< Get device status */ 86 kUSB_DeviceControlGetEndpointStatus, /*!< Get endpoint status */ 87 kUSB_DeviceControlSetDeviceAddress, /*!< Set device address */ 88 kUSB_DeviceControlGetSynchFrame, /*!< Get current frame */ 89 kUSB_DeviceControlResume, /*!< Drive controller to generate a resume signal in USB bus */ 90 kUSB_DeviceControlSleepResume, /*!< Drive controller to generate a LPM resume signal in USB bus */ 91 kUSB_DeviceControlSuspend, /*!< Drive controller to enetr into suspend mode */ 92 kUSB_DeviceControlSleep, /*!< Drive controller to enetr into sleep mode */ 93 kUSB_DeviceControlSetDefaultStatus, /*!< Set controller to default status */ 94 kUSB_DeviceControlGetSpeed, /*!< Get current speed */ 95 kUSB_DeviceControlGetOtgStatus, /*!< Get OTG status */ 96 kUSB_DeviceControlSetOtgStatus, /*!< Set OTG status */ 97 kUSB_DeviceControlSetTestMode, /*!< Drive xCHI into test mode */ 98 kUSB_DeviceControlGetRemoteWakeUp, /*!< Get flag of LPM Remote Wake-up Enabled by USB host. */ 99 #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U)) 100 kUSB_DeviceControlDcdInitModule, 101 kUSB_DeviceControlDcdDeinitModule, 102 #endif 103 } usb_device_control_type_t; 104 105 /*! @brief USB device controller initialization function typedef */ 106 typedef usb_status_t (*usb_device_controller_init_t)(uint8_t controllerId, 107 usb_device_handle handle, 108 usb_device_controller_handle *controllerHandle); 109 110 /*! @brief USB device controller de-initialization function typedef */ 111 typedef usb_status_t (*usb_device_controller_deinit_t)(usb_device_controller_handle controllerHandle); 112 113 /*! @brief USB device controller send data function typedef */ 114 typedef usb_status_t (*usb_device_controller_send_t)(usb_device_controller_handle controllerHandle, 115 uint8_t endpointAddress, 116 uint8_t *buffer, 117 uint32_t length); 118 119 /*! @brief USB device controller receive data function typedef */ 120 typedef usb_status_t (*usb_device_controller_recv_t)(usb_device_controller_handle controllerHandle, 121 uint8_t endpointAddress, 122 uint8_t *buffer, 123 uint32_t length); 124 125 /*! @brief USB device controller cancel transfer function in a specified endpoint typedef */ 126 typedef usb_status_t (*usb_device_controller_cancel_t)(usb_device_controller_handle controllerHandle, 127 uint8_t endpointAddress); 128 129 /*! @brief USB device controller control function typedef */ 130 typedef usb_status_t (*usb_device_controller_control_t)(usb_device_controller_handle controllerHandle, 131 usb_device_control_type_t command, 132 void *param); 133 134 /*! @brief USB device controller interface structure */ 135 typedef struct _usb_device_controller_interface_struct 136 { 137 usb_device_controller_init_t deviceInit; /*!< Controller initialization */ 138 usb_device_controller_deinit_t deviceDeinit; /*!< Controller de-initialization */ 139 usb_device_controller_send_t deviceSend; /*!< Controller send data */ 140 usb_device_controller_recv_t deviceRecv; /*!< Controller receive data */ 141 usb_device_controller_cancel_t deviceCancel; /*!< Controller cancel transfer */ 142 usb_device_controller_control_t deviceControl; /*!< Controller control */ 143 } usb_device_controller_interface_struct_t; 144 145 /*! @brief USB device status structure */ 146 typedef struct _usb_device_struct 147 { 148 #if ((defined(USB_DEVICE_CONFIG_REMOTE_WAKEUP)) && (USB_DEVICE_CONFIG_REMOTE_WAKEUP > 0U)) 149 volatile uint64_t hwTick; /*!< Current hw tick(ms)*/ 150 #endif 151 usb_device_controller_handle controllerHandle; /*!< Controller handle */ 152 const usb_device_controller_interface_struct_t *controllerInterface; /*!< Controller interface handle */ 153 #if USB_DEVICE_CONFIG_USE_TASK 154 usb_osa_msgq_handle notificationQueue; /*!< Message queue */ 155 #endif 156 usb_device_callback_t deviceCallback; /*!< Device callback function pointer */ 157 usb_device_endpoint_callback_struct_t 158 epCallback[USB_DEVICE_CONFIG_ENDPOINTS << 1U]; /*!< Endpoint callback function structure */ 159 uint8_t deviceAddress; /*!< Current device address */ 160 uint8_t controllerId; /*!< Controller ID */ 161 uint8_t state; /*!< Current device state */ 162 #if ((defined(USB_DEVICE_CONFIG_REMOTE_WAKEUP)) && (USB_DEVICE_CONFIG_REMOTE_WAKEUP > 0U)) 163 uint8_t remotewakeup; /*!< Remote wakeup is enabled or not */ 164 #endif 165 uint8_t isResetting; /*!< Is doing device reset or not */ 166 #if (defined(USB_DEVICE_CONFIG_USE_TASK) && (USB_DEVICE_CONFIG_USE_TASK > 0U)) 167 uint8_t epCallbackDirectly; /*!< Whether call ep callback directly when the task is enabled */ 168 #endif 169 } usb_device_struct_t; 170 171 /******************************************************************************* 172 * API 173 ******************************************************************************/ 174 175 /*! @}*/ 176 177 #endif /* __USB_DEVICE_DCI_H__ */ 178