Electronic – What are the limitations of the USB Composite device

hidusbusb deviceusb-host

I am looking at coding a USB device that is capable of encapsulating two USB devices. I would like to create a HID keyboard with a single extra USB port. A mass storage device would be connected to the port.

I was wondering, would I be able to program the keyboard to register it as a composite device encapsulating the mass storage and the keyboard?

My current thought process is to declare the keyboard as having 2 interfaces. I was thinking of simply copying the USB commands from the mass drive into one of the interfaces of the keyboard. Is this possible?

If this is incorrect thinking, please let me know what the data formatting of the interfaces is suppose to be.

Thank you.

Also, this is for educational purposes to expand my knowledge of USB.

Best Answer

You can't have a "HID keyboard" with a "single extra port"; the device of this kind must be a compound device, made of a two-port hub, with one port connected to non-removable HID device. The other port can be permanently connected to a mass-storage device. In this case you might not need to wrap all this as a composite device (a device supporting two alternative classes).

Designing correct set of descriptors for these kind of devices is awfully complicated (at least from a hardware guy perspective), but you can use ready-to-go guides from, say, Keil compiler support, MDK Middleware for USB Device and Host Communication. This link is for an example of composite USB device built upon two their previous tutorials, "USB Device HID", and "USB Device mass storage". I hope this is exactly what you need.