ruabmbua / hidapi-rs

Rust bindings for the hidapi C library
MIT License
165 stars 79 forks source link

Do i need to write a windows driver to be able to talk to my custom USB HID device? #112

Closed Aggeloz closed 1 year ago

Aggeloz commented 1 year ago

Im using an ESP32S2 which has native usb support and i want to be able to send reports between a rust program and my custom usb device but so far the only way i can read data from the device is on linux when i give sudo permissions to the device path. In windows i can open the device but when i send a report the rust program cant read it at all.

lnicola commented 1 year ago

so far the only way i can read data from the device is on linux when i give sudo permissions to the device path

Not sure about the Windows question, but on Linux this is usually handled with an udev rule, e.g.:

ACTION=="add|change", SUBSYSTEMS=="usb", ATTRS{idVendor}=="04d9", ATTRS{idProduct}=="a052", MODE:="0666"

or

SUBSYSTEM=="usb", ATTRS{idVendor}=="1781", ATTRS{idProduct}=="0c9f", GROUP="uucp"
ruabmbua commented 1 year ago

Here is what I did with my custom USB peripheral on linux:

/etc/udev/rules.d/90-rlogic.rules

SUBSYSTEM=="usb", ATTRS{idVendor}=="dead", ATTRS{idProduct}=="beef", TAG+="uaccess", MODE="0666"

Regarding windows: I really do not know, but I think it at least has been necessary to have a custom dummy driver for USB devices of any kind. At least I ran into this problem often in the win7/8 era with different electronic tools / jtags / serial to usb converters / adb.

It often came down to just installing a driver from a vendor.

However if your device is really a HID device, I think windows should have default settings to allow access from any user currently logged into a session. This is apparently why HID is a popular protocol, because it simplifies software on windows.

lnicola commented 1 year ago

If I think about it, that CO2 meter sample used to work fine for me on Windows, so it might be something specific to your device.

Aggeloz commented 1 year ago

If I think about it, that CO2 meter sample used to work fine for me on Windows, so it might be something specific to your device.

Where could i find that code sample?

lnicola commented 1 year ago

https://github.com/ruabmbua/hidapi-rs/blob/master/examples/co2mon.rs