Write something to linux hid device?

会有一股神秘感。 提交于 2019-12-23 11:43:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!