1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef HID_DDK_TYPES_H
17 #define HID_DDK_TYPES_H
18 /**
19  * @addtogroup HidDdk
20  * @{
21  *
22  * @brief Provides HID DDK interfaces, including creating a device, sending an event, and destroying a device.
23  *
24  * @syscap SystemCapability.Driver.HID.Extension
25  * @since 11
26  * @version 1.0
27  */
28 
29 /**
30  * @file hid_ddk_types.h
31  *
32  * @brief Provides definitions of enum variables and structs in the HID DDK.
33  *
34  * File to include: <hid/hid_ddk_types.h>
35  * @since 11
36  * @version 1.0
37  */
38 
39 #include <stdint.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif /* __cplusplus */
44 
45 /**
46  * @brief Defines event information.
47  *
48  * @since 11
49  * @version 1.0
50  */
51 typedef struct Hid_EmitItem {
52     /** Event type */
53     uint16_t type;
54     /** Event code */
55     uint16_t code;
56     /** Event value */
57     uint32_t value;
58 } Hid_EmitItem;
59 
60 /**
61  * @brief Enumerates the input devices.
62  *
63  * @since 11
64  * @version 1.0
65  */
66 typedef enum {
67     /** Pointer device */
68     HID_PROP_POINTER = 0x00,
69     /** Direct input device */
70     HID_PROP_DIRECT = 0x01,
71     /** Touch device with bottom keys */
72     HID_PROP_BUTTON_PAD = 0x02,
73     /** Full multi-touch device */
74     HID_PROP_SEMI_MT = 0x03,
75     /** Touch device with top soft keys */
76     HID_PROP_TOP_BUTTON_PAD = 0x04,
77     /** Pointing stick */
78     HID_PROP_POINTING_STICK = 0x05,
79     /** Accelerometer */
80     HID_PROP_ACCELEROMETER = 0x06
81 } Hid_DeviceProp;
82 
83 /**
84  * @brief Defines the basic device information.
85  *
86  * @since 11
87  * @version 1.0
88  */
89 typedef struct Hid_Device {
90     /** Device name */
91     const char *deviceName;
92     /** Vendor ID */
93     uint16_t vendorId;
94     /** Product ID */
95     uint16_t productId;
96     /** Version */
97     uint16_t version;
98     /** Bus type */
99     uint16_t bustype;
100     /** Device properties */
101     Hid_DeviceProp *properties;
102     /** Number of device properties */
103     uint16_t propLength;
104 } Hid_Device;
105 
106 /**
107  * @brief Enumerates the event types.
108  *
109  * @since 11
110  * @version 1.0
111  */
112 typedef enum {
113     /** Synchronization event */
114     HID_EV_SYN = 0x00,
115     /** Key event */
116     HID_EV_KEY = 0x01,
117     /** Relative coordinate event */
118     HID_EV_REL = 0x02,
119     /** Absolute coordinate event */
120     HID_EV_ABS = 0x03,
121     /** Other special event */
122     HID_EV_MSC = 0x04
123 } Hid_EventType;
124 
125 /**
126  * @brief Enumerates the synchronization event codes.
127  *
128  * @since 11
129  * @version 1.0
130  */
131 typedef enum {
132     /** Indicates the end of an event. */
133     HID_SYN_REPORT = 0,
134     /** Indicates configuration synchronization. */
135     HID_SYN_CONFIG = 1,
136     /** Indicates the end of a multi-touch ABS data packet. */
137     HID_SYN_MT_REPORT = 2,
138     /** Indicates that the event is discarded. */
139     HID_SYN_DROPPED = 3
140 } Hid_SynEvent;
141 
142 /**
143  * @brief Enumerates the key value codes.
144  *
145  * @since 11
146  * @version 1.0
147  */
148 typedef enum {
149     /** Key A */
150     HID_KEY_A = 30,
151     /** Key B */
152     HID_KEY_B = 48,
153     /** Key C */
154     HID_KEY_C = 46,
155     /** Key D */
156     HID_KEY_D = 32,
157     /** Key E */
158     HID_KEY_E = 18,
159     /** Key F */
160     HID_KEY_F = 33,
161     /** Key G */
162     HID_KEY_G = 34,
163     /** Key H */
164     HID_KEY_H = 35,
165     /** Key I */
166     HID_KEY_I = 23,
167     /** Key J */
168     HID_KEY_J = 36,
169     /** Key K */
170     HID_KEY_K = 37,
171     /** Key L */
172     HID_KEY_L = 38,
173     /** Key M */
174     HID_KEY_M = 50,
175     /** Key N */
176     HID_KEY_N = 49,
177     /** Key O */
178     HID_KEY_O = 24,
179     /** Key P */
180     HID_KEY_P = 25,
181     /** Key Q */
182     HID_KEY_Q = 16,
183     /** Key R */
184     HID_KEY_R = 19,
185     /** Key S */
186     HID_KEY_S = 31,
187     /** Key T */
188     HID_KEY_T = 20,
189     /** Key U */
190     HID_KEY_U = 22,
191     /** Key V */
192     HID_KEY_V = 47,
193     /** Key W */
194     HID_KEY_W = 17,
195     /** Key X */
196     HID_KEY_X = 45,
197     /** Key Y */
198     HID_KEY_Y = 21,
199     /** Key Z */
200     HID_KEY_Z = 44,
201     /** Key Esc */
202     HID_KEY_ESC = 1,
203     /** Key 0 */
204     HID_KEY_0 = 11,
205     /** Key 1 */
206     HID_KEY_1 = 2,
207     /** Key 2 */
208     HID_KEY_2 = 3,
209     /** Key 3 */
210     HID_KEY_3 = 4,
211     /** Key 4 */
212     HID_KEY_4 = 5,
213     /** Key 5 */
214     HID_KEY_5 = 6,
215     /** Key 6 */
216     HID_KEY_6 = 7,
217     /** Key 7 */
218     HID_KEY_7 = 8,
219     /** Key 8 */
220     HID_KEY_8 = 9,
221     /** Key 9 */
222     HID_KEY_9 = 10,
223     /** Key grave (`) */
224     HID_KEY_GRAVE = 41,
225     /** Key minum (-) */
226     HID_KEY_MINUS = 12,
227     /** Key equals (=) */
228     HID_KEY_EQUALS = 13,
229     /** Key backspace */
230     HID_KEY_BACKSPACE = 14,
231     /** Key left bracket ([) */
232     HID_KEY_LEFT_BRACKET = 26,
233     /** Key right bracket (]) */
234     HID_KEY_RIGHT_BRACKET = 27,
235     /** Key Enter */
236     HID_KEY_ENTER = 28,
237     /** Key left Shift */
238     HID_KEY_LEFT_SHIFT = 42,
239     /** Key backslash (\) */
240     HID_KEY_BACKSLASH = 43,
241     /** Key semicolon (;) */
242     HID_KEY_SEMICOLON = 39,
243     /** Key apostrophe (') */
244     HID_KEY_APOSTROPHE = 40,
245     /** Key space */
246     HID_KEY_SPACE = 57,
247     /** Key slash (/) */
248     HID_KEY_SLASH = 53,
249     /** Key comma (,) */
250     HID_KEY_COMMA = 51,
251     /** Key period (.) */
252     HID_KEY_PERIOD = 52,
253     /** Key right Shift */
254     HID_KEY_RIGHT_SHIFT = 54,
255     /** Numeral 0 on the numeric keypad */
256     HID_KEY_NUMPAD_0 = 82,
257     /** Numeral 1 on the numeric keypad */
258     HID_KEY_NUMPAD_1 = 79,
259     /** Numeral 2 on the numeric keypad */
260     HID_KEY_NUMPAD_2 = 80,
261     /** Numeral 3 on the numeric keypad */
262     HID_KEY_NUMPAD_3 = 81,
263     /** Numeral 4 on the numeric keypad */
264     HID_KEY_NUMPAD_4 = 75,
265     /** Numeral 5 on the numeric keypad */
266     HID_KEY_NUMPAD_5 = 76,
267     /** Numeral 6 on the numeric keypad*/
268     HID_KEY_NUMPAD_6 = 77,
269     /** Numeral 7 on the numeric keypad */
270     HID_KEY_NUMPAD_7 = 71,
271     /** Numeral 8 on the numeric keypad */
272     HID_KEY_NUMPAD_8 = 72,
273     /** Numeral 9 on the numeric keypad */
274     HID_KEY_NUMPAD_9 = 73,
275     /** Arithmetic operator / (division) on the numeric keypad */
276     HID_KEY_NUMPAD_DIVIDE = 70,
277     /** Arithmetic operator * (multiplication) on the numeric keypad */
278     HID_KEY_NUMPAD_MULTIPLY = 55,
279     /** Arithmetic operator - (subtraction) on the numeric keypad */
280     HID_KEY_NUMPAD_SUBTRACT = 74,
281     /** Arithmetic operator + (addition) on the numeric keypad */
282     HID_KEY_NUMPAD_ADD = 78,
283     /** Decimal point (.) on the numeric keypad */
284     HID_KEY_NUMPAD_DOT = 83,
285     /** Key Print Screen */
286     HID_KEY_SYSRQ = 99,
287     /** Key Delete */
288     HID_KEY_DELETE = 111,
289     /** Key Mute */
290     HID_KEY_MUTE = 113,
291     /** Key for volume down */
292     HID_KEY_VOLUME_DOWN = 114,
293     /** Key for volume up */
294     HID_KEY_VOLUME_UP = 115,
295     /** Key for decreasing brightness */
296     HID_KEY_BRIGHTNESS_DOWN = 224,
297     /** Key for increasing brightness */
298     HID_KEY_BRIGHTNESS_UP = 225,
299     /** Button 0 */
300     HID_BTN_0 = 0x100,
301     /** Button 1 */
302     HID_BTN_1 = 0x101,
303     /** Button 2 */
304     HID_BTN_2 = 0x102,
305     /** Button 3 */
306     HID_BTN_3 = 0x103,
307     /** Button 4 */
308     HID_BTN_4 = 0x104,
309     /** Button 5 */
310     HID_BTN_5 = 0x105,
311     /** Button 6 */
312     HID_BTN_6 = 0x106,
313     /** Button 7 */
314     HID_BTN_7 = 0x107,
315     /** Button 8 */
316     HID_BTN_8 = 0x108,
317     /** Button 9 */
318     HID_BTN_9 = 0x109,
319     /** Left mouse button */
320     HID_BTN_LEFT = 0x110,
321     /** Right mouse button */
322     HID_BTN_RIGHT = 0x111,
323     /** Middle mouse button */
324     HID_BTN_MIDDLE = 0x112,
325     /** Side mouse button */
326     HID_BTN_SIDE = 0x113,
327     /** Extra mouse button */
328     HID_BTN_EXTRA = 0x114,
329     /** Mouse forward button */
330     HID_BTN_FORWARD = 0x115,
331     /** Mouse backward button */
332     HID_BTN_BACKWARD = 0x116,
333     /** Mouse task button */
334     HID_BTN_TASK = 0x117,
335     /** Pen */
336     HID_BTN_TOOL_PEN = 0x140,
337     /** Rubber */
338     HID_BTN_TOOL_RUBBER = 0x141,
339     /** Brush */
340     HID_BTN_TOOL_BRUSH = 0x142,
341     /** Pencil */
342     HID_BTN_TOOL_PENCIL = 0x143,
343     /** Air brush */
344     HID_BTN_TOOL_AIRBRUSH = 0x144,
345     /** Finger */
346     HID_BTN_TOOL_FINGER = 0x145,
347     /** Mouse */
348     HID_BTN_TOOL_MOUSE = 0x146,
349     /** Lens */
350     HID_BTN_TOOL_LENS = 0x147,
351     /** Five-finger touch */
352     HID_BTN_TOOL_QUINT_TAP = 0x148,
353     /** Stylus 3 */
354     HID_BTN_STYLUS3 = 0x149,
355     /** Touch */
356     HID_BTN_TOUCH = 0x14a,
357     /** Stylus */
358     HID_BTN_STYLUS = 0x14b,
359     /** Stylus 2 */
360     HID_BTN_STYLUS2 = 0x14c,
361     /** Two-finger touch */
362     HID_BTN_TOOL_DOUBLE_TAP = 0x14d,
363     /** Three-finger touch */
364     HID_BTN_TOOL_TRIPLE_TAP = 0x14e,
365     /** Four-finger touch */
366     HID_BTN_TOOL_QUAD_TAP = 0x14f,
367     /** Scroll wheel */
368     HID_BTN_WHEEL = 0x150
369 } Hid_KeyCode;
370 
371 /**
372  * @brief Enumerates the absolute coordinate codes.
373  *
374  * @since 11
375  * @version 1.0
376  */
377 typedef enum {
378     /** X axis */
379     HID_ABS_X = 0x00,
380     /** Y axis */
381     HID_ABS_Y = 0x01,
382     /** Z axis */
383     HID_ABS_Z = 0x02,
384     /** X axis of the right analog stick */
385     HID_ABS_RX = 0x03,
386     /** Y axis of the right analog stick */
387     HID_ABS_RY = 0x04,
388     /** Z axis of the right analog stick */
389     HID_ABS_RZ = 0x05,
390     /** Throttle */
391     HID_ABS_THROTTLE = 0x06,
392     /** Rudder */
393     HID_ABS_RUDDER = 0x07,
394     /** Scroll wheel */
395     HID_ABS_WHEEL = 0x08,
396     /** Gas */
397     HID_ABS_GAS = 0x09,
398     /** Brake */
399     HID_ABS_BRAKE = 0x0a,
400     /** HAT0X */
401     HID_ABS_HAT0X = 0x10,
402     /** HAT0Y */
403     HID_ABS_HAT0Y = 0x11,
404     /** HAT1X */
405     HID_ABS_HAT1X = 0x12,
406     /** HAT1Y */
407     HID_ABS_HAT1Y = 0x13,
408     /** HAT2X */
409     HID_ABS_HAT2X = 0x14,
410     /** HAT2Y */
411     HID_ABS_HAT2Y = 0x15,
412     /** HAT3X */
413     HID_ABS_HAT3X = 0x16,
414     /** HAT3Y */
415     HID_ABS_HAT3Y = 0x17,
416     /** Pressure */
417     HID_ABS_PRESSURE = 0x18,
418     /** Distance */
419     HID_ABS_DISTANCE = 0x19,
420     /** Inclination of X axis */
421     HID_ABS_TILT_X = 0x1a,
422     /** Inclination of Y axis */
423     HID_ABS_TILT_Y = 0x1b,
424     /** Width of the touch tool */
425     HID_ABS_TOOL_WIDTH = 0x1c,
426     /** Volume */
427     HID_ABS_VOLUME = 0x20,
428     /** Others */
429     HID_ABS_MISC = 0x28
430 } Hid_AbsAxes;
431 
432 /**
433  * @brief Enumerates the relative coordinate codes.
434  *
435  * @since 11
436  * @version 1.0
437  */
438 typedef enum {
439     /** X axis */
440     HID_REL_X = 0x00,
441     /** Y axis */
442     HID_REL_Y = 0x01,
443     /** Z axis */
444     HID_REL_Z = 0x02,
445     /** X axis of the right analog stick */
446     HID_REL_RX = 0x03,
447     /** Y axis of the right analog stick */
448     HID_REL_RY = 0x04,
449     /** Z axis of the right analog stick */
450     HID_REL_RZ = 0x05,
451     /** Horizontal scroll wheel */
452     HID_REL_HWHEEL = 0x06,
453     /** Scale */
454     HID_REL_DIAL = 0x07,
455     /** Scroll wheel */
456     HID_REL_WHEEL = 0x08,
457     /** Others */
458     HID_REL_MISC = 0x09,
459     /* Reserved */
460     HID_REL_RESERVED = 0x0a,
461     /** High-resolution scroll wheel */
462     HID_REL_WHEEL_HI_RES = 0x0b,
463     /** High-resolution horizontal scroll wheel */
464     HID_REL_HWHEEL_HI_RES = 0x0c
465 } Hid_RelAxes;
466 
467 /**
468  * @brief Enumerates the codes of other input events.
469  *
470  * @since 11
471  * @version 1.0
472  */
473 typedef enum {
474     /** Serial number */
475     HID_MSC_SERIAL = 0x00,
476     /** Pulse */
477     HID_MSC_PULSE_LED = 0x01,
478     /** Gesture */
479     HID_MSC_GESTURE = 0x02,
480     /** Start event */
481     HID_MSC_RAW = 0x03,
482     /** Scan */
483     HID_MSC_SCAN = 0x04,
484     /** Timestamp */
485     HID_MSC_TIMESTAMP = 0x05
486 } Hid_MscEvent;
487 
488 /**
489  * @brief Defines an array of the event type codes.
490  *
491  * @since 11
492  * @version 1.0
493  */
494 typedef struct Hid_EventTypeArray {
495     /** Event type code */
496     Hid_EventType *hidEventType;
497     /** Length of the array */
498     uint16_t length;
499 } Hid_EventTypeArray;
500 
501 /**
502  * @brief Defines an array of key value properties.
503  *
504  * @since 11
505  * @version 1.0
506  */
507 typedef struct Hid_KeyCodeArray {
508     /** Key value code */
509     Hid_KeyCode *hidKeyCode;
510     /** Length of the array */
511     uint16_t length;
512 } Hid_KeyCodeArray;
513 
514 /**
515  * @brief Defines an array of absolute coordinate properties.
516  *
517  * @since 11
518  * @version 1.0
519  */
520 typedef struct Hid_AbsAxesArray {
521     /** Absolute coordinate property code */
522     Hid_AbsAxes *hidAbsAxes;
523     /** Length of the array */
524     uint16_t length;
525 } Hid_AbsAxesArray;
526 
527 /**
528  * @brief Defines an array of relative coordinate properties.
529  *
530  * @since 11
531  * @version 1.0
532  */
533 typedef struct Hid_RelAxesArray {
534     /** Relative coordinate property code */
535     Hid_RelAxes *hidRelAxes;
536     /** Length of the array */
537     uint16_t length;
538 } Hid_RelAxesArray;
539 
540 /**
541  * @brief Defines an array of other special event properties.
542  *
543  * @since 11
544  * @version 1.0
545  */
546 typedef struct Hid_MscEventArray {
547     /** Code of the event property */
548     Hid_MscEvent *hidMscEvent;
549     /** Length of the array */
550     uint16_t length;
551 } Hid_MscEventArray;
552 
553 /**
554  * @brief Defines the event properties of a device to be observed.
555  *
556  * @since 11
557  * @version 1.0
558  */
559 typedef struct Hid_EventProperties {
560     /** Array of event type codes */
561     struct Hid_EventTypeArray hidEventTypes;
562     /** Array of key value codes */
563     struct Hid_KeyCodeArray hidKeys;
564     /** Array of absolute coordinate property codes */
565     struct Hid_AbsAxesArray hidAbs;
566     /** Array of relative coordinate property codes */
567     struct Hid_RelAxesArray hidRelBits;
568     /** Array of other event property codes */
569     struct Hid_MscEventArray hidMiscellaneous;
570 
571     /** Maximum values of the absolute coordinates */
572     int32_t hidAbsMax[64];
573     /** Minimum values of the absolute coordinates */
574     int32_t hidAbsMin[64];
575     /** Fuzzy values of the absolute coordinates */
576     int32_t hidAbsFuzz[64];
577     /** Fixed values of the absolute coordinates */
578     int32_t hidAbsFlat[64];
579 } Hid_EventProperties;
580 
581 /**
582  * @brief Defines the error codes used in the HID DDK.
583  *
584  * @since 11
585  * @version 1.0
586  */
587 typedef enum {
588     /** Operation successful */
589     HID_DDK_SUCCESS = 0,
590     /** Operation failed */
591     HID_DDK_FAILURE = -1,
592     /** Invalid parameter */
593     HID_DDK_INVALID_PARAMETER = -2,
594     /** Invalid operation */
595     HID_DDK_INVALID_OPERATION = -3,
596     /** Null pointer exception */
597     HID_DDK_NULL_PTR = -4,
598     /** Timeout */
599     HID_DDK_TIMEOUT = -5,
600     /** Permission denied */
601     HID_DDK_NO_PERM = -6
602 } Hid_DdkErrCode;
603 #ifdef __cplusplus
604 }
605 /** @} */
606 #endif /* __cplusplus */
607 #endif // HID_DDK_TYPES_H
608