USB OTG: Possible to perform emulation of slave device on master with drivers recognized

raspberry pislaveusb

I'm not exactly sure if this should be under a separate StackExchange topic altogether (programming maybe?), if it is, please move it and sorry for the inconvenience.

I'm planning to build a device using either a Raspberry Pi A or Radxa board with the aim of emulating a slave device (unified keyboard and mouse) via commands sent by the board (possibly by a slave device to the board? or a network protocol). As I understand from the specifications of the two boards, there are USB OTG ports that allow for acting as a slave device, however from my knowledge, USB OTG only allows a fixed set of functions as a slave device. Is it possible to make the specific USB port I wish to perform emulation from slave-only considering it is an OTG port? Also, how do I handle driver recognition in this case? Where is the firmware embedded for USB OTG?

Best Answer

Ok, so you need a device with at least 2 USB ports. One of these must be a slave port which you will connect to a host PC and the other port must be a host which you will connect a keyboard/mouse/whatever. Your device will then enumerate and handle the slave device(s) on its host port, process any information and/or events from these devices, and then forward this data out of its slave port up to the host PC. So to answer your question simply: yes this is possible.

But, I don't think its going to be possible with either of the boards you're looking at. The one half would be fairly straightforward. These boards would be quite happy using one of their USB ports to talk to your keyboard/mouse device(s). The problem comes about when you want to use them to emulate a particular type of slave device to your host PC. These kind of boards are typically configured to provide a very limited selection of USB profiles to choose from when connecting them to a PC (such as a mass-storage device, serial port emulation, camera or possibly some kind of debugging interface) and you'd find it quite difficult to change this to look like something else - in your case a HID device like a keyboard and/or mouse. I'm not saying its impossible, but I don't know enough about these boards and its not obvious from their simple overviews that they support this.

This is the kind of application where you will probably need to work at a lower level - more directly with the firmware on a suitable microcontroller or microprocessor.

If I were to try to pull something like this off, I'd be inclined to set up a pair of microcontrollers back-to-back. One of them is the USB OTG host to your keyboard/mouse, the other one acts as a keyboard/mouse compound device to your host PC, and they're connected to each other using SPI.