You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As discussed in #61 , it may make sense to create a new libusb backend to remove some limitations of the native HID APIs under Windows. The users will need to use WinUSB driver to replace the native HID driver in order to make use of this (if using libusb HID backend, then the limitation still applies).
I am not so sure if there is any benefit to extend this to macOS, but it can be done as well with the latest kernel driver detaching function of libusb under macOS.
I choose to use usbdk backend so that I do not need to replace the HID driver with WinUSB. And it may be able to find more devices like USB keyboard and mouse if they are present.
modified files and Windows 64bit binaries are included in the following zip file. hidapi_libusb.zip
C:\work\hid\hidapi\libusb [master ≡ +7 ~1 -0 !]> .\hidtest-libusb.exe
hidapi test/example tool. Compiled with hidapi version 0.11.0, runtime version 0.10.1.
Compile-time version is different than runtime version of hidapi.
]nDevice Found
type: 046d c534
path: 0001:0008:00
serial_number: (null)
Manufacturer: Logitech
Product: USB Receiver
Release: 2901
Interface: 0
Usage (page): 0x0 (0x0)
Device Found
type: 046d c534
path: 0001:0008:01
serial_number: (null)
Manufacturer: Logitech
Product: USB Receiver
Release: 2901
Interface: 1
Usage (page): 0x0 (0x0)
Device Found
type: 047f c056
path: 0001:001d:03
serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3
Manufacturer: Plantronics
Product: Plantronics Blackwire 3220 Series
Release: 210
Interface: 3
Usage (page): 0x0 (0x0)
Device Found
type: 04d8 003f
path: 0001:001c:00
serial_number: (null)
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: 0
Usage (page): 0x0 (0x0)
Manufacturer String: Microchip Technology Inc.
Product String: Simple HID Device Demo
Serial Number String: (1033)
Indexed String 1: Microchip Technology Inc.
Unable to send a feature report.
Unable to get a feature report.
(null)Unable to write()
Error: (null)
Unable to write() (2)
waiting...
waiting...
waiting...
waiting...
C:\work\hid\hidapi\libusb [master ≡ +7 ~1 -0 !]> .\hidtest-libusb.exe
hidapi test/example tool. Compiled with hidapi version 0.11.0, runtime version 0.10.1.
Compile-time version is different than runtime version of hidapi.
]nDevice Found
type: 413c b06e
path: 0003:0007:00
serial_number: (null)
Manufacturer: (null)
Product:
Release: 101
Interface: 0
Usage (page): 0x0 (0x0)
Device Found
type: 046d c534
path: 0001:0002:00
serial_number: (null)
Manufacturer: Logitech
Product: USB Receiver
Release: 2901
Interface: 0
Usage (page): 0x0 (0x0)
Device Found
type: 046d c534
path: 0001:0002:01
serial_number: (null)
Manufacturer: Logitech
Product: USB Receiver
Release: 2901
Interface: 1
Usage (page): 0x0 (0x0)
Device Found
type: 047f c056
path: 0003:001c:03
serial_number: D1CEC32927974D5F9BD6B2AEBF2EA8E3
Manufacturer: Plantronics
Product: Plantronics Blackwire 3220 Series
Release: 210
Interface: 3
Usage (page): 0x0 (0x0)
Device Found
type: 413c 2107
path: 0003:000d:00
serial_number: (null)
Manufacturer: DELL
Product: Dell USB Entry Keyboard
Release: 178
Interface: 0
Usage (page): 0x0 (0x0)
Device Found
type: 413c b06f
path: 0003:000a:00
serial_number: (null)
Manufacturer: (null)
Product:
Release: 101
Interface: 0
Usage (page): 0x0 (0x0)
Device Found
type: 046d c077
path: 0003:000e:00
serial_number: (null)
Manufacturer: Logitech
Product: USB Optical Mouse
Release: 7200
Interface: 0
Usage (page): 0x0 (0x0)
unable to open device
Instead of using "hacks" to make it functional I'd rather suggest to refactor libusb backend of HIDAPI and switch to C11 instead of using POSIX/pthread API.
That way we will have a clean implementation compliant with the C Standard.
In order for your USB HID device to be found by the libusb backend (hidapi_libusb2.zip), there are two possibilities.
Take note this is only applicable to device listed under Windows Device Manager as "Human Interface Devices" --> "USB Input Device". Keyboard/mouse and Bluetooth/I2C/SPI HID devices are not supported.
keep using the default kernel HID driver, then it has same (actually more) limitation as HIDAPI with the normal Windows HID API backend. But it is not recommended to use libusb HID backend because of all the limitations. So we recommend you to use HIDAPI instead.
change the USB HID driver to WinUSB. In that case, certain limitations will be lifted. For example, now you can use control transfer to get the HID report descriptors.
I'm working on a program which would benefit from using the libusb backend of hidapi due to needing the ability to send control transfers. I was wondering if the libusb backend is available on windows. Libusb works on windows, but the build instructions never mention how to or if it's even possible and I had no luck getting it to compile myself.
I'll add some context to this: I'm working with skylanders portals which are HID devices, but they recieve commands over control transfers, something you wouldn't normally do for an HID device, but what can you do about it. My current code uses hidapi with a workaround to get the device handle from hidapi and manually runs the required win32 functions, but I'd prefer to use libusb (I can still extract the libusb handle from what I saw) and then use that functionality to send control transfers, and maybe utilize the hotplug functionality
Right now there is no official support of libusb backend for Windows or macOS, but there steps has been made towards that direction with the help of the community.
You may try in scope of your project (or even contribute if you feel like it) to define the HIDAPI thread abstraction for libusb and define the HIDAPI_THREAD_MODEL_INCLUDE pointing to that implementation.
See https://github.com/libusb/hidapi/pull/582/files for details.
But it will work if I test with the default fx2hid FW (two bytes input/output report loopback), if I switch the driver to WinUSB. So I will say the current libusb codes kind of work under Windows even though it will suffer the same issue as #274.
You can see that libusb mod works in this case while unmodifed hidapitester will not work since it only works with Windows HID driver.
Of course my mod is a quick hack -- needs proper changes to the code, auto-tools script and CMake files.
And it may need further work to remove the dependanices to libiconv as well.
BTW, I am not so sure where I introduce the dependancy to libwinpthread-1.dll. It would be good to remove the dependancy as well. The default Windows version (using native Windows HID API) does not have those dependancies.
But it will work if I test with the default fx2hid FW (two bytes input/output report loopback), if I switch the driver to WinUSB. So I will say the current libusb codes kind of work under Windows even though it will suffer the same issue as #274.
Same if I use my mod of Jan Axelson's USB PIC Generic HID example, mentioned here. Both hidapi git and PR #728 work fine, basically with report IDs for input/output reports and feature reports.
Activity
mcuee commentedon Aug 8, 2021
Reference discussion for macOS: libusb/libusb#911
mcuee commentedon Aug 8, 2021
Quick hack for mac/hid.c
Codes from:
https://blog.albertarmea.com/post/47089939939/using-pthreadbarrier-on-mac-os-x
mcuee commentedon Aug 8, 2021
Quick hack for Makefile.macOS
mcuee commentedon Aug 8, 2021
Runlog for macOS with hidtest using the quick mod libusb backend.
mcuee commentedon Aug 9, 2021
Under Windows, here is the output, with a quick mod of the following file.
https://gitlab.com/CalcProgrammer1/OpenRGB/-/blob/master/dependencies/hidapi/hidapi.c
I choose to use usbdk backend so that I do not need to replace the HID driver with WinUSB. And it may be able to find more devices like USB keyboard and mouse if they are present.
modified files and Windows 64bit binaries are included in the following zip file.
hidapi_libusb.zip
mcuee commentedon Aug 11, 2021
Of course, it is also possible not to use usbdk, just comment out the following line in hid.c.
hidapi_libusb2.zip
Youw commentedon Aug 12, 2021
Instead of using "hacks" to make it functional I'd rather suggest to refactor libusb backend of HIDAPI and switch to C11 instead of using POSIX/pthread API.
That way we will have a clean implementation compliant with the C Standard.
Thoughts?
mcuee commentedon Aug 12, 2021
Yes, that will be great.
Haha, my hack is just a quick demo to show that it is possible.
mcuee commentedon Aug 27, 2021
In order for your USB HID device to be found by the libusb backend (hidapi_libusb2.zip), there are two possibilities.
Take note this is only applicable to device listed under Windows Device Manager as "Human Interface Devices" --> "USB Input Device". Keyboard/mouse and Bluetooth/I2C/SPI HID devices are not supported.
https://github.com/libusb/libusb/wiki/Windows#known-restrictions
HID keyboards and mice cannot be accessed using the native HID driver as Windows reserves exclusive access to them.
Multiple HID top level collections are currently not supported (only the first top level collection will be used).
mcuee commentedon Aug 27, 2021
hidapi_libusb.zip uses the USBDK backend of the libusb, so it may be able to find more devices than hidapi_libusb2.zip. For example, it may be able to find some USB mice/keyboards. But it requires the installation of usbdk. libusb usbdk backend may be less stable than using WinUSB backend.
https://github.com/daynix/UsbDk/releases
mcuee commentedon Aug 31, 2021
64bit Windows binary with hidapitester here (not using usbdk). libusb-1.0.dll is a mod version of 1.0.24.11650 with pull request libusb/libusb#986 to fix the Windows HID backend issue.
https://github.com/mcuee/hidapitester/releases/tag/v8610dc6
5 remaining items
mcuee commentedon May 11, 2023
I think in the end, this is not an important work (not much real use in reality) and therefore I will close it for now.
[-]libusb backend for Windows and macOS[/-][+]libusb backend for Windows and macOS (Low Priority)[/+]mcuee commentedon May 14, 2023
Re-open as a low priority item.
[-]libusb backend for Windows and macOS (Low Priority)[/-][+]libusb backend for Windows and macOS[/+]mcuee commentedon Oct 25, 2024
From #706, comment by mandar1jn.
mandar1jn commentedon Oct 25, 2024
I'll add some context to this: I'm working with skylanders portals which are HID devices, but they recieve commands over control transfers, something you wouldn't normally do for an HID device, but what can you do about it. My current code uses hidapi with a workaround to get the device handle from hidapi and manually runs the required win32 functions, but I'd prefer to use libusb (I can still extract the libusb handle from what I saw) and then use that functionality to send control transfers, and maybe utilize the hotplug functionality
Youw commentedon Nov 21, 2024
Right now there is no official support of libusb backend for Windows or macOS, but there steps has been made towards that direction with the help of the community.
You may try in scope of your project (or even contribute if you feel like it) to define the HIDAPI thread abstraction for libusb and define the
HIDAPI_THREAD_MODEL_INCLUDEpointing to that implementation.See https://github.com/libusb/hidapi/pull/582/files for details.
mcuee commentedon Apr 1, 2025
Quick hack for hidapitester to use libusb backend under Windows.
mcuee commentedon Apr 1, 2025
PR #728 almost works under Windows but there is one extra byte written and read.
Youw commentedon Apr 1, 2025
So you've replaced a standard HID driver with WinUSB one to perform this test?
mcuee commentedon Apr 1, 2025
No, the above test was using libusb-1.0 Windows HID backend.
If I switch to WinUSB driver, it does not work, matching the testing result I had with PR #728 under Linux and FreeBSD.
mcuee commentedon Apr 1, 2025
@Youw
But it will work if I test with the default fx2hid FW (two bytes input/output report loopback), if I switch the driver to WinUSB. So I will say the current libusb codes kind of work under Windows even though it will suffer the same issue as #274.
You can see that libusb mod works in this case while unmodifed hidapitester will not work since it only works with Windows HID driver.
Of course my mod is a quick hack -- needs proper changes to the code, auto-tools script and CMake files.
And it may need further work to remove the dependanices to libiconv as well.
I will also need to test under macOS.
BTW, I am not so sure where I introduce the dependancy to libwinpthread-1.dll. It would be good to remove the dependancy as well. The default Windows version (using native Windows HID API) does not have those dependancies.
My mod of hidapitester Makefiles and the binaries (MSYS2 uscrt64 build).
hidapitester_git.zip
mcuee commentedon Apr 2, 2025
Same if I use my mod of Jan Axelson's USB PIC Generic HID example, mentioned here. Both hidapi git and PR #728 work fine, basically with report IDs for input/output reports and feature reports.
Using WinUSB driver and not native Windows HID driver in the following tests.
Switch back to Windows HID driver and use hidapi git. This is just to prove the FW is working.