P.O.S.
Joined: 19 Nov 2006 Posts: 1 Location: Gliwice, POLAND
|
USB descriptor - only first interface working |
Posted: Wed Nov 22, 2006 8:26 pm |
|
|
Hello,
I work on CCS USB development kit board, ICD-U40, PCW 3.241
I am trying to write a code similar to examples supplied with CCS USB demo kit. HID data port + mouse + keyboard in one device as 3 interfaces (using 5 endpoints 3IN/2OUT)
here's my descriptor code:
Code: |
const char USB_CLASS_SPECIFIC_DESC[] = {
//hid report descriptor for interface 0 (HID data port)
0x06, 0, 255, // Usage Page = Vendor Defined
0x09, 1, // Usage = IO device
0xa1, 1, // Collection = Application
0x19, 1, // Usage minimum
0x29, 8, // Usage maximum
0x15, 0x80, // Logical minimum (-128)
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
0x75, 8, // Report size = 8 (bits)
0x95, 2, // Report count = 16 bits (2 bytes)
0x91, 2, // Output (Data, Var, Abs)
0xc0, // End Collection ==31
//hid report descriptor for interface 1 (mouse)
0x05, 0x01, // usage page (generic desktop) ==32,33
0x09, 0x02, // usage (mouse)
0xA1, 0x01, // collection (application) This collection encompasses the report format
0x09, 0x01, // usage (pointer) Choose the key code usage page
0xA1, 0x00, // collection (physical) Physical collection
0x05, 0x09, // usage page (buttons) Choose the “button” usage page
0x19, 0x01, // usage minimum
0x29, 0x03, // usage maximum
0x15, 0x00, // logical minimum
0x25, 0x01, // logical maximum
0x95, 0x03, // report count
0x75, 0x01, // report size
0x81, 0x02, // input (data, variable, absolute)
0x95, 0x01, // report count
0x75, 0x05, // report size
0x81, 0x01, // input (constant) Bit stuff to fill byte
0x05, 0x01, // usage page (generic desktop)
0x09, 0x30, // usage (X)
0x09, 0x31, // usage (Y)
0x09, 0x38 // usage (wheel)
0x15, 0x81, // logical minimum (-127)
0x25, 0x7F, // logical maximum (127)
0x75, 0x08, // report size
0x95, 0x03, // report count
0x81, 0x06, // input (data, variable, absolute)
0xC0, // end collection End physical collection
0xC0, // end collection End application collection // ==83
//hid report descriptor for interface 2 (keyboard)
0x05, 0x01, //usage page (generic desktop) //==84,85
0x09, 0x06, //usage (keyboard)
0xA1, 0x01, //collection (application)
0x05, 0x07, //usage page (key codes)
0x19, 0xE0, //usage min (224)
0x29, 0xE7, //usage max (231)
0x15, 0x00, //logical min
0x25, 0x01, //logical max
0x75, 0x01, //report size
0x95, 0x08, //report count
0x81, 0x02, //input (data, variable, absolute) [modifier byte]
0x75, 0x08, //report size
0x95, 0x01, //report count
0x81, 0x01, //input (constant) [reserved byte]
0x05, 0x08, //usage page (page# for leds)
0x19, 0x01, //usage min
0x29, 0x05, //usage max
0x75, 0x01, //report size
0x95, 0x05, //report count
0x91, 0x02, //output (data, var, abs) [led report]
0x75, 0x03, //report size
0x95, 0x01, //report count
0x91, 0x01, //output (constant) [led report padding]
0x05, 0x07, //usage page (key codes)
0x19, 0x00, //usage min (0)
0x29, 0x65, //usage max (101)
0x75, 0x08, //report size (8)
0x95, 0x05, //report count (5)
0x15, 0x00, //logical min (0)
0x25, 0x65, //logical max (101)
0x81, 0x00, //input (data, array) //
0xC0 //end collection //==145
};
const int16 USB_CLASS_SPECIFIC_DESC_LOOKUP[USB_NUM_CONFIGURATIONS][3] =
{
//config 1
//interface 0
0,
//interface 1
32,
//interface 2
84
};
const int16 USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[USB_NUM_CONFIGURATIONS][3] =
{
//config 1
//interface 0
32,
//interface 1
52,
//interface 2
63
};
#DEFINE USB_TOTAL_CONFIG_LEN 98
const char USB_CONFIG_DESC[] = {
//IN ORDER TO COMPLY WITH WINDOWS HOSTS, THE ORDER OF THIS ARRAY MUST BE:
// config(s)
// interface(s)
// class(es)
// endpoint(s)
//config_descriptor for config index 1
USB_DESC_CONFIG_LEN, //length of descriptor size ==1
USB_DESC_CONFIG_TYPE, //constant CONFIGURATION (CONFIGURATION 0x02) ==2
USB_TOTAL_CONFIG_LEN,0, //size of all data returned for this config ==3,4 |
1, //number of interfaces this device supports ==5 Code: |
0x01, //identifier for this configuration. (IF we had more than one configurations) ==6
0x02, //index of string descriptor for this configuration ==7
0xC0, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 unused and bit7=1 ==8
0x32, //maximum bus power required (maximum milliamperes/2) (0x32 = 100mA)
//interface descriptor 1
USB_DESC_INTERFACE_LEN, //length of descriptor =10
USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04) =11
0x00, //number defining this interface (IF we had more than one interface) ==12
0x00, //alternate setting ==13
2, //number of endpoins, except 0 (pic167xx has 3, but we dont have to use all). ==14
0x03, //class code, 03 = HID ==15
0x00, //subclass code //boot ==16
0x00, //protocol code ==17
0x03, //index of string descriptor for interface ==18
//class descriptor 1 (HID)
USB_DESC_CLASS_LEN, //length of descriptor ==19
USB_DESC_CLASS_TYPE, //dscriptor type (0x21 == HID) ==20
0x00,0x01, //hid class release number (1.0) (try 1.10) ==21,22
0x00, //localized country code (0 = none) ==23 |
0x02, //number of hid class descrptors that follow (2) ==24 Code: |
0x22, //report descriptor type (0x22 == HID) ==25
USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[0][0], 0x00, //length of report descriptor ==26,27
//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor ==28
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==29
0x81, //endpoint number and direction (0x81 = EP1 IN) ==30
0x03, //transfer type supported (0x03 is interrupt) ==31
USB_EP1_TX_SIZE,0x00, //maximum packet size supported ==32,33
250, //polling interval, in ms. (cant be smaller than 10) ==34
//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor ==35
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==36
0x01, //endpoint number and direction (0x01 = EP1 OUT) ==37
0x03, //transfer type supported (0x03 is interrupt) ==38
USB_EP1_RX_SIZE,0x00, //maximum packet size supported ==39,40
10, //polling interval, in ms. (cant be smaller than 10) ==41
//interface descriptor 2 (MOUSE)
USB_DESC_INTERFACE_LEN, //length of descriptor =42
USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04) =43
0x01, //number defining this interface (IF we had more than one interface) ==44
0x00, //alternate setting ==45
1, //number of endpoints for this interface //46
0x03, //class code, 03 = HID ==47
0x01, //subclass code //boot ==48
0x02, //protocol code (mouse) ==49
0x04, //index of string descriptor for interface ==50
//class descriptor 2 (HID)
USB_DESC_CLASS_LEN, //length of descriptor ==51
USB_DESC_CLASS_TYPE, //dscriptor type (0x21 == HID) ==52
0x00,0x01, //hid class release number (1.0) (try 1.10) ==53,54
0x00, //localized country code (0 = none) ==55 |
0x01, //number of hid class descrptors that follow (1) ==56 Code: |
0x22, //report descriptor type (0x22 == HID) ==57
USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[0][1], 0x00, //length of report descriptor ==58,59
//endpoint descriptor 2
USB_DESC_ENDPOINT_LEN, //length of descriptor ==60
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==61
0x82, //endpoint number and direction (0x81 = EP1 IN) ==62
USB_ENDPOINT_TYPE_INTERRUPT, //transfer type supported (0x03 is interrupt) ==63
USB_EP2_TX_SIZE,0x00, //maximum packet size supported ==64,65
10, //polling interval, in ms. (cant be smaller than 10 for slow speed devices) ==66
//interface descriptor 3 (KEYBOARD)
USB_DESC_INTERFACE_LEN, //length of descriptor =67
USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04) =35
0x02, //number defining this interface (IF we had more than one interface) ==36
0x00, //alternate setting ==37
2, //number of endpoints for this interface //38
0x03, //class code, 03 = HID ==39
0x01, //subclass code //boot ==40
0x01, //protocol code (keyboard) ==41
0x05, //index of string descriptor for interface ==75
//class descriptor 3 (HID)
USB_DESC_CLASS_LEN, //length of descriptor ==76
USB_DESC_CLASS_TYPE, //dscriptor type (0x21 == HID)
0x00,0x01, //hid class release number (1.0) (try 1.10)
0x00, //localized country code (0 = none)
[color=blue][b] 0x01, //number of hid class descrptors that follow (1)[/b][/color]
0x22, //report descriptor type (0x22 == HID)
USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[0][2], 0x00, //length of report descriptor
//endpoint descriptor 3 IN
USB_DESC_ENDPOINT_LEN, //length of descriptor ==52
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==53
0x83, //endpoint number and direction (0x81 = EP1 IN) ==54
USB_ENDPOINT_TYPE_INTERRUPT, //transfer type supported (0x03 is interrupt) ==55
USB_EP3_TX_SIZE,0x00, //maximum packet size supported ==56,57
10, //polling interval, in ms. (cant be smaller than 10 for slow speed devices) ==58
//endpoint descriptor 3 OUT
USB_DESC_ENDPOINT_LEN, //length of descriptor ==52
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==53
0x03, //endpoint number and direction (0x81 = EP1 IN) ==54
USB_ENDPOINT_TYPE_INTERRUPT, //transfer type supported (0x03 is interrupt) ==55
USB_EP3_RX_SIZE,0x00, //maximum packet size supported ==56,57
10 //polling interval, in ms. (cant be smaller than 10 for slow speed devices) ==98
};
#define USB_NUM_HID_INTERFACES 3
#define USB_MAX_NUM_INTERFACES 3
const char USB_NUM_INTERFACES[USB_NUM_CONFIGURATIONS]={3};
const int16 USB_CLASS_DESCRIPTORS[USB_NUM_CONFIGURATIONS][3][1]=
{
//config 1
//interface 0
//class 1
18,
//interface 1
//class 1
50,
//interface 1
//class 1
75
};
const char USB_DEVICE_DESC[USB_DESC_DEVICE_LEN] ={
//starts of with device configuration. only one possible
USB_DESC_DEVICE_LEN, //the length of this report ==1
0x01, //the constant DEVICE (DEVICE 0x01) ==2
0x10,0x01, //usb version in bcd (pic167xx is 1.1) ==3,4
0x00, //class code ==5
0x00, //subclass code ==6
0x00, //protocol code ==7
USB_MAX_EP0_PACKET_LENGTH, //max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8) ==8
0x61,0x04, //vendor id (0x04D8 is Microchip, or is it 0x0461 ??)
0x20,0x00, //product id ==11,12
0x00,0x01, //device release number ==13,14
0x01, //index of string description of manufacturer ==15
0x02, //index of string descriptor of the product ==16
0x00, //index of string descriptor of serial number ==17
USB_NUM_CONFIGURATIONS //number of possible configurations ==18
};
char USB_STRING_DESC_OFFSET[]={0,4,10,28,52,62};
char const USB_STRING_DESC[]={
//string 0
4, //length of string index
USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
0x09,0x04, //Microsoft Defined for US-English
//string 1
...and there goes the rest of strings
|
When i change the number of interfaces that the device support (highlited with RED) to 3, the device stops sending data on any endpoint. when I change it to 1, the first interface is working correctly.
Could You please tell me what are the blue lines in class descriptors (number of HID class descriptors that follow)? I've read the HID class definition PDF but it didn't clear my doubts much.
Or maybe I made some other error?
Thanks for any replies! ![Smile](images/smiles/icon_smile.gif) |
|