13

I'm asking this because I haven't found anything clear about this subject after searching for days. So, I'm sorry if the question already exists.

I'm working in a project, just for fun, where I want to control the PC mouse from the Raspberry Pi. The user input would be done by any kind of hardware connected to the RP, my main doubt is about how to control to send the movement instructions to the PC from the RP through USB.

I know that I have to enable the OTG mode in order to make the PC recognize it as a usb device, but I have no idea about how to send the mouse movements to the PC through the USB and make Windows / Linux understand it. I found that "Linux-USB Gadget API Framework" exists, but there is no example about using it, and I don't actually know if it is the best approach.

Could you please give me some clues or resources to help me?

Thank you very much.

1 Answers1

7

Try using g_hid module mentioned by @goldilocks:

  1. Add a line dtoverlay=dwc2 to your config.txt and reboot
  2. Insert the driver driver with modprobe g_hid
  3. Run hid_gadget_test /dev/hidg0 keyboard. You may need to build the program first, using the sample code provided here.

Another, more flexible way to achieve that you want (without writing custom drivers) is to use gadgetfs. I know at least one project which turned a small ARM computer into USB/Bluetooth keyboard/mouse/gamepad using this approach.

Unfortunately, the status of gadgetfs on Rapsberry Pi is uncertain. This thread suggests it doesn't work, but it's unclear what the author tried to do exactly. I'd suggest to try it nevertheless:

  1. Add a line dtoverlay=dwc2 to your config.txt and reboot
  2. Insert the gadget FS driver with modprobe gadgetfs
  3. Mount the userspace filesystem with mkdir /dev/gadget; mount -t gadgetfs none /dev/gadget/

If you get no errors at this point, you'll be able to use gadgetfs libraries like this one to program your custom USB devices.

Dmitry Grigoryev
  • 28,277
  • 6
  • 54
  • 147