| 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 |
|
|---|
| 29 | /** @addtogroup libusbhid
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | * @brief USB HID parser.
|
|---|
| 34 | */
|
|---|
| 35 | #ifndef LIBUSBHID_HID_REPORT_ITEMS_H_
|
|---|
| 36 | #define LIBUSBHID_HID_REPORT_ITEMS_H_
|
|---|
| 37 |
|
|---|
| 38 | #include <stdint.h>
|
|---|
| 39 |
|
|---|
| 40 | /**
|
|---|
| 41 | * Item prefix
|
|---|
| 42 | */
|
|---|
| 43 | #define USB_HID_ITEM_SIZE(data) ((uint8_t)(data & 0x3))
|
|---|
| 44 | #define USB_HID_ITEM_TAG(data) ((uint8_t)((data & 0xF0) >> 4))
|
|---|
| 45 | #define USB_HID_ITEM_TAG_CLASS(data) ((uint8_t)((data & 0xC) >> 2))
|
|---|
| 46 | #define USB_HID_ITEM_IS_LONG(data) (data == 0xFE)
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | /**
|
|---|
| 50 | * Extended usage macros
|
|---|
| 51 | */
|
|---|
| 52 | #define USB_HID_IS_EXTENDED_USAGE(usage) ((usage & 0xFFFF0000) != 0)
|
|---|
| 53 | #define USB_HID_EXTENDED_USAGE_PAGE(usage) ((usage & 0xFFFF0000) >> 16)
|
|---|
| 54 | #define USB_HID_EXTENDED_USAGE(usage) (usage & 0xFFFF)
|
|---|
| 55 |
|
|---|
| 56 | /**
|
|---|
| 57 | * Input/Output/Feature Item flags
|
|---|
| 58 | */
|
|---|
| 59 | /** Constant (1) / Variable (0) */
|
|---|
| 60 | #define USB_HID_ITEM_FLAG_CONSTANT(flags) ((flags & 0x1) == 0x1)
|
|---|
| 61 | /** Variable (1) / Array (0) */
|
|---|
| 62 | #define USB_HID_ITEM_FLAG_VARIABLE(flags) ((flags & 0x2) == 0x2)
|
|---|
| 63 | /** Absolute / Relative*/
|
|---|
| 64 | #define USB_HID_ITEM_FLAG_RELATIVE(flags) ((flags & 0x4) == 0x4)
|
|---|
| 65 | /** Wrap / No Wrap */
|
|---|
| 66 | #define USB_HID_ITEM_FLAG_WRAP(flags) ((flags & 0x8) == 0x8)
|
|---|
| 67 | #define USB_HID_ITEM_FLAG_LINEAR(flags) ((flags & 0x10) == 0x10)
|
|---|
| 68 | #define USB_HID_ITEM_FLAG_PREFERRED(flags) ((flags & 0x20) == 0x20)
|
|---|
| 69 | #define USB_HID_ITEM_FLAG_POSITION(flags) ((flags & 0x40) == 0x40)
|
|---|
| 70 | #define USB_HID_ITEM_FLAG_VOLATILE(flags) ((flags & 0x80) == 0x80)
|
|---|
| 71 | #define USB_HID_ITEM_FLAG_BUFFERED(flags) ((flags & 0x100) == 0x100)
|
|---|
| 72 |
|
|---|
| 73 | /* MAIN ITEMS */
|
|---|
| 74 | #define USB_HID_TAG_CLASS_MAIN 0x0
|
|---|
| 75 | #define USB_HID_REPORT_TAG_INPUT 0x8
|
|---|
| 76 | #define USB_HID_REPORT_TAG_OUTPUT 0x9
|
|---|
| 77 | #define USB_HID_REPORT_TAG_FEATURE 0xB
|
|---|
| 78 | #define USB_HID_REPORT_TAG_COLLECTION 0xA
|
|---|
| 79 | #define USB_HID_REPORT_TAG_END_COLLECTION 0xC
|
|---|
| 80 |
|
|---|
| 81 | /* GLOBAL ITEMS */
|
|---|
| 82 | #define USB_HID_TAG_CLASS_GLOBAL 0x1
|
|---|
| 83 | #define USB_HID_REPORT_TAG_USAGE_PAGE 0x0
|
|---|
| 84 | #define USB_HID_REPORT_TAG_LOGICAL_MINIMUM 0x1
|
|---|
| 85 | #define USB_HID_REPORT_TAG_LOGICAL_MAXIMUM 0x2
|
|---|
| 86 | #define USB_HID_REPORT_TAG_PHYSICAL_MINIMUM 0x3
|
|---|
| 87 | #define USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM 0x4
|
|---|
| 88 | #define USB_HID_REPORT_TAG_UNIT_EXPONENT 0x5
|
|---|
| 89 | #define USB_HID_REPORT_TAG_UNIT 0x6
|
|---|
| 90 | #define USB_HID_REPORT_TAG_REPORT_SIZE 0x7
|
|---|
| 91 | #define USB_HID_REPORT_TAG_REPORT_ID 0x8
|
|---|
| 92 | #define USB_HID_REPORT_TAG_REPORT_COUNT 0x9
|
|---|
| 93 | #define USB_HID_REPORT_TAG_PUSH 0xA
|
|---|
| 94 | #define USB_HID_REPORT_TAG_POP 0xB
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 | /* LOCAL ITEMS */
|
|---|
| 98 | #define USB_HID_TAG_CLASS_LOCAL 0x2
|
|---|
| 99 | #define USB_HID_REPORT_TAG_USAGE 0x0
|
|---|
| 100 | #define USB_HID_REPORT_TAG_USAGE_MINIMUM 0x1
|
|---|
| 101 | #define USB_HID_REPORT_TAG_USAGE_MAXIMUM 0x2
|
|---|
| 102 | #define USB_HID_REPORT_TAG_DESIGNATOR_INDEX 0x3
|
|---|
| 103 | #define USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM 0x4
|
|---|
| 104 | #define USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM 0x5
|
|---|
| 105 | #define USB_HID_REPORT_TAG_STRING_INDEX 0x7
|
|---|
| 106 | #define USB_HID_REPORT_TAG_STRING_MINIMUM 0x8
|
|---|
| 107 | #define USB_HID_REPORT_TAG_STRING_MAXIMUM 0x9
|
|---|
| 108 | #define USB_HID_REPORT_TAG_DELIMITER 0xA
|
|---|
| 109 |
|
|---|
| 110 | #endif
|
|---|
| 111 | /**
|
|---|
| 112 | * @}
|
|---|
| 113 | */
|
|---|