165116Sn_hibma/* $NetBSD: usb.h,v 1.8 2000/08/13 22:22:02 augustss Exp $ */ 261560Sn_hibma 361560Sn_hibma/* 461560Sn_hibma * Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org> 561560Sn_hibma * All rights reserved. 661560Sn_hibma * 761560Sn_hibma * Redistribution and use in source and binary forms, with or without 861560Sn_hibma * modification, are permitted provided that the following conditions 961560Sn_hibma * are met: 1061560Sn_hibma * 1. Redistributions of source code must retain the above copyright 1161560Sn_hibma * notice, this list of conditions and the following disclaimer. 1261560Sn_hibma * 2. Redistributions in binary form must reproduce the above copyright 1361560Sn_hibma * notice, this list of conditions and the following disclaimer in the 1461560Sn_hibma * documentation and/or other materials provided with the distribution. 1561560Sn_hibma * 1661560Sn_hibma * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1761560Sn_hibma * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1861560Sn_hibma * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1961560Sn_hibma * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2061560Sn_hibma * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2161560Sn_hibma * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2261560Sn_hibma * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2361560Sn_hibma * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2461560Sn_hibma * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2561560Sn_hibma * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2661560Sn_hibma * SUCH DAMAGE. 2761560Sn_hibma * 2861560Sn_hibma * $FreeBSD$ 2961560Sn_hibma * 3061560Sn_hibma */ 3161560Sn_hibma 32208023Sthompsa#include <stdint.h> 3372065Sbde 3461560Sn_hibmatypedef struct report_desc *report_desc_t; 3561560Sn_hibma 3661560Sn_hibmatypedef struct hid_data *hid_data_t; 3761560Sn_hibma 3861560Sn_hibmatypedef enum hid_kind { 39205728Skaiw hid_input, hid_output, hid_feature, hid_collection, hid_endcollection 4067217Sn_hibma} hid_kind_t; 4161560Sn_hibma 4261560Sn_hibmatypedef struct hid_item { 4361560Sn_hibma /* Global */ 44205728Skaiw uint32_t _usage_page; 45205728Skaiw int32_t logical_minimum; 46205728Skaiw int32_t logical_maximum; 47205728Skaiw int32_t physical_minimum; 48205728Skaiw int32_t physical_maximum; 49205728Skaiw int32_t unit_exponent; 50205728Skaiw int32_t unit; 51205728Skaiw int32_t report_size; 52205728Skaiw int32_t report_ID; 5361560Sn_hibma#define NO_REPORT_ID 0 54205728Skaiw int32_t report_count; 5561560Sn_hibma /* Local */ 56205728Skaiw uint32_t usage; 57205728Skaiw int32_t usage_minimum; 58205728Skaiw int32_t usage_maximum; 59205728Skaiw int32_t designator_index; 60205728Skaiw int32_t designator_minimum; 61205728Skaiw int32_t designator_maximum; 62205728Skaiw int32_t string_index; 63205728Skaiw int32_t string_minimum; 64205728Skaiw int32_t string_maximum; 65205728Skaiw int32_t set_delimiter; 6661560Sn_hibma /* Misc */ 67205728Skaiw int32_t collection; 68205728Skaiw int collevel; 6961560Sn_hibma enum hid_kind kind; 70205728Skaiw uint32_t flags; 71205728Skaiw /* Location */ 72205728Skaiw uint32_t pos; 73205728Skaiw /* unused */ 7461560Sn_hibma struct hid_item *next; 7561560Sn_hibma} hid_item_t; 7661560Sn_hibma 7765116Sn_hibma#define HID_PAGE(u) (((u) >> 16) & 0xffff) 7861560Sn_hibma#define HID_USAGE(u) ((u) & 0xffff) 79225839Smav#define HID_HAS_GET_SET_REPORT 1 8061560Sn_hibma 81130030Sdes__BEGIN_DECLS 82130030Sdes 8361560Sn_hibma/* Obtaining a report descriptor, descr.c: */ 8492917Sobrienreport_desc_t hid_get_report_desc(int file); 8592917Sobrienreport_desc_t hid_use_report_desc(unsigned char *data, unsigned int size); 8692917Sobrienvoid hid_dispose_report_desc(report_desc_t); 87187994Salfredint hid_get_report_id(int file); 88187994Salfredint hid_set_immed(int fd, int enable); 8961560Sn_hibma 9061560Sn_hibma/* Parsing of a HID report descriptor, parse.c: */ 91113273Smdoddhid_data_t hid_start_parse(report_desc_t d, int kindset, int id); 9292917Sobrienvoid hid_end_parse(hid_data_t s); 9392917Sobrienint hid_get_item(hid_data_t s, hid_item_t *h); 94113273Smdoddint hid_report_size(report_desc_t d, enum hid_kind k, int id); 95205728Skaiwint hid_locate(report_desc_t d, unsigned int usage, enum hid_kind k, 96205728Skaiw hid_item_t *h, int id); 9761560Sn_hibma 9861560Sn_hibma/* Conversion to/from usage names, usage.c: */ 9992917Sobrienconst char *hid_usage_page(int i); 10092917Sobrienconst char *hid_usage_in_page(unsigned int u); 10192917Sobrienvoid hid_init(const char *file); 102113193Smdoddint hid_parse_usage_in_page(const char *name); 103113193Smdoddint hid_parse_usage_page(const char *name); 10461560Sn_hibma 10561560Sn_hibma/* Extracting/insertion of data, data.c: */ 106208023Sthompsaint32_t hid_get_data(const void *p, const hid_item_t *h); 107208023Sthompsavoid hid_set_data(void *p, const hid_item_t *h, int32_t data); 108225839Smavint hid_get_report(int fd, enum hid_kind k, 109225839Smav unsigned char *data, unsigned int size); 110225839Smavint hid_set_report(int fd, enum hid_kind k, 111225839Smav unsigned char *data, unsigned int size); 112130030Sdes 113130030Sdes__END_DECLS 114