问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/6846341/write-something-to-linux-hid-device