aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Thompson <thompsa@FreeBSD.org>2010-05-20 00:05:33 +0000
committerAndrew Thompson <thompsa@FreeBSD.org>2010-05-20 00:05:33 +0000
commita24aaef7828ea5ec74d10ac326096aee818c36c7 (patch)
tree00fab3800453f3efc65b646cf5a1bd9cd1a1fc77
parentdb86a57ecee9dfdaabde125fd23a03a590f2e591 (diff)
Notes
-rw-r--r--sys/dev/usb/usb_hid.c24
-rw-r--r--sys/dev/usb/usbhid.h4
2 files changed, 23 insertions, 5 deletions
diff --git a/sys/dev/usb/usb_hid.c b/sys/dev/usb/usb_hid.c
index f13bbf1b1b40..806cb2511632 100644
--- a/sys/dev/usb/usb_hid.c
+++ b/sys/dev/usb/usb_hid.c
@@ -653,8 +653,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;
@@ -683,16 +684,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
*------------------------------------------------------------------------*/
diff --git a/sys/dev/usb/usbhid.h b/sys/dev/usb/usbhid.h
index 885a9b0d977b..c07454f764a3 100644
--- a/sys/dev/usb/usbhid.h
+++ b/sys/dev/usb/usbhid.h
@@ -229,7 +229,9 @@ int hid_report_size(const void *buf, usb_size_t len, enum hid_kind k,
int hid_locate(const void *desc, usb_size_t size, uint32_t usage,
enum hid_kind kind, uint8_t index, struct hid_location *loc,
uint32_t *flags, uint8_t *id);
-uint32_t hid_get_data(const uint8_t *buf, usb_size_t len,
+int32_t hid_get_data(const uint8_t *buf, usb_size_t len,
+ struct hid_location *loc);
+uint32_t hid_get_data_unsigned(const uint8_t *buf, usb_size_t len,
struct hid_location *loc);
int hid_is_collection(const void *desc, usb_size_t size, uint32_t usage);
struct usb_hid_descriptor *hid_get_descriptor_from_usb(