7

I'm developing an application that will communicate with attached USB HID device. The problem is that there is no real device yet (it is under development by another part of our team), so, I'd really like to have some way to emulate it.

The ideal utility which I can think of should look like this: a kernel module, that, when loaded, creates two device nodes in the system:

  • a virtual usb-hid device, which is indistinguishable from any real usb-hid device node, probably /dev/hidraw0; and of course this device should be seen by whatever usb-hid libraries I'd use, for example, hidapi.
  • a service device node, like /dev/virtual_hid_1.

So, when anyone writes to /dev/virtual_hid_1, this data should be literally read from /dev/hidraw0, and vice versa.

This way, I can write some debug app in any language I want, be it python or whatever; it should merely write and read to and from /dev/virtual_hid_1. It would be very convenient for development.

Is there something like this?

5
  1. You might be interested in an inexpensive, elegant and open hardware solution for emulating usb devices in development: The micropython board. (I have no affilation with this hardware).

    It is a small standalone board that runs python 3, and plugs into the usb where it can appear as, for example, a mouse HID, or keyboard HID. You just copy your python source file to the device and it runs it. A beautiful concept.

    Ok, it is not really meant for what you want, and you may need to download the sdk and do a bit of work in C to have it appear exactly as you need, but the bulk of your code would be in python. There are ttl level serial ports, i2c, spi etc ports.

  2. For an alternative solution, there is a board that emulates usb devices with python but I'm not sure if you can buy a finished product.

  3. There is also usb emulation using usbip with no extra hardware, which I haven't looked at yet.

3

You're probably looking for uhid kernel module. See documentation in kernel sources:

With UHID, a user-space transport driver can create kernel hid-devices for each device connected to the user-space controlled bus. The UHID API defines the I/O events provided from the kernel to user-space and vice versa.

There is an example user-space application in ./samples/uhid/uhid-example.c

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.