Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 May 2010 00:05:33 +0000 (UTC)
From:      Andrew Thompson <thompsa@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r208321 - stable/8/sys/dev/usb
Message-ID:  <201005200005.o4K05XqB028538@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: thompsa
Date: Thu May 20 00:05:33 2010
New Revision: 208321
URL: http://svn.freebsd.org/changeset/base/208321

Log:
  MFC r208012
  
   Support getting signed and unsigned HID data.
  
  Submitted by:	Alex Deiter

Modified:
  stable/8/sys/dev/usb/usb_hid.c
  stable/8/sys/dev/usb/usbhid.h
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)
  stable/8/sys/dev/xen/xenpci/   (props changed)
  stable/8/sys/geom/sched/   (props changed)

Modified: stable/8/sys/dev/usb/usb_hid.c
==============================================================================
--- stable/8/sys/dev/usb/usb_hid.c	Wed May 19 23:56:26 2010	(r208320)
+++ stable/8/sys/dev/usb/usb_hid.c	Thu May 20 00:05:33 2010	(r208321)
@@ -653,8 +653,9 @@ hid_locate(const void *desc, usb_size_t 
 /*------------------------------------------------------------------------*
  *	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_siz
 
 	/* 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
  *------------------------------------------------------------------------*/

Modified: stable/8/sys/dev/usb/usbhid.h
==============================================================================
--- stable/8/sys/dev/usb/usbhid.h	Wed May 19 23:56:26 2010	(r208320)
+++ stable/8/sys/dev/usb/usbhid.h	Thu May 20 00:05:33 2010	(r208321)
@@ -229,7 +229,9 @@ int	hid_report_size(const void *buf, usb
 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(



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201005200005.o4K05XqB028538>