Page 1 of 1

usbHidReportDescriptor type of confilct

Posted: Mon Oct 20, 2014 5:10 pm
by xiao
The HID device has 5 bytes of report defined to host,
ie. 0xA, 0xB, 0xC, 0xD, 0x1
the last byte always 0x1

Code: Select all

static void buildReport(void)
{

   reportBuffer[0] = adcvalue1>>8;
   reportBuffer[1] = adcvalue1;
   reportBuffer[2] = adcvalue2>>8;
   reportBuffer[3] = adcvalue2;
   reportBuffer[4] = 0x01;

}



but actually and usb bus logging has been seen with pattern like this, 5 bytes and 6 bytes are constantly swapping.
0xA, 0xB, 0xC, 0xD, 0x1
0x0, 0xA, 0xB, 0xC, 0xD, 0x1

(this is actual screen capture, no picture could be posted here.)

usbdrv is 20120109, compiling is ok and working as aforementioned. we want to swtich to usbdrv 20121206 in order to see if this usbdrv and different version related. however, the same code is not be able to compile and given error message of type of usbHidReportDescriptor of conflict.

gcc avr 4.3.3 (winavr 20100110)

error is following,

Code: Select all

main.c:58: error: conflicting types for 'usbDescriptorHidReport'
usbdrv/usbdrv.h:477: error: previous declaration of 'usbDescriptorHidReport' was here
main.c: In function 'timerPoll':
main.c:140: warning: unused variable 'timerCnt'
make: *** [main.o] Error 1

please help.

Re: usbHidReportDescriptor type of confilct

Posted: Mon Oct 20, 2014 10:08 pm
by blargg
Compare the two indicated lines and look for a discrepancy in the types, e.g. uchar in one, char in the other, const in one, no const in the other, PROGMEM in one, no PROGMEM in the other.

Re: usbHidReportDescriptor type of confilct

Posted: Tue Oct 21, 2014 4:42 pm
by xiao
blargg wrote:Compare the two indicated lines and look for a discrepancy in the types, e.g. uchar in one, char in the other, const in one, no const in the other, PROGMEM in one, no PROGMEM in the other.


can you please help what to do, because the usbdrv are so different.

USBDRV_VERSION 20120109, compile OK

Code: Select all

extern
#if !(USB_CFG_DESCR_PROPS_HID_REPORT & USB_PROP_IS_RAM)
PROGMEM
#endif
char usbDescriptorHidReport[];


USBDRV_VERSION 20121206, compile NG

Code: Select all

extern
#if !(USB_CFG_DESCR_PROPS_HID_REPORT & USB_PROP_IS_RAM)
PROGMEM const
#endif
char usbDescriptorHidReport[];



the C code

Code: Select all

/* ------------------------------------------------------------------------- */
/* USB report descriptor */
PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = {
    0x05, 0x01,        // USAGE_PAGE (Generic Desktop = 01)
   0x09, 0x05,        // USAGE (Game Pad = 05)
   0xa1, 0x01,        // COLLECTION (Application)
   0x09, 0x01,        //   USAGE (Pointer)
   0xa1, 0x00,        //   COLLECTION (Physical)
   0x09, 0x30,        //     USAGE (X)
   0x09, 0x31,        //     USAGE (Y)
   0x15, 0x00,        //   LOGICAL_MINIMUM (0)
   0x26, 0xff, 0x00,  //     LOGICAL_MAXIMUM (255)
   0x75, 0x08,        //   REPORT_SIZE (8bits)
   0x95, 0x04,        //   REPORT_COUNT (2)
   0x81, 0x02,        //   INPUT (Data,Var,Abs)
   0xc0,              // END_COLLECTION
   
   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 (1bit)
   0x95, 0x08,        // REPORT_COUNT (8)
   0x81, 0x02,        // INPUT (Data,Var,Abs)
   0xc0               // END_COLLECTION
};

Re: usbHidReportDescriptor type of confilct

Posted: Wed Oct 22, 2014 5:01 am
by ulao
usbHidReportDescriptor needs to be
PROGMEM const char usbHidReportDescriptor
or
const ROGMEM char usbHidReportDescriptor
I forget the order that is required and I'm sure that wont be the only error you encounter. I believe i had 50 some lines to fix. Its actually the IDE that is giving you the grief.

Re: usbHidReportDescriptor type of confilct

Posted: Wed Oct 22, 2014 5:30 am
by xiao
ulao wrote:usbHidReportDescriptor needs to be
PROGMEM const char usbHidReportDescriptor
or
const ROGMEM char usbHidReportDescriptor
I forget the order that is required and I'm sure that wont be the only error you encounter. I believe i had 50 some lines to fix. Its actually the IDE that is giving you the grief.



thanks anyway.

we used the command line with avr-gcc only with makefile, seems the usbdrv.h has changed all define with the latest release, still no success on compilation.

another thing, as we want to increase the report size from 5 bytes to 8 byte, what else to do with tweaking ? assign more bytes to the report buffer, seems not feasible.

code as below,

Code: Select all

//2014-10-20, orignal buffer size, test ok, except one extra byte 0x0 from device ???
//static uchar    reportBuffer[5];    /* buffer for HID reports, type game controller*/
//2014-10-22, adjust buffer size, want to send more bytes on report, not working
static uchar    reportBuffer[8];    /* buffer for HID reports, type game controller*/


Code: Select all

   //2014-10-20, test for usb bus logging
   reportBuffer[0] = 500 / 0x100; // quotient = 0x01 (500 = 0x01f4, form 2 bytes, 0x01, 0xf4)
   reportBuffer[1] = 500 % 0x100; // remainder = 0xf4
   reportBuffer[2] = 1000 / 0x100; // 1000 = 0x03e8
   reportBuffer[3] = 1000 % 0x100;
   reportBuffer[4] = 0x01;
   //2014-10-22, adjust buffer size, want to send more bytes on report, not working
   reportBuffer[5] = 0xa;
   reportBuffer[6] = 0xa;
   reportBuffer[7] = 0xa;

Re: usbHidReportDescriptor type of confilct

Posted: Wed Oct 22, 2014 7:35 am
by blargg
Looks like you were probably just missing 'const'. Often const-correctness is only later done correctly in a library, requiring addition of const in some user code as in this case. So ulao's suggestion seems to be what you need to follow to get it compiling.

As for a larger report, you need to update the descriptor to specify the larger report, and any code which assumed the previous size (hopefully it just uses sizeof reportBuffer). You originally posted about a problem with the smalller report and compiling a newer version to see if that fixes it. I suggest you get that working before trying to expand the report.

Re: usbHidReportDescriptor type of confilct

Posted: Wed Oct 22, 2014 1:37 pm
by xiao
blargg wrote:Looks like you were probably just missing 'const'. Often const-correctness is only later done correctly in a library, requiring addition of const in some user code as in this case. So ulao's suggestion seems to be what you need to follow to get it compiling.

As for a larger report, you need to update the descriptor to specify the larger report, and any code which assumed the previous size (hopefully it just uses sizeof reportBuffer). You originally posted about a problem with the smalller report and compiling a newer version to see if that fixes it. I suggest you get that working before trying to expand the report.


thanks. compiling with switching to latest usbdrv is done and works.

The increased report size has not functioning properly. usb bus logging is seeing this error, reset..etc

Code: Select all

  23                                   ok                                                      197.2.0        
  23.1                                 RESET                                                   199.1.0       
  23.1                                 USTS   c0000012                  babble detected        200.1.0       
  23                                   RESET                                                   201.1.0       
  23.1                                 USTS   c0000030                  endpoint halted        202.1.0       
  23                                   ok                                                      201.2.0   

Re: usbHidReportDescriptor type of confilct

Posted: Wed Oct 22, 2014 5:12 pm
by ulao
another thing, as we want to increase the report size from 5 bytes to 8 byte, what else to do with tweaking ? assign more bytes to the report buffer, seems not feasibl
This seems a bit unclear. You don't set the size the report does? If you want to send more then the report needs, yes you need to add padding to the report.

Re: usbHidReportDescriptor type of confilct

Posted: Thu Oct 23, 2014 5:09 am
by xiao
ulao wrote:
another thing, as we want to increase the report size from 5 bytes to 8 byte, what else to do with tweaking ? assign more bytes to the report buffer, seems not feasibl
This seems a bit unclear. You don't set the size the report does? If you want to send more then the report needs, yes you need to add padding to the report.



thanks for update, let us rephrase the query,

original code of 5 bytes of report, compile ok, hid device running, ok

Code: Select all

static uchar    reportBuffer[5];    /* buffer for HID reports, type game controller*/
   reportBuffer[0] = 500 / 0x100; // quotient = 0x01 (500 = 0x01f4, form 2 bytes, 0x01, 0xf4)
   reportBuffer[1] = 500 % 0x100; // remainder = 0xf4
   reportBuffer[2] = 1000 / 0x100; // 1000 = 0x03e8
   reportBuffer[3] = 1000 % 0x100;
   reportBuffer[4] = 0x01;



attempted to upward adjust our report to be 8 bytes as padding 3 more dummy bytes for testing, compile ok, hid device recognized by PC, but the running has error of halt, not even a single bytes of report. we therefore might omitted something or, do not thoroughly understand how to modified the code to fit the purpose.

Code: Select all

static uchar    reportBuffer[8];    /* buffer for HID reports, type game controller*/
   reportBuffer[0] = 500 / 0x100; // quotient = 0x01 (500 = 0x01f4, form 2 bytes, 0x01, 0xf4)
   reportBuffer[1] = 500 % 0x100; // remainder = 0xf4
   reportBuffer[2] = 1000 / 0x100; // 1000 = 0x03e8
   reportBuffer[3] = 1000 % 0x100;
   reportBuffer[4] = 0x01;
   reportBuffer[5] = 0xa;
   reportBuffer[6] = 0xa;
   reportBuffer[7] = 0xa;



the code of report size, please help to advise how would be adjusted as there are more than one report_size appeared to be. thanks.

Code: Select all

PROGMEM const char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = {    
    0x05, 0x01,        // USAGE_PAGE (Generic Desktop = 01)
   0x09, 0x05,        // USAGE (Game Pad = 05)
   0xa1, 0x01,        // COLLECTION (Application)
   0x09, 0x01,        //   USAGE (Pointer)
   0xa1, 0x00,        //   COLLECTION (Physical)
   0x09, 0x30,        //     USAGE (X)
   0x09, 0x31,        //     USAGE (Y)
   0x15, 0x00,        //   LOGICAL_MINIMUM (0)
   0x26, 0xff, 0x00,  //     LOGICAL_MAXIMUM (255)
   0x75, 0x08,        //   REPORT_SIZE (8bits)
   0x95, 0x04,        //   REPORT_COUNT (2)
   0x81, 0x02,        //   INPUT (Data,Var,Abs)
   0xc0,              // END_COLLECTION
   
   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 (1bit)
   0x95, 0x08,        // REPORT_COUNT (8)
   0x81, 0x02,        // INPUT (Data,Var,Abs)
   0xc0               // END_COLLECTION
};

Re: usbHidReportDescriptor type of confilct

Posted: Fri Oct 24, 2014 5:56 pm
by ulao
I'm really confused by your report here and what you are expecting?

Your descriptor shows it needs 10 bytes( 2 analogs and 8 buttons), BTW buttons are normally done with one report ( 8 bits: a bit mask), I'm guessing you know that.
EDIT!!!
0x95, 0x04, // REPORT_COUNT (2) <--- ahhh... see never do this, always adjust the comments!!! Your thew me off a bit there but i'll leave what I wrote not seeing this.
EDIT!!!

reportBuffer[0] = x ( 0 to ff )
reportBuffer[1] = y ( 0 to ff )
reportBuffer[2] button 1 (0 or 1)
reportBuffer[3] button 2 (0 or 1)
reportBuffer[4] button 3 (0 or 1)
reportBuffer[5] button 4 (0 or 1)
reportBuffer[6] button 5 (0 or 1)
reportBuffer[7] button 6 (0 or 1)
reportBuffer[8] button 7 (0 or 1)
reportBuffer[9] button 8 (0 or 1)

So yes your fist code will work as its 5 bytes long, and it just doubles that equaling 10. The second code is 7 bytes and that is not dividable by 10 so it stops reporting.

It looks like you are trying to stuff 4 bytes to X and Y of the report? ( my thinking before I saw your comment typeo)
reportBuffer[0] = 500 / 0x100; // quotient = 0x01 (500 = 0x01f4, form 2 bytes, 0x01, 0xf4)
reportBuffer[1] = 500 % 0x100; // remainder = 0xf4
reportBuffer[2] = 1000 / 0x100; // 1000 = 0x03e8
reportBuffer[3] = 1000 % 0x100;

report 2 and 3 are only 1 bit in length, so clearly you are going about this with a misunderstanding. Explain the data sizes you are trying to pass in. If you need to pass in more then 255 for X or Y then your report needs to be split up.


If my guess is right you want this?
reportBuffer[0] = Little Endian of X
reportBuffer[1] = Big Endian of X
reportBuffer[2] = Little Endian of Y
reportBuffer[3] = Bittle Endian of Y
reportBuffer[4] = buttons (0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80)
reportBuffer[5] = padding.
reportBuffer[6] = padding.
reportBuffer[7] = padding.

If so try this ( check your Endianess)

Code: Select all

    PROGMEM const char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = {    
        0x05, 0x01,        // USAGE_PAGE (Generic Desktop = 01)
       0x09, 0x05,        // USAGE (Game Pad = 05)
       0xa1, 0x01,        // COLLECTION (Application)
       0x09, 0x01,        //   USAGE (Pointer)
       0xa1, 0x00,        //   COLLECTION (Physical)
       0x09, 0x30,        //     USAGE (X)
       0x09, 0x30,        //     USAGE (X)
       0x09, 0x30,        //     USAGE (Y)
       0x09, 0x30,        //     USAGE (Y)
       0x15, 0x00,        //   LOGICAL_MINIMUM (0)
       0x26, 0xff, 0x00,  //     LOGICAL_MAXIMUM (255)
       0x75, 0x08,        //   REPORT_SIZE (8bits)
       0x95, 0x04,        //   REPORT_COUNT (4)
       0x81, 0x02,        //   INPUT (Data,Var,Abs)
       0xc0,              // END_COLLECTION
       
       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, 0x08,        // REPORT_SIZE (8)
       0x95, 0x01,        // REPORT_COUNT (1)
       0x81, 0x02,        // INPUT (Data,Var,Abs)
       0xc0               // END_COLLECTION
    };


also depending on the supplication this is not always allowed.
0x09, 0x30, // USAGE (X)
0x09, 0x30, // USAGE (X)
0x09, 0x30, // USAGE (Y)
0x09, 0x30, // USAGE (Y)
try this if the above gives you troubles.
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (X)
0x09, 0x32, // USAGE (Y)
0x09, 0x33, // USAGE (Y)

Re: usbHidReportDescriptor type of confilct

Posted: Fri Oct 24, 2014 10:17 pm
by blargg
ulao, hah, a day or so ago when I was looking at the report posted here, I was thinking to myself "those comments could easily differ from the actual values. The comments are in such a structured format, surely someone has made some macros that could allow entry directly in that form, to avoid chance of inconsitency."

Re: usbHidReportDescriptor type of confilct

Posted: Mon Oct 27, 2014 4:04 am
by ulao
So did it all work out then?

I think this makes descriptors and comments as well. http://hidedit.org/

Re: usbHidReportDescriptor type of confilct

Posted: Mon Oct 27, 2014 7:49 am
by xiao
thanks

we have work out the 8 bytes report and HID device is working as expected in Windows.

Because of the device is constantly sending data to USB host upon power up, the own application has intent to receive those raw bytes at purpose. With PC host, there is no any side effect so far (Win7 / Win8/ Win XP), but with android phone, once the device is plugged in with OTG cable, it will triggers those android phone icon in randomly selection, perhaps the result of this "game pad" descriptor and the original design.

Due to a clone of existing project (win32) and aims to port for android platform, this result is not anticipated. we would like to change this device descriptor from game pad to some sort of other, what could be better if there is only few bytes of raw data to host ?

Re: usbHidReportDescriptor type of confilct

Posted: Mon Oct 27, 2014 2:30 pm
by ulao
Sorry not clear why you need to change the device but consider.
0x09, 0x05, // USAGE (Game Pad = 05)
0x09, 0x04, // USAGE (Joy Stick= 04)