update version to v2.0.3

This commit is contained in:
Artery-MCU
2022-03-03 19:34:56 +08:00
parent 052a4b7d94
commit d2285506f0
1031 changed files with 20057 additions and 3999 deletions

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file cdc_desc.c
* @version v2.0.2
* @date 2021-12-31
* @version v2.0.3
* @date 2022-02-11
* @brief usb cdc device descriptor
**************************************************************************
* Copyright notice & Disclaimer
@@ -41,18 +41,18 @@
* @{
*/
usbd_desc_t *get_device_descriptor(void);
usbd_desc_t *get_device_qualifier(void);
usbd_desc_t *get_device_configuration(void);
usbd_desc_t *get_device_other_speed(void);
usbd_desc_t *get_device_lang_id(void);
usbd_desc_t *get_device_manufacturer_string(void);
usbd_desc_t *get_device_product_string(void);
usbd_desc_t *get_device_serial_string(void);
usbd_desc_t *get_device_interface_string(void);
usbd_desc_t *get_device_config_string(void);
static usbd_desc_t *get_device_descriptor(void);
static usbd_desc_t *get_device_qualifier(void);
static usbd_desc_t *get_device_configuration(void);
static usbd_desc_t *get_device_other_speed(void);
static usbd_desc_t *get_device_lang_id(void);
static usbd_desc_t *get_device_manufacturer_string(void);
static usbd_desc_t *get_device_product_string(void);
static usbd_desc_t *get_device_serial_string(void);
static usbd_desc_t *get_device_interface_string(void);
static usbd_desc_t *get_device_config_string(void);
uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf);
static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf);
static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len);
static void get_serial_num(void);
static uint8_t g_usbd_desc_buffer[256];
@@ -60,7 +60,7 @@ static uint8_t g_usbd_desc_buffer[256];
/**
* @brief device descriptor handler structure
*/
usbd_desc_handler desc_handler =
usbd_desc_handler cdc_desc_handler =
{
get_device_descriptor,
get_device_qualifier,
@@ -80,7 +80,7 @@ usbd_desc_handler desc_handler =
#if defined ( __ICCARM__ ) /* iar compiler */
#pragma data_alignment=4
#endif
ALIGNED_HEAD uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN] ALIGNED_TAIL =
ALIGNED_HEAD static uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN] ALIGNED_TAIL =
{
USB_DEVICE_DESC_LEN, /* bLength */
USB_DESCIPTOR_TYPE_DEVICE, /* bDescriptorType */
@@ -90,10 +90,10 @@ ALIGNED_HEAD uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN] ALIGNED_TAIL =
0x00, /* bDeviceSubClass */
0x00, /* bDeviceProtocol */
USB_MAX_EP0_SIZE, /* bMaxPacketSize */
LBYTE(USBD_VENDOR_ID), /* idVendor */
HBYTE(USBD_VENDOR_ID), /* idVendor */
LBYTE(USBD_PRODUCT_ID), /* idProduct */
HBYTE(USBD_PRODUCT_ID), /* idProduct */
LBYTE(USBD_CDC_VENDOR_ID), /* idVendor */
HBYTE(USBD_CDC_VENDOR_ID), /* idVendor */
LBYTE(USBD_CDC_PRODUCT_ID), /* idProduct */
HBYTE(USBD_CDC_PRODUCT_ID), /* idProduct */
0x00, /* bcdDevice rel. 2.00 */
0x02,
USB_MFC_STRING, /* Index of manufacturer string */
@@ -108,12 +108,12 @@ ALIGNED_HEAD uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN] ALIGNED_TAIL =
#if defined ( __ICCARM__ ) /* iar compiler */
#pragma data_alignment=4
#endif
ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_CDC_CONFIG_DESC_SIZE] ALIGNED_TAIL =
{
USB_DEVICE_CFG_DESC_LEN, /* bLength: configuration descriptor size */
USB_DESCIPTOR_TYPE_CONFIGURATION, /* bDescriptorType: configuration */
LBYTE(USBD_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
HBYTE(USBD_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
LBYTE(USBD_CDC_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
HBYTE(USBD_CDC_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
0x02, /* bNumInterfaces: 2 interface */
0x01, /* bConfigurationValue: configuration value */
0x00, /* iConfiguration: index of string descriptor describing
@@ -134,8 +134,8 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
0x05, /* bFunctionLength: size of this descriptor in bytes */
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
USBD_CDC_SUBTYPE_HEADER, /* bDescriptorSubtype: Header function Descriptor 0x00*/
LBYTE(BCD_NUM),
HBYTE(BCD_NUM), /* bcdCDC: USB class definitions for communications */
LBYTE(CDC_BCD_NUM),
HBYTE(CDC_BCD_NUM), /* bcdCDC: USB class definitions for communications */
0x05, /* bFunctionLength: size of this descriptor in bytes */
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
@@ -158,9 +158,9 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
USBD_CDC_INT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
USB_EPT_DESC_INTERRUPT, /* bmAttributes: endpoint attributes */
LBYTE(USBD_CMD_MAXPACKET_SIZE),
HBYTE(USBD_CMD_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
LBYTE(USBD_CDC_CMD_MAXPACKET_SIZE),
HBYTE(USBD_CDC_CMD_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
CDC_HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
@@ -177,17 +177,17 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
USBD_CDC_BULK_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
LBYTE(USBD_IN_MAXPACKET_SIZE),
HBYTE(USBD_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
0x00, /* bInterval: interval for polling endpoint for data transfers */
LBYTE(USBD_CDC_IN_MAXPACKET_SIZE),
HBYTE(USBD_CDC_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
0x00, /* bInterval: interval for polling endpoint for data transfers */
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
USBD_CDC_BULK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
LBYTE(USBD_OUT_MAXPACKET_SIZE),
HBYTE(USBD_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
0x00, /* bInterval: interval for polling endpoint for data transfers */
LBYTE(USBD_CDC_OUT_MAXPACKET_SIZE),
HBYTE(USBD_CDC_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
0x00, /* bInterval: interval for polling endpoint for data transfers */
};
/**
@@ -196,9 +196,9 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
#if defined ( __ICCARM__ ) /* iar compiler */
#pragma data_alignment=4
#endif
ALIGNED_HEAD uint8_t g_string_lang_id[USBD_SIZ_STRING_LANGID] ALIGNED_TAIL =
ALIGNED_HEAD static uint8_t g_string_lang_id[USBD_CDC_SIZ_STRING_LANGID] ALIGNED_TAIL =
{
USBD_SIZ_STRING_LANGID,
USBD_CDC_SIZ_STRING_LANGID,
USB_DESCIPTOR_TYPE_STRING,
0x09,
0x04,
@@ -210,42 +210,42 @@ ALIGNED_HEAD uint8_t g_string_lang_id[USBD_SIZ_STRING_LANGID] ALIGNED_TAIL =
#if defined ( __ICCARM__ ) /* iar compiler */
#pragma data_alignment=4
#endif
ALIGNED_HEAD uint8_t g_string_serial[USBD_SIZ_STRING_SERIAL] ALIGNED_TAIL =
ALIGNED_HEAD static uint8_t g_string_serial[USBD_CDC_SIZ_STRING_SERIAL] ALIGNED_TAIL =
{
USBD_SIZ_STRING_SERIAL,
USBD_CDC_SIZ_STRING_SERIAL,
USB_DESCIPTOR_TYPE_STRING,
};
/* device descriptor */
usbd_desc_t device_descriptor =
static usbd_desc_t device_descriptor =
{
USB_DEVICE_DESC_LEN,
g_usbd_descriptor
};
/* config descriptor */
usbd_desc_t config_descriptor =
static usbd_desc_t config_descriptor =
{
USBD_CONFIG_DESC_SIZE,
USBD_CDC_CONFIG_DESC_SIZE,
g_usbd_configuration
};
/* langid descriptor */
usbd_desc_t langid_descriptor =
static usbd_desc_t langid_descriptor =
{
USBD_SIZ_STRING_LANGID,
USBD_CDC_SIZ_STRING_LANGID,
g_string_lang_id
};
/* serial descriptor */
usbd_desc_t serial_descriptor =
static usbd_desc_t serial_descriptor =
{
USBD_SIZ_STRING_SERIAL,
USBD_CDC_SIZ_STRING_SERIAL,
g_string_serial
};
usbd_desc_t vp_desc;
static usbd_desc_t vp_desc;
/**
* @brief standard usb unicode convert
@@ -253,7 +253,7 @@ usbd_desc_t vp_desc;
* @param unicode_buf: unicode buffer
* @retval length
*/
uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
{
uint16_t str_len = 0, id_pos = 2;
uint8_t *tmp_str = string;
@@ -266,7 +266,7 @@ uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
}
str_len = str_len * 2 + 2;
unicode_buf[0] = str_len;
unicode_buf[0] = (uint8_t)str_len;
unicode_buf[1] = USB_DESCIPTOR_TYPE_STRING;
return str_len;
@@ -327,7 +327,7 @@ static void get_serial_num(void)
* @param none
* @retval usbd_desc
*/
usbd_desc_t *get_device_descriptor(void)
static usbd_desc_t *get_device_descriptor(void)
{
return &device_descriptor;
}
@@ -337,7 +337,7 @@ usbd_desc_t *get_device_descriptor(void)
* @param none
* @retval usbd_desc
*/
usbd_desc_t * get_device_qualifier(void)
static usbd_desc_t * get_device_qualifier(void)
{
return NULL;
}
@@ -347,7 +347,7 @@ usbd_desc_t * get_device_qualifier(void)
* @param none
* @retval usbd_desc
*/
usbd_desc_t *get_device_configuration(void)
static usbd_desc_t *get_device_configuration(void)
{
return &config_descriptor;
}
@@ -357,7 +357,7 @@ usbd_desc_t *get_device_configuration(void)
* @param none
* @retval usbd_desc
*/
usbd_desc_t *get_device_other_speed(void)
static usbd_desc_t *get_device_other_speed(void)
{
return NULL;
}
@@ -367,7 +367,7 @@ usbd_desc_t *get_device_other_speed(void)
* @param none
* @retval usbd_desc
*/
usbd_desc_t *get_device_lang_id(void)
static usbd_desc_t *get_device_lang_id(void)
{
return &langid_descriptor;
}
@@ -378,9 +378,9 @@ usbd_desc_t *get_device_lang_id(void)
* @param none
* @retval usbd_desc
*/
usbd_desc_t *get_device_manufacturer_string(void)
static usbd_desc_t *get_device_manufacturer_string(void)
{
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_CDC_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
vp_desc.descriptor = g_usbd_desc_buffer;
return &vp_desc;
}
@@ -390,9 +390,9 @@ usbd_desc_t *get_device_manufacturer_string(void)
* @param none
* @retval usbd_desc
*/
usbd_desc_t *get_device_product_string(void)
static usbd_desc_t *get_device_product_string(void)
{
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_CDC_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
vp_desc.descriptor = g_usbd_desc_buffer;
return &vp_desc;
}
@@ -402,7 +402,7 @@ usbd_desc_t *get_device_product_string(void)
* @param none
* @retval usbd_desc
*/
usbd_desc_t *get_device_serial_string(void)
static usbd_desc_t *get_device_serial_string(void)
{
get_serial_num();
return &serial_descriptor;
@@ -413,9 +413,9 @@ usbd_desc_t *get_device_serial_string(void)
* @param none
* @retval usbd_desc
*/
usbd_desc_t *get_device_interface_string(void)
static usbd_desc_t *get_device_interface_string(void)
{
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_CDC_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
vp_desc.descriptor = g_usbd_desc_buffer;
return &vp_desc;
}
@@ -425,9 +425,9 @@ usbd_desc_t *get_device_interface_string(void)
* @param none
* @retval usbd_desc
*/
usbd_desc_t *get_device_config_string(void)
static usbd_desc_t *get_device_config_string(void)
{
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_CDC_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
vp_desc.descriptor = g_usbd_desc_buffer;
return &vp_desc;
}