/*---------------------------------------------------------------------*/
/* --- STC MCU Limited ------------------------------------------------*/
/* --- STC 1T Series MCU Demo Programme -------------------------------*/
/* --- Mobile: (86)13922805190 ----------------------------------------*/
/* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
/* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
/* --- Web: www.STCAI.com ---------------------------------------------*/
/* --- BBS: www.STCAIMCU.com  -----------------------------------------*/
/* --- QQ:  800003751 -------------------------------------------------*/
/* 如果要在程序中使用此代码,请在程序中注明使用了STC的资料及程序        */
/*---------------------------------------------------------------------*/

#include "stc.h"
#include "usb_desc.h"

char code DEVICEDESC[18] =
{
    0x12,                   //bLength(18);
    0x01,                   //bDescriptorType(Device);
    0x00,0x02,              //bcdUSB(2.00);
	
    0xEF,                   //bDeviceClass(2:Communication Device Class);
    0x02,                   //bDeviceSubClass0);
    0x01,                   //bDeviceProtocol(0);
//    0x00,                   //bDeviceClass(2:Communication Device Class);
//    0x00,                   //bDeviceSubClass0);
//    0x00,                   //bDeviceProtocol(0);
//	
    0x40,                   //bMaxPacketSize0(64);
    0xbf,0x34,              //idVendor(34bf);
    0x0f,0xff,              //idProduct(ff02);
    0x00,0x01,              //bcdDevice(1.00);
    0x01,                   //iManufacturer(1);
    0x02,                   //iProduct(2);
    0x00,                   //iSerialNumber(0);
    0x01,                   //bNumConfigurations(1);
};
//const uint8_t Mouse_ConfigDescriptor[Mouse_SIZ_CONFIG_DESC] =
//{
//  配置描述符   //Configuration Descriptor 只能有1个

//  /*功能1 HID键盘*/
//  IAD描述符    //复合设备才有 在单接口的设备这个可以不要
//		  接口1描述符   //Interface Descriptor
//		  类描述符    //Class Desdriptor
//		  端点描述符  //Endpoint Descriptor
//  
//  /*功能2 虚拟串口*/  
//  IAD描述符    //复合设备才有 在单接口的设备这个可以不要
//		  接口3描述符   //Interface Descriptor
//		  类描述符    //Class Desdriptor
//		  端点描述符  //Endpoint Descriptor

//  /*如果有多个接口 下面还可以继续添加*/
//  ...
//}


char code CONFIGDESC[changdu] =
{
    0x09,                   //bLength(9);
    0x02,                   //bDescriptorType(Configuration);
    changdu,0x00,              //wTotalLength(67);
    0x03,                   //bNumInterfaces(4);
    0x01,                   //bConfigurationValue(1);
    0x00,                   //iConfiguration(0);
    0x80,                   //bmAttributes(BUSPower);
    0x32,                   //MaxPower(100mA);

/*************************************功能1 HID键盘**************************************/
	/*IAD描述符*/
	0x08,   //bLength：IAD描述符大小 
	0x0B,   //bDescriptorType：IAD描述符类型
	0x00,   //bFirstInterface：功能1 HID键盘的第一个接口描述符是在总的配置描述符中的第几个从0开始数
	0x01,   //bInferfaceCount：功能1 HID键盘有1个接口描述符
//	0x00,   //bFunctionClass：同单HID功能时，设备符中的bDeviceClass	
	0X03,
	
	0x00,   //bFunctionSubClass：同单HID功能时，设备符中的bDeviceSubClass
	0x00,   //bFunctionProtocol：同单HID功能时，设备符中的bDeviceProtocol
	0x01,   //iFunction：字符串描述中关于此设备的索引(个人理解是一个字符串描述符中有比如0~5是功能1的字符串，
			//6~10是功能2的字符串,如果是功能2的话，此值为6)
	
	/*******************第一个接口描述符*********************/
	    0x09,                   //bLength(9);
		0x04,                   //bDescriptorType(Interface);
		0x00,                   //bInterfaceNumber(0);
		0x00,                   //bAlternateSetting(0);
		0x02,                   //bNumEndpoints(2);
		0x03,                   //bInterfaceClass(HID);
		0x01,                   //bInterfaceSubClass(Boot);
		0x01,                   //bInterfaceProtocol(Keyboard);
		0x00,                   //iInterface(0);
	/******************HID描述符************************/
		0x09,                   //bLength(9);
		0x21,                   //bDescriptorType(HID);
		0x10,0x01,              //bcdHID(1.01);
//		0x00,                   //bCountryCode(0);
		0X21,
		0x01,                   //bNumDescriptors(1);
		0x22,                   //bDescriptorType(HID Report);
		0x41,0x00,              //wDescriptorLength(65);
	/**********************输入端点描述符***********************/
		0x07,                   //bLength(7);
		0x05,                   //bDescriptorType(Endpoint);
		0x81,                   //bEndpointAddress(EndPoint1 as IN);
		0x03,                   //bmAttributes(Interrupt);
		0x08,0x00,              //wMaxPacketSize(8);
		0x0a,                   //bInterval(10ms);
	/**********************输出端点描述符***********************/
		0x07,                   //bLength(7);
		0x05,                   //bDescriptorType(Endpoint);
		0x01,                   //bEndpointAddress(EndPoint1 as OUT);
		0x03,                   //bmAttributes(Interrupt);
		0x01,0x00,              //wMaxPacketSize(1);
		0x0a,                   //bInterval(10ms);

/*************************************功能2 cdc**************************************/
	/*IAD描述符 66*/
	/* Interface Association Descriptor(IAD Descriptor)  */ 
	0x08,   /*  bLength  */
	0x0B,   /*  bDescriptorType*/
	0x01,   /*  bFirstInterface*/
//	0x01,   /*  bInterfaceCount*/
	0x02,   /*  bInterfaceCount*/
	
	0x02,   /*  bFunctionClass --CDC*/
//	0x00,   /*  bFunctionSubClass*/
//	0x00,   /*  bFunctionProtocoll*/
	0x02,   /*  bFunctionSubClass*/
	0x01,   /*  bFunctionProtocoll*/
	
	0x00,   /*  iFunction */  
	
	/*******************第一个接口描述符*********************/
		0x09,                   //bLength(9);
		0x04,                   //bDescriptorType(Interface);
		0x01,                   //bInterfaceNumber(0);
		0x00,                   //bAlternateSetting(0);
		
		0x01,                   //bNumEndpoints(1);
		0x02,                   //bInterfaceClass(Communication Interface Class);
		0x02,                   //bInterfaceSubClass(Abstract Control Model);
		0x01,                   //bInterfaceProtocol(Common AT commands);
		0x00,                   //iInterface(0);

		0x05,                   //bLength(5);
		0x24,                   //bDescriptorType(CS_INTERFACE);
		0x00,                   //bDescriptorSubtype(Header Functional Descriptor);
		0x10,0x01,              //bcdCDC(1.10);

		0x05,                   //bLength(5);
		0x24,                   //bDescriptorType(CS_INTERFACE);
		0x01,                   //bDescriptorSubtype(Call Management Functional Descriptor);
		0x00,                   //bmCapabilities(Device does not handles call management itself);
		0x01,                   //bDataInterface(1);

		0x04,                   //bLength(4);
		0x24,                   //bDescriptorType(CS_INTERFACE);
		0x02,                   //bDescriptorSubtype(Abstract Control Management Functional Descriptor);
		0x02,                   //bmCapabilities(Set/Get_Line_Coding,Serial_State,Set_Control_Line_State);

		0x05,                   //bLength(5);
		0x24,                   //bDescriptorType(CS_INTERFACE);
		0x06,                   //bDescriptorSubtype(Union Functional descriptor);
		0x00,                   //bMasterInterface(0);
		0x01,                   //bSlaveInterface0(1);

		0x07,                   //bLength(7);
		0x05,                   //bDescriptorType(Endpoint);
		0x82,                   //bEndpointAddress(EndPoint2 as IN);
		0x03,                   //bmAttributes(Interrupt);
		0x40,0x00,              //wMaxPacketSize(64);
		0xff,                   //bInterval(255ms);

		0x09,                   //bLength(9);
		0x04,                   //bDescriptorType(Interface);
		0x02,                   //bInterfaceNumber(1);
		0x00,                   //bAlternateSetting(0);
		0x02,                   //bNumEndpoints(2);
		0x0a,                   //bInterfaceClass(Data Interface Class);
		0x00,                   //bInterfaceSubClass(AData Interface Class SubClass Codes);
		0x00,                   //bInterfaceProtocol(USB SPEC);
		0x00,                   //iInterface(0);

	/**********************输入端点描述符***********************/
		0x07,                   //bLength(7);
		0x05,                   //bDescriptorType(Endpoint);
		0x83,                   //bEndpointAddress(EndPoint1 as IN);
		0x02,                   //bmAttributes(Bulk);
		0x40,0x00,              //wMaxPacketSize(64);
		0x00,                   //bInterval(Ignored);
	/**********************输出端点描述符***********************/
		0x07,                   //bLength(7);
		0x05,                   //bDescriptorType(Endpoint);
		0x03,                   //bEndpointAddress(EndPoint1 as OUT);
		0x02,                   //bmAttributes(Bulk);
		0x40,0x00,              //wMaxPacketSize(64);
		0x00,                   //bInterval(Ignored);
};
























char code HIDREPORTDESC[65] =
{
    0x05,0x01,              //USAGE_PAGE(Generic Desktop);
    0x09,0x06,              //USAGE(Keyboard);
    0xa1,0x01,              //COLLECTION(Application);
    0x05,0x07,              //  USAGE_PAGE(Keyboard);
    0x19,0xe0,              //  USAGE_MINIMUM(224);
    0x29,0xe7,              //  USAGE_MAXIMUM(255);
    0x15,0x00,              //  LOGICAL_MINIMUM(0);
    0x25,0x01,              //  LOGICAL_MAXIMUM(1);
    0x75,0x01,              //  REPORT_SIZE(1);
    0x95,0x08,              //  REPORT_COUNT(8);
    0x81,0x02,              //  INPUT(Data,Variable,Absolute);
    
    0x75,0x08,              //  REPORT_SIZE(8);
    0x95,0x01,              //  REPORT_COUNT(1);
    0x81,0x01,              //  INPUT(Constant);
    
    0x19,0x00,              //  USAGE_MINIMUM(0);
    0x29,0x65,              //  USAGE_MAXIMUM(101);
    0x15,0x00,              //  LOGICAL_MINIMUM(0);
    0x25,0x65,              //  LOGICAL_MAXIMUM(101);
    0x75,0x08,              //  REPORT_SIZE(8);
    0x95,0x06,              //  REPORT_COUNT(6);
    0x81,0x00,              //  INPUT(Data,Array);
    
    0x05,0x08,              //  USAGE_PAGE(LEDs);
    0x19,0x01,              //  USAGE_MINIMUM(1);
    0x29,0x03,              //  USAGE_MAXIMUM(3);
    0x15,0x00,              //  LOGICAL_MINIMUM(0);
    0x25,0x01,              //  LOGICAL_MAXIMUM(1);
    0x75,0x01,              //  REPORT_SIZE(1);
    0x95,0x03,              //  REPORT_COUNT(3);
    0x91,0x02,              //  OUTPUT(Data,Variable,Absolute);
    
    0x75,0x05,              //  REPORT_SIZE(5);
    0x95,0x01,              //  REPORT_COUNT(1);
    0x91,0x01,              //  OUTPUT(Constant);
    
    0xc0,                   //END_COLLECTION;
};

char code LANGIDDESC[4] =
{
    0x04,0x03,
    0x09,0x04,
};

char code MANUFACTDESC[8] =
{
    0x08,0x03,
    'S',0,
    'T',0,
    'C',0,
};

char code PRODUCTDESC[30] =
{
    0x1e,0x03,
    'S',0,
    'T',0,
    'C',0,
    ' ',0,
    'U',0,
    'S',0,
    'B',0,
    ' ',0,
    'S',0,
    'e',0,
    'r',0,
    'i',0,
    'a',0,
    'l',0,
};

char code PACKET0[2] = 
{
    0, 0,
};

char code PACKET1[2] = 
{
    1, 0,
};
