Page 1 of 1

joystick with mouse? [ resolved ]

Posted: Mon Jun 08, 2009 1:16 am
by ulao
So would it even be possible to make a HID work with a mouse and joystick. I want to emulate the Gemini controller. It was a atari on the top and the paddle on the bottom. Seem like a simple task but how could I out put mouse HID data with Joystick HID data in the same device?

Re: joystick with mouse?

Posted: Thu Jun 25, 2009 1:15 am
by Grendel
Two methods:

1. create an interface for each device (see viewtopic.php?f=8&t=2911)
2. define two reports in a single HID report descriptor (there should be examples of that in the reference/public projects)

Re: joystick with mouse?

Posted: Thu Jun 25, 2009 3:08 pm
by ulao
thx, looking for that.

Re: joystick with mouse?

Posted: Sun Jul 05, 2009 6:03 am
by ulao
Not finding any examples out there, and the common example on the net is missing the keyboard_mouse file. Seems I'm not the first person to realize that. but was wondering if I'm heading in the right direction.

I need the Top-Level Collection method as far as I can tell. Is it just a mater of combining two hids?

Code: Select all

    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x05,                    // USAGE (Game Pad)
    0xa1, 0x01,                    // COLLECTION (Application)
   0x85, 0x01,                // Report ID (1)
    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 (8)
    0x95, 0x02,                    //   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 (1)
    0x95, 0x08,                    // REPORT_COUNT (8)
    0x81, 0x02,                    // INPUT (Data,Var,Abs)
    0xc0,

   0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x02,                    // USAGE (Mouse)
    0xa1, 0x01,                    // COLLECTION (Application)
   0x85, 0x02,                // Report ID (1)
    0x09, 0x01,                    //   USAGE (Pointer)
    0xA1, 0x00,                    //   COLLECTION (Physical)
    0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
    0x09, 0x30,                    //     USAGE (X)
    0x09, 0x31,                    //     USAGE (Y)
    0x75, 0x08,                    //     REPORT_SIZE (8)
    0x95, 0x02,                    //     REPORT_COUNT (2)
    0x81, 0x06,                    //     INPUT (Data,Var,Rel)
    0xC0,                          //   END_COLLECTION
    0xC0,                          // END COLLECTION

};

and adjusted my report size from 3 to 5.

This seems to give me a hid mouse, but how did the os know what PID it was? Is that what the Report ID (1) is for?

Also where is the mouse data in my report, the report[0],[1],[2] are now not working did I bump them up and now I have report[0-6]?

Re: joystick with mouse?

Posted: Sun Jul 05, 2009 9:30 am
by rinku
ulao wrote:Not finding any examples out there, and the common example on the net is missing the keyboard_mouse file. Seems I'm not the first person to realize that. but was wondering if I'm heading in the right direction.

I need the Top-Level Collection method as far as I can tell. Is it just a mater of combining two hids?

Code: Select all

    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x05,                    // USAGE (Game Pad)
    0xa1, 0x01,                    // COLLECTION (Application)
   0x85, 0x01,                // Report ID (1)
    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 (8)
    0x95, 0x02,                    //   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 (1)
    0x95, 0x08,                    // REPORT_COUNT (8)
    0x81, 0x02,                    // INPUT (Data,Var,Abs)
    0xc0,

   0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x02,                    // USAGE (Mouse)
    0xa1, 0x01,                    // COLLECTION (Application)
   0x85, 0x02,                // Report ID (1)
    0x09, 0x01,                    //   USAGE (Pointer)
    0xA1, 0x00,                    //   COLLECTION (Physical)
    0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
    0x09, 0x30,                    //     USAGE (X)
    0x09, 0x31,                    //     USAGE (Y)
    0x75, 0x08,                    //     REPORT_SIZE (8)
    0x95, 0x02,                    //     REPORT_COUNT (2)
    0x81, 0x06,                    //     INPUT (Data,Var,Rel)
    0xC0,                          //   END_COLLECTION
    0xC0,                          // END COLLECTION

};

and adjusted my report size from 3 to 5.

This seems to give me a hid mouse, but how did the os know what PID it was? Is that what the Report ID (1) is for?

Also where is the mouse data in my report, the report[0],[1],[2] are now not working did I bump them up and now I have report[0-6]?


Yes, the Top level collection is one of the method for combining more than one HID's.

You need to add a extra byte of report ID in your report buffer, for example in your Gamepad Descriptor, the total size of the report is 3 bytes and the Report ID is set to 1, so your report would be 4 bytes and should look like:
[ReportID=0x01] [X value] [Y value] [bitmapped button value]
From the Report ID the host will know this data is comming from the Gamepad.

Similarly for your mouse Descriptor, you have only two bytes of buffer for X-Y displacement, and the Report ID is two, so you need 3 bytes of report for that, as bellow:
[ReportID=0x02] [X value] [Y value]

Also I think your Device descriptor is not correct, I think that usage of buttons and pointing device shoud be in same Physical Collection, but you have terminated the Physical Collection before the button usage, also your pointing INPUt data should contain "Input (Data, Variable, Relative)" i.e for X & Y value. Im not sure about these... may be you would like to check..

Re: joystick with mouse?

Posted: Sun Jul 05, 2009 6:06 pm
by ulao
rinku, thx so much, I believe I understand the report size now.

BTW I needed two usbSetInterrupt calls..but seems I cant get it to work right.. This example only moves the mouse and the game pad is skipped.


Code: Select all

            if (curGamepad->report_size == 7 ) // should only be the case for atari
            {
               reportBuffer[0] = 0x02;// copy in mouse data. used only for atari paddles
               reportBuffer[1] = reportBuffer[4];
               reportBuffer[2] = reportBuffer[5];
               usbSetInterrupt(reportBuffer, curGamepad->report_size);//for mouse
            }


Does something need to be done in between the two usbSetInterrupt's

Re: joystick with mouse?

Posted: Sun Jul 05, 2009 8:34 pm
by ulao
accidental post..

Re: joystick with mouse?

Posted: Sun Jul 05, 2009 10:24 pm
by ulao
rinku, thx so much, I believe I understand the report size now.

BTW I needed two usbSetInterrupt calls.. You may have known this but for any future viewers..

Code: Select all

   if(must_report)
      {
         if (usbInterruptIsReady() && mouseGamePad==0)
         {    
            must_report = 0;
            if (curGamepad->report_size == 7 ) mouseGamePad=1;//change to mouse report
            curGamepad->buildReport(reportBuffer);
            usbSetInterrupt(reportBuffer, curGamepad->report_size);
         }
      }
      if(must_report)
      {
         if (usbInterruptIsReady() && mouseGamePad==1)
         {    
            mouseGamePad=0;
            curGamepad->buildReport(reportBuffer);
            reportBuffer[0] = 0x02;// copy in mouse data. used only for atari paddles
            reportBuffer[1] = reportBuffer[4];
            reportBuffer[2] = reportBuffer[5];
            usbSetInterrupt(reportBuffer, curGamepad->report_size);
         }
      }