Page 1 of 1

How to handle multiple reports correctly?

Posted: Mon Feb 08, 2010 11:34 pm
by z0ttel
Hi all,

it's me with a stupid question again :roll:

I was wondering how to handle a HID descriptor with multiple report ids correctly? For example, if I had a device with a HID descriptor containing two reports (report id(1) and report id(2)), would it be sufficient to modify the function "usbFunctionSetup" delivered with the HID-mouse-example in this way?

Code: Select all

static uint32_t UsbReport_t_1;    /* Data for report id(1) */
static uint32_t UsbReport_t_2;    /* Data for report id(2) */

usbMsgLen_t usbFunctionSetup(uchar data[8])
{
    usbRequest_t    *rq = (void *)data;
    uchar           localReportId;
    uchar           localSize;

    /* The following requests are never used. But since they are required by
     * the specification, we implement them in this example.
     */
    if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){    /* class request type */
        if(rq->bRequest == USBRQ_HID_GET_REPORT){  /* wValue: ReportType (highbyte), ReportID (lowbyte) */

            /* Get current Report ID */
            localReportId = rq->wValue.bytes[0];

            /* Determine which report to send */
            switch (localReportId) {

                case 0x01:  usbMsgPtr = (void *)&UsbReport_t_1;
                            localSize = sizeof(UsbReport_t_1);
                            break;
                case 0x02:  usbMsgPtr = (void *)&UsbReport_t_2;
                            localSize = sizeof(UsbReport_t_2);
                            break;
            }
            return localSize;
        }else if(rq->bRequest == USBRQ_HID_GET_IDLE){
            usbMsgPtr = &idleRate;
            return 1;
        }else if(rq->bRequest == USBRQ_HID_SET_IDLE){
            idleRate = rq->wValue.bytes[1];
        }
    }else{
        /* no vendor specific requests implemented */
    }
    return 0;   /* default for not implemented requests: return no data back to host */



Would that work or would I have to do something else/additional?

Thanks in advance for any comments!

Re: How to handle multiple reports correctly?

Posted: Sun Feb 28, 2010 6:36 pm
by christian
The report-ID must also be the first byte of the report data. The reports sizes all increase by one byte.

Re: How to handle multiple reports correctly?

Posted: Sun Feb 28, 2010 6:59 pm
by z0ttel
christian wrote:The report-ID must also be the first byte of the report data. The reports sizes all increase by one byte.


Hello Christian,

thanks for your answer. I already had that in mind. So it should work with the posted code or are there any other modifications neccessary?

Re: How to handle multiple reports correctly?

Posted: Sun Feb 28, 2010 7:03 pm
by christian
Sorry, have not checked your code... I think it should work, but only a test can give you a definitive answer.