My USB device has one HID Class interface.
I have currently defined in my report descriptor 2 devices: a mouse (report ID == 1) and a keyboard (report ID == 2).
I have set the HID polling period to 100ms.
In order to let the host know I'm sending keyboard or mouse data, I must precede said data with the report ID, as in:
//Mouse data for the host
0x01 //report ID for mouse
0x0n //buttons
0xnn //delta X
0xnn //delta y
So, I'm facing a situation where I can only update the host about one of these devices at a time.
My question is: is there a way to send both reports (mouse and keyboard) simultaneously?
If not, do you think doubling the polling frequency and alternating between both devices would be an adequate solution?
Two different reports are always reported sequentially, as they both use the same interrupt pipe to get through.
Now if you dont require to use Boot protocol keyboard and mouse reports, you may design a custom report descriptor which describes a single report with both mouse and keyboard data included. This way, you'll be able to send both the datasets synchronously.
Having a lower polling interval will be easier, though.
Example report descriptor:
0x05, 0x01, // UsagePage (desktop)
0x09, 0x06, // Usage (Keyboard)
0xa1, 0x01, // Collection (Application)
0x85, 0x01, // ReportID (1)
0x25, 0x01, // LogicalMaximum (1)
0x75, 0x01, // ReportSize (1)
0x95, 0x08, // ReportCount (8)
0x05, 0x07, // UsagePage (keyboard)
0x19, 0xe0, // UsageMinimum (LeftControl)
0x29, 0xe7, // UsageMaximum (RightGui)
0x81, 0x02, // Input (Variable)
0x26, 0xdd, 0x00, // LogicalMaximum (221)
0x75, 0x08, // ReportSize (8)
0x95, 0x06, // ReportCount (6)
0x19, 0x00, // UsageMinimum (NoEvent)
0x29, 0xdd, // UsageMaximum (KeypadHexadecimal)
0x81, 0x00, // Input
0x25, 0x01, // LogicalMaximum (1)
0x75, 0x01, // ReportSize (1)
0x95, 0x03, // ReportCount (3)
0x05, 0x08, // UsagePage (led)
0x19, 0x01, // UsageMinimum (NumLock)
0x29, 0x03, // UsageMaximum (ScrollLock)
0x91, 0x02, // Output (Variable)
0x15, 0x81, // LogicalMinimum (-127)
0x25, 0x7f, // LogicalMaximum (127)
0x75, 0x08, // ReportSize (8)
0x95, 0x02, // ReportCount (2)
0x05, 0x01, // UsagePage (desktop)
0x09, 0x30, // Usage (X)
0x09, 0x31, // Usage (Y)
0x81, 0x04, // Input (Relative)
0x15, 0x00, // LogicalMinimum (0)
0x25, 0x01, // LogicalMaximum (1)
0x75, 0x01, // ReportSize (1)
0x95, 0x03, // ReportCount (3)
0x05, 0x09, // UsagePage (button)
0x19, 0x01, // UsageMinimum (Button(1))
0x29, 0x03, // UsageMaximum (Button(3))
0x81, 0x02, // Input (Variable)
0xc0, // EndCollection
This describes:
an Input report #1 containing:
Data Byte : [0 ][1 .. 6][7 ][8 ][9 ]
Data : [Modifiers][Keys ][Mouse dx][Mouse dy][Mouse Btns]
an Output report #1 containing:
Data Byte : [0 ]
Data : [Kbd leds]