1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef HIDUTIL_HIDDEFS_H_
17 #define HIDUTIL_HIDDEFS_H_
18 
19 namespace HidUtil {
20 
21 // HID specification constants definition
22 //
23 // Definitions are from HID specification v1.11, which can be obtained from http://www.usb.org
24 //
25 // Preferred namespace for namespace restriction than enum class as enum class has strong type
26 // which is inconvenient in a parser, in which input binary values has to be compared with these
27 // definitions frequnetly.
28 namespace HidDef {
29 // Hid spec 6.2.2.3
30 namespace TagType {
31 enum {
32     MAIN,
33     GLOBAL,
34     LOCAL,
35     RESERVED
36 };
37 } // namespace TagType
38 
39 // HID spec 6.2.2.4
40 namespace ReportFlag {
41 enum {
42     DATA_CONST = 1,
43     ARRAY_VARIABLE = 2,
44     WRAP = 4,
45     NONLINEAR = 8,
46     NO_PREFERRED = 0x10,
47     NULL_STATE = 0x20,
48     VOLATILE = 0x40,
49     // bit 7 reserved
50     BUFFERED_BYTES = 0x100
51 };
52 } // namespace ReportFlag
53 
54 // HID spec 6.2.2.5
55 namespace MainTag {
56 enum {
57     INPUT = 8,
58     OUTPUT = 9,
59     COLLECTION = 10,
60     FEATURE = 11,
61     END_COLLECTION = 12,
62     LONG_ITEM = 15,
63 };
64 } // namespace MainTag
65 
66 // HID spec 6.2.2.6
67 namespace CollectionType {
68 enum {
69     PHYSICAL = 0,
70     APPLICATION,
71     LOGICAL,
72     REPORT,
73     NAMED_ARRAY,
74     USAGE_SWITCH,
75     USAGE_MODIFIER
76 };
77 } // namespace CollectionType
78 
79 // HID spec 6.2.2.7
80 namespace GlobalTag {
81 enum {
82     USAGE_PAGE,
83     LOGICAL_MINIMUM,
84     LOGICAL_MAXIMUM,
85     PHYSICAL_MINIMUM,
86     PHYSICAL_MAXIMUM,
87     UNIT_EXPONENT,
88     UNIT,
89     REPORT_SIZE,
90     REPORT_ID,
91     REPORT_COUNT,
92     PUSH,
93     POP
94 };
95 } //namespace GlobalTag
96 
97 // HID spec 6.2.2.8
98 namespace LocalTag {
99 enum HidLocalTag {
100     USAGE,
101     USAGE_MINIMUM,
102     USAGE_MAXIMUM,
103     DESIGNATOR_INDEX,
104     DESIGNATOR_MINIMUM,
105     DESIGNATOR_MAXIMUM,
106     // there is a hole here in the spec
107     STRING_INDEX = 7,
108     STRING_MINIMUM,
109     STRING_MAXIMUM,
110     DELIMITOR
111 };
112 } // namespace LocalTag
113 
114 } //namespace HidDef
115 } //namespace HidUtil
116 
117 #endif // HIDUTIL_HIDDEFS_H_
118