aboutsummaryrefslogtreecommitdiffstats
path: root/sys/dev/usb/usb_hid.c
diff options
context:
space:
mode:
authorAndrew Thompson <thompsa@FreeBSD.org>2010-05-12 22:50:23 +0000
committerAndrew Thompson <thompsa@FreeBSD.org>2010-05-12 22:50:23 +0000
commit5fdb3a67ac91cf5f46c38fe9b2b11eb28ee55fed (patch)
tree82be5c95a113342f861e9926b764dba4eb8684dd /sys/dev/usb/usb_hid.c
parentc68e91c3a4f7111a622b55a167bfee9152dfbf05 (diff)
downloadsrc-5fdb3a67ac91cf5f46c38fe9b2b11eb28ee55fed.tar.gz
src-5fdb3a67ac91cf5f46c38fe9b2b11eb28ee55fed.zip
Support getting signed and unsigned HID data.
Submitted by: Alex Deiter Reviewed by: Hans Petter Selaksy
Notes
Notes: svn path=/head/; revision=208012
Diffstat (limited to 'sys/dev/usb/usb_hid.c')
-rw-r--r--sys/dev/usb/usb_hid.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/sys/dev/usb/usb_hid.c b/sys/dev/usb/usb_hid.c
index 1f93227be1f0..3bc3cccbbd5f 100644
--- a/sys/dev/usb/usb_hid.c
+++ b/sys/dev/usb/usb_hid.c
@@ -646,8 +646,9 @@ hid_locate(const void *desc, usb_size_t size, uint32_t u, enum hid_kind k,
/*------------------------------------------------------------------------*
* hid_get_data
*------------------------------------------------------------------------*/
-uint32_t
-hid_get_data(const uint8_t *buf, usb_size_t len, struct hid_location *loc)
+static uint32_t
+hid_get_data_sub(const uint8_t *buf, usb_size_t len, struct hid_location *loc,
+ int is_signed)
{
uint32_t hpos = loc->pos;
uint32_t hsize = loc->size;
@@ -676,16 +677,31 @@ hid_get_data(const uint8_t *buf, usb_size_t len, struct hid_location *loc)
/* Correctly shift down data */
data = (data >> (hpos % 8));
+ n = 32 - hsize;
/* Mask and sign extend in one */
- n = 32 - hsize;
- data = ((int32_t)data << n) >> n;
+ if (is_signed != 0)
+ data = (int32_t)((int32_t)data << n) >> n;
+ else
+ data = (uint32_t)((uint32_t)data << n) >> n;
DPRINTFN(11, "hid_get_data: loc %d/%d = %lu\n",
loc->pos, loc->size, (long)data);
return (data);
}
+int32_t
+hid_get_data(const uint8_t *buf, usb_size_t len, struct hid_location *loc)
+{
+ return (hid_get_data_sub(buf, len, loc, 1));
+}
+
+uint32_t
+hid_get_data_unsigned(const uint8_t *buf, usb_size_t len, struct hid_location *loc)
+{
+ return (hid_get_data_sub(buf, len, loc, 0));
+}
+
/*------------------------------------------------------------------------*
* hid_is_collection
*------------------------------------------------------------------------*/