Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hidapi vs libusb for Linux

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:

libhidapi-dev      
libhidapi-libusb0  
libhidrd0-dbg      
libhidapi-hidraw0  
libhidrd0          
libhidrd0-dev

And

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
like image 525
user3342816 Avatar asked Dec 24 '22 00:12

user3342816


1 Answers

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.

Update: As of June 4th 2019, hidapi was moved to libusb/hidapi and is now being actively maintained again.

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.

like image 149
Haystack Avatar answered Dec 25 '22 12:12

Haystack