1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef HDF_HID_ADAPTER_H
10 #define HDF_HID_ADAPTER_H
11 
12 #include "hdf_input_device_manager.h"
13 
14 #ifdef DIV_ROUND_UP
15 #undef DIV_ROUND_UP
16 #endif
17 #define DIV_ROUND_UP(nr, d) (((nr) + (d) - 1) / (d))
18 
19 #ifdef BYTE_HAS_BITS
20 #undef BYTE_HAS_BITS
21 #endif
22 #define BYTE_HAS_BITS 8
23 
24 #ifdef BITS_TO_LONG
25 #undef BITS_TO_LONG
26 #endif
27 #define BITS_TO_LONG(count) DIV_ROUND_UP(count, BYTE_HAS_BITS * sizeof(unsigned long))
28 
29 #define INPUT_PROP_MAX    0x1f
30 #define HDF_INPUT_PROP_CNT    (INPUT_PROP_MAX + 1)
31 #define EV_MAX            0x1f
32 #define HDF_EV_CNT            (EV_MAX + 1)
33 #define ABS_MAX           0x3f
34 #define HDF_ABS_CNT           (ABS_MAX + 1)
35 #define REL_MAX           0x0f
36 #define HDF_REL_CNT           (REL_MAX + 1)
37 #define KEY_MAX           0x2ff
38 #define HDF_KEY_CNT           (KEY_MAX + 1)
39 #define SND_MAX           0x07
40 #define HDF_SND_CNT           (SND_MAX + 1)
41 #define LED_MAX           0x0f
42 #define HDF_LED_CNT           (LED_MAX + 1)
43 #define MSC_MAX           0x07
44 #define HDF_MSC_CNT           (MSC_MAX + 1)
45 #define SW_MAX            0x0f
46 #define HDF_SW_CNT            (SW_MAX + 1)
47 #define FF_MAX            0x7f
48 #define HDF_FF_CNT            (FF_MAX + 1)
49 
50 typedef struct {
51     int32_t axis;
52     int32_t min;
53     int32_t max;
54     int32_t fuzz;
55     int32_t flat;
56     int32_t range;
57 } AbsAttr;
58 
59 typedef struct HidInformation {
60     uint32_t devType;
61     const char *devName;
62 
63     unsigned long devProp[BITS_TO_LONG(HDF_INPUT_PROP_CNT)];
64     unsigned long eventType[BITS_TO_LONG(HDF_EV_CNT)];
65     unsigned long absCode[BITS_TO_LONG(HDF_ABS_CNT)];
66     unsigned long relCode[BITS_TO_LONG(HDF_REL_CNT)];
67     unsigned long keyCode[BITS_TO_LONG(HDF_KEY_CNT)];
68     unsigned long ledCode[BITS_TO_LONG(HDF_LED_CNT)];
69     unsigned long miscCode[BITS_TO_LONG(HDF_MSC_CNT)];
70     unsigned long soundCode[BITS_TO_LONG(HDF_SND_CNT)];
71     unsigned long forceCode[BITS_TO_LONG(HDF_FF_CNT)];
72     unsigned long switchCode[BITS_TO_LONG(HDF_SW_CNT)];
73     AbsAttr axisInfo[HDF_ABS_CNT];
74 
75     uint16_t bustype;
76     uint16_t vendor;
77     uint16_t product;
78     uint16_t version;
79 } HidInfo;
80 
81 enum HidType {
82     HID_TYPE_TOUCH,               /* Touchscreen */
83     HID_TYPE_KEY,                 /* Physical key */
84     HID_TYPE_BUTTON,              /* Virtual button */
85     HID_TYPE_CROWN,               /* Watch crown */
86     HID_TYPE_BEGIN_POS = 33,    /* HID type start position */
87     HID_TYPE_ENCODER,             /* Encoder */
88     HID_TYPE_MOUSE,             /* Mouse */
89     HID_TYPE_KEYBOARD,          /* Keyboard */
90     HID_TYPE_ROCKER,              /* ROCKER */
91     HID_TYPE_TRACKBALL,           /* TRACKBALL */
92     HID_TYPE_UNKNOWN,           /* Unknown input device type */
93 };
94 
95 void SendInfoToHdf(HidInfo *info);
96 void* HidRegisterHdfInputDev(HidInfo *info);
97 void HidUnregisterHdfInputDev(const void *inputDev);
98 void HidReportEvent(const void *inputDev, uint32_t type, uint32_t code, int32_t value);
99 
100 #endif
101