xref: /haiku/src/add-ons/kernel/drivers/input/hid_shared/HIDDataTypes.h (revision 2b4bf3eef6a26d0221f803c296baae95a2ef2426)
1 /*
2  * Copyright 2009-2011, Michael Lotz, mmlr@mlotz.ch.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef HID_DATA_TYPES_H
6 #define HID_DATA_TYPES_H
7 
8 
9 #include <lendian_bitfield.h>
10 
11 
12 #define ITEM_TYPE_MAIN						0x0
13 #define ITEM_TYPE_GLOBAL					0x1
14 #define ITEM_TYPE_LOCAL						0x2
15 #define ITEM_TYPE_LONG						0x3
16 
17 #define ITEM_TAG_MAIN_INPUT					0x8
18 #define ITEM_TAG_MAIN_OUTPUT				0x9
19 #define ITEM_TAG_MAIN_FEATURE				0xb
20 #define ITEM_TAG_MAIN_COLLECTION			0xa
21 #define ITEM_TAG_MAIN_END_COLLECTION		0xc
22 
23 #define ITEM_TAG_GLOBAL_USAGE_PAGE			0x0
24 #define ITEM_TAG_GLOBAL_LOGICAL_MINIMUM		0x1
25 #define ITEM_TAG_GLOBAL_LOGICAL_MAXIMUM		0x2
26 #define ITEM_TAG_GLOBAL_PHYSICAL_MINIMUM	0x3
27 #define ITEM_TAG_GLOBAL_PHYSICAL_MAXIMUM	0x4
28 #define ITEM_TAG_GLOBAL_UNIT_EXPONENT		0x5
29 #define ITEM_TAG_GLOBAL_UNIT				0x6
30 #define ITEM_TAG_GLOBAL_REPORT_SIZE			0x7
31 #define ITEM_TAG_GLOBAL_REPORT_ID			0x8
32 #define ITEM_TAG_GLOBAL_REPORT_COUNT		0x9
33 #define ITEM_TAG_GLOBAL_PUSH				0xa
34 #define ITEM_TAG_GLOBAL_POP					0xb
35 
36 #define ITEM_TAG_LOCAL_USAGE				0x0
37 #define ITEM_TAG_LOCAL_USAGE_MINIMUM		0x1
38 #define ITEM_TAG_LOCAL_USAGE_MAXIMUM		0x2
39 #define ITEM_TAG_LOCAL_DESIGNATOR_INDEX		0x3
40 #define ITEM_TAG_LOCAL_DESIGNATOR_MINIMUM	0x4
41 #define ITEM_TAG_LOCAL_DESIGNATOR_MAXIMUM	0x5
42 #define ITEM_TAG_LOCAL_STRING_INDEX			0x7
43 #define ITEM_TAG_LOCAL_STRING_MINIMUM		0x8
44 #define ITEM_TAG_LOCAL_STRING_MAXIMUM		0x9
45 #define ITEM_TAG_LOCAL_DELIMITER			0xa
46 
47 #define ITEM_TAG_LONG						0xf
48 
49 #define COLLECTION_PHYSICAL					0x00
50 #define COLLECTION_APPLICATION				0x01
51 #define COLLECTION_LOGICAL					0x02
52 #define COLLECTION_REPORT					0x03
53 #define COLLECTION_NAMED_ARRAY				0x04
54 #define COLLECTION_USAGE_SWITCH				0x05
55 #define COLLECTION_USAGE_MODIFIER			0x06
56 #define COLLECTION_ALL						0xff
57 
58 #define UNIT_SYSTEM							0x0
59 #define UNIT_LENGTH							0x1
60 #define UNIT_MASS							0x2
61 #define UNIT_TIME							0x3
62 #define UNIT_TEMPERATURE					0x4
63 #define UNIT_CURRENT						0x5
64 #define UNIT_LUMINOUS_INTENSITY				0x6
65 
66 #define USAGE_PAGE_SHIFT					16
67 #define USAGE_PAGE_MASK						0xffff
68 #define USAGE_ID_SHIFT						0
69 #define USAGE_ID_MASK						0xffff
70 
71 
72 typedef struct item_prefix {
73 	B_LBITFIELD8_3(
74 		size	: 2,
75 		type	: 2,
76 		tag		: 4
77 	);
78 } _PACKED item_prefix;
79 
80 
81 typedef struct short_item {
82 	item_prefix	prefix;
83 
84 	union {
85 		uint8	as_uint8[4];
86 		int8	as_int8[4];
87 		uint16	as_uint16[2];
88 		int16	as_int16[2];
89 		uint32	as_uint32;
90 		int32	as_int32;
91 	} data;
92 } _PACKED short_item;
93 
94 
95 typedef struct long_item {
96 	item_prefix	prefix;
97 	uint8		data_size;
98 	uint8		long_item_tag;
99 	uint8		data[0];
100 } _PACKED long_item;
101 
102 
103 typedef struct main_item_data {
104 	B_LBITFIELD16_9(
105 		data_constant	: 1,
106 		array_variable	: 1,
107 		relative		: 1,
108 		wrap			: 1,
109 		non_linear		: 1,
110 		no_preferred	: 1,
111 		null_state		: 1,
112 		is_volatile		: 1,
113 		bits_bytes		: 1
114 	);
115 
116 	//uint8			reserved[2];
117 } _PACKED main_item_data;
118 
119 
120 typedef union main_item_data_converter {
121 	main_item_data	main_data;
122 	uint16			flat_data;
123 } main_item_data_converter;
124 
125 
126 typedef struct usage_value {
127 	union {
128 		struct {
129 			uint16	usage_id;
130 			uint16	usage_page;
131 		} _PACKED s;
132 		uint32		extended;
133 	} u;
134 
135 	bool			is_extended;
136 
usage_valueusage_value137 					usage_value()
138 					{
139 						u.extended = 0;
140 						is_extended = false;
141 					}
142 } usage_value;
143 
144 
145 typedef struct global_item_state {
146 	uint16			usage_page;
147 	uint32			logical_minimum;
148 	uint32			logical_maximum;
149 	uint32			physical_minimum;
150 	uint32			physical_maximum;
151 	uint8			unit_exponent;
152 	uint8			unit;
153 	uint32			report_size;
154 	uint32			report_count;
155 	uint8			report_id;
156 	global_item_state *link;
157 } global_item_state;
158 
159 
160 typedef struct local_item_state {
161 	usage_value *	usage_stack;
162 	uint32			usage_stack_used;
163 	usage_value		usage_minimum;
164 	usage_value		usage_maximum;
165 	bool			usage_minimum_set;
166 	bool			usage_maximum_set;
167 	uint32			designator_index;
168 	bool			designator_index_set;
169 	uint32			designator_minimum;
170 	uint32			designator_maximum;
171 	uint8			string_index;
172 	bool			string_index_set;
173 	uint8			string_minimum;
174 	uint8			string_maximum;
175 } local_item_state;
176 
177 #endif // HID_DATA_TYPES_H
178