1 /* usb_descriptor.h - header for common device descriptor */
2 
3 /*
4  * Copyright (c) 2017 PHYTEC Messtechnik GmbH
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #ifndef __USB_DESCRIPTOR_H__
10 #define __USB_DESCRIPTOR_H__
11 
12 #include <zephyr/sys/slist.h>
13 
14 /*
15  * The USB Unicode bString is encoded in UTF16LE, which means it takes up
16  * twice the amount of bytes than the same string encoded in ASCII7.
17  * Use this macro to determine the length of the bString array.
18  *
19  * bString length without null character:
20  *   bString_length = (sizeof(initializer_string) - 1) * 2
21  * or:
22  *   bString_length = sizeof(initializer_string) * 2 - 2
23  */
24 #define USB_BSTRING_LENGTH(s)		(sizeof(s) * 2 - 2)
25 
26 /*
27  * The length of the string descriptor (bLength) is calculated from the
28  * size of the two octets bLength and bDescriptorType plus the
29  * length of the UTF16LE string:
30  *
31  *   bLength = 2 + bString_length
32  *   bLength = 2 + sizeof(initializer_string) * 2 - 2
33  *   bLength = sizeof(initializer_string) * 2
34  * Use this macro to determine the bLength of the string descriptor.
35  */
36 #define USB_STRING_DESCRIPTOR_LENGTH(s)	(sizeof(s) * 2)
37 
38 /* Automatic endpoint assignment */
39 #define AUTO_EP_IN			0x80
40 #define AUTO_EP_OUT			0x00
41 
42 /* Common part of device data */
43 struct usb_dev_data {
44 	const struct device *dev;
45 	sys_snode_t node;
46 };
47 
48 struct usb_dev_data *usb_get_dev_data_by_cfg(sys_slist_t *list,
49 					     struct usb_cfg_data *cfg);
50 struct usb_dev_data *usb_get_dev_data_by_iface(sys_slist_t *list,
51 					       uint8_t iface_num);
52 struct usb_dev_data *usb_get_dev_data_by_ep(sys_slist_t *list, uint8_t ep);
53 
54 int usb_get_str_descriptor_idx(void *ptr);
55 
56 uint8_t *usb_update_sn_string_descriptor(void);
57 uint8_t *usb_get_device_descriptor(void);
58 
59 #endif /* __USB_DESCRIPTOR_H__ */
60