1 /*
2 * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
3 * Copyright 2016 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8 #include "usb_device_config.h"
9 #include "usb.h"
10 #include "usb_device.h"
11
12 #include "usb_device_class.h"
13 #include "usb_device_cdc_acm.h"
14
15 #include "usb_device_descriptor.h"
16
17 /*******************************************************************************
18 * Variables
19 ******************************************************************************/
20 /* Define endpoint for communication class */
21 usb_device_endpoint_struct_t g_UsbDeviceCdcVcomCicEndpoints[USB_CDC_VCOM_ENDPOINT_CIC_COUNT] = {
22 {
23 USB_CDC_VCOM_INTERRUPT_IN_ENDPOINT | (USB_IN << 7U),
24 USB_ENDPOINT_INTERRUPT,
25 FS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE,
26 FS_CDC_VCOM_INTERRUPT_IN_INTERVAL,
27 },
28 };
29
30 /* Define endpoint for data class */
31 usb_device_endpoint_struct_t g_UsbDeviceCdcVcomDicEndpoints[USB_CDC_VCOM_ENDPOINT_DIC_COUNT] = {
32 {
33 USB_CDC_VCOM_BULK_IN_ENDPOINT | (USB_IN << 7U),
34 USB_ENDPOINT_BULK,
35 FS_CDC_VCOM_BULK_IN_PACKET_SIZE,
36 0U,
37 },
38 {
39 USB_CDC_VCOM_BULK_OUT_ENDPOINT | (USB_OUT << 7U),
40 USB_ENDPOINT_BULK,
41 FS_CDC_VCOM_BULK_OUT_PACKET_SIZE,
42 0U,
43 }};
44
45 /* Define interface for communication class */
46 usb_device_interface_struct_t g_UsbDeviceCdcVcomCommunicationInterface[] = {{0,
47 {
48 USB_CDC_VCOM_ENDPOINT_CIC_COUNT,
49 g_UsbDeviceCdcVcomCicEndpoints,
50 },
51 NULL}};
52
53 /* Define interface for data class */
54 usb_device_interface_struct_t g_UsbDeviceCdcVcomDataInterface[] = {{0,
55 {
56 USB_CDC_VCOM_ENDPOINT_DIC_COUNT,
57 g_UsbDeviceCdcVcomDicEndpoints,
58 },
59 NULL}};
60
61 /* Define interfaces for virtual com */
62 usb_device_interfaces_struct_t g_UsbDeviceCdcVcomInterfaces[USB_CDC_VCOM_INTERFACE_COUNT] = {
63 {USB_CDC_VCOM_CIC_CLASS, USB_CDC_VCOM_CIC_SUBCLASS, USB_CDC_VCOM_CIC_PROTOCOL, USB_CDC_VCOM_COMM_INTERFACE_INDEX,
64 g_UsbDeviceCdcVcomCommunicationInterface,
65 sizeof(g_UsbDeviceCdcVcomCommunicationInterface) / sizeof(usb_device_interface_struct_t)},
66 {USB_CDC_VCOM_DIC_CLASS, USB_CDC_VCOM_DIC_SUBCLASS, USB_CDC_VCOM_DIC_PROTOCOL, USB_CDC_VCOM_DATA_INTERFACE_INDEX,
67 g_UsbDeviceCdcVcomDataInterface, sizeof(g_UsbDeviceCdcVcomDataInterface) / sizeof(usb_device_interface_struct_t)},
68 };
69
70 /* Define configurations for virtual com */
71 usb_device_interface_list_t g_UsbDeviceCdcVcomInterfaceLIST_[USB_DEVICE_CONFIGURATION_COUNT] = {
72 {
73 USB_CDC_VCOM_INTERFACE_COUNT,
74 g_UsbDeviceCdcVcomInterfaces,
75 },
76 };
77
78 /* Define class information for virtual com */
79 usb_device_class_struct_t g_UsbDeviceCdcVcomConfig = {
80 g_UsbDeviceCdcVcomInterfaceLIST_,
81 kUSB_DeviceClassTypeCdc,
82 USB_DEVICE_CONFIGURATION_COUNT,
83 };
84
85 /* Define device descriptor */
86 USB_DMA_INIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
87 uint8_t g_UsbDeviceDescriptor[] = {
88 /* Size of this descriptor in bytes */
89 USB_DESCRIPTOR_LENGTH_DEVICE,
90 /* DEVICE Descriptor Type */
91 USB_DESCRIPTOR_TYPE_DEVICE,
92 /* USB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H). */
93 USB_SHORT_GET_LOW(USB_DEVICE_SPECIFIC_BCD_VERSION),
94 USB_SHORT_GET_HIGH(USB_DEVICE_SPECIFIC_BCD_VERSION),
95 /* Class code (assigned by the USB-IF). */
96 USB_DEVICE_CLASS,
97 /* Subclass code (assigned by the USB-IF). */
98 USB_DEVICE_SUBCLASS,
99 /* Protocol code (assigned by the USB-IF). */
100 USB_DEVICE_PROTOCOL,
101 /* Maximum packet size for endpoint zero (only 8, 16, 32, or 64 are valid) */
102 USB_CONTROL_MAX_PACKET_SIZE,
103 /* Vendor ID (assigned by the USB-IF) */
104 0xC9U,
105 0x1FU,
106 /* Product ID (assigned by the manufacturer) */
107 0x94,
108 0x00,
109 /* Device release number in binary-coded decimal */
110 USB_SHORT_GET_LOW(USB_DEVICE_DEMO_BCD_VERSION),
111 USB_SHORT_GET_HIGH(USB_DEVICE_DEMO_BCD_VERSION),
112 /* Index of string descriptor describing manufacturer */
113 0x01,
114 /* Index of string descriptor describing product */
115 0x02,
116 /* Index of string descriptor describing the device's serial number */
117 0x00,
118 /* Number of possible configurations */
119 USB_DEVICE_CONFIGURATION_COUNT,
120 };
121
122 /* Define configuration descriptor */
123 USB_DMA_INIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
124 uint8_t g_UsbDeviceConfigurationDescriptor[] = {
125 /* Size of this descriptor in bytes */
126 USB_DESCRIPTOR_LENGTH_CONFIGURE,
127 /* CONFIGURATION Descriptor Type */
128 USB_DESCRIPTOR_TYPE_CONFIGURE,
129 /* Total length of data returned for this configuration. */
130 USB_SHORT_GET_LOW(USB_DESCRIPTOR_LENGTH_CONFIGURE + USB_DESCRIPTOR_LENGTH_INTERFACE +
131 USB_DESCRIPTOR_LENGTH_CDC_HEADER_FUNC + USB_DESCRIPTOR_LENGTH_CDC_CALL_MANAG +
132 USB_DESCRIPTOR_LENGTH_CDC_ABSTRACT + USB_DESCRIPTOR_LENGTH_CDC_UNION_FUNC +
133 USB_DESCRIPTOR_LENGTH_ENDPOINT + USB_DESCRIPTOR_LENGTH_INTERFACE +
134 USB_DESCRIPTOR_LENGTH_ENDPOINT + USB_DESCRIPTOR_LENGTH_ENDPOINT),
135 USB_SHORT_GET_HIGH(USB_DESCRIPTOR_LENGTH_CONFIGURE + USB_DESCRIPTOR_LENGTH_INTERFACE +
136 USB_DESCRIPTOR_LENGTH_CDC_HEADER_FUNC + USB_DESCRIPTOR_LENGTH_CDC_CALL_MANAG +
137 USB_DESCRIPTOR_LENGTH_CDC_ABSTRACT + USB_DESCRIPTOR_LENGTH_CDC_UNION_FUNC +
138 USB_DESCRIPTOR_LENGTH_ENDPOINT + USB_DESCRIPTOR_LENGTH_INTERFACE +
139 USB_DESCRIPTOR_LENGTH_ENDPOINT + USB_DESCRIPTOR_LENGTH_ENDPOINT),
140 /* Number of interfaces supported by this configuration */
141 USB_CDC_VCOM_INTERFACE_COUNT,
142 /* Value to use as an argument to the SetConfiguration() request to select this configuration */
143 USB_CDC_VCOM_CONFIGURE_INDEX,
144 /* Index of string descriptor describing this configuration */
145 0,
146 /* Configuration characteristics D7: Reserved (set to one) D6: Self-powered D5: Remote Wakeup D4...0: Reserved
147 (reset to zero) */
148 (USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_D7_MASK) |
149 (USB_DEVICE_CONFIG_SELF_POWER << USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_SELF_POWERED_SHIFT) |
150 (USB_DEVICE_CONFIG_REMOTE_WAKEUP << USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_REMOTE_WAKEUP_SHIFT),
151 /* Maximum power consumption of the USB * device from the bus in this specific * configuration when the device is
152 fully * operational. Expressed in 2 mA units * (i.e., 50 = 100 mA). */
153 USB_DEVICE_MAX_POWER,
154
155 /* Communication Interface Descriptor */
156 USB_DESCRIPTOR_LENGTH_INTERFACE, USB_DESCRIPTOR_TYPE_INTERFACE, USB_CDC_VCOM_COMM_INTERFACE_INDEX, 0x00,
157 USB_CDC_VCOM_ENDPOINT_CIC_COUNT, USB_CDC_VCOM_CIC_CLASS, USB_CDC_VCOM_CIC_SUBCLASS, USB_CDC_VCOM_CIC_PROTOCOL,
158 0x00, /* Interface Description String Index*/
159
160 /* CDC Class-Specific descriptor */
161 USB_DESCRIPTOR_LENGTH_CDC_HEADER_FUNC, /* Size of this descriptor in bytes */
162 USB_DESCRIPTOR_TYPE_CDC_CS_INTERFACE, /* CS_INTERFACE Descriptor Type */
163 USB_CDC_HEADER_FUNC_DESC, 0x10,
164 0x01, /* USB Class Definitions for Communications the Communication specification version 1.10 */
165
166 USB_DESCRIPTOR_LENGTH_CDC_CALL_MANAG, /* Size of this descriptor in bytes */
167 USB_DESCRIPTOR_TYPE_CDC_CS_INTERFACE, /* CS_INTERFACE Descriptor Type */
168 USB_CDC_CALL_MANAGEMENT_FUNC_DESC,
169 0x01, /*Bit 0: Whether device handle call management itself 1, Bit 1: Whether device can send/receive call
170 management information over a Data Class Interface 0 */
171 0x01, /* Indicates multiplexed commands are handled via data interface */
172
173 USB_DESCRIPTOR_LENGTH_CDC_ABSTRACT, /* Size of this descriptor in bytes */
174 USB_DESCRIPTOR_TYPE_CDC_CS_INTERFACE, /* CS_INTERFACE Descriptor Type */
175 USB_CDC_ABSTRACT_CONTROL_FUNC_DESC,
176 0x06, /* Bit 0: Whether device supports the request combination of Set_Comm_Feature, Clear_Comm_Feature, and
177 Get_Comm_Feature 0, Bit 1: Whether device supports the request combination of Set_Line_Coding,
178 Set_Control_Line_State, Get_Line_Coding, and the notification Serial_State 1, Bit ... */
179
180 USB_DESCRIPTOR_LENGTH_CDC_UNION_FUNC, /* Size of this descriptor in bytes */
181 USB_DESCRIPTOR_TYPE_CDC_CS_INTERFACE, /* CS_INTERFACE Descriptor Type */
182 USB_CDC_UNION_FUNC_DESC, 0x00, /* The interface number of the Communications or Data Class interface */
183 0x01, /* Interface number of subordinate interface in the Union */
184
185 /*Notification Endpoint descriptor */
186 USB_DESCRIPTOR_LENGTH_ENDPOINT, USB_DESCRIPTOR_TYPE_ENDPOINT, USB_CDC_VCOM_INTERRUPT_IN_ENDPOINT | (USB_IN << 7U),
187 USB_ENDPOINT_INTERRUPT, USB_SHORT_GET_LOW(FS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE),
188 USB_SHORT_GET_HIGH(FS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE), FS_CDC_VCOM_INTERRUPT_IN_INTERVAL,
189
190 /* Data Interface Descriptor */
191 USB_DESCRIPTOR_LENGTH_INTERFACE, USB_DESCRIPTOR_TYPE_INTERFACE, USB_CDC_VCOM_DATA_INTERFACE_INDEX, 0x00,
192 USB_CDC_VCOM_ENDPOINT_DIC_COUNT, USB_CDC_VCOM_DIC_CLASS, USB_CDC_VCOM_DIC_SUBCLASS, USB_CDC_VCOM_DIC_PROTOCOL,
193 0x00, /* Interface Description String Index*/
194
195 /*Bulk IN Endpoint descriptor */
196 USB_DESCRIPTOR_LENGTH_ENDPOINT, USB_DESCRIPTOR_TYPE_ENDPOINT, USB_CDC_VCOM_BULK_IN_ENDPOINT | (USB_IN << 7U),
197 USB_ENDPOINT_BULK, USB_SHORT_GET_LOW(FS_CDC_VCOM_BULK_IN_PACKET_SIZE),
198 USB_SHORT_GET_HIGH(FS_CDC_VCOM_BULK_IN_PACKET_SIZE), 0x00, /* The polling interval value is every 0 Frames */
199
200 /*Bulk OUT Endpoint descriptor */
201 USB_DESCRIPTOR_LENGTH_ENDPOINT, USB_DESCRIPTOR_TYPE_ENDPOINT, USB_CDC_VCOM_BULK_OUT_ENDPOINT | (USB_OUT << 7U),
202 USB_ENDPOINT_BULK, USB_SHORT_GET_LOW(FS_CDC_VCOM_BULK_OUT_PACKET_SIZE),
203 USB_SHORT_GET_HIGH(FS_CDC_VCOM_BULK_OUT_PACKET_SIZE), 0x00, /* The polling interval value is every 0 Frames */
204 };
205
206 /* Define string descriptor */
207 USB_DMA_INIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
208 uint8_t g_UsbDeviceString0[] = {2U + 2U, USB_DESCRIPTOR_TYPE_STRING, 0x09, 0x04};
209
210 USB_DMA_INIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
211 uint8_t g_UsbDeviceString1[] = {
212 2U + 2U * 18U, USB_DESCRIPTOR_TYPE_STRING,
213 (uint8_t)'N', 0x00U,
214 (uint8_t)'X', 0x00U,
215 (uint8_t)'P', 0x00U,
216 (uint8_t)' ', 0x00U,
217 (uint8_t)'S', 0x00U,
218 (uint8_t)'E', 0x00U,
219 (uint8_t)'M', 0x00U,
220 (uint8_t)'I', 0x00U,
221 (uint8_t)'C', 0x00U,
222 (uint8_t)'O', 0x00U,
223 (uint8_t)'N', 0x00U,
224 (uint8_t)'D', 0x00U,
225 (uint8_t)'U', 0x00U,
226 (uint8_t)'C', 0x00U,
227 (uint8_t)'T', 0x00U,
228 (uint8_t)'O', 0x00U,
229 (uint8_t)'R', 0x00U,
230 (uint8_t)'S', 0x00U,
231 };
232
233 USB_DMA_INIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
234 uint8_t g_UsbDeviceString2[] = {
235 2U + 2U * 20U, USB_DESCRIPTOR_TYPE_STRING,
236 (uint8_t)'M', 0U,
237 (uint8_t)'C', 0U,
238 (uint8_t)'U', 0U,
239 (uint8_t)' ', 0U,
240 (uint8_t)'V', 0U,
241 (uint8_t)'I', 0U,
242 (uint8_t)'R', 0U,
243 (uint8_t)'T', 0U,
244 (uint8_t)'U', 0U,
245 (uint8_t)'A', 0U,
246 (uint8_t)'L', 0U,
247 (uint8_t)' ', 0U,
248 (uint8_t)'C', 0U,
249 (uint8_t)'O', 0U,
250 (uint8_t)'M', 0U,
251 (uint8_t)' ', 0U,
252 (uint8_t)'D', 0U,
253 (uint8_t)'E', 0U,
254 (uint8_t)'M', 0U,
255 (uint8_t)'O', 0U,
256 };
257
258 uint8_t *g_UsbDeviceStringDescriptorArray[USB_DEVICE_STRING_COUNT] = {g_UsbDeviceString0, g_UsbDeviceString1,
259 g_UsbDeviceString2};
260
261 /* Define string descriptor size */
262 uint32_t g_UsbDeviceStringDescriptorLength[USB_DEVICE_STRING_COUNT] = {
263 sizeof(g_UsbDeviceString0), sizeof(g_UsbDeviceString1), sizeof(g_UsbDeviceString2)};
264 usb_language_t g_UsbDeviceLanguage[USB_DEVICE_LANGUAGE_COUNT] = {{
265 g_UsbDeviceStringDescriptorArray,
266 g_UsbDeviceStringDescriptorLength,
267 (uint16_t)0x0409,
268 }};
269
270 usb_language_list_t g_UsbDeviceLanguageList = {
271 g_UsbDeviceString0,
272 sizeof(g_UsbDeviceString0),
273 g_UsbDeviceLanguage,
274 USB_DEVICE_LANGUAGE_COUNT,
275 };
276
277 /*******************************************************************************
278 * Code
279 ******************************************************************************/
280 /*!
281 * @brief USB device get device descriptor function.
282 *
283 * This function gets the device descriptor of the USB device.
284 *
285 * @param handle The USB device handle.
286 * @param deviceDescriptor The pointer to the device descriptor structure.
287 *
288 * @return A USB error code or kStatus_USB_Success.
289 */
USB_DeviceGetDeviceDescriptor(usb_device_handle handle,usb_device_get_device_descriptor_struct_t * deviceDescriptor)290 usb_status_t USB_DeviceGetDeviceDescriptor(usb_device_handle handle,
291 usb_device_get_device_descriptor_struct_t *deviceDescriptor)
292 {
293 deviceDescriptor->buffer = g_UsbDeviceDescriptor;
294 deviceDescriptor->length = USB_DESCRIPTOR_LENGTH_DEVICE;
295 return kStatus_USB_Success;
296 }
297
298 /*!
299 * @brief USB device get configuration descriptor function.
300 *
301 * This function gets the configuration descriptor of the USB device.
302 *
303 * @param handle The USB device handle.
304 * @param configurationDescriptor The pointer to the configuration descriptor structure.
305 *
306 * @return A USB error code or kStatus_USB_Success.
307 */
USB_DeviceGetConfigurationDescriptor(usb_device_handle handle,usb_device_get_configuration_descriptor_struct_t * configurationDescriptor)308 usb_status_t USB_DeviceGetConfigurationDescriptor(
309 usb_device_handle handle, usb_device_get_configuration_descriptor_struct_t *configurationDescriptor)
310 {
311 if ((uint8_t)USB_CDC_VCOM_CONFIGURE_INDEX > configurationDescriptor->configuration)
312 {
313 configurationDescriptor->buffer = g_UsbDeviceConfigurationDescriptor;
314 configurationDescriptor->length = USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL;
315 return kStatus_USB_Success;
316 }
317 return kStatus_USB_InvalidRequest;
318 }
319
320 /*!
321 * @brief USB device get string descriptor function.
322 *
323 * This function gets the string descriptor of the USB device.
324 *
325 * @param handle The USB device handle.
326 * @param stringDescriptor Pointer to the string descriptor structure.
327 *
328 * @return A USB error code or kStatus_USB_Success.
329 */
USB_DeviceGetStringDescriptor(usb_device_handle handle,usb_device_get_string_descriptor_struct_t * stringDescriptor)330 usb_status_t USB_DeviceGetStringDescriptor(usb_device_handle handle,
331 usb_device_get_string_descriptor_struct_t *stringDescriptor)
332 {
333 if (stringDescriptor->stringIndex == 0U)
334 {
335 stringDescriptor->buffer = (uint8_t *)g_UsbDeviceLanguageList.languageString;
336 stringDescriptor->length = g_UsbDeviceLanguageList.stringLength;
337 }
338 else
339 {
340 uint8_t languageId = 0U;
341 uint8_t languageIndex = USB_DEVICE_STRING_COUNT;
342
343 for (; languageId < (uint8_t)USB_DEVICE_LANGUAGE_COUNT; languageId++)
344 {
345 if (stringDescriptor->languageId == g_UsbDeviceLanguageList.languageList[languageId].languageId)
346 {
347 if (stringDescriptor->stringIndex < (uint8_t)USB_DEVICE_STRING_COUNT)
348 {
349 languageIndex = stringDescriptor->stringIndex;
350 }
351 break;
352 }
353 }
354
355 if ((uint8_t)USB_DEVICE_STRING_COUNT == languageIndex)
356 {
357 return kStatus_USB_InvalidRequest;
358 }
359 stringDescriptor->buffer = (uint8_t *)g_UsbDeviceLanguageList.languageList[languageId].string[languageIndex];
360 stringDescriptor->length = g_UsbDeviceLanguageList.languageList[languageId].length[languageIndex];
361 }
362 return kStatus_USB_Success;
363 }
364
365 /*!
366 * @brief USB device set speed function.
367 *
368 * This function sets the speed of the USB device.
369 *
370 * Due to the difference of HS and FS descriptors, the device descriptors and configurations need to be updated to match
371 * current speed.
372 * As the default, the device descriptors and configurations are configured by using FS parameters for both EHCI and
373 * KHCI.
374 * When the EHCI is enabled, the application needs to call this function to update device by using current speed.
375 * The updated information includes endpoint max packet size, endpoint interval, etc.
376 *
377 * @param handle The USB device handle.
378 * @param speed Speed type. USB_SPEED_HIGH/USB_SPEED_FULL/USB_SPEED_LOW.
379 *
380 * @return A USB error code or kStatus_USB_Success.
381 */
USB_DeviceSetSpeed(usb_device_handle handle,uint8_t speed)382 usb_status_t USB_DeviceSetSpeed(usb_device_handle handle, uint8_t speed)
383 {
384 usb_descriptor_union_t *ptr1;
385 usb_descriptor_union_t *ptr2;
386
387 ptr1 = (usb_descriptor_union_t *)(void *)(&g_UsbDeviceConfigurationDescriptor[0]);
388 ptr2 = (usb_descriptor_union_t
389 *)(void *)(&g_UsbDeviceConfigurationDescriptor[USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL - 1U]);
390
391 while (ptr1 < ptr2)
392 {
393 if (ptr1->common.bDescriptorType == USB_DESCRIPTOR_TYPE_ENDPOINT)
394 {
395 if (USB_SPEED_HIGH == speed)
396 {
397 if (((ptr1->endpoint.bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_MASK) ==
398 USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_IN) &&
399 ((uint8_t)USB_CDC_VCOM_INTERRUPT_IN_ENDPOINT ==
400 (ptr1->endpoint.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)))
401 {
402 ptr1->endpoint.bInterval = HS_CDC_VCOM_INTERRUPT_IN_INTERVAL;
403 USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(HS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE,
404 ptr1->endpoint.wMaxPacketSize);
405 }
406 else if (((ptr1->endpoint.bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_MASK) ==
407 USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_IN) &&
408 ((uint8_t)USB_CDC_VCOM_BULK_IN_ENDPOINT ==
409 (ptr1->endpoint.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)))
410 {
411 USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(HS_CDC_VCOM_BULK_IN_PACKET_SIZE, ptr1->endpoint.wMaxPacketSize);
412 }
413 else if (((ptr1->endpoint.bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_MASK) ==
414 USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_OUT) &&
415 ((uint8_t)USB_CDC_VCOM_BULK_OUT_ENDPOINT ==
416 (ptr1->endpoint.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)))
417 {
418 USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(HS_CDC_VCOM_BULK_OUT_PACKET_SIZE, ptr1->endpoint.wMaxPacketSize);
419 }
420 else
421 {
422 /* MISRA C-2012 Rule 15.7 */
423 }
424 }
425 else
426 {
427 if (((ptr1->endpoint.bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_MASK) ==
428 USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_IN) &&
429 ((uint8_t)USB_CDC_VCOM_INTERRUPT_IN_ENDPOINT ==
430 (ptr1->endpoint.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)))
431 {
432 ptr1->endpoint.bInterval = FS_CDC_VCOM_INTERRUPT_IN_INTERVAL;
433 USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(FS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE,
434 ptr1->endpoint.wMaxPacketSize);
435 }
436 else if (((ptr1->endpoint.bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_MASK) ==
437 USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_IN) &&
438 ((uint8_t)USB_CDC_VCOM_BULK_IN_ENDPOINT ==
439 (ptr1->endpoint.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)))
440 {
441 USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(FS_CDC_VCOM_BULK_IN_PACKET_SIZE, ptr1->endpoint.wMaxPacketSize);
442 }
443 else if (((ptr1->endpoint.bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_MASK) ==
444 USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_OUT) &&
445 ((uint8_t)USB_CDC_VCOM_BULK_OUT_ENDPOINT ==
446 (ptr1->endpoint.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)))
447 {
448 USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(FS_CDC_VCOM_BULK_OUT_PACKET_SIZE, ptr1->endpoint.wMaxPacketSize);
449 }
450 else
451 {
452 /* MISRA C-2012 Rule 15.7 */
453 }
454 }
455 }
456 ptr1 = (usb_descriptor_union_t *)(void *)((uint8_t *)ptr1 + ptr1->common.bLength);
457 }
458
459 for (int i = 0; i < USB_CDC_VCOM_ENDPOINT_CIC_COUNT; i++)
460 {
461 if (USB_SPEED_HIGH == speed)
462 {
463 g_UsbDeviceCdcVcomCicEndpoints[i].maxPacketSize = HS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE;
464 }
465 else
466 {
467 g_UsbDeviceCdcVcomCicEndpoints[i].maxPacketSize = FS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE;
468 }
469 }
470 for (int i = 0; i < USB_CDC_VCOM_ENDPOINT_DIC_COUNT; i++)
471 {
472 if (USB_SPEED_HIGH == speed)
473 {
474 if (0U !=
475 (g_UsbDeviceCdcVcomDicEndpoints[i].endpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_MASK))
476 {
477 g_UsbDeviceCdcVcomDicEndpoints[i].maxPacketSize = HS_CDC_VCOM_BULK_IN_PACKET_SIZE;
478 }
479 else
480 {
481 g_UsbDeviceCdcVcomDicEndpoints[i].maxPacketSize = HS_CDC_VCOM_BULK_OUT_PACKET_SIZE;
482 }
483 }
484 else
485 {
486 if (0U !=
487 (g_UsbDeviceCdcVcomDicEndpoints[i].endpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_MASK))
488 {
489 g_UsbDeviceCdcVcomDicEndpoints[i].maxPacketSize = FS_CDC_VCOM_BULK_IN_PACKET_SIZE;
490 }
491 else
492 {
493 g_UsbDeviceCdcVcomDicEndpoints[i].maxPacketSize = FS_CDC_VCOM_BULK_OUT_PACKET_SIZE;
494 }
495 }
496 }
497
498 return kStatus_USB_Success;
499 }
500