📄 cdc_usb_config.c
字号:
#include "usb.h"
#include "uart.h"
#define USB_VENDOR_ID 0x0425u
#define USB_PRODUCT_ID 0x050eu
#define USB_DEVICE_REL_NUM 0x0003
hcc_u8 string_descriptor0[4] = {4, 0x3, 0x09, 0x04 };
hcc_u8 str_manufacturer[26] = {
26, 0x3, 'C',0, 'M',0, 'X',0,
' ',0, 'S',0, 'y',0, 's',0,
't',0, 'e',0, 'm',0, 's',0,
' ',0
};
hcc_u8 str_config[44] = {
44, 0x3, 'D',0, 'e',0, 'f',0,
'a',0, 'u',0, 'l',0, 't',0,
' ',0, 'c',0, 'o',0, 'n',0,
'f',0, 'i',0, 'g',0, 'u',0,
'r',0, 'a',0, 't',0, 'i',0,
'o',0, 'n',0
};
hcc_u8 str_interface[8] = {
8, 0x3, 'C',0, 'D',0, 'C',0
};
hcc_u8 str_serail_number[10] = {
10, 0x3, 'V',0, '0',0, '.',0,
'1',0
};
hcc_u8 str_product[18] = {
18,0x03,'C',0,'T',0,'P',0,
' ',0,'S',0,'U',0,'D',0,
'A',0
};
hcc_u8 * const usb_string_descriptors[USB_NO_OF_STRING_DESC] = {
string_descriptor0,
str_manufacturer,
str_product,
str_serail_number,
str_config,
str_interface
};
hcc_u8 usb_device_descriptor[] = {
USB_FILL_DEV_DESC(0x0200, 0, 0, 0, EP0_PACKET_SIZE, USB_VENDOR_ID, USB_PRODUCT_ID
, USB_DEVICE_REL_NUM, 1, 2, 3, 1)
};
#define USB_FILL_HDR_FUNCT_DESCR(cdc_ver)\
0x5, 0x24, 0x0, (hcc_u8)(cdc_ver), (hcc_u8)((cdc_ver)>>8)
#define USB_FILL_CALL_MGM_FUNCT_DESCR(capability, dataifc)\
0x5, 0x24, 0x1, (hcc_u8)(capability), (hcc_u8)(dataifc)
#define USB_FILL_ACM_FUNCT_DESCR(capability)\
0x4, 0x24, 0x2, (hcc_u8)(capability)
#define USB_FILL_UNION_FUNCT_DESCR(master_ifc, no_of_slaves)\
0x4+(no_of_slaves), 0x24, 0x6, (hcc_u8)(master_ifc)
hcc_u8 usb_config_descriptor[] = {
USB_FILL_CFG_DESC(9+9+7+7, 1, 1, 4, CFGD_ATTR_BUS_PWR, 0x32),
USB_FILL_IFC_DESC(0, 0, 2, 0xff, 0x02, 0xFF, 5),
USB_FILL_EP_DESC(0x2, EPD_DIR_TX, EPD_ATTR_BULK, EP2_PACKET_SIZE, 0x0),
USB_FILL_EP_DESC(0x3, EPD_DIR_RX, EPD_ATTR_BULK, EP3_PACKET_SIZE, 0x0),
};
void *get_device_descriptor(void)
{
return(usb_device_descriptor);
}
hcc_u8 is_cfgd_index(hcc_u16 cndx)
{
return((hcc_u8)(cndx == 1 ? 1 : 0));
}
void *get_cfg_descriptor(hcc_u8 cndx)
{
return(cndx ? usb_config_descriptor : usb_config_descriptor);
}
hcc_u8 is_str_index(hcc_u8 sndx)
{
return((hcc_u8)(sndx < (sizeof(usb_string_descriptors)/sizeof(usb_string_descriptors[0]))? 1 : 0));
}
void *get_str_descriptor(hcc_u8 sndx)
{
return(usb_string_descriptors[sndx]);
}
hcc_u8 is_ifc_ndx(hcc_u8 c, hcc_u8 i, hcc_u8 is)
{
if (c==1 && is == 0)
{
if (i==0 || i==1)
{
return(1);
}
}
return(0);
}
hcc_u8 is_ep_ndx(hcc_u8 c, hcc_u8 i, hcc_u8 is, hcc_u8 ep)
{
if (c==1 && is==0)
{
if (i==0 && ep < 1)
{
return(1);
}
if (i==1 && ep < 2)
{
return(1);
}
}
return(0);
}
void * get_ep_descriptor(hcc_u8 c, hcc_u8 i, hcc_u8 is, hcc_u8 ep)
{
hcc_u8 a;
a = i;
if (ep==0)
{
return(&usb_config_descriptor[9+9]);
}
else
{
return(&usb_config_descriptor[9+9+7]);
}
return((void *)(c + is ? 0 : 0));
}
hcc_u8 buf_ep00[EP0_PACKET_SIZE];
hcc_u8 buf_ep01[EP0_PACKET_SIZE];
hcc_u8 buf_ep20[EP2_PACKET_SIZE];
hcc_u8 buf_ep21[EP2_PACKET_SIZE];
hcc_u8 buf_ep30[EP3_PACKET_SIZE];
hcc_u8 buf_ep31[EP3_PACKET_SIZE];
void *get_ep_rx_buffer(hcc_u8 ep, hcc_u8 buf)
{
switch(ep)
{
case 0:
if (!buf)
{
return(buf_ep00);
}
else
{
return(buf_ep01);
}
break;
case 2:
if (!buf)
{
return(buf_ep20);
}
else
{
return(buf_ep21);
}
break;
case 3:
if (!buf)
{
return(buf_ep30);
}
else
{
return(buf_ep31);
}
break;
}
return(0);
}
/****************************** END OF FILE **********************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -