USBPassThru icon indicating copy to clipboard operation
USBPassThru copied to clipboard

Example for passthrough of a composite device?

Open Deckoz2302 opened this issue 4 years ago • 1 comments

Have a composite device here, Mouse report ID 0, Keyboard 1(with several other reports) Below an example of the HID report descriptor

HID Descriptor Page 1 HID Descriptor Page 2

How would you initialize a composite device? Like this?

HIDBoot < USB_HID_PROTOCOL_KEYBOARD | USB_HID_PROTOCOL_MOUSE > HidComposite(&Usb);
HIDBoot<USB_HID_PROTOCOL_KEYBOARD>    HidKeyboard(&Usb);  // Is this needed with composite init above??
HIDBoot<USB_HID_PROTOCOL_MOUSE>    HidMouse(&Usb); // Is this needed with composite init above?

KbdRptParser KbdPrs;
MouseRptParser MousePrs;

void setup()
{
  Serial.begin( 115200 );
  uint8_t attempts = 30;
  while (!Serial && attempts--) {
    delay(100); // Wait for serial port to connect for up to 3 seconds
  }
  Serial.println("Start");

  if (Usb.Init() == -1) {
    Serial.println("USB host shield did not start.");
  }
  delay( 200 );

  HidComposite.SetReportParser(1, &KbdPrs);
  HidComposite.SetReportParser(0, &MousePrs);
  HidKeyboard.SetReportParser(1, &KbdPrs);  // needed if using HidComposite?
  HidMouse.SetReportParser(0, &MousePrs);  // needed if using HidComposite?

  // begin both? or should I used another library for composites?
  Keyboard.begin(); 
  Mouse.begin();
}

Deckoz2302 avatar Oct 04 '20 19:10 Deckoz2302

As you asked for an initialization routine but didn't describe a problem maybe my approach helps you − or maybe is of interest for other readers:

When I used the USBMsePassThru.ino example it worked for a single mouse but failed with the trackpoint in my USB Keyboard (ThinkPad Lenovo KU-1255). I disabled the HID().SendReport() because it was wrongly wired and clickend randomly for this device. Then I analyzed the bytes coming from the "correct standard mouse" and from the trackpoint. The Trackpoint has one static bye in the beginning, so all following bytes had to be shifted:

    if (len == 6) {
      uint8_t mouseRpt[4];
      mouseRpt[0] = buf[1];
      mouseRpt[1] = buf[2];
      mouseRpt[2] = buf[3];
      mouseRpt[3] = buf[4];

With that the pass through worked correctly. Both the first and last value had no meaning for this device.

When scrolling horizontally a 3 byte block with a leading 16 + scroll value + static 0 was sent which I don't want to forward, this is why I added the hardcoded length check.

manuel-91 avatar Feb 01 '21 21:02 manuel-91