5b8c8084a261de1b6f66ac75f659d9be7b46fafe
[gps-watch.git] / src / common / usb_device_descriptor.h
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 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 #ifndef _USB_DEVICE_DESCRIPTOR_H_
35 #define _USB_DEVICE_DESCRIPTOR_H_ 1
36
37 /*******************************************************************************
38 * Definitions
39 ******************************************************************************/
40 #define USB_DEVICE_SPECIFIC_BCD_VERSION (0x0200)
41 #define USB_DEVICE_DEMO_BCD_VERSION (0x0101U)
42
43 /* Communication  Class Codes */
44 #define CDC_COMM_CLASS (0x02)
45 /* Data  Class Codes */
46 #define CDC_DATA_CLASS (0x0A)
47
48 /* Communication Class SubClass Codes */
49 #define USB_CDC_DIRECT_LINE_CONTROL_MODEL (0x01)
50 #define USB_CDC_ABSTRACT_CONTROL_MODEL (0x02)
51 #define USB_CDC_TELEPHONE_CONTROL_MODEL (0x03)
52 #define USB_CDC_MULTI_CHANNEL_CONTROL_MODEL (0x04)
53 #define USB_CDC_CAPI_CONTROL_MOPDEL (0x05)
54 #define USB_CDC_ETHERNET_NETWORKING_CONTROL_MODEL (0x06)
55 #define USB_CDC_ATM_NETWORKING_CONTROL_MODEL (0x07)
56 #define USB_CDC_WIRELESS_HANDSET_CONTROL_MODEL (0x08)
57 #define USB_CDC_DEVICE_MANAGEMENT (0x09)
58 #define USB_CDC_MOBILE_DIRECT_LINE_MODEL (0x0A)
59 #define USB_CDC_OBEX (0x0B)
60 #define USB_CDC_ETHERNET_EMULATION_MODEL (0x0C)
61
62 /* Communication Class Protocol Codes */
63 #define USB_CDC_NO_CLASS_SPECIFIC_PROTOCOL (0x00) /*also for Data Class Protocol Code */
64 #define USB_CDC_AT_250_PROTOCOL (0x01)
65 #define USB_CDC_AT_PCCA_101_PROTOCOL (0x02)
66 #define USB_CDC_AT_PCCA_101_ANNEX_O (0x03)
67 #define USB_CDC_AT_GSM_7_07 (0x04)
68 #define USB_CDC_AT_3GPP_27_007 (0x05)
69 #define USB_CDC_AT_TIA_CDMA (0x06)
70 #define USB_CDC_ETHERNET_EMULATION_PROTOCOL (0x07)
71 #define USB_CDC_EXTERNAL_PROTOCOL (0xFE)
72 #define USB_CDC_VENDOR_SPECIFIC (0xFF) /*also for Data Class Protocol Code */
73
74 /* Data Class Protocol Codes */
75 #define USB_CDC_PYHSICAL_INTERFACE_PROTOCOL (0x30)
76 #define USB_CDC_HDLC_PROTOCOL (0x31)
77 #define USB_CDC_TRANSPARENT_PROTOCOL (0x32)
78 #define USB_CDC_MANAGEMENT_PROTOCOL (0x50)
79 #define USB_CDC_DATA_LINK_Q931_PROTOCOL (0x51)
80 #define USB_CDC_DATA_LINK_Q921_PROTOCOL (0x52)
81 #define USB_CDC_DATA_COMPRESSION_V42BIS (0x90)
82 #define USB_CDC_EURO_ISDN_PROTOCOL (0x91)
83 #define USB_CDC_RATE_ADAPTION_ISDN_V24 (0x92)
84 #define USB_CDC_CAPI_COMMANDS (0x93)
85 #define USB_CDC_HOST_BASED_DRIVER (0xFD)
86 #define USB_CDC_UNIT_FUNCTIONAL (0xFE)
87
88 /* Descriptor SubType in Communications Class Functional Descriptors */
89 #define USB_CDC_HEADER_FUNC_DESC (0x00)
90 #define USB_CDC_CALL_MANAGEMENT_FUNC_DESC (0x01)
91 #define USB_CDC_ABSTRACT_CONTROL_FUNC_DESC (0x02)
92 #define USB_CDC_DIRECT_LINE_FUNC_DESC (0x03)
93 #define USB_CDC_TELEPHONE_RINGER_FUNC_DESC (0x04)
94 #define USB_CDC_TELEPHONE_REPORT_FUNC_DESC (0x05)
95 #define USB_CDC_UNION_FUNC_DESC (0x06)
96 #define USB_CDC_COUNTRY_SELECT_FUNC_DESC (0x07)
97 #define USB_CDC_TELEPHONE_MODES_FUNC_DESC (0x08)
98 #define USB_CDC_TERMINAL_FUNC_DESC (0x09)
99 #define USB_CDC_NETWORK_CHANNEL_FUNC_DESC (0x0A)
100 #define USB_CDC_PROTOCOL_UNIT_FUNC_DESC (0x0B)
101 #define USB_CDC_EXTENSION_UNIT_FUNC_DESC (0x0C)
102 #define USB_CDC_MULTI_CHANNEL_FUNC_DESC (0x0D)
103 #define USB_CDC_CAPI_CONTROL_FUNC_DESC (0x0E)
104 #define USB_CDC_ETHERNET_NETWORKING_FUNC_DESC (0x0F)
105 #define USB_CDC_ATM_NETWORKING_FUNC_DESC (0x10)
106 #define USB_CDC_WIRELESS_CONTROL_FUNC_DESC (0x11)
107 #define USB_CDC_MOBILE_DIRECT_LINE_FUNC_DESC (0x12)
108 #define USB_CDC_MDLM_DETAIL_FUNC_DESC (0x13)
109 #define USB_CDC_DEVICE_MANAGEMENT_FUNC_DESC (0x14)
110 #define USB_CDC_OBEX_FUNC_DESC (0x15)
111 #define USB_CDC_COMMAND_SET_FUNC_DESC (0x16)
112 #define USB_CDC_COMMAND_SET_DETAIL_FUNC_DESC (0x17)
113 #define USB_CDC_TELEPHONE_CONTROL_FUNC_DESC (0x18)
114 #define USB_CDC_OBEX_SERVICE_ID_FUNC_DESC (0x19)
115
116 /* usb descritpor length */
117 #define USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL (67)
118 #define USB_DESCRIPTOR_LENGTH_CDC_HEADER_FUNC (5)
119 #define USB_DESCRIPTOR_LENGTH_CDC_CALL_MANAG (5)
120 #define USB_DESCRIPTOR_LENGTH_CDC_ABSTRACT (4)
121 #define USB_DESCRIPTOR_LENGTH_CDC_UNION_FUNC (5)
122
123 #define USB_DEVICE_CONFIGURATION_COUNT (1)
124 #define USB_DEVICE_STRING_COUNT (3)
125 #define USB_DEVICE_LANGUAGE_COUNT (1)
126
127 #define USB_CDC_VCOM_CONFIGURE_INDEX (1)
128
129 #define USB_CDC_VCOM_ENDPOINT_CIC_COUNT (1)
130 #define USB_CDC_VCOM_ENDPOINT_DIC_COUNT (2)
131 #define USB_CDC_VCOM_INTERRUPT_IN_ENDPOINT (1)
132 #define USB_CDC_VCOM_BULK_IN_ENDPOINT (2)
133 #define USB_CDC_VCOM_BULK_OUT_ENDPOINT (3)
134 #define USB_CDC_VCOM_INTERFACE_COUNT (2)
135 #define USB_CDC_VCOM_COMM_INTERFACE_INDEX (0)
136 #define USB_CDC_VCOM_DATA_INTERFACE_INDEX (1)
137
138 #define HS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE (16)
139 #define FS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE (16)
140 #define HS_CDC_VCOM_INTERRUPT_IN_INTERVAL (0x07) /* 2^(7-1) = 8ms */
141 #define FS_CDC_VCOM_INTERRUPT_IN_INTERVAL (0x08)
142 #define HS_CDC_VCOM_BULK_IN_PACKET_SIZE (512)
143 #define FS_CDC_VCOM_BULK_IN_PACKET_SIZE (64)
144 #define HS_CDC_VCOM_BULK_OUT_PACKET_SIZE (512)
145 #define FS_CDC_VCOM_BULK_OUT_PACKET_SIZE (64)
146
147 #define USB_DESCRIPTOR_LENGTH_STRING0 (4)
148 #define USB_DESCRIPTOR_LENGTH_STRING1 (38)
149 #define USB_DESCRIPTOR_LENGTH_STRING2 (42)
150
151 #define USB_DESCRIPTOR_TYPE_CDC_CS_INTERFACE (0x24)
152 #define USB_DESCRIPTOR_TYPE_CDC_CS_ENDPOINT (0x25)
153
154 #define USB_DEVICE_CLASS (0x02)
155 #define USB_DEVICE_SUBCLASS (0x00)
156 #define USB_DEVICE_PROTOCOL (0x00)
157
158 #define USB_DEVICE_MAX_POWER (0x32)
159
160 #define USB_CDC_VCOM_CIC_CLASS (CDC_COMM_CLASS)
161 #define USB_CDC_VCOM_CIC_SUBCLASS (USB_CDC_ABSTRACT_CONTROL_MODEL)
162 #define USB_CDC_VCOM_CIC_PROTOCOL (USB_CDC_NO_CLASS_SPECIFIC_PROTOCOL)
163
164 #define USB_CDC_VCOM_DIC_CLASS (CDC_DATA_CLASS)
165 #define USB_CDC_VCOM_DIC_SUBCLASS (0x00)
166 #define USB_CDC_VCOM_DIC_PROTOCOL (USB_CDC_NO_CLASS_SPECIFIC_PROTOCOL)
167
168 /*******************************************************************************
169 * API
170 ******************************************************************************/
171 /*!
172  * @brief USB device callback function.
173  *
174  * This function handles the usb device specific requests.
175  *
176  * @param handle          The USB device handle.
177  * @param event           The USB device event type.
178  * @param param           The parameter of the device specific request.
179  *
180  * @return A USB error code or kStatus_USB_Success.
181  */
182 extern usb_status_t USB_DeviceCallback(usb_device_handle handle, uint32_t event, void *param);
183
184 /*!
185  * @brief USB device set speed function.
186  *
187  * This function sets the speed of the USB device.
188  *
189  * Due to the difference of HS and FS descriptors, the device descriptors and configurations need to be updated to match
190  * current speed.
191  * As the default, the device descriptors and configurations are configured by using FS parameters for both EHCI and
192  * KHCI.
193  * When the EHCI is enabled, the application needs to call this fucntion to update device by using current speed.
194  * The updated information includes endpoint max packet size, endpoint interval, etc.
195  *
196  * @param handle The USB device handle.
197  * @param speed Speed type. USB_SPEED_HIGH/USB_SPEED_FULL/USB_SPEED_LOW.
198  *
199  * @return A USB error code or kStatus_USB_Success.
200  */
201 extern usb_status_t USB_DeviceSetSpeed(usb_device_handle handle, uint8_t speed);
202
203 #endif /* _USB_DEVICE_DESCRIPTOR_H_ */