usb_desc.h

来自「TI公司的CCS一些常用的函数库」· C头文件 代码 · 共 310 行 · 第 1/2 页

H
310
字号
      0x25, 0x7F,        // Logical maximum (127)

      0x75, 8,        // Report size = 8 (bits)
      0x95, 2,        // Report count = 16 bits (2 bytes)
      0x81, 2,        // Input (Data, Var, Abs)
      0x19, 1,        // Usage minimum
      0x29, 8,        // Usage maximum
      0x91, 2,        // Output (Data, Var, Abs)
      0xc0            // End Collection
   };

#ELSE

   //usb descriptor reports
   #DEFINE USB_NUM_CONFIGURATIONS 1
   #DEFINE USB_NUM_INTERFACES     1
   #DEFINE USB_NUM_ENDPOINTS      2          //endpoint 1 OUT, endpoint 1 IN.  endpoint 0 doesnt count here
   #DEFINE USB_NUM_CLASSES        0            //hid

   //you cant use pointers when storing constants to program memory.
   BYTE CONST USB_CONFIG_DESCRIPTORS[USB_NUM_CONFIGURATIONS]={0};//0
   BYTE CONST USB_INTERFACE_DESCRIPTORS[USB_NUM_INTERFACES]={9};//9
   BYTE CONST USB_ENDPOINT_DESCRIPTORS[USB_NUM_ENDPOINTS]={18,25};//27

   #DEFINE USB_TOTAL_CONFIG_LEN      32  //config+interface+endpoint+endpoint (2 endpoints)

   //device descriptor
   BYTE CONST USB_DEVICE_DESC[USB_DEVICE_DESC_LEN] ={
         USB_DEVICE_DESC_LEN,          //the length of this report
         0x01,                //constant DEVICE (0x01)
         0x10,0x01,           //usb version in bcd
         0x00,                //class code (if 0, interface defines class.  FF is vendor defined)
         0x00,                //subclass code
         0x00,                //protocol code
         USB_MAX_EP0_PACKET_LENGTH,   //max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8)
         0x61,0x04,           //vendor id (0x04D8 is Microchip)
         0x03,0x00,           //product id
         0x00,0x01,           //device release number
         0x01,                //index of string description of manufacturer. therefore we point to string_1 array (see below)
         0x02,                //index of string descriptor of the product
         0x00,                //index of string descriptor of serial number
         USB_NUM_CONFIGURATIONS   //number of possible configurations
   };


   //configuration descriptor
   BYTE CONST USB_CONFIG_DESC[USB_TOTAL_CONFIG_LEN] = {
   //config_descriptor for config index 1
         USB_CONFIG_DESC_LEN,     //length of descriptor size
         USB_CONFIG_DESC_KEY,         //constant CONFIGURATION (0x02)
         USB_TOTAL_CONFIG_LEN,0,  //size of all data returned for this config
         USB_NUM_INTERFACES,      //number of interfaces this device supports
         0x01,                //identifier for this configuration.  (IF we had more than one configurations)
         0x00,                //index of string descriptor for this configuration
         0xC0,                //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 reserved and bit7=1
         0x32,                //maximum bus power required (maximum milliamperes/2)  (0x32 = 100mA)

   //interface descriptor 0 alt 0
         USB_INTERFACE_DESC_LEN,  //length of descriptor
         USB_INTERFACE_DESC_KEY,      //constant INTERFACE (0x04)
         0x00,                //number defining this interface (IF we had more than one interface)
         0x00,                //alternate setting
         USB_NUM_ENDPOINTS,       //number of endpoints, except 0.
         0xFF,                //class code, FF = vendor defined
         0xFF,                //subclass code, FF = vendor
         0xFF,                //protocol code, FF = vendor
         0x00,                //index of string descriptor for interface

   //endpoint descriptor
         USB_ENDPOINT_DESC_LEN, //length of descriptor
         USB_ENDPOINT_DESC_KEY,     //constant ENDPOINT (0x05)
         0x81,              //endpoint number and direction (0x81 = EP1 IN)
         0x02,              //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt)
         0x40,0x00,         //maximum packet size supported
         0x01,              //polling interval in ms. (for interrupt transfers ONLY)

   //endpoint descriptor
         USB_ENDPOINT_DESC_LEN, //length of descriptor
         USB_ENDPOINT_DESC_KEY,     //constant ENDPOINT (0x05)
         0x01,              //endpoint number and direction (0x01 = EP1 OUT)
         0x02,              //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt)
         0x40,0x00,         //maximum packet size supported
         0x01,              //polling interval in ms. (for interrupt transfers ONLY)

  };
#ENDIF


//////////////////////////////////////////////////////////////////
///
///   start string descriptors
///   String 0 is a special language string, and must be defined.  People in U.S.A. can leave this alone.
///
///   You must define the length else get_next_string_character() will not see the string
///   Current code only supports 10 strings (0 thru 9)
///
//////////////////////////////////////////////////////////////////

#DEFINE USB_STRING_0_LEN 4
BYTE CONST USB_STRING_0[4] = {  //string index 0 is special
         USB_STRING_0_LEN, //length of string index
         0x03, //descriptor type 0x03 (STRING)
         0x09,0x04   //Microsoft Defined for US-English
};

#DEFINE USB_STRING_1_LEN 8
BYTE CONST USB_STRING_1[8] = { //we defined string index 1 earlier as manuf string
         USB_STRING_1_LEN, //length of string index
         0x03, //descriptor type 0x03 (STRING)
         'C',0,
         'C',0,
         'S',0
};

#IF USB_HID_DEVICE
   #DEFINE USB_STRING_2_LEN 26
   BYTE CONST USB_STRING_2[26] = {  //we defined string index 2 as description of prodcut
            USB_STRING_2_LEN, //length of string index
            0x03, //descriptor type 0x03 (STRING)
            'C',0,
            'C',0,
            'S',0,
            ' ',0,
            'H',0,
            'I',0,
            'D',0,
            ' ',0,
            'D',0,
            'e',0,
            'm',0,
            'o',0
   };
#else
   #DEFINE USB_STRING_2_LEN 28
   BYTE CONST USB_STRING_2[28] = {  //we defined string index 2 as description of prodcut
            USB_STRING_2_LEN, //length of string index
            0x03, //descriptor type 0x03 (STRING)
            'C',0,
            'C',0,
            'S',0,
            ' ',0,
            'B',0,
            'u',0,
            'l',0,
            'k',0,
            ' ',0,
            'D',0,
            'e',0,
            'm',0,
            'o',0
   };
#endif

#ENDIF

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?