hidapi vs libusb for Linux

Asked by At

Writing some C code for USB mouse.

More specifically writing configuration and information to mouse like poll, sensitivity, button actions, colors (light), tactile alters, OLED etc.

Started out with this old article where libhid is recommended over libusb.

Looking at libhid it seems to since have died. Last commit on that project is from 2012, - and it is C++. But I found some links saying one should go over to hidapi.

However, hidapi also seems to be fairly dead. Last commit from 2016. Or perhaps it is simply stable?

It could look like one is better off using libusb after all. Starting out with a 15 year old article - it is not that much of a stretch.

Question is if I am missing something? Is libusb the way to go?

Have done some quick tests with libusb-1.0.0-dev

#include <libusb-1.0/libusb.h>

and it works nice - at least for the quick tests I have done. But a HID library would perhaps be better?

From native package options I have at least:



libusb-0.1-4                 libusbmuxd4
libusb-1.0-0                 libusbmuxd-dev
libusb-1.0-0-dev             libusbmuxd-tools
libusb-1.0-doc               libusb-ocaml
libusbauth-configparser1     libusb-ocaml-dev
libusbauth-configparser-dev  libusbprog0v5
libusb-dev                   libusbprog-dev
libusbguard0                 libusbredirhost1
libusbhid-common             libusbredirhost-dev
libusb-java                  libusbredirparser1
libusb-java-dbg              libusbredirparser-dev
libusb-java-doc              libusbtc08-1
libusb-java-lib              libusbtc08-dev

1 Answers

Tezlastorme On Best Solutions

libusb recommend using hidapi for USB HID devices. hidapi can use a different backend depending on the OS, e.g. hid.dll in Windows, either hidraw or libusb in Linux, so it's using native USB drivers.

Be aware though that hidapi doesn't give you the same level of control over the packets you send. It's higher level than libusb and some of the parameters that it uses for requests are fixed (e.g. bRequest value).

hidapi is also not currently maintained, if that is a concern to you.

Personally I'd say use hidapi if it works fine for your project, but if the device's protocol doesn't follow the HID standard then you'll run into trouble and will probably need the control that libusb gives you.