2017-07-06 19:56:28 +08:00
|
|
|
/* usb_descriptor.h - header for common device descriptor */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 PHYTEC Messtechnik GmbH
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __USB_DESCRIPTOR_H__
|
|
|
|
#define __USB_DESCRIPTOR_H__
|
|
|
|
|
2018-04-06 20:53:24 +08:00
|
|
|
/*
|
|
|
|
* The USB Unicode bString is encoded in UTF16LE, which means it takes up
|
|
|
|
* twice the amount of bytes than the same string encoded in ASCII7.
|
|
|
|
* Use this macro to determine the length of the bString array.
|
|
|
|
*
|
|
|
|
* bString length without null character:
|
|
|
|
* bString_length = (sizeof(initializer_string) - 1) * 2
|
|
|
|
* or:
|
|
|
|
* bString_length = sizeof(initializer_string) * 2 - 2
|
|
|
|
*/
|
|
|
|
#define USB_BSTRING_LENGTH(s) (sizeof(s) * 2 - 2)
|
2017-07-06 19:56:28 +08:00
|
|
|
|
2018-04-06 20:53:24 +08:00
|
|
|
/*
|
|
|
|
* The length of the string descriptor (bLength) is calculated from the
|
|
|
|
* size of the two octets bLength and bDescriptorType plus the
|
|
|
|
* length of the UTF16LE string:
|
|
|
|
*
|
|
|
|
* bLength = 2 + bString_length
|
|
|
|
* bLength = 2 + sizeof(initializer_string) * 2 - 2
|
|
|
|
* bLength = sizeof(initializer_string) * 2
|
|
|
|
* Use this macro to determine the bLength of the string descriptor.
|
|
|
|
*/
|
|
|
|
#define USB_STRING_DESCRIPTOR_LENGTH(s) (sizeof(s) * 2)
|
2017-10-16 19:11:15 +08:00
|
|
|
|
2019-02-12 17:37:23 +08:00
|
|
|
/* Automatic endpoint assignment */
|
2019-04-30 16:28:27 +08:00
|
|
|
#define AUTO_EP_IN 0x80
|
|
|
|
#define AUTO_EP_OUT 0x00
|
2019-02-12 17:37:23 +08:00
|
|
|
|
2019-02-01 20:59:26 +08:00
|
|
|
/* Common part of device data */
|
|
|
|
struct usb_dev_data {
|
|
|
|
struct device *dev;
|
|
|
|
sys_snode_t node;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct usb_dev_data *usb_get_dev_data_by_cfg(sys_slist_t *list,
|
|
|
|
struct usb_cfg_data *cfg);
|
|
|
|
struct usb_dev_data *usb_get_dev_data_by_iface(sys_slist_t *list,
|
|
|
|
u8_t iface_num);
|
|
|
|
struct usb_dev_data *usb_get_dev_data_by_ep(sys_slist_t *list, u8_t ep);
|
|
|
|
|
2018-04-28 07:17:30 +08:00
|
|
|
int usb_get_str_descriptor_idx(void *ptr);
|
|
|
|
|
2018-05-23 10:23:21 +08:00
|
|
|
u8_t *usb_update_sn_string_descriptor(void);
|
2017-07-06 19:56:28 +08:00
|
|
|
u8_t *usb_get_device_descriptor(void);
|
|
|
|
|
|
|
|
#endif /* __USB_DESCRIPTOR_H__ */
|