5

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.

4

1 回答 1

3

USB HID 设备主要是输入设备,因此它们通常不提供 OUT 端点(它们是 HID 规范允许的,但我从未见过)。如果未提供 OUT 端点,则通过控制端点 (EP0) 发送输出报告。URB 应该是这样的:

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

当然,有一些功能可以做到这一点。从内核中,您可以查看 hiddev_lookup_report/usbhid_submit_report。从用户态,如果你使用 /dev/usb/hiddev?你可以试试 HIDIOCSREPORT ioctl,如果你使用 /dev/hidraw? 您只需将 write() 写入其中。

HID 还定义了“功能”,这是一种输出控制机制,但我从未使用过它们。

于 2011-07-28T08:54:25.377 回答