common: Implement TimeAndPos::distance_cm().
[gps-watch.git] / src / common / usb_device_dci.h
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
4  * Copyright 2016 NXP
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted (subject to the limitations in the disclaimer below) provided
9  * that the following conditions are met:
10  *
11  * o Redistributions of source code must retain the above copyright notice, this list
12  *   of conditions and the following disclaimer.
13  *
14  * o Redistributions in binary form must reproduce the above copyright notice, this
15  *   list of conditions and the following disclaimer in the documentation and/or
16  *   other materials provided with the distribution.
17  *
18  * o Neither the name of the copyright holder nor the names of its
19  *   contributors may be used to endorse or promote products derived from this
20  *   software without specific prior written permission.
21  *
22  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #ifndef __USB_DEVICE_DCI_H__
36 #define __USB_DEVICE_DCI_H__
37
38 /*!
39  * @addtogroup usb_device_controller_driver
40  * @{
41  */
42
43 /*******************************************************************************
44  * Definitions
45  ******************************************************************************/
46
47 /*! @brief Macro to define controller handle */
48 #define usb_device_controller_handle usb_device_handle
49
50 /*! @brief Available notify types for device notification */
51 typedef enum _usb_device_notification
52 {
53     kUSB_DeviceNotifyBusReset = 0x10U, /*!< Reset signal detected */
54     kUSB_DeviceNotifySuspend,          /*!< Suspend signal detected */
55     kUSB_DeviceNotifyResume,           /*!< Resume signal detected */
56     kUSB_DeviceNotifyLPMSleep,         /*!< LPM signal detected */
57     kUSB_DeviceNotifyLPMResume,        /*!< Resume signal detected */
58     kUSB_DeviceNotifyError,            /*!< Errors happened in bus */
59     kUSB_DeviceNotifyDetach,           /*!< Device disconnected from a host */
60     kUSB_DeviceNotifyAttach,           /*!< Device connected to a host */
61 #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U))
62     kUSB_DeviceNotifyDcdTimeOut,               /*!< Device charger detection timeout */
63     kUSB_DeviceNotifyDcdUnknownPortType,       /*!< Device charger detection unknown port type */
64     kUSB_DeviceNotifySDPDetected,              /*!< The SDP facility is detected */
65     kUSB_DeviceNotifyChargingPortDetected,     /*!< The charging port is detected */
66     kUSB_DeviceNotifyChargingHostDetected,     /*!< The CDP facility is detected */
67     kUSB_DeviceNotifyDedicatedChargerDetected, /*!< The DCP facility is detected */
68 #endif
69 } usb_device_notification_t;
70
71 /*! @brief Device notification message structure */
72 typedef struct _usb_device_callback_message_struct
73 {
74     uint8_t *buffer; /*!< Transferred buffer */
75     uint32_t length; /*!< Transferred data length */
76     uint8_t code;    /*!< Notification code */
77     uint8_t isSetup; /*!< Is in a setup phase */
78 } usb_device_callback_message_struct_t;
79
80 /*! @brief Control type for controller */
81 typedef enum _usb_device_control_type
82 {
83     kUSB_DeviceControlRun = 0U,          /*!< Enable the device functionality */
84     kUSB_DeviceControlStop,              /*!< Disable the device functionality */
85     kUSB_DeviceControlEndpointInit,      /*!< Initialize a specified endpoint */
86     kUSB_DeviceControlEndpointDeinit,    /*!< De-initialize a specified endpoint */
87     kUSB_DeviceControlEndpointStall,     /*!< Stall a specified endpoint */
88     kUSB_DeviceControlEndpointUnstall,   /*!< Unstall a specified endpoint */
89     kUSB_DeviceControlGetDeviceStatus,   /*!< Get device status */
90     kUSB_DeviceControlGetEndpointStatus, /*!< Get endpoint status */
91     kUSB_DeviceControlSetDeviceAddress,  /*!< Set device address */
92     kUSB_DeviceControlGetSynchFrame,     /*!< Get current frame */
93     kUSB_DeviceControlResume,            /*!< Drive controller to generate a resume signal in USB bus */
94     kUSB_DeviceControlSleepResume,       /*!< Drive controller to generate a LPM resume signal in USB bus */
95     kUSB_DeviceControlSuspend,           /*!< Drive controller to enetr into suspend mode */
96     kUSB_DeviceControlSleep,             /*!< Drive controller to enetr into sleep mode */
97     kUSB_DeviceControlSetDefaultStatus,  /*!< Set controller to default status */
98     kUSB_DeviceControlGetSpeed,          /*!< Get current speed */
99     kUSB_DeviceControlGetOtgStatus,      /*!< Get OTG status */
100     kUSB_DeviceControlSetOtgStatus,      /*!< Set OTG status */
101     kUSB_DeviceControlSetTestMode,       /*!< Drive xCHI into test mode */
102     kUSB_DeviceControlGetRemoteWakeUp,   /*!< Get flag of LPM Remote Wake-up Enabled by USB host. */
103 #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U))
104     kUSB_DeviceControlDcdInitModule,
105     kUSB_DeviceControlDcdDeinitModule,
106 #endif
107 } usb_device_control_type_t;
108
109 /*! @brief USB device controller initialization function typedef */
110 typedef usb_status_t (*usb_device_controller_init_t)(uint8_t controllerId,
111                                                      usb_device_handle handle,
112                                                      usb_device_controller_handle *controllerHandle);
113
114 /*! @brief USB device controller de-initialization function typedef */
115 typedef usb_status_t (*usb_device_controller_deinit_t)(usb_device_controller_handle controllerHandle);
116
117 /*! @brief USB device controller send data function typedef */
118 typedef usb_status_t (*usb_device_controller_send_t)(usb_device_controller_handle controllerHandle,
119                                                      uint8_t endpointAddress,
120                                                      uint8_t *buffer,
121                                                      uint32_t length);
122
123 /*! @brief USB device controller receive data function typedef */
124 typedef usb_status_t (*usb_device_controller_recv_t)(usb_device_controller_handle controllerHandle,
125                                                      uint8_t endpointAddress,
126                                                      uint8_t *buffer,
127                                                      uint32_t length);
128
129 /*! @brief USB device controller cancel transfer function in a specified endpoint typedef */
130 typedef usb_status_t (*usb_device_controller_cancel_t)(usb_device_controller_handle controllerHandle,
131                                                        uint8_t endpointAddress);
132
133 /*! @brief USB device controller control function typedef */
134 typedef usb_status_t (*usb_device_controller_control_t)(usb_device_controller_handle controllerHandle,
135                                                         usb_device_control_type_t command,
136                                                         void *param);
137
138 /*! @brief USB device controller interface structure */
139 typedef struct _usb_device_controller_interface_struct
140 {
141     usb_device_controller_init_t deviceInit;       /*!< Controller initialization */
142     usb_device_controller_deinit_t deviceDeinit;   /*!< Controller de-initialization */
143     usb_device_controller_send_t deviceSend;       /*!< Controller send data */
144     usb_device_controller_recv_t deviceRecv;       /*!< Controller receive data */
145     usb_device_controller_cancel_t deviceCancel;   /*!< Controller cancel transfer */
146     usb_device_controller_control_t deviceControl; /*!< Controller control */
147 } usb_device_controller_interface_struct_t;
148
149 /*! @brief USB device status structure */
150 typedef struct _usb_device_struct
151 {
152 #if ((defined(USB_DEVICE_CONFIG_REMOTE_WAKEUP)) && (USB_DEVICE_CONFIG_REMOTE_WAKEUP > 0U))
153     volatile uint64_t hwTick; /*!< Current hw tick(ms)*/
154 #endif
155     usb_device_controller_handle controllerHandle;                       /*!< Controller handle */
156     const usb_device_controller_interface_struct_t *controllerInterface; /*!< Controller interface handle */
157 #if USB_DEVICE_CONFIG_USE_TASK
158     usb_osa_msgq_handle notificationQueue; /*!< Message queue */
159 #endif
160     usb_device_callback_t deviceCallback; /*!< Device callback function pointer */
161     usb_device_endpoint_callback_struct_t
162         epCallback[USB_DEVICE_CONFIG_ENDPOINTS << 1U]; /*!< Endpoint callback function structure */
163     uint8_t deviceAddress;                             /*!< Current device address */
164     uint8_t controllerId;                              /*!< Controller ID */
165     uint8_t state;                                     /*!< Current device state */
166 #if ((defined(USB_DEVICE_CONFIG_REMOTE_WAKEUP)) && (USB_DEVICE_CONFIG_REMOTE_WAKEUP > 0U))
167     uint8_t remotewakeup; /*!< Remote wakeup is enabled or not */
168 #endif
169     uint8_t isResetting; /*!< Is doing device reset or not */
170 #if (defined(USB_DEVICE_CONFIG_USE_TASK) && (USB_DEVICE_CONFIG_USE_TASK > 0U))
171     uint8_t epCallbackDirectly; /*!< Whether call ep callback directly when the task is enabled */
172 #endif
173 } usb_device_struct_t;
174
175 /*******************************************************************************
176  * API
177  ******************************************************************************/
178
179 /*! @}*/
180
181 #endif /* __USB_DEVICE_DCI_H__ */