[9d05599] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Matej Klonfar
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[74b1e40] | 29 | /** @addtogroup libusb
|
---|
[9d05599] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | * USB HID report descriptor and report data parser
|
---|
| 34 | */
|
---|
[74b1e40] | 35 | #ifndef LIBUSB_HIDPATH_H_
|
---|
| 36 | #define LIBUSB_HIDPATH_H_
|
---|
[9d05599] | 37 |
|
---|
[36f0738] | 38 | #include <errno.h>
|
---|
[faa44e58] | 39 | #include <usb/hid/hidparser.h>
|
---|
[9d05599] | 40 | #include <stdint.h>
|
---|
| 41 | #include <adt/list.h>
|
---|
| 42 |
|
---|
[74b1e40] | 43 |
|
---|
[a76b01b4] | 44 |
|
---|
[f3b39b4] | 45 | /*
|
---|
[74b1e40] | 46 | * Flags of usage paths comparison modes.
|
---|
| 47 | *
|
---|
| 48 | */
|
---|
[f3b39b4] | 49 | /** Wanted usage path must be exactly the same as the searched one. This
|
---|
| 50 | * option cannot be combined with the others.
|
---|
[9d05599] | 51 | */
|
---|
[5f7b75a] | 52 | #define USB_HID_PATH_COMPARE_STRICT 0
|
---|
[74b1e40] | 53 |
|
---|
| 54 | /**
|
---|
| 55 | * Wanted usage path must be the suffix in the searched one.
|
---|
| 56 | */
|
---|
[5f7b75a] | 57 | #define USB_HID_PATH_COMPARE_END 1
|
---|
[74b1e40] | 58 |
|
---|
| 59 | /**
|
---|
[f3b39b4] | 60 | * Only usage page are compared along the usage path. This option can be
|
---|
| 61 | * combined with others.
|
---|
[74b1e40] | 62 | */
|
---|
[5f7b75a] | 63 | #define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY 2
|
---|
[74b1e40] | 64 |
|
---|
| 65 | /**
|
---|
| 66 | * Searched usage page must be prefix of the other one.
|
---|
| 67 | */
|
---|
[5f7b75a] | 68 | #define USB_HID_PATH_COMPARE_BEGIN 4
|
---|
[9d05599] | 69 |
|
---|
[74b1e40] | 70 | /**
|
---|
| 71 | * Searched couple of usage page and usage can be anywhere in usage path.
|
---|
| 72 | * This option is deprecated.
|
---|
| 73 | */
|
---|
| 74 | #define USB_HID_PATH_COMPARE_ANYWHERE 8
|
---|
[9d05599] | 75 |
|
---|
[a76b01b4] | 76 |
|
---|
[74b1e40] | 77 | /**
|
---|
| 78 | * Item of usage path structure. Last item of linked list describes one item
|
---|
| 79 | * in report, the others describe superior Collection tags. Usage and Usage
|
---|
| 80 | * page of report item can be changed due to data in report.
|
---|
| 81 | */
|
---|
[9d05599] | 82 | typedef struct {
|
---|
[74b1e40] | 83 | /** Usage page of report item. Zero when usage page can be changed. */
|
---|
[9d05599] | 84 | uint32_t usage_page;
|
---|
[5b0cf63] | 85 | /** Usage of report item. Zero when usage can be changed. */
|
---|
[9d05599] | 86 | uint32_t usage;
|
---|
| 87 |
|
---|
[74b1e40] | 88 | /** Attribute of Collection tag in report descriptor*/
|
---|
[9d05599] | 89 | uint8_t flags;
|
---|
[74b1e40] | 90 |
|
---|
[b72efe8] | 91 | /** Link to usb_hid_report_path_t.items list */
|
---|
| 92 | link_t rpath_items_link;
|
---|
[9d05599] | 93 | } usb_hid_report_usage_path_t;
|
---|
| 94 |
|
---|
[74b1e40] | 95 |
|
---|
[a76b01b4] | 96 |
|
---|
[74b1e40] | 97 | /**
|
---|
| 98 | * USB HID usage path structure.
|
---|
| 99 | * */
|
---|
[9d05599] | 100 | typedef struct {
|
---|
[b72efe8] | 101 | /** Length of usage path */
|
---|
| 102 | int depth;
|
---|
[74b1e40] | 103 |
|
---|
[f3b39b4] | 104 | /** Report id. Zero is reserved and means that report id is not used.
|
---|
| 105 | * */
|
---|
[9d05599] | 106 | uint8_t report_id;
|
---|
| 107 |
|
---|
[b72efe8] | 108 | /** Link to usb_hid_report_path_t.collection_paths list. */
|
---|
| 109 | link_t cpath_link;
|
---|
[9d05599] | 110 |
|
---|
[b72efe8] | 111 | /** List of usage path items. */
|
---|
| 112 | list_t items; /* of usb_hid_report_usage_path_t */
|
---|
[9d05599] | 113 | } usb_hid_report_path_t;
|
---|
| 114 |
|
---|
[a76b01b4] | 115 |
|
---|
[9d05599] | 116 | usb_hid_report_path_t *usb_hid_report_path(void);
|
---|
| 117 |
|
---|
| 118 | void usb_hid_report_path_free(usb_hid_report_path_t *path);
|
---|
| 119 |
|
---|
[b7fd2a0] | 120 | errno_t usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path,
|
---|
[5b0cf63] | 121 | uint8_t report_id);
|
---|
[9d05599] | 122 |
|
---|
[5b0cf63] | 123 | errno_t usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path,
|
---|
| 124 | int32_t usage_page, int32_t usage);
|
---|
[9d05599] | 125 |
|
---|
| 126 | void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path);
|
---|
| 127 |
|
---|
| 128 | void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path);
|
---|
| 129 |
|
---|
[5b0cf63] | 130 | void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path,
|
---|
| 131 | int32_t tag, int32_t data);
|
---|
[9d05599] | 132 |
|
---|
[f3b39b4] | 133 | int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path,
|
---|
[5b0cf63] | 134 | usb_hid_report_path_t *path, int flags);
|
---|
[9d05599] | 135 |
|
---|
[f3b39b4] | 136 | usb_hid_report_path_t *usb_hid_report_path_clone(
|
---|
[5b0cf63] | 137 | usb_hid_report_path_t *usage_path);
|
---|
[9d05599] | 138 |
|
---|
| 139 | void usb_hid_print_usage_path(usb_hid_report_path_t *path);
|
---|
| 140 |
|
---|
| 141 | #endif
|
---|
| 142 | /**
|
---|
| 143 | * @}
|
---|
| 144 | */
|
---|