125d1d43dSNick Hibma /* $NetBSD: usb.h,v 1.8 2000/08/13 22:22:02 augustss Exp $ */ 29e2046dfSNick Hibma 35e53a4f9SPedro F. Giffuni /*- 4b61a5730SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 55e53a4f9SPedro F. Giffuni * 69e2046dfSNick Hibma * Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org> 79e2046dfSNick Hibma * All rights reserved. 89e2046dfSNick Hibma * 99e2046dfSNick Hibma * Redistribution and use in source and binary forms, with or without 109e2046dfSNick Hibma * modification, are permitted provided that the following conditions 119e2046dfSNick Hibma * are met: 129e2046dfSNick Hibma * 1. Redistributions of source code must retain the above copyright 139e2046dfSNick Hibma * notice, this list of conditions and the following disclaimer. 149e2046dfSNick Hibma * 2. Redistributions in binary form must reproduce the above copyright 159e2046dfSNick Hibma * notice, this list of conditions and the following disclaimer in the 169e2046dfSNick Hibma * documentation and/or other materials provided with the distribution. 179e2046dfSNick Hibma * 189e2046dfSNick Hibma * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 199e2046dfSNick Hibma * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 209e2046dfSNick Hibma * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 219e2046dfSNick Hibma * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 229e2046dfSNick Hibma * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 239e2046dfSNick Hibma * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 249e2046dfSNick Hibma * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 259e2046dfSNick Hibma * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 269e2046dfSNick Hibma * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 279e2046dfSNick Hibma * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 289e2046dfSNick Hibma * SUCH DAMAGE. 299e2046dfSNick Hibma * 309e2046dfSNick Hibma */ 319e2046dfSNick Hibma 32*230efedaSAndreas Kempe #ifndef _USBHID_H_ 33*230efedaSAndreas Kempe #define _USBHID_H_ 34*230efedaSAndreas Kempe 35ff7ad950SAndrew Thompson #include <stdint.h> 36ea81d432SBruce Evans 379e2046dfSNick Hibma typedef struct report_desc *report_desc_t; 389e2046dfSNick Hibma 399e2046dfSNick Hibma typedef struct hid_data *hid_data_t; 409e2046dfSNick Hibma 419e2046dfSNick Hibma typedef enum hid_kind { 42cde58781SKai Wang hid_input, hid_output, hid_feature, hid_collection, hid_endcollection 439e2046dfSNick Hibma } hid_kind_t; 449e2046dfSNick Hibma 459e2046dfSNick Hibma typedef struct hid_item { 469e2046dfSNick Hibma /* Global */ 47cde58781SKai Wang uint32_t _usage_page; 48cde58781SKai Wang int32_t logical_minimum; 49cde58781SKai Wang int32_t logical_maximum; 50cde58781SKai Wang int32_t physical_minimum; 51cde58781SKai Wang int32_t physical_maximum; 52cde58781SKai Wang int32_t unit_exponent; 53cde58781SKai Wang int32_t unit; 54cde58781SKai Wang int32_t report_size; 55cde58781SKai Wang int32_t report_ID; 569e2046dfSNick Hibma #define NO_REPORT_ID 0 57cde58781SKai Wang int32_t report_count; 589e2046dfSNick Hibma /* Local */ 59cde58781SKai Wang uint32_t usage; 60cde58781SKai Wang int32_t usage_minimum; 61cde58781SKai Wang int32_t usage_maximum; 62cde58781SKai Wang int32_t designator_index; 63cde58781SKai Wang int32_t designator_minimum; 64cde58781SKai Wang int32_t designator_maximum; 65cde58781SKai Wang int32_t string_index; 66cde58781SKai Wang int32_t string_minimum; 67cde58781SKai Wang int32_t string_maximum; 68cde58781SKai Wang int32_t set_delimiter; 699e2046dfSNick Hibma /* Misc */ 70cde58781SKai Wang int32_t collection; 719e2046dfSNick Hibma int collevel; 729e2046dfSNick Hibma enum hid_kind kind; 73cde58781SKai Wang uint32_t flags; 74cde58781SKai Wang /* Location */ 75cde58781SKai Wang uint32_t pos; 76cde58781SKai Wang /* unused */ 779e2046dfSNick Hibma struct hid_item *next; 789e2046dfSNick Hibma } hid_item_t; 799e2046dfSNick Hibma 8025d1d43dSNick Hibma #define HID_PAGE(u) (((u) >> 16) & 0xffff) 819e2046dfSNick Hibma #define HID_USAGE(u) ((u) & 0xffff) 827778ab7eSAlexander Motin #define HID_HAS_GET_SET_REPORT 1 839e2046dfSNick Hibma 84e404f751SDag-Erling Smørgrav __BEGIN_DECLS 85e404f751SDag-Erling Smørgrav 869e2046dfSNick Hibma /* Obtaining a report descriptor, descr.c: */ 8769160b1eSDavid E. O'Brien report_desc_t hid_get_report_desc(int file); 8869160b1eSDavid E. O'Brien report_desc_t hid_use_report_desc(unsigned char *data, unsigned int size); 8969160b1eSDavid E. O'Brien void hid_dispose_report_desc(report_desc_t); 907e474656SAlfred Perlstein int hid_get_report_id(int file); 917e474656SAlfred Perlstein int hid_set_immed(int fd, int enable); 929e2046dfSNick Hibma 939e2046dfSNick Hibma /* Parsing of a HID report descriptor, parse.c: */ 94cf0e07e5SMatthew N. Dodd hid_data_t hid_start_parse(report_desc_t d, int kindset, int id); 9569160b1eSDavid E. O'Brien void hid_end_parse(hid_data_t s); 9669160b1eSDavid E. O'Brien int hid_get_item(hid_data_t s, hid_item_t *h); 97cf0e07e5SMatthew N. Dodd int hid_report_size(report_desc_t d, enum hid_kind k, int id); 98cde58781SKai Wang int hid_locate(report_desc_t d, unsigned int usage, enum hid_kind k, 99cde58781SKai Wang hid_item_t *h, int id); 1009e2046dfSNick Hibma 1019e2046dfSNick Hibma /* Conversion to/from usage names, usage.c: */ 10269160b1eSDavid E. O'Brien const char *hid_usage_page(int i); 10369160b1eSDavid E. O'Brien const char *hid_usage_in_page(unsigned int u); 10469160b1eSDavid E. O'Brien void hid_init(const char *file); 105234e6b87SMatthew N. Dodd int hid_parse_usage_in_page(const char *name); 106234e6b87SMatthew N. Dodd int hid_parse_usage_page(const char *name); 1079e2046dfSNick Hibma 1089e2046dfSNick Hibma /* Extracting/insertion of data, data.c: */ 109ff7ad950SAndrew Thompson int32_t hid_get_data(const void *p, const hid_item_t *h); 110ff7ad950SAndrew Thompson void hid_set_data(void *p, const hid_item_t *h, int32_t data); 1117778ab7eSAlexander Motin int hid_get_report(int fd, enum hid_kind k, 1127778ab7eSAlexander Motin unsigned char *data, unsigned int size); 1137778ab7eSAlexander Motin int hid_set_report(int fd, enum hid_kind k, 1147778ab7eSAlexander Motin unsigned char *data, unsigned int size); 115e404f751SDag-Erling Smørgrav 116e404f751SDag-Erling Smørgrav __END_DECLS 117*230efedaSAndreas Kempe 118*230efedaSAndreas Kempe #endif /* !_USBHID_H_ */ 119