Kinetis Bootloader  2.0.0
Common bootloader for Kinetis devices
src/bm_usb/usb_descriptor.h
1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * All rights reserved.
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 Freescale Semiconductor, Inc. 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_DESCRIPTOR_H__
32 #define __USB_DESCRIPTOR_H__ 1
33 
34 #include "bootloader_common.h"
35 #include "usb_device_config.h"
36 #include "usb.h"
37 #include "usb_device.h"
38 
39 #include "usb_device_class.h"
40 #include "usb_device_hid.h"
41 #include "usb_device_msc.h"
42 
43 #include "usb_descriptor.h"
44 
45 #define USB_BCD_VERSION (0x0200)
46 
47 /*******************************************************************************
48  * For generic HID
49  *******************************************************************************/
50 
51 /* usb descritpor length */
52 #define USB_DEVICE_DESCRIPTOR_LENGTH (18)
53 
54 #if (USB_DEVICE_CONFIG_HID == 0) && (USB_DEVICE_CONFIG_MSC == 1)
55 #define USB_CONFIGURE_DESCRIPTOR_LENGTH (32) // 64, HID_only = 41, MSC_ONLY = 32
56 #elif(USB_DEVICE_CONFIG_HID == 1) && (USB_DEVICE_CONFIG_MSC == 0)
57 #define USB_CONFIGURE_DESCRIPTOR_LENGTH (41) // 64, HID_only = 41, MSC_ONLY = 32
58 #elif(USB_DEVICE_CONFIG_HID == 1) && (USB_DEVICE_CONFIG_MSC == 1)
59 #define USB_CONFIGURE_DESCRIPTOR_LENGTH (64) // 64, HID_only = 41, MSC_ONLY = 32
60 #else
61 #define USB_CONFIGURE_DESCRIPTOR_LENGTH (41) // 64, HID_only = 41, MSC_ONLY = 32
62 #endif
63 
64 #define USB_HID_REPORT_DESC_SIZE (76)
65 #define USB_HID_GENERIC_DESCRIPTOR_LENGTH (32)
66 #define USB_CONFIGURE_ONLY_DESCRIPTOR_LENGTH (9)
67 #define USB_INTERFACE_DESCRIPTOR_LENGTH (9)
68 #define USB_HID_DESCRIPTOR_LENGTH (9)
69 #define USB_ENDPOINT_DESCRIPTOR_LENGTH (7)
70 #define USB_MSC_DISK_REPORT_DESCRIPTOR_LENGTH (63)
71 #define USB_IAD_DESC_SIZE (8)
72 
73 #define USB_CONFIGURE_COUNT (1)
74 #define USB_STRING_COUNT (4)
75 #define USB_LANGUAGE_COUNT (1)
76 
77 #if (USB_DEVICE_CONFIG_HID == 1) && (USB_DEVICE_CONFIG_MSC == 1)
78 // HID + MSC composite device
79 #define USB_HID_CONFIG_INDEX (USB_CONFIGURE_ONLY_DESCRIPTOR_LENGTH)
80 #define USB_MSC_CONFIG_INDEX \
81  (USB_HID_CONFIG_INDEX + 2 * USB_ENDPOINT_DESCRIPTOR_LENGTH + USB_INTERFACE_DESCRIPTOR_LENGTH + \
82  USB_HID_DESCRIPTOR_LENGTH)
83 #elif(USB_DEVICE_CONFIG_HID == 1) && (USB_DEVICE_CONFIG_MSC == 0)
84 // HID-Only device
85 #define USB_HID_CONFIG_INDEX (USB_CONFIGURE_ONLY_DESCRIPTOR_LENGTH)
86 #define USB_MSC_CONFIG_INDEX (0)
87 #elif(USB_DEVICE_CONFIG_HID == 0) && (USB_DEVICE_CONFIG_MSC == 1)
88 // MSC-only device
89 #define USB_HID_CONFIG_INDEX (0)
90 #define USB_MSC_CONFIG_INDEX (USB_CONFIGURE_ONLY_DESCRIPTOR_LENGTH)
91 #else
92 // No USB
93 #define USB_HID_CONFIG_INDEX (USB_CONFIGURE_ONLY_DESCRIPTOR_LENGTH)
94 #define USB_MSC_CONFIG_INDEX \
95  (USB_HID_CONFIG_INDEX + 2 * USB_ENDPOINT_DESCRIPTOR_LENGTH + USB_INTERFACE_DESCRIPTOR_LENGTH + \
96  USB_HID_DESCRIPTOR_LENGTH)
97 #endif
98 
99 #define HS_BULK_IN_PACKET_SIZE (512)
100 #define HS_BULK_OUT_PACKET_SIZE (512)
101 #define FS_BULK_IN_PACKET_SIZE (64)
102 #define FS_BULK_OUT_PACKET_SIZE (64)
103 
104 // MSC
105 #define USB_MSC_CLASS (0x08)
106 /* scsi command set */
107 #define USB_MSC_SUBCLASS (0x06)
108 /* bulk only transport protocol */
109 #define USB_MSC_PROTOCOL (0x50)
110 
111 #define USB_MSC_CONFIGURE_INDEX (1)
112 #define USB_MSC_ENDPOINT_COUNT (2)
113 #define USB_MSC_BULK_IN_ENDPOINT (3)
114 #define USB_MSC_BULK_OUT_ENDPOINT (4)
115 #define USB_MSC_INTERFACE_COUNT (1)
116 
117 #if (USB_DEVICE_CONFIG_HID == 1) && (USB_DEVICE_CONFIG_MSC == 1)
118 #define USB_HID_GENERIC_INTERFACE_INDEX (0)
119 #define USB_MSC_INTERFACE_INDEX (1)
120 #else
121 #define USB_HID_GENERIC_INTERFACE_INDEX (0)
122 #define USB_MSC_INTERFACE_INDEX (0)
123 #endif
124 
125 // HID
126 #define USB_HID_GENERIC_CONFIGURE_INDEX (1)
127 #define USB_HID_GENERIC_INTERFACE_COUNT (1)
128 
129 #define USB_HID_GENERIC_IN_BUFFER_LENGTH (8)
130 #define USB_HID_GENERIC_OUT_BUFFER_LENGTH (8)
131 #define USB_HID_GENERIC_ENDPOINT_COUNT (2)
132 #define USB_HID_GENERIC_ENDPOINT_IN (1)
133 #define USB_HID_GENERIC_ENDPOINT_OUT (2)
134 
135 #define USB_HID_GENERIC_CLASS (0x03)
136 #define USB_HID_GENERIC_SUBCLASS (0x00)
137 #define USB_HID_GENERIC_PROTOCOL (0x00)
138 
139 #define HS_HID_GENERIC_INTERRUPT_OUT_PACKET_SIZE (8)
140 #define FS_HID_GENERIC_INTERRUPT_OUT_PACKET_SIZE (8)
141 #define HS_HID_GENERIC_INTERRUPT_OUT_INTERVAL (0x04) /* 2^(4-1) = 1ms */
142 #define FS_HID_GENERIC_INTERRUPT_OUT_INTERVAL (0x01)
143 
144 #define HS_HID_GENERIC_INTERRUPT_IN_PACKET_SIZE (8)
145 #define FS_HID_GENERIC_INTERRUPT_IN_PACKET_SIZE (8)
146 #define HS_HID_GENERIC_INTERRUPT_IN_INTERVAL (0x04) /* 2^(4-1) = 1ms */
147 #define FS_HID_GENERIC_INTERRUPT_IN_INTERVAL (0x01)
148 
149 #if (USB_DEVICE_CONFIG_HID == 1) && (USB_DEVICE_CONFIG_MSC == 1)
150 #define USB_COMPOSITE_INTERFACE_COUNT (USB_HID_GENERIC_INTERFACE_COUNT + USB_MSC_INTERFACE_COUNT)
151 #elif(USB_DEVICE_CONFIG_HID == 1) && (USB_DEVICE_CONFIG_MSC == 0)
152 #define USB_COMPOSITE_INTERFACE_COUNT (USB_HID_GENERIC_INTERFACE_COUNT)
153 #elif(USB_DEVICE_CONFIG_HID == 0) && (USB_DEVICE_CONFIG_MSC == 1)
154 #define USB_COMPOSITE_INTERFACE_COUNT (USB_MSC_INTERFACE_COUNT)
155 #else
156 #define USB_COMPOSITE_INTERFACE_COUNT (USB_HID_GENERIC_INTERFACE_COUNT)
157 #endif
158 
159 #define USB_COMPOSITE_CONFIGURE_INDEX (1)
160 
161 #define USB_STRING_DESCRIPTOR_HEADER_LENGTH (0x02)
162 #define USB_STRING_DESCRIPTOR_0_LENGTH (0x02)
163 #define USB_STRING_DESCRIPTOR_1_LENGTH (56)
164 #define USB_STRING_DESCRIPTOR_2_LENGTH (40)
165 #if ((USB_DEVICE_CONFIG_MSC > 0U) && (USB_DEVICE_CONFIG_HID > 0U)) // MSC + HID
166 #define USB_STRING_DESCRIPTOR_3_LENGTH (60)
167 #elif((USB_DEVICE_CONFIG_MSC == 0U) && (USB_DEVICE_CONFIG_HID > 0U)) // Only HID
168 #define USB_STRING_DESCRIPTOR_3_LENGTH (44)
169 #elif((USB_DEVICE_CONFIG_MSC > 0U) && (USB_DEVICE_CONFIG_HID == 0U)) // Only MSC
170 #define USB_STRING_DESCRIPTOR_3_LENGTH (28)
171 #else
172 #define USB_STRING_DESCRIPTOR_3_LENGTH (2)
173 #endif
174 #define USB_STRING_DESCRIPTOR_ERROR_LENGTH (32)
175 
176 #define USB_DEVICE_CLASS (0x00)
177 #define USB_DEVICE_SUBCLASS (0x00)
178 #define USB_DEVICE_PROTOCOL (0x00)
179 
180 #define USB_CONFIGURE_DRAWN (0x32)
181 
183 // Definitions
185 enum _usb_descriptor_index
186 {
187  kUsbDescriptorIndex_VidLow = 8,
188  kUsbDescriptorIndex_VidHigh = 9,
189  kUsbDescriptorIndex_PidLow = 10,
190  kUsbDescriptorIndex_PidHigh = 11
191 };
192 
193 typedef struct _usb_hid_config_descriptor
194 {
195  usb_descriptor_interface_t interface; /* Interface descriptor */
196  usb_descriptor_interface_t hid_report; /* Interface descriptor */
197  usb_descriptor_endpoint_t endpoint_in; /* Endpoint descriptor */
198  usb_descriptor_endpoint_t endpoint_out; /* Endpoint descriptor */
200 
201 typedef struct _usb_msc_config_descriptor
202 {
203  usb_descriptor_interface_t interface; /* Interface descriptor */
204  usb_descriptor_endpoint_t endpoint_in; /* Endpoint descriptor */
205  usb_descriptor_endpoint_t endpoint_out; /* Endpoint descriptor */
207 
208 extern usb_device_class_struct_t g_hid_generic_class;
209 extern usb_device_class_struct_t g_msc_class;
210 
211 /* Configure the device according to the USB speed. */
212 extern usb_status_t usb_device_set_speed(usb_device_handle handle, uint8_t speed);
213 
214 /* Get device descriptor request */
215 usb_status_t usb_device_get_device_descriptor(usb_device_handle handle,
216  usb_device_get_device_descriptor_struct_t *device_descriptor);
217 
218 /* Get device configuration descriptor request */
219 usb_status_t usb_device_get_configuration_descriptor(
220  usb_device_handle handle, usb_device_get_configuration_descriptor_struct_t *configuration_descriptor);
221 
222 /* Get device string descriptor request */
223 usb_status_t usb_device_get_string_descriptor(usb_device_handle handle,
224  usb_device_get_string_descriptor_struct_t *string_descriptor);
225 
226 /* Get hid descriptor request */
227 usb_status_t usb_device_get_hid_descriptor(usb_device_handle handle,
228  usb_device_get_hid_descriptor_struct_t *hid_descriptor);
229 
230 /* Get hid report descriptor request */
231 usb_status_t usb_device_get_hid_report_descriptor(usb_device_handle handle,
232  usb_device_get_hid_report_descriptor_struct_t *hid_report_descriptor);
233 
234 /* Get hid physical descriptor request */
235 usb_status_t usb_device_get_hid_physical_descriptor(
236  usb_device_handle handle, usb_device_get_hid_physical_descriptor_struct_t *hid_physical_descriptor);
237 
238 extern uint8_t g_device_descriptor[];
239 extern usb_language_list_t g_language_list;
240 
241 extern usb_language_list_t *g_language_ptr;
242 
243 #endif /* __USB_DESCRIPTOR_H__ */
Definition: src/bm_usb/usb_descriptor.h:201
Definition: src/bm_usb/usb_descriptor.h:193