简体   繁体   中英

Write something to linux hid device?

I am learning linux hid driver programming, i know how to read a message from hid device
but, i am puzzled how to write something to the device ? such as usb hid keyboard, i can use xset or some other program to control the leds of the keyboard, how to archive that? Any tips please!
thanks advance.

USB HID devices are mostly input devices, so they don't usually provide an OUT endpoint (they are allowed by the HID specification but I've never seen one). If an OUT endpoint is not provided, then output reports are sent through the control endpoint (EP0). The URB should be something like this:

bmRequestType = 0x21     (To class interface)
bRequest = 0x09          (SET_REPORT)
wValue = 0x02 <report_code>
wIndex = <interface>     (Usually 0x0001)
wLength = <Data length>
Data = <report_code> <data>...

Naturally, there are functions that do just that. From kernel, you may look at hiddev_lookup_report/usbhid_submit_report. From userland, if you use /dev/usb/hiddev? you may try the HIDIOCSREPORT ioctl, and if you use /dev/hidraw? you simply write() into it.

HID also defines "Features", that are an output control mechanism, but I've never used them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM