problem: USB HID report descriptor length - driving me nuts!

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
onocentaur
Posts: 5
Joined: Thu Feb 25, 2010 10:07 pm

problem: USB HID report descriptor length - driving me nuts!

Post by onocentaur » Thu Feb 25, 2010 10:21 pm

Hi,
I'm working on a usb game controller, based on the PS2USB v2 example project: http://vusb.wikidot.com/project:ps2usb. My coding and AVR skills are limited so I don't exactly know what I'm doing...
Anyway, first step is to modify the code to deal with only one controller - simple, just remove the 2nd pad setup and output functions, and remove half the USB HID report descriptor. Now this works, but only if I set USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH to 99 or more in usbconfig.h, despite the descriptor being only 63 long:

Code: Select all

PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { /* USB report descriptor */

    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x04,                    // USAGE (Joystick)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x09, 0x01,                    //   USAGE (Pointer)
    0xa1, 0x00,                    //   COLLECTION (Physical)
    0x85, 0x01,                    //     REPORT_ID (1)
    0x09, 0x30,                    //     USAGE (X)
    0x09, 0x31,                    //     USAGE (Y)
    0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
    0x25, 0x0f,                    //     LOGICAL_MAXIMUM (15)
    0x75, 0x04,                    //     REPORT_SIZE (4)
    0x95, 0x02,                    //     REPORT_COUNT (2)
    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
    0x09, 0x32,                    //     USAGE (Z)
    0x09, 0x33,                    //     USAGE (Rx)
    0x09, 0x34,                    //     USAGE (Ry)
    0x09, 0x35,                    //     USAGE (Rz)
    0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
    0x26, 0xff, 0x00,              //     LOGICAL_MAXIMUM (255)
    0x75, 0x08,                    //     REPORT_SIZE (8)
    0x95, 0x04,                    //     REPORT_COUNT (4)
    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
    0x05, 0x09,                    //     USAGE_PAGE (Button)
    0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
    0x29, 0x10,                    //     USAGE_MAXIMUM (Button 16)
    0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
    0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
    0x75, 0x01,                    //     REPORT_SIZE (1)
    0x95, 0x10,                    //     REPORT_COUNT (16)
    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
    0xc0,                          //     END_COLLECTION
    0xc0,                          // END_COLLECTION

};

If I set the descriptor length to 98 or less, then the usb device does not appear in /dev/input (it appears as /dev/input/js0 when set to any value 99-126 - haven't tried larger than 126).
Am I missing something obvious? Can anyone help?! Thanks!
Last edited by onocentaur on Sat Feb 27, 2010 2:39 pm, edited 1 time in total.

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: USB HID report descriptor length problem

Post by ulao » Fri Feb 26, 2010 12:05 am

I have done the same thing, my code adds pressure buttons, guitar hero support, and I ripped out the pad. I wont post it as its very large and not what you asked but few things..

here is my report

Code: Select all

const char analog_usbHidReportDescriptor[] PROGMEM = {
    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x05,                    // USAGE (Gamepad)
    0xa1, 0x01,                    // COLLECTION (Application)
   
    0x09, 0x01,                    //   USAGE (Pointer)   
   0xa1, 0x00,                    //   COLLECTION (Physical)
   0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
    0x09, 0x30,                    //     USAGE (X)
    0x09, 0x31,                    //     USAGE (Y)
   
   0x09, 0x33,                  //     USAGE (Rx)
   0x09, 0x34,                  //     USAGE (Ry)

   0x09, 0x35,                  //     USAGE (Rz)   
   0x09, 0x36,                  //     USAGE (Slider)   

    0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
    0x26, 0xFF, 0x00,              //     LOGICAL_MAXIMUM (255)
    0x75, 0x08,                    //     REPORT_SIZE (8)
    0x95, 0x06,                    //     REPORT_COUNT (6)
    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
   0xc0,                          //   END_COLLECTION (Physical)

    0x05, 0x09,                    //   USAGE_PAGE (Button)
    0x19, 0x01,                    //   USAGE_MINIMUM (Button 1)
    0x29, 0x10,                    //   USAGE_MAXIMUM (Button 14)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
    0x75, 0x01,                    //   REPORT_SIZE (1)
    0x95, 0x10,                    //   REPORT_COUNT (16)
    0x81, 0x02,                    //   INPUT (Data,Var,Abs)

    0xc0
};


I use a REPORT SIZE of 8, The way they do two reports is by using the first byte as the ID, a 1 or 0. So you need to bump down all reports..

example:

reportBuffer[1] will be reportBuffer[0]
reportBuffer[2] will be reportBuffer[1]
reportBuffer[3] will be reportBuffer[2]

etc..

onocentaur
Posts: 5
Joined: Thu Feb 25, 2010 10:07 pm

Re: USB HID report descriptor length problem

Post by onocentaur » Fri Feb 26, 2010 9:17 am

Thanks for the reply.
So you've just not used USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH when actually defining your descriptor? Interesting, I'll try that later.
What does your usbconfig.h have for USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH?

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: USB HID report descriptor length problem

Post by ulao » Fri Feb 26, 2010 4:20 pm

its 0, but I think its done that way so that it can be set in the PROGMEM array. I derived this from another project. But I would think you can set USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH to 8 if your set up is done that way.

onocentaur
Posts: 5
Joined: Thu Feb 25, 2010 10:07 pm

Re: USB HID report descriptor length problem

Post by onocentaur » Fri Feb 26, 2010 5:06 pm

Hmmm. I've no idea what I've done (I'm not sure I've changed anything at all!) but it now works with the correct descriptor length.

Thanks anyway :D

onocentaur
Posts: 5
Joined: Thu Feb 25, 2010 10:07 pm

Re: problem: USB HID report descriptor length - driving me nuts!

Post by onocentaur » Sat Feb 27, 2010 2:47 pm

Okay, so it was working. Now it's doing the same thing again!!

Here's what's happening at the moment.
When I have the following usbHidReportDescriptor in my code:

Code: Select all

PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { /* USB report descriptor */

    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x04,                    // USAGE (Joystick)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x09, 0x01,                    //   USAGE (Pointer)
    0xa1, 0x00,                    //   COLLECTION (Physical)
    0x09, 0x30,                    //     USAGE (X)
    0x09, 0x31,                    //     USAGE (Y)
    0x09, 0x33,                    //     USAGE (Rx)
    0x09, 0x34,                    //     USAGE (Ry)
    0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
    0x26, 0xff, 0x00,              //     LOGICAL_MAXIMUM (255)
    0x75, 0x08,                    //     REPORT_SIZE (8)
    0x95, 0x04,                    //     REPORT_COUNT (4)
    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
    0x05, 0x09,                    //     USAGE_PAGE (Button)
    0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
    0x29, 0x18,                    //     USAGE_MAXIMUM (Button 24)
    0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
    0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
    0x75, 0x01,                    //     REPORT_SIZE (1)
    0x95, 0x18,                    //     REPORT_COUNT (24)
    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
     0xc0,                          // END_COLLECTION
  0xc0,                          //     END_COLLECTION
   
};
with USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH defined as 47 in usbconfig.h, it works fine.

Now if I adjust the desriptor to this:

Code: Select all

PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { /* USB report descriptor */

    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x04,                    // USAGE (Joystick)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x09, 0x01,                    //   USAGE (Pointer)
    0xa1, 0x00,                    //   COLLECTION (Physical)
    0x09, 0x30,                    //     USAGE (X)
    0x09, 0x31,                    //     USAGE (Y)
    0x09, 0x33,                    //     USAGE (Rx)
    0x09, 0x34,                    //     USAGE (Ry)
    0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
    0x26, 0xff, 0x00,              //     LOGICAL_MAXIMUM (255)
    0x75, 0x08,                    //     REPORT_SIZE (8)
    0x95, 0x04,                    //     REPORT_COUNT (4)
    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
    0x05, 0x09,                    //     USAGE_PAGE (Button)
    0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
    0x29, 0x10,                    //     USAGE_MAXIMUM (Button 16)
    0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
    0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
    0x75, 0x01,                    //     REPORT_SIZE (1)
    0x95, 0x10,                    //     REPORT_COUNT (16)
    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
    0x05, 0x09,                    //     USAGE_PAGE (Button)
    0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
    0x29, 0x08,                    //     USAGE_MAXIMUM (Button 8)
    0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
    0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
    0x75, 0x01,                    //     REPORT_SIZE (1)
    0x95, 0x08,                    //     REPORT_COUNT (8)
    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
     0xc0,                          // END_COLLECTION
  0xc0,                          //     END_COLLECTION
   
};
and set USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH to 63, then despite having the same overall reportbuffer length, then it doesn't work! I've tried numerous examples of editing the report descriptor length and code and it doesn't ever work - this is the simplest way I've though of to explain it.
Bizarrely, changing the descriptor has worked at least once because I've edited the code from the original PS2USB to this... If anyone can help, I'd be very grateful, this is driving me crazy!!

UPDATE: Okay, I think I'm going insane. I just swapped the entire usbdrv subdirectory for one downloaded 'as new' from the v-usb home, and.. it worked. So, swapped back in the 'old' usbdrv to try and see wtf was going on, and.. it worked....
will post updates!

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: problem: USB HID report descriptor length - driving me nuts!

Post by ulao » Sat Feb 27, 2010 5:29 pm

Are you doing a clean before compile?

onocentaur
Posts: 5
Joined: Thu Feb 25, 2010 10:07 pm

Re: problem: USB HID report descriptor length - driving me nuts!

Post by onocentaur » Sat Feb 27, 2010 6:55 pm

Yes, always make clean first...
Okay, so having swapped out usbdrv I'm now now longer having the problem. It's more than likely I'm an idiot. I don't know what was happening but i'm glad it stopped. I sincerely hope I won't have to post again with the same issue tomorrow :oops:

chris-irs

Re: problem: USB HID report descriptor length - driving me nuts!

Post by chris-irs » Tue Nov 09, 2010 1:21 pm

Hi!
Although there has been no post for a while... I have got some similar problem with an at32uc3a microcontroller, it is doing strange things, sometimes usb works, sometimes not... do you now have some more explanations why it is now working?
Thanks a lot.
Chris

Post Reply