How to handle multiple reports correctly?

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
z0ttel
Posts: 11
Joined: Thu Dec 27, 2007 3:21 pm

How to handle multiple reports correctly?

Post by z0ttel » Mon Feb 08, 2010 11:34 pm

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!

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: How to handle multiple reports correctly?

Post by christian » Sun Feb 28, 2010 6:36 pm

The report-ID must also be the first byte of the report data. The reports sizes all increase by one byte.

z0ttel
Posts: 11
Joined: Thu Dec 27, 2007 3:21 pm

Re: How to handle multiple reports correctly?

Post by z0ttel » Sun Feb 28, 2010 6:59 pm

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?

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: How to handle multiple reports correctly?

Post by christian » Sun Feb 28, 2010 7:03 pm

Sorry, have not checked your code... I think it should work, but only a test can give you a definitive answer.

Post Reply