Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I implement a device with multiple classes #85

Closed
arkap opened this issue Mar 15, 2022 · 5 comments
Closed

How do I implement a device with multiple classes #85

arkap opened this issue Mar 15, 2022 · 5 comments

Comments

@arkap
Copy link

arkap commented Mar 15, 2022

I'm struggling to understand how one would create a UsbDevice which announces itself as two devices. In my case I would like it to both be a serial port and a MIDI device. From the descriptions it seems I would have to create only one UsbDevice but How can I tell that device that it has multiple classes?

@Disasm
Copy link
Member

Disasm commented Mar 16, 2022

Yes, you need to create one UsbDevice and multiple classes. Then you pass all the classes as an argument to UsbDevice::poll().

@arkap
Copy link
Author

arkap commented Mar 21, 2022

Thank you. I keep running into problems. This is what I've done:

  1. create a USB serial class (usbd_serial::SerialPort)
  2. create a USB MIDI class (usbd_midi::midi_device::MidiClass)
  3. create a UsbDevice

My issues are as follows: If I create the UsbDevice before the UsbClasses it does not get recognized

usb 1-1: device descriptor read/64, error -110

If I create the UsbDevice after the UsbClasses and poll like this dev.poll(&mut [serial, midi]), I get

usb 1-1: new full-speed USB device number 97 using xhci_hcd
usb 1-1: unable to read config index 0 descriptor/start: -32
usb 1-1: chopping to 0 config(s)
usb 1-1: can't read configurations, error -32

If I create the UsbDevice after the UsbClasses and poll like this dev.poll(&mut [midi]), i.e. only the MidiClass, I get

usb 1-1: new full-speed USB device number 110 using xhci_hcd
usb 1-1: config 1 has an invalid interface number: 2 but max is 1
usb 1-1: config 1 has an invalid interface number: 3 but max is 1
usb 1-1: config 1 has no interface number 0
usb 1-1: config 1 has no interface number 1
usb 1-1: New USB device found, idVendor=2222, idProduct=3333, bcdDevice= 0.10
usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1: Product: XXX
usb 1-1: Manufacturer: XXX
usb 1-1: SerialNumber: XXX
usb 1-1: 2:1 : does not exist

If I create the UsbDevice after the UsbClasses and poll only serial, I get a working USB serial connection.

It looks to me like there is something wrong with how the MidiClass handles the handshake with the USB host. Any ideas on how to narrow down the error here?

@Disasm
Copy link
Member

Disasm commented Mar 21, 2022

Try control-buffer-256 feature of usb-device, probably 128-byte buffer is too small for both serial and MIDI.
And yes, you need to create UsbDevice after UsbClasses and then pass all the classes to dev.poll.

@arkap
Copy link
Author

arkap commented Mar 22, 2022

Yes, that fixed it. Thank you! :)

@ryan-summers
Copy link
Member

It seems to me that with const-generics, or with managed, we can make the control buffer allocation simpler. I've opened #90 to track this, but it sounds like otherwise your issue has been resolved, so I'm closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants