-
Notifications
You must be signed in to change notification settings - Fork 403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libusb backend for Windows and macOS #319
Comments
Reference discussion for macOS: libusb/libusb#911 |
Quick hack for mac/hid.c
|
Quick hack for Makefile.macOS
|
Runlog for macOS with hidtest using the quick mod libusb backend.
|
Under Windows, here is the output, with a quick mod of the following file. 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.
|
Of course, it is also possible not to use usbdk, just comment out the following line in hid.c.
|
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. Thoughts? |
Yes, that will be great. Haha, my hack is just a quick demo to show that it is possible. |
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
|
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. |
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. |
Since I do not know much about pthread and C++11 threading, and since ChatGPT is now popular, I asked ChatGPT to do the job. Unfortuantely ChatGPT is not able to finish the full conversion and always got stuck. (Edit: delete the code as it is not good). |
Loool :) |
Glad to hear that. Interestingly I ask ChatGPT to convert the simple libusb https://github.com/libusb/libusb/blob/master/tests/stress_mt.c However, if I ask it to convert into C11, the result codes do not even compile since MinGW does not support C11 |
That's a bummer :( Writing an entire backend in C++ has many proc and cons. One of the most important ones - dependency on C++ Standard library. But maybe, having an experimental (additional, not replacement) C++ port of libusb backend of HIDAPI - should be a "fun project" at least. |
FYI: Apple clang does not support C11 threading either. Ref: |
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. |
Re-open as a low priority item. |
From #706, comment by mandar1jn.
|
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. |
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.
The text was updated successfully, but these errors were encountered: