diff options
| author | augustss <augustss@NetBSD.org> | 1999-05-11 21:02:24 +0000 |
|---|---|---|
| committer | augustss <augustss@NetBSD.org> | 1999-05-11 21:02:24 +0000 |
| commit | 18f11488db9780b3c871d8eae0d124f4d8f3d99b (patch) | |
| tree | 32f4c9ef2f52496291871eabf2bf9a802117117c /lib/libusb/data.c | |
| parent | dfa799a037ad9f000cb03e8226e9d481ea27ff53 (diff) | |
Make USB HID processing into a library.
Diffstat (limited to 'lib/libusb/data.c')
| -rw-r--r-- | lib/libusb/data.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/libusb/data.c b/lib/libusb/data.c new file mode 100644 index 00000000000..3b78d0fc94b --- /dev/null +++ b/lib/libusb/data.c @@ -0,0 +1,59 @@ +/* $NetBSD: data.c,v 1.1 1999/05/11 21:02:24 augustss Exp $ */ + +/* + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Lennart Augustsson (augustss@netbsd.org). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdlib.h> +#include "usb.h" + +unsigned int +getdata(void *p, hid_item_t *h) +{ + unsigned char *buf = p; + unsigned int hpos = h->pos; /* bit position of data */ + unsigned int hsize = h->report_size; /* bit length of data */ + unsigned int data; + int i, end, offs; + + if (hsize == 0) + return (0); + offs = hpos / 8; + end = (hpos + hsize) / 8 - offs; + data = 0; + for (i = 0; i <= end; i++) + data |= buf[offs + i] << (i*8); + data >>= hpos % 8; + data &= (1 << hsize) - 1; + if (h->logical_minimum < 0) { + /* Need to sign extend */ + hsize = sizeof data * 8 - hsize; + data = ((int)data << hsize) >> hsize; + } + return (data); +} |
