svn commit: r224567 - projects/hid/lib/libusbhid
Alexander Motin
mav at FreeBSD.org
Mon Aug 1 08:34:00 UTC 2011
Author: mav
Date: Mon Aug 1 08:34:00 2011
New Revision: 224567
URL: http://svn.freebsd.org/changeset/base/224567
Log:
Add hid_get_report()/hid_set_report() functions to the libusbhid, wrapping
respective IOCTLs.
Modified:
projects/hid/lib/libusbhid/data.c
projects/hid/lib/libusbhid/usbhid.3
projects/hid/lib/libusbhid/usbhid.h
Modified: projects/hid/lib/libusbhid/data.c
==============================================================================
--- projects/hid/lib/libusbhid/data.c Mon Aug 1 08:22:40 2011 (r224566)
+++ projects/hid/lib/libusbhid/data.c Mon Aug 1 08:34:00 2011 (r224567)
@@ -29,10 +29,14 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <errno.h>
#include <sys/param.h>
#include <assert.h>
#include <stdlib.h>
+#include <string.h>
+#include <dev/usb/usb_ioctl.h>
#include "usbhid.h"
+#include "usbvar.h"
int32_t
hid_get_data(const void *p, const hid_item_t *h)
@@ -114,3 +118,31 @@ hid_set_data(void *p, const hid_item_t *
buf[offs + i] = (buf[offs + i] & (mask >> (i*8))) |
((data >> (i*8)) & 0xff);
}
+
+int
+hid_get_report(int fd, enum hid_kind k, unsigned char *data, unsigned int size)
+{
+ struct usb_gen_descriptor ugd;
+
+ memset(&ugd, 0, sizeof(ugd));
+ ugd.ugd_data = hid_pass_ptr(data);
+ ugd.ugd_maxlen = size;
+ ugd.ugd_report_type = k + 1;
+ if (ioctl(fd, USB_GET_REPORT, &ugd) < 0)
+ return (errno);
+ return (0);
+}
+
+int
+hid_set_report(int fd, enum hid_kind k, unsigned char *data, unsigned int size)
+{
+ struct usb_gen_descriptor ugd;
+
+ memset(&ugd, 0, sizeof(ugd));
+ ugd.ugd_data = hid_pass_ptr(data);
+ ugd.ugd_maxlen = size;
+ ugd.ugd_report_type = k + 1;
+ if (ioctl(fd, USB_SET_REPORT, &ugd) < 0)
+ return (errno);
+ return (0);
+}
Modified: projects/hid/lib/libusbhid/usbhid.3
==============================================================================
--- projects/hid/lib/libusbhid/usbhid.3 Mon Aug 1 08:22:40 2011 (r224566)
+++ projects/hid/lib/libusbhid/usbhid.3 Mon Aug 1 08:34:00 2011 (r224567)
@@ -44,7 +44,9 @@
.Nm hid_usage_in_page ,
.Nm hid_init ,
.Nm hid_get_data ,
-.Nm hid_set_data
+.Nm hid_set_data ,
+.Nm hid_get_report ,
+.Nm hid_set_report
.Nd USB HID access routines
.Sh LIBRARY
.Lb libusbhid
@@ -84,6 +86,10 @@
.Fn hid_get_data "const void *data" "const hid_item_t *h"
.Ft void
.Fn hid_set_data "void *buf" "const hid_item_t *h" "int data"
+.Ft int
+.Fn hid_get_report "int fd" "enum hid_kind k" "unsigned char *data" "unsigned int size"
+.Ft int
+.Fn hid_set_report "int fd" "enum hid_kind k" "unsigned char *data" "unsigned int size"
.Sh DESCRIPTION
The
.Nm
@@ -105,6 +111,14 @@ Synchronous HID operation can be enabled
If the second argument is zero synchronous HID operation is disabled.
Else synchronous HID operation is enabled.
The function returns a negative value on failure.
+.Pp
+.Fn hid_get_report
+and
+.Fn hid_set_report
+functions allow to synchronously get and set specific report if device
+supports it.
+For devices with multiple report IDs, wanted ID should be provided in the
+first byte of the buffer for both get and set.
.Ss Descriptor Functions
The report descriptor ID can be obtained by calling
.Fn hid_get_report_id .
Modified: projects/hid/lib/libusbhid/usbhid.h
==============================================================================
--- projects/hid/lib/libusbhid/usbhid.h Mon Aug 1 08:22:40 2011 (r224566)
+++ projects/hid/lib/libusbhid/usbhid.h Mon Aug 1 08:34:00 2011 (r224567)
@@ -76,6 +76,7 @@ typedef struct hid_item {
#define HID_PAGE(u) (((u) >> 16) & 0xffff)
#define HID_USAGE(u) ((u) & 0xffff)
+#define HID_HAS_GET_SET_REPORT 1
__BEGIN_DECLS
@@ -104,5 +105,9 @@ int hid_parse_usage_page(const char *nam
/* Extracting/insertion of data, data.c: */
int32_t hid_get_data(const void *p, const hid_item_t *h);
void hid_set_data(void *p, const hid_item_t *h, int32_t data);
+int hid_get_report(int fd, enum hid_kind k,
+ unsigned char *data, unsigned int size);
+int hid_set_report(int fd, enum hid_kind k,
+ unsigned char *data, unsigned int size);
__END_DECLS
More information about the svn-src-projects
mailing list