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