mirror of
https://github.com/ArteryTek/AT32F415_Firmware_Library.git
synced 2026-05-21 01:12:20 +00:00
update version to v2.0.3
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_class.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb cdc class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -40,39 +40,33 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
usb_sts_type class_init_handler(void *udev);
|
||||
usb_sts_type class_clear_handler(void *udev);
|
||||
usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup);
|
||||
usb_sts_type class_ept0_tx_handler(void *udev);
|
||||
usb_sts_type class_ept0_rx_handler(void *udev);
|
||||
usb_sts_type class_in_handler(void *udev, uint8_t ept_num);
|
||||
usb_sts_type class_out_handler(void *udev, uint8_t ept_num);
|
||||
usb_sts_type class_sof_handler(void *udev);
|
||||
usb_sts_type class_event_handler(void *udev, usbd_event_type event);
|
||||
static usb_sts_type class_init_handler(void *udev);
|
||||
static usb_sts_type class_clear_handler(void *udev);
|
||||
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup);
|
||||
static usb_sts_type class_ept0_tx_handler(void *udev);
|
||||
static usb_sts_type class_ept0_rx_handler(void *udev);
|
||||
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num);
|
||||
static usb_sts_type class_out_handler(void *udev, uint8_t ept_num);
|
||||
static usb_sts_type class_sof_handler(void *udev);
|
||||
static usb_sts_type class_event_handler(void *udev, usbd_event_type event);
|
||||
|
||||
void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len);
|
||||
/* usb rx and tx buffer */
|
||||
static uint32_t alt_setting = 0;
|
||||
static uint8_t g_rx_buff[USBD_OUT_MAXPACKET_SIZE];
|
||||
//static uint8_t g_tx_buff[USBD_IN_MAXPACKET_SIZE];
|
||||
static uint8_t g_cmd[USBD_CMD_MAXPACKET_SIZE];
|
||||
static uint8_t g_req;
|
||||
static uint16_t g_len, g_rxlen;
|
||||
__IO uint8_t g_tx_completed = 1, g_rx_completed = 0;
|
||||
static usb_sts_type cdc_struct_init(cdc_struct_type *pcdc);
|
||||
extern void usb_usart_config( linecoding_type linecoding);
|
||||
static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len);
|
||||
|
||||
linecoding_type linecoding =
|
||||
linecoding_type linecoding =
|
||||
{
|
||||
115200,
|
||||
0x00,
|
||||
0x00,
|
||||
0x08
|
||||
0,
|
||||
0,
|
||||
8
|
||||
};
|
||||
|
||||
/* static variable */
|
||||
|
||||
/* cdc data struct */
|
||||
cdc_struct_type cdc_struct;
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler class_handler =
|
||||
usbd_class_handler cdc_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
class_clear_handler,
|
||||
@@ -83,31 +77,33 @@ usbd_class_handler class_handler =
|
||||
class_out_handler,
|
||||
class_sof_handler,
|
||||
class_event_handler,
|
||||
&cdc_struct
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief initialize usb custom hid endpoint
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_init_handler(void *udev)
|
||||
static usb_sts_type class_init_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
|
||||
/* init cdc struct */
|
||||
cdc_struct_init(pcdc);
|
||||
|
||||
/* open in endpoint */
|
||||
usbd_ept_open(pudev, USBD_CDC_INT_EPT, EPT_INT_TYPE, USBD_CMD_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_CDC_INT_EPT, EPT_INT_TYPE, USBD_CDC_CMD_MAXPACKET_SIZE);
|
||||
|
||||
/* open in endpoint */
|
||||
usbd_ept_open(pudev, USBD_CDC_BULK_IN_EPT, EPT_BULK_TYPE, USBD_IN_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_CDC_BULK_IN_EPT, EPT_BULK_TYPE, USBD_CDC_IN_MAXPACKET_SIZE);
|
||||
|
||||
/* open out endpoint */
|
||||
usbd_ept_open(pudev, USBD_CDC_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_CDC_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_CDC_OUT_MAXPACKET_SIZE);
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, g_rx_buff, USBD_OUT_MAXPACKET_SIZE);
|
||||
|
||||
g_tx_completed = 1;
|
||||
usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, pcdc->g_rx_buff, USBD_CDC_OUT_MAXPACKET_SIZE);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -117,7 +113,7 @@ usb_sts_type class_init_handler(void *udev)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_clear_handler(void *udev)
|
||||
static usb_sts_type class_clear_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
@@ -140,10 +136,11 @@ usb_sts_type class_clear_handler(void *udev)
|
||||
* @param setup: setup packet
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
|
||||
switch(setup->bmRequestType & USB_REQ_TYPE_RESERVED)
|
||||
{
|
||||
@@ -153,14 +150,14 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
if(setup->bmRequestType & USB_REQ_DIR_DTH)
|
||||
{
|
||||
usb_vcp_cmd_process(udev, setup->bRequest, g_cmd, setup->wLength);
|
||||
usbd_ctrl_send(pudev, g_cmd, setup->wLength);
|
||||
usb_vcp_cmd_process(udev, setup->bRequest, pcdc->g_cmd, setup->wLength);
|
||||
usbd_ctrl_send(pudev, pcdc->g_cmd, setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_req = setup->bRequest;
|
||||
g_len = setup->wLength;
|
||||
usbd_ctrl_recv(pudev, g_cmd, g_len);
|
||||
pcdc->g_req = setup->bRequest;
|
||||
pcdc->g_len = setup->wLength;
|
||||
usbd_ctrl_recv(pudev, pcdc->g_cmd, pcdc->g_len);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -173,10 +170,10 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
case USB_STD_REQ_GET_INTERFACE:
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&alt_setting, 1);
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&pcdc->alt_setting, 1);
|
||||
break;
|
||||
case USB_STD_REQ_SET_INTERFACE:
|
||||
alt_setting = setup->wValue;
|
||||
pcdc->alt_setting = setup->wValue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -194,7 +191,7 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_ept0_tx_handler(void *udev)
|
||||
static usb_sts_type class_ept0_tx_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
@@ -208,16 +205,17 @@ usb_sts_type class_ept0_tx_handler(void *udev)
|
||||
* @param udev: usb device core handler type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
uint32_t recv_len = usbd_get_recv_len(pudev, 0);
|
||||
/* ...user code... */
|
||||
if( g_req == SET_LINE_CODING)
|
||||
if( pcdc->g_req == SET_LINE_CODING)
|
||||
{
|
||||
/* class process */
|
||||
usb_vcp_cmd_process(udev, g_req, g_cmd, recv_len);
|
||||
usb_vcp_cmd_process(udev, pcdc->g_req, pcdc->g_cmd, recv_len);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -229,16 +227,17 @@ usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
usbd_flush_tx_fifo(pudev, ept_num);
|
||||
g_tx_completed = 1;
|
||||
pcdc->g_tx_completed = 1;
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -249,16 +248,17 @@ usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
|
||||
/* get endpoint receive data length */
|
||||
g_rxlen = usbd_get_recv_len(pudev, ept_num);
|
||||
pcdc->g_rxlen = usbd_get_recv_len(pudev, ept_num);
|
||||
|
||||
/*set recv flag*/
|
||||
g_rx_completed = 1;
|
||||
pcdc->g_rx_completed = 1;
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -268,7 +268,7 @@ usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_sof_handler(void *udev)
|
||||
static usb_sts_type class_sof_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
@@ -283,7 +283,7 @@ usb_sts_type class_sof_handler(void *udev)
|
||||
* @param event: usb device event
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
switch(event)
|
||||
@@ -313,6 +313,23 @@ usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device cdc init
|
||||
* @param pcdc: to the structure of cdc_struct
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type cdc_struct_init(cdc_struct_type *pcdc)
|
||||
{
|
||||
pcdc->g_tx_completed = 1;
|
||||
pcdc->g_rx_completed = 0;
|
||||
pcdc->alt_setting = 0;
|
||||
pcdc->linecoding.bitrate = linecoding.bitrate;
|
||||
pcdc->linecoding.data = linecoding.data;
|
||||
pcdc->linecoding.format = linecoding.format;
|
||||
pcdc->linecoding.parity = linecoding.parity;
|
||||
return USB_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class rx data process
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
@@ -322,21 +339,22 @@ usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
{
|
||||
uint16_t i_index = 0;
|
||||
uint16_t tmp_len = g_rxlen;
|
||||
uint16_t tmp_len = 0;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
|
||||
if(g_rx_completed == 0)
|
||||
if(pcdc->g_rx_completed == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
g_rx_completed = 0;
|
||||
tmp_len = g_rxlen;
|
||||
for(i_index = 0; i_index < g_rxlen; i_index ++)
|
||||
pcdc->g_rx_completed = 0;
|
||||
tmp_len = pcdc->g_rxlen;
|
||||
for(i_index = 0; i_index < pcdc->g_rxlen; i_index ++)
|
||||
{
|
||||
recv_data[i_index] = g_rx_buff[i_index];
|
||||
recv_data[i_index] = pcdc->g_rx_buff[i_index];
|
||||
}
|
||||
|
||||
usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, g_rx_buff, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, pcdc->g_rx_buff, USBD_CDC_OUT_MAXPACKET_SIZE);
|
||||
|
||||
return tmp_len;
|
||||
}
|
||||
@@ -352,9 +370,10 @@ error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
{
|
||||
error_status status = SUCCESS;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
if(g_tx_completed)
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
if(pcdc->g_tx_completed)
|
||||
{
|
||||
g_tx_completed = 0;
|
||||
pcdc->g_tx_completed = 0;
|
||||
usbd_ept_send(pudev, USBD_CDC_BULK_IN_EPT, send_data, len);
|
||||
}
|
||||
else
|
||||
@@ -364,7 +383,6 @@ error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief usb device function
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
@@ -373,25 +391,31 @@ error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
* @param len: buffer length
|
||||
* @retval none
|
||||
*/
|
||||
void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len)
|
||||
static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
switch(cmd)
|
||||
{
|
||||
case SET_LINE_CODING:
|
||||
linecoding.bitrate = (uint32_t)(buff[0] | (buff[1] << 8) | (buff[2] << 16) | (buff[3] <<24));
|
||||
linecoding.format = buff[4];
|
||||
linecoding.parity = buff[5];
|
||||
linecoding.data = buff[6];
|
||||
pcdc->linecoding.bitrate = (uint32_t)(buff[0] | (buff[1] << 8) | (buff[2] << 16) | (buff[3] <<24));
|
||||
pcdc->linecoding.format = buff[4];
|
||||
pcdc->linecoding.parity = buff[5];
|
||||
pcdc->linecoding.data = buff[6];
|
||||
#ifdef USB_VIRTUAL_COMPORT
|
||||
/* set hardware usart */
|
||||
usb_usart_config(pcdc->linecoding);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case GET_LINE_CODING:
|
||||
buff[0] = (uint8_t)linecoding.bitrate;
|
||||
buff[1] = (uint8_t)(linecoding.bitrate >> 8);
|
||||
buff[2] = (uint8_t)(linecoding.bitrate >> 16);
|
||||
buff[3] = (uint8_t)(linecoding.bitrate >> 24);
|
||||
buff[4] = (uint8_t)(linecoding.format);
|
||||
buff[5] = (uint8_t)(linecoding.parity);
|
||||
buff[6] = (uint8_t)(linecoding.data);
|
||||
buff[0] = (uint8_t)pcdc->linecoding.bitrate;
|
||||
buff[1] = (uint8_t)(pcdc->linecoding.bitrate >> 8);
|
||||
buff[2] = (uint8_t)(pcdc->linecoding.bitrate >> 16);
|
||||
buff[3] = (uint8_t)(pcdc->linecoding.bitrate >> 24);
|
||||
buff[4] = (uint8_t)(pcdc->linecoding.format);
|
||||
buff[5] = (uint8_t)(pcdc->linecoding.parity);
|
||||
buff[6] = (uint8_t)(pcdc->linecoding.data);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_class.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb cdc class file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -57,15 +57,9 @@ extern "C" {
|
||||
/**
|
||||
* @brief usb cdc in and out max packet size define
|
||||
*/
|
||||
#define USBD_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_OUT_MAXPACKET_SIZE 0x40
|
||||
#define USBD_CMD_MAXPACKET_SIZE 0x08
|
||||
|
||||
/**
|
||||
* @brief usb cdc class request code define
|
||||
*/
|
||||
#define SET_LINE_CODING 0x20
|
||||
#define GET_LINE_CODING 0x21
|
||||
#define USBD_CDC_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_CDC_OUT_MAXPACKET_SIZE 0x40
|
||||
#define USBD_CDC_CMD_MAXPACKET_SIZE 0x08
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -76,15 +70,19 @@ extern "C" {
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief usb cdc class set line coding struct
|
||||
* @brief usb cdc class struct
|
||||
*/
|
||||
typedef struct
|
||||
typedef struct
|
||||
{
|
||||
uint32_t bitrate; /* line coding baud rate */
|
||||
uint8_t format; /* line coding foramt */
|
||||
uint8_t parity; /* line coding parity */
|
||||
uint8_t data; /* line coding data bit */
|
||||
}linecoding_type;
|
||||
uint32_t alt_setting;
|
||||
uint8_t g_rx_buff[USBD_CDC_OUT_MAXPACKET_SIZE];
|
||||
uint8_t g_cmd[USBD_CDC_CMD_MAXPACKET_SIZE];
|
||||
uint8_t g_req;
|
||||
uint16_t g_len, g_rxlen;
|
||||
__IO uint8_t g_tx_completed, g_rx_completed;
|
||||
linecoding_type linecoding;
|
||||
}cdc_struct_type;
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -93,7 +91,7 @@ typedef struct
|
||||
/** @defgroup USB_cdc_class_exported_functions
|
||||
* @{
|
||||
*/
|
||||
extern usbd_class_handler class_handler;
|
||||
extern usbd_class_handler cdc_class_handler;
|
||||
uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data);
|
||||
error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len);
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -42,18 +42,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];
|
||||
@@ -61,7 +61,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,
|
||||
@@ -81,7 +81,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 */
|
||||
@@ -91,10 +91,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 */
|
||||
@@ -109,12 +109,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
|
||||
@@ -135,8 +135,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 */
|
||||
@@ -159,9 +159,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 */
|
||||
@@ -178,16 +178,16 @@ 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 */
|
||||
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 */
|
||||
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 */
|
||||
};
|
||||
|
||||
@@ -197,9 +197,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,
|
||||
@@ -211,42 +211,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
|
||||
@@ -254,7 +254,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;
|
||||
@@ -328,7 +328,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;
|
||||
}
|
||||
@@ -338,7 +338,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;
|
||||
}
|
||||
@@ -348,7 +348,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;
|
||||
}
|
||||
@@ -358,7 +358,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;
|
||||
}
|
||||
@@ -368,7 +368,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;
|
||||
}
|
||||
@@ -379,9 +379,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;
|
||||
}
|
||||
@@ -391,9 +391,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;
|
||||
}
|
||||
@@ -403,7 +403,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;
|
||||
@@ -414,9 +414,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;
|
||||
}
|
||||
@@ -426,9 +426,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;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_desc.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb cdc descriptor header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -46,51 +46,36 @@ extern "C" {
|
||||
/** @defgroup USB_cdc_desc_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief usb bcd number define
|
||||
*/
|
||||
#define BCD_NUM 0x0110
|
||||
#define CDC_BCD_NUM 0x0110
|
||||
|
||||
/**
|
||||
* @brief usb vendor id and product id define
|
||||
*/
|
||||
#define USBD_VENDOR_ID 0x2E3C
|
||||
#define USBD_PRODUCT_ID 0x5740
|
||||
#define USBD_CDC_VENDOR_ID 0x2E3C
|
||||
#define USBD_CDC_PRODUCT_ID 0x5740
|
||||
|
||||
/**
|
||||
* @brief usb descriptor size define
|
||||
*/
|
||||
#define USBD_CONFIG_DESC_SIZE 67
|
||||
#define USBD_SIZ_STRING_LANGID 4
|
||||
#define USBD_SIZ_STRING_SERIAL 0x1A
|
||||
#define USBD_CDC_CONFIG_DESC_SIZE 67
|
||||
#define USBD_CDC_SIZ_STRING_LANGID 4
|
||||
#define USBD_CDC_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
/**
|
||||
* @brief usb string define(vendor, product configuration, interface)
|
||||
*/
|
||||
#define USBD_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_DESC_PRODUCT_STRING "AT32 Virtual Com Port "
|
||||
#define USBD_DESC_CONFIGURATION_STRING "Virtual ComPort Config"
|
||||
#define USBD_DESC_INTERFACE_STRING "Virtual ComPort Interface"
|
||||
#define USBD_CDC_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_CDC_DESC_PRODUCT_STRING "AT32 Virtual Com Port "
|
||||
#define USBD_CDC_DESC_CONFIGURATION_STRING "Virtual ComPort Config"
|
||||
#define USBD_CDC_DESC_INTERFACE_STRING "Virtual ComPort Interface"
|
||||
|
||||
/**
|
||||
* @brief usb endpoint interval define
|
||||
*/
|
||||
#define HID_BINTERVAL_TIME 0xFF
|
||||
|
||||
/**
|
||||
* @brief usb hid class descriptor define
|
||||
*/
|
||||
#define USBD_CDC_CS_INTERFACE 0x24
|
||||
#define USBD_CDC_CS_ENDPOINT 0x25
|
||||
|
||||
/**
|
||||
* @brief usb hid class sub-type define
|
||||
*/
|
||||
#define USBD_CDC_SUBTYPE_HEADER 0x00
|
||||
#define USBD_CDC_SUBTYPE_CMF 0x01
|
||||
#define USBD_CDC_SUBTYPE_ACM 0x02
|
||||
#define USBD_CDC_SUBTYPE_UFD 0x06
|
||||
#define CDC_HID_BINTERVAL_TIME 0xFF
|
||||
|
||||
/**
|
||||
* @brief usb mcu id address deine
|
||||
@@ -98,14 +83,11 @@ extern "C" {
|
||||
#define MCU_ID1 (0x1FFFF7E8)
|
||||
#define MCU_ID2 (0x1FFFF7EC)
|
||||
#define MCU_ID3 (0x1FFFF7F0)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
extern uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN];
|
||||
extern uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE];
|
||||
extern usbd_desc_handler desc_handler;
|
||||
extern usbd_desc_handler cdc_desc_handler;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user