update version to v2.0.7

This commit is contained in:
Artery-MCU
2022-03-03 19:28:16 +08:00
parent e1d3f6e2c9
commit eb00682e95
2098 changed files with 11432 additions and 6380 deletions

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file cdc_keyboard_class.c
* @version v2.0.6
* @date 2021-12-31
* @version v2.0.7
* @date 2022-02-11
* @brief usb cdc and keyboard class type
**************************************************************************
* Copyright notice & Disclaimer
@@ -40,36 +40,24 @@
* @{
*/
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);
usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup);
usb_sts_type keyboard_class_setup_handler(void *udev, usb_setup_type *setup);
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);
static usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup);
static usb_sts_type keyboard_class_setup_handler(void *udev, usb_setup_type *setup);
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 uint32_t hid_protocol = 0;
static uint32_t hid_set_idle = 0;
static uint8_t hid_state;
uint8_t hid_set_report[64];
static uint8_t g_rx_buff[USBD_OUT_MAXPACKET_SIZE];
static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len);
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;
__IO uint8_t g_keyboard_tx_completed = 0;
vcp_keyboard_type vcp_keyboard_struct;
#define SHIFT 0x80
const unsigned char _asciimap[128] =
const static unsigned char _asciimap[128] =
{
0x00,// NUL
0x00,// SOH
@@ -202,7 +190,7 @@ const unsigned char _asciimap[128] =
0 // DEL
};
linecoding_type linecoding =
linecoding_type linecoding_vcpkybrd =
{
115200,
0x00,
@@ -225,6 +213,7 @@ usbd_class_handler cdc_keyboard_class_handler =
class_out_handler,
class_sof_handler,
class_event_handler,
&vcp_keyboard_struct
};
/**
@@ -232,37 +221,41 @@ usbd_class_handler cdc_keyboard_class_handler =
* @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;
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
#ifndef USB_EPT_AUTO_MALLOC_BUFFER
/* use user define buffer address */
usbd_ept_buf_custom_define(pudev, USBD_CDC_INT_EPT, EPT2_TX_ADDR);
usbd_ept_buf_custom_define(pudev, USBD_CDC_BULK_IN_EPT, EPT1_TX_ADDR);
usbd_ept_buf_custom_define(pudev, USBD_CDC_BULK_OUT_EPT, EPT1_RX_ADDR);
usbd_ept_buf_custom_define(pudev, USBD_HID_IN_EPT, EPT3_TX_ADDR);
usbd_ept_buf_custom_define(pudev, USBD_VCPKYBRD_CDC_INT_EPT, EPT2_TX_ADDR);
usbd_ept_buf_custom_define(pudev, USBD_VCPKYBRD_CDC_BULK_IN_EPT, EPT1_TX_ADDR);
usbd_ept_buf_custom_define(pudev, USBD_VCPKYBRD_CDC_BULK_OUT_EPT, EPT1_RX_ADDR);
usbd_ept_buf_custom_define(pudev, USBD_VCPKYBRD_HID_IN_EPT, EPT3_TX_ADDR);
#endif
/* open in endpoint */
usbd_ept_open(pudev, USBD_CDC_INT_EPT, EPT_INT_TYPE, USBD_CMD_MAXPACKET_SIZE);
usbd_ept_open(pudev, USBD_VCPKYBRD_CDC_INT_EPT, EPT_INT_TYPE, USBD_VCPKYBRD_CMD_MAXPACKET_SIZE);
/* open in endpoint */
usbd_ept_open(pudev, USBD_CDC_BULK_IN_EPT, EPT_BULK_TYPE, USBD_OUT_MAXPACKET_SIZE);
usbd_ept_open(pudev, USBD_VCPKYBRD_CDC_BULK_IN_EPT, EPT_BULK_TYPE, USBD_VCPKYBRD_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_VCPKYBRD_CDC_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_VCPKYBRD_OUT_MAXPACKET_SIZE);
/* open hid in endpoint */
usbd_ept_open(pudev, USBD_HID_IN_EPT, EPT_INT_TYPE, USBD_OUT_MAXPACKET_SIZE);
usbd_ept_open(pudev, USBD_VCPKYBRD_HID_IN_EPT, EPT_INT_TYPE, USBD_VCPKYBRD_IN_MAXPACKET_SIZE);
/* set out endpoint to receive status */
usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, g_rx_buff, USBD_OUT_MAXPACKET_SIZE);
usbd_ept_recv(pudev, USBD_VCPKYBRD_CDC_BULK_OUT_EPT, vcpkybrd->g_rx_buff, USBD_VCPKYBRD_OUT_MAXPACKET_SIZE);
g_tx_completed = 1;
g_keyboard_tx_completed = 1;
vcpkybrd->g_tx_completed = 1;
vcpkybrd->g_keyboard_tx_completed = 1;
vcpkybrd->linecoding.bitrate = linecoding_vcpkybrd.bitrate;
vcpkybrd->linecoding.data = linecoding_vcpkybrd.data;
vcpkybrd->linecoding.format = linecoding_vcpkybrd.format;
vcpkybrd->linecoding.parity = linecoding_vcpkybrd.parity;
return status;
}
@@ -271,22 +264,22 @@ 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;
/* close in endpoint */
usbd_ept_close(pudev, USBD_CDC_INT_EPT);
usbd_ept_close(pudev, USBD_VCPKYBRD_CDC_INT_EPT);
/* close in endpoint */
usbd_ept_close(pudev, USBD_CDC_BULK_IN_EPT);
usbd_ept_close(pudev, USBD_VCPKYBRD_CDC_BULK_IN_EPT);
/* close out endpoint */
usbd_ept_close(pudev, USBD_CDC_BULK_OUT_EPT);
usbd_ept_close(pudev, USBD_VCPKYBRD_CDC_BULK_OUT_EPT);
/* close in endpoint */
usbd_ept_close(pudev, USBD_HID_IN_EPT);
usbd_ept_close(pudev, USBD_VCPKYBRD_HID_IN_EPT);
return status;
}
@@ -297,14 +290,14 @@ 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;
switch(setup->bmRequestType & USB_REQ_RECIPIENT_MASK)
{
case USB_REQ_RECIPIENT_INTERFACE:
if(setup->wIndex == HID_KEYBOARD_INTERFACE)
if(setup->wIndex == VCPKYBRD_KEYBOARD_INTERFACE)
{
keyboard_class_setup_handler(pudev, setup);
}
@@ -326,10 +319,11 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
* @param setup: setup packet
* @retval status of usb_sts_type
*/
usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup)
static usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup)
{
usb_sts_type status = USB_OK;
usbd_core_type *pudev = (usbd_core_type *)udev;
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
switch(setup->bmRequestType & USB_REQ_TYPE_RESERVED)
{
@@ -339,14 +333,14 @@ usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup)
{
if(setup->bmRequestType & USB_REQ_DIR_DTH)
{
usb_vcp_cmd_process(pudev, setup->bRequest, g_cmd, setup->wLength);
usbd_ctrl_send(pudev, g_cmd, setup->wLength);
usb_vcp_cmd_process(udev, setup->bRequest, vcpkybrd->g_cmd, setup->wLength);
usbd_ctrl_send(pudev, vcpkybrd->g_cmd, setup->wLength);
}
else
{
g_req = setup->bRequest;
g_len = setup->wLength;
usbd_ctrl_recv(pudev, g_cmd, g_len);
vcpkybrd->g_req = setup->bRequest;
vcpkybrd->g_len = setup->wLength;
usbd_ctrl_recv(pudev, vcpkybrd->g_cmd, vcpkybrd->g_len);
}
}
@@ -359,10 +353,10 @@ usb_sts_type cdc_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 *)&vcpkybrd->alt_setting, 1);
break;
case USB_STD_REQ_SET_INTERFACE:
alt_setting = setup->wValue;
vcpkybrd->alt_setting = setup->wValue;
break;
default:
break;
@@ -381,10 +375,11 @@ usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup)
* @param setup: setup packet
* @retval status of usb_sts_type
*/
usb_sts_type keyboard_class_setup_handler(void *udev, usb_setup_type *setup)
static usb_sts_type keyboard_class_setup_handler(void *udev, usb_setup_type *setup)
{
usb_sts_type status = USB_OK;
usbd_core_type *pudev = (usbd_core_type *)udev;
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
uint16_t len;
uint8_t *buf;
@@ -395,20 +390,20 @@ usb_sts_type keyboard_class_setup_handler(void *udev, usb_setup_type *setup)
switch(setup->bRequest)
{
case HID_REQ_SET_PROTOCOL:
hid_protocol = (uint8_t)setup->wValue;
vcpkybrd->hid_protocol = (uint8_t)setup->wValue;
break;
case HID_REQ_GET_PROTOCOL:
usbd_ctrl_send(pudev, (uint8_t *)&hid_protocol, 1);
usbd_ctrl_send(pudev, (uint8_t *)&vcpkybrd->hid_protocol, 1);
break;
case HID_REQ_SET_IDLE:
hid_set_idle = (uint8_t)(setup->wValue >> 8);
vcpkybrd->hid_set_idle = (uint8_t)(setup->wValue >> 8);
break;
case HID_REQ_GET_IDLE:
usbd_ctrl_send(pudev, (uint8_t *)&hid_set_idle, 1);
usbd_ctrl_send(pudev, (uint8_t *)&vcpkybrd->hid_set_idle, 1);
break;
case HID_REQ_SET_REPORT:
hid_state = HID_REQ_SET_REPORT;
usbd_ctrl_recv(pudev, hid_set_report, setup->wLength);
vcpkybrd->hid_state = HID_REQ_SET_REPORT;
usbd_ctrl_recv(pudev, vcpkybrd->hid_set_report, setup->wLength);
break;
default:
usbd_ctrl_unsupport(pudev);
@@ -422,21 +417,21 @@ usb_sts_type keyboard_class_setup_handler(void *udev, usb_setup_type *setup)
case USB_STD_REQ_GET_DESCRIPTOR:
if(setup->wValue >> 8 == HID_REPORT_DESC)
{
len = MIN(USBD_HID_SIZ_REPORT_DESC, setup->wLength);
buf = (uint8_t *)g_usbd_hid_report;
len = MIN(USBD_VCPKYBRD_HID_SIZ_REPORT_DESC, setup->wLength);
buf = (uint8_t *)g_usbd_vcpkybrd_hid_report;
}
else if(setup->wValue >> 8 == HID_DESCRIPTOR_TYPE)
{
len = MIN(9, setup->wLength);
buf = (uint8_t *)g_hid_usb_desc;
buf = (uint8_t *)g_vcpkybrd_hid_usb_desc;
}
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
break;
case USB_STD_REQ_GET_INTERFACE:
usbd_ctrl_send(pudev, (uint8_t *)&alt_setting, 1);
usbd_ctrl_send(pudev, (uint8_t *)&vcpkybrd->alt_setting, 1);
break;
case USB_STD_REQ_SET_INTERFACE:
alt_setting = setup->wValue;
vcpkybrd->alt_setting = setup->wValue;
break;
default:
break;
@@ -454,7 +449,7 @@ usb_sts_type keyboard_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;
@@ -468,23 +463,23 @@ usb_sts_type class_ept0_tx_handler(void *udev)
* @param udev: to the structure of usbd_core_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;
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
uint32_t recv_len = usbd_get_recv_len(pudev, 0);
/* ...user code... */
if( g_req == SET_LINE_CODING)
if( vcpkybrd->g_req == SET_LINE_CODING)
{
/* class process */
usb_vcp_cmd_process(udev, g_req, g_cmd, recv_len);
usb_vcp_cmd_process(udev, vcpkybrd->g_req, vcpkybrd->g_cmd, recv_len);
}
if( hid_state == HID_REQ_SET_REPORT)
if( vcpkybrd->hid_state == HID_REQ_SET_REPORT)
{
/* hid buffer process */
hid_state = 0;
vcpkybrd->hid_state = 0;
}
return status;
}
@@ -495,20 +490,22 @@ 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)
{
usb_sts_type status = USB_OK;
usbd_core_type *pudev = (usbd_core_type *)udev;
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
/* ...user code...
trans next packet data
*/
if((ept_num & 0x7F) == (USBD_CDC_BULK_IN_EPT & 0x7F))
if((ept_num & 0x7F) == (USBD_VCPKYBRD_CDC_BULK_IN_EPT & 0x7F))
{
g_tx_completed = 1;
vcpkybrd->g_tx_completed = 1;
}
if((ept_num & 0x7F) == (USBD_HID_IN_EPT & 0x7F))
if((ept_num & 0x7F) == (USBD_VCPKYBRD_HID_IN_EPT & 0x7F))
{
g_keyboard_tx_completed = 1;
vcpkybrd->g_keyboard_tx_completed = 1;
}
@@ -521,16 +518,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;
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
/* get endpoint receive data length */
g_rxlen = usbd_get_recv_len(pudev, ept_num);
vcpkybrd->g_rxlen = usbd_get_recv_len(pudev, ept_num);
/*set recv flag*/
g_rx_completed = 1;
vcpkybrd->g_rx_completed = 1;
return status;
}
@@ -540,7 +538,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;
@@ -555,7 +553,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)
@@ -586,25 +584,26 @@ usb_sts_type class_event_handler(void *udev, usbd_event_type event)
* @param recv_data: receive buffer
* @retval receive data len
*/
uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data)
uint16_t usb_vcpkybrd_vcp_get_rxdata(void *udev, uint8_t *recv_data)
{
uint16_t i_index = 0;
usbd_core_type *pudev = (usbd_core_type *)udev;
uint16_t tmp_len = g_rxlen;
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
uint16_t tmp_len = 0;
if(g_rx_completed == 0)
if(vcpkybrd->g_rx_completed == 0)
{
return 0;
}
g_rx_completed = 0;
vcpkybrd->g_rx_completed = 0;
tmp_len = g_rxlen;
for(i_index = 0; i_index < g_rxlen; i_index ++)
tmp_len = vcpkybrd->g_rxlen;
for(i_index = 0; i_index < vcpkybrd->g_rxlen; i_index ++)
{
recv_data[i_index] = g_rx_buff[i_index];
recv_data[i_index] = vcpkybrd->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_VCPKYBRD_CDC_BULK_OUT_EPT, vcpkybrd->g_rx_buff, USBD_VCPKYBRD_OUT_MAXPACKET_SIZE);
return tmp_len;
}
@@ -616,14 +615,15 @@ uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data)
* @param len: send length
* @retval error status
*/
error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len)
error_status usb_vcpkybrd_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)
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
if(vcpkybrd->g_tx_completed)
{
g_tx_completed = 0;
usbd_ept_send(pudev, USBD_CDC_BULK_IN_EPT, send_data, len);
vcpkybrd->g_tx_completed = 0;
usbd_ept_send(pudev, USBD_VCPKYBRD_CDC_BULK_IN_EPT, send_data, len);
}
else
{
@@ -641,25 +641,27 @@ 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;
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_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];
vcpkybrd->linecoding.bitrate = (uint32_t)(buff[0] | (buff[1] << 8) | (buff[2] << 16) | (buff[3] <<24));
vcpkybrd->linecoding.format = buff[4];
vcpkybrd->linecoding.parity = buff[5];
vcpkybrd->linecoding.data = buff[6];
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)vcpkybrd->linecoding.bitrate;
buff[1] = (uint8_t)(vcpkybrd->linecoding.bitrate >> 8);
buff[2] = (uint8_t)(vcpkybrd->linecoding.bitrate >> 16);
buff[3] = (uint8_t)(vcpkybrd->linecoding.bitrate >> 24);
buff[4] = (uint8_t)(vcpkybrd->linecoding.format);
buff[5] = (uint8_t)(vcpkybrd->linecoding.parity);
buff[6] = (uint8_t)(vcpkybrd->linecoding.data);
break;
default:
@@ -674,13 +676,13 @@ void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len)
* @param len: report length
* @retval status of usb_sts_type
*/
usb_sts_type class_send_report(void *udev, uint8_t *report, uint16_t len)
usb_sts_type usb_vcpkybrd_class_send_report(void *udev, uint8_t *report, uint16_t len)
{
usb_sts_type status = USB_OK;
usbd_core_type *pudev = (usbd_core_type *)udev;
if(usbd_connect_state_get(pudev) == USB_CONN_STATE_CONFIGURED)
usbd_ept_send(pudev, USBD_HID_IN_EPT, report, len);
usbd_ept_send(pudev, USBD_VCPKYBRD_HID_IN_EPT, report, len);
return status;
}
@@ -692,7 +694,7 @@ usb_sts_type class_send_report(void *udev, uint8_t *report, uint16_t len)
* @param op: operation
* @retval none
*/
void usb_hid_keyboard_send_char(void *udev, uint8_t ascii_code)
void usb_vcpkybrd_keyboard_send_char(void *udev, uint8_t ascii_code)
{
uint8_t key_data = 0;
static uint8_t temp = 0;
@@ -721,13 +723,13 @@ void usb_hid_keyboard_send_char(void *udev, uint8_t ascii_code)
{
keyboard_buf[0] = 0;
keyboard_buf[2] = 0;
class_send_report(udev, keyboard_buf, 8);
usb_vcpkybrd_class_send_report(udev, keyboard_buf, 8);
}
else
{
keyboard_buf[0] = key_data;
keyboard_buf[2] = ascii_code;
class_send_report(udev, keyboard_buf, 8);
usb_vcpkybrd_class_send_report(udev, keyboard_buf, 8);
}
}

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file cdc_keyboard_class.h
* @version v2.0.6
* @date 2021-12-31
* @version v2.0.7
* @date 2022-02-11
* @brief usb cdc and keyboard class file
**************************************************************************
* Copyright notice & Disclaimer
@@ -50,35 +50,19 @@ extern "C" {
/**
* @brief usb use endpoint define
*/
#define USBD_CDC_INT_EPT 0x82
#define USBD_CDC_BULK_IN_EPT 0x81
#define USBD_CDC_BULK_OUT_EPT 0x01
#define USBD_HID_IN_EPT 0x83
#define USBD_VCPKYBRD_CDC_INT_EPT 0x82
#define USBD_VCPKYBRD_CDC_BULK_IN_EPT 0x81
#define USBD_VCPKYBRD_CDC_BULK_OUT_EPT 0x01
#define USBD_VCPKYBRD_HID_IN_EPT 0x83
/**
* @brief usb 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
#define USBD_VCPKYBRD_IN_MAXPACKET_SIZE 0x40
#define USBD_VCPKYBRD_OUT_MAXPACKET_SIZE 0x40
#define USBD_VCPKYBRD_CMD_MAXPACKET_SIZE 0x08
/**
* @brief usb cdc class request code define
*/
#define SET_LINE_CODING 0x20
#define GET_LINE_CODING 0x21
/**
* @brief usb hid class request code define
*/
#define HID_REQ_SET_PROTOCOL 0x0B
#define HID_REQ_GET_PROTOCOL 0x03
#define HID_REQ_SET_IDLE 0x0A
#define HID_REQ_GET_IDLE 0x02
#define HID_REQ_SET_REPORT 0x09
#define HID_REQ_GET_REPORT 0x01
#define HID_DESCRIPTOR_TYPE 0x21
#define HID_REPORT_DESC 0x22
/**
* @}
*/
@@ -87,16 +71,24 @@ extern "C" {
* @{
*/
/**
* @brief usb cdc class set line coding 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;
uint32_t hid_protocol;
uint32_t hid_set_idle;
uint8_t hid_set_report[64];
uint8_t g_rx_buff[USBD_VCPKYBRD_OUT_MAXPACKET_SIZE];
uint8_t g_cmd[USBD_VCPKYBRD_CMD_MAXPACKET_SIZE];
uint8_t g_req;
uint8_t hid_state;
uint16_t g_len, g_rxlen;
__IO uint8_t g_tx_completed;
__IO uint8_t g_rx_completed;
__IO uint8_t g_keyboard_tx_completed;
linecoding_type linecoding;
}vcp_keyboard_type;
/**
* @}
@@ -106,11 +98,10 @@ typedef struct
* @{
*/
extern usbd_class_handler cdc_keyboard_class_handler;
extern __IO uint8_t g_keyboard_tx_completed;
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);
usb_sts_type class_send_report(void *udev, uint8_t *report, uint16_t len);
void usb_hid_keyboard_send_char(void *udev, uint8_t ascii_code);
uint16_t usb_vcpkybrd_vcp_get_rxdata(void *udev, uint8_t *recv_data);
error_status usb_vcpkybrd_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len);
usb_sts_type usb_vcpkybrd_class_send_report(void *udev, uint8_t *report, uint16_t len);
void usb_vcpkybrd_keyboard_send_char(void *udev, uint8_t ascii_code);
/**
* @}

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file cdc_keyboard_desc.c
* @version v2.0.6
* @date 2021-12-31
* @version v2.0.7
* @date 2022-02-11
* @brief usb cdc and keyboard device descriptor
**************************************************************************
* Copyright notice & Disclaimer
@@ -40,18 +40,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];
@@ -79,7 +79,7 @@ usbd_desc_handler cdc_keyboard_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 */
@@ -89,10 +89,10 @@ ALIGNED_HEAD uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN] ALIGNED_TAIL =
0x02, /* bDeviceSubClass */
0x01, /* 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_VCPKYBRD_VENDOR_ID), /* idVendor */
HBYTE(USBD_VCPKYBRD_VENDOR_ID), /* idVendor */
LBYTE(USBD_VCPKYBRD_PRODUCT_ID), /* idProduct */
HBYTE(USBD_VCPKYBRD_PRODUCT_ID), /* idProduct */
0x00, /* bcdDevice rel. 2.00 */
0x02,
USB_MFC_STRING, /* Index of manufacturer string */
@@ -107,12 +107,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_VCPKYBRD_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_VCPKYBRD_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
HBYTE(USBD_VCPKYBRD_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
0x03, /* bNumInterfaces: 2 interface */
0x01, /* bConfigurationValue: configuration value */
0x00, /* iConfiguration: index of string descriptor describing
@@ -131,7 +131,7 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
CDC_INTERFACE, /* bInterfaceNumber: number of interface */
VCPKYBRD_CDC_INTERFACE, /* bInterfaceNumber: number of interface */
0x00, /* bAlternateSetting: alternate set */
0x01, /* bNumEndpoints: number of endpoints */
USB_CLASS_CODE_CDC, /* bInterfaceClass: CDC class code */
@@ -142,8 +142,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(VCPKYBRD_BCD_NUM),
HBYTE(VCPKYBRD_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 */
@@ -164,16 +164,16 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
USBD_CDC_INT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
USBD_VCPKYBRD_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_VCPKYBRD_CMD_MAXPACKET_SIZE),
HBYTE(USBD_VCPKYBRD_CMD_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
VCPKYBRD_HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
CDC_DATA_INTERFACE, /* bInterfaceNumber: number of interface */
VCPKYBRD_CDC_DATA_INTERFACE, /* bInterfaceNumber: number of interface */
0x00, /* bAlternateSetting: alternate set */
0x02, /* bNumEndpoints: number of endpoints */
USB_CLASS_CODE_CDCDATA, /* bInterfaceClass: CDC-data class code */
@@ -183,18 +183,18 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
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 */
USBD_VCPKYBRD_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_VCPKYBRD_IN_MAXPACKET_SIZE),
HBYTE(USBD_VCPKYBRD_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 */
USBD_VCPKYBRD_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_VCPKYBRD_OUT_MAXPACKET_SIZE),
HBYTE(USBD_VCPKYBRD_OUT_MAXPACKET_SIZE),/* wMaxPacketSize: maximum packe size this endpoint */
0x00, /* bInterval: interval for polling endpoint for data transfers */
0x08, /* bLength */
@@ -208,7 +208,7 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
HID_KEYBOARD_INTERFACE, /* bInterfaceNumber: number of interface */
VCPKYBRD_KEYBOARD_INTERFACE, /* bInterfaceNumber: number of interface */
0x00, /* bAlternateSetting: alternate set */
0x01, /* bNumEndpoints: number of endpoints */
USB_CLASS_CODE_HID, /* bInterfaceClass: class code hid */
@@ -218,21 +218,21 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
0x09, /* bLength: size of HID descriptor in bytes */
HID_CLASS_DESC_HID, /* bDescriptorType: HID descriptor type */
LBYTE(HID_BCD_NUM),
HBYTE(HID_BCD_NUM), /* bcdHID: HID class specification release number */
LBYTE(VCPKYBRD_BCD_NUM),
HBYTE(VCPKYBRD_BCD_NUM), /* bcdHID: HID class specification release number */
0x00, /* bCountryCode: hardware target conutry */
0x01, /* bNumDescriptors: number of HID class descriptor to follow */
HID_CLASS_DESC_REPORT, /* bDescriptorType: report descriptor type */
LBYTE(sizeof(g_usbd_hid_report)),
HBYTE(sizeof(g_usbd_hid_report)), /* wDescriptorLength: total length of reprot descriptor */
LBYTE(sizeof(g_usbd_vcpkybrd_hid_report)),
HBYTE(sizeof(g_usbd_vcpkybrd_hid_report)), /* wDescriptorLength: total length of reprot descriptor */
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
USBD_HID_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
USBD_VCPKYBRD_HID_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
USB_EPT_DESC_INTERRUPT, /* bmAttributes: endpoint attributes */
LBYTE(USBD_IN_MAXPACKET_SIZE),
HBYTE(USBD_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
LBYTE(USBD_VCPKYBRD_IN_MAXPACKET_SIZE),
HBYTE(USBD_VCPKYBRD_IN_MAXPACKET_SIZE),/* wMaxPacketSize: maximum packe size this endpoint */
VCPKYBRD_HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
};
/**
@@ -241,17 +241,17 @@ 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_hid_usb_desc[9] ALIGNED_TAIL =
ALIGNED_HEAD uint8_t g_vcpkybrd_hid_usb_desc[9] ALIGNED_TAIL =
{
0x09, /* bLength: size of HID descriptor in bytes */
HID_CLASS_DESC_HID, /* bDescriptorType: HID descriptor type */
LBYTE(HID_BCD_NUM),
HBYTE(HID_BCD_NUM), /* bcdHID: HID class specification release number */
LBYTE(VCPKYBRD_BCD_NUM),
HBYTE(VCPKYBRD_BCD_NUM), /* bcdHID: HID class specification release number */
0x00, /* bCountryCode: hardware target conutry */
0x01, /* bNumDescriptors: number of HID class descriptor to follow */
HID_CLASS_DESC_REPORT, /* bDescriptorType: report descriptor type */
LBYTE(sizeof(g_usbd_hid_report)),
HBYTE(sizeof(g_usbd_hid_report)), /* wDescriptorLength: total length of reprot descriptor */
LBYTE(sizeof(g_usbd_vcpkybrd_hid_report)),
HBYTE(sizeof(g_usbd_vcpkybrd_hid_report)), /* wDescriptorLength: total length of reprot descriptor */
};
/**
@@ -260,7 +260,7 @@ ALIGNED_HEAD uint8_t g_hid_usb_desc[9] ALIGNED_TAIL =
#if defined ( __ICCARM__ ) /* iar compiler */
#pragma data_alignment=4
#endif
ALIGNED_HEAD uint8_t g_usbd_hid_report[USBD_HID_SIZ_REPORT_DESC] ALIGNED_TAIL =
ALIGNED_HEAD uint8_t g_usbd_vcpkybrd_hid_report[USBD_VCPKYBRD_HID_SIZ_REPORT_DESC] ALIGNED_TAIL =
{
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
@@ -301,9 +301,9 @@ ALIGNED_HEAD uint8_t g_usbd_hid_report[USBD_HID_SIZ_REPORT_DESC] 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_VCPKYBRD_SIZ_STRING_LANGID] ALIGNED_TAIL =
{
USBD_SIZ_STRING_LANGID,
USBD_VCPKYBRD_SIZ_STRING_LANGID,
USB_DESCIPTOR_TYPE_STRING,
0x09,
0x04,
@@ -315,42 +315,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_VCPKYBRD_SIZ_STRING_SERIAL] ALIGNED_TAIL =
{
USBD_SIZ_STRING_SERIAL,
USBD_VCPKYBRD_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_VCPKYBRD_CONFIG_DESC_SIZE,
g_usbd_configuration
};
/* langid descriptor */
usbd_desc_t langid_descriptor =
static usbd_desc_t langid_descriptor =
{
USBD_SIZ_STRING_LANGID,
USBD_VCPKYBRD_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_VCPKYBRD_SIZ_STRING_SERIAL,
g_string_serial
};
usbd_desc_t vp_desc;
static usbd_desc_t vp_desc;
/**
* @brief standard usb unicode convert
@@ -358,7 +358,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;
@@ -432,7 +432,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;
}
@@ -442,7 +442,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;
}
@@ -452,7 +452,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;
}
@@ -462,7 +462,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;
}
@@ -472,7 +472,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;
}
@@ -483,9 +483,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_VCPKYBRD_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
vp_desc.descriptor = g_usbd_desc_buffer;
return &vp_desc;
}
@@ -495,9 +495,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_VCPKYBRD_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
vp_desc.descriptor = g_usbd_desc_buffer;
return &vp_desc;
}
@@ -507,7 +507,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;
@@ -518,9 +518,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_VCPKYBRD_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
vp_desc.descriptor = g_usbd_desc_buffer;
return &vp_desc;
}
@@ -530,9 +530,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_VCPKYBRD_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
vp_desc.descriptor = g_usbd_desc_buffer;
return &vp_desc;
}

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file cdc_keyboard_desc.h
* @version v2.0.6
* @date 2021-12-31
* @version v2.0.7
* @date 2022-02-11
* @brief usb cdc and keyboard descriptor header file
**************************************************************************
* Copyright notice & Disclaimer
@@ -50,67 +50,42 @@ extern "C" {
/**
* @brief usb bcd number define
*/
#define BCD_NUM 0x0110
#define VCPKYBRD_BCD_NUM 0x0110
/**
* @brief usb vendor id and product id define
*/
#define USBD_VENDOR_ID 0x2E3C
#define USBD_PRODUCT_ID 0x5750
#define USBD_VCPKYBRD_VENDOR_ID 0x2E3C
#define USBD_VCPKYBRD_PRODUCT_ID 0x5750
/**
* @brief usb bcd number define
*/
#define HID_BCD_NUM 0x0110
/**
* @brief usb hid class descriptor define
*/
#define HID_CLASS_DESC_HID 0x21
#define HID_CLASS_DESC_REPORT 0x22
#define HID_CLASS_DESC_PHYSICAL 0x23
/**
* @brief usb descriptor size define
*/
#define USBD_CONFIG_DESC_SIZE 108
#define USBD_HID_SIZ_REPORT_DESC 63
#define USBD_SIZ_STRING_LANGID 4
#define USBD_SIZ_STRING_SERIAL 0x1A
#define USBD_VCPKYBRD_CONFIG_DESC_SIZE 108
#define USBD_VCPKYBRD_HID_SIZ_REPORT_DESC 63
#define USBD_VCPKYBRD_SIZ_STRING_LANGID 4
#define USBD_VCPKYBRD_SIZ_STRING_SERIAL 0x1A
/**
* @brief usb string define(vendor, product configuration, interface)
*/
#define USBD_DESC_MANUFACTURER_STRING "Artery"
#define USBD_DESC_PRODUCT_STRING "AT32 Composite VCP and Keyboard"
#define USBD_DESC_CONFIGURATION_STRING "Composite VCP and Keyboard Config"
#define USBD_DESC_INTERFACE_STRING "Composite VCP and Keyboard Interface"
#define USBD_VCPKYBRD_DESC_MANUFACTURER_STRING "Artery"
#define USBD_VCPKYBRD_DESC_PRODUCT_STRING "AT32 Composite VCP and Keyboard"
#define USBD_VCPKYBRD_DESC_CONFIGURATION_STRING "Composite VCP and Keyboard Config"
#define USBD_VCPKYBRD_DESC_INTERFACE_STRING "Composite VCP and Keyboard Interface"
/**
* @brief usb endpoint interval define
*/
#define HID_BINTERVAL_TIME 0x0A
/**
* @brief usb cdc class descriptor define
*/
#define USBD_CDC_CS_INTERFACE 0x24
#define USBD_CDC_CS_ENDPOINT 0x25
/**
* @brief usb cdc 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 VCPKYBRD_HID_BINTERVAL_TIME 0x0A
/**
* @brief usb interface define
*/
#define CDC_INTERFACE 0x00
#define CDC_DATA_INTERFACE 0x01
#define HID_KEYBOARD_INTERFACE 0x02
#define VCPKYBRD_CDC_INTERFACE 0x00
#define VCPKYBRD_CDC_DATA_INTERFACE 0x01
#define VCPKYBRD_KEYBOARD_INTERFACE 0x02
/**
* @brief usb mcu id address deine
@@ -122,13 +97,11 @@ extern "C" {
/**
* @}
*/
extern uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN];
extern uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE];
extern uint8_t g_usbd_hid_report[USBD_HID_SIZ_REPORT_DESC];
extern uint8_t g_hid_usb_desc[9];
extern uint8_t g_usbd_vcpkybrd_hid_report[USBD_VCPKYBRD_HID_SIZ_REPORT_DESC];
extern uint8_t g_vcpkybrd_hid_usb_desc[9];
extern usbd_desc_handler cdc_keyboard_desc_handler;
/**
* @}
*/