• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INPUT_DEVICE_MANAGER_H
10 #define HDF_INPUT_DEVICE_MANAGER_H
11 
12 #include "input-event-codes.h"
13 #include "osal_mutex.h"
14 #include "hdf_types.h"
15 #include "hdf_device_desc.h"
16 
17 #ifdef HDF_LOG_TAG
18 #undef HDF_LOG_TAG
19 #endif
20 #define HDF_LOG_TAG HDF_INPUT_DRV
21 #define INPUT_DEV_PATH_LEN 64
22 #define MAX_INPUT_DEV_NUM  32
23 #define DEV_NAME_LEN 64
24 #define ONLINE    0
25 #define OFFLINE   1
26 
27 #ifdef DIV_ROUND_UP
28 #undef DIV_ROUND_UP
29 #endif
30 #define DIV_ROUND_UP(nr, d) (((nr) + (d) - 1) / (d))
31 
32 #define BYTE_HAS_BITS 8
33 #define BITS_TO_UINT64(count)    DIV_ROUND_UP(count, BYTE_HAS_BITS * sizeof(unsigned long))
34 
35 #define BITS_PER_LONG  32
36 #define SET_BIT(nr)    (1UL << ((nr) % BITS_PER_LONG))
37 
38 #define FF_MAX    0x7f
39 #define FF_CNT    (FF_MAX + 1)
40 
41 #define CHECK_RETURN_VALUE(ret) do { \
42     if ((ret) != HDF_SUCCESS) { \
43         return ret; \
44     } \
45 } while (0)
46 
47 typedef struct {
48     uint32_t devId;
49     uint32_t devType;
50 } DevDesc;
51 
52 typedef struct {
53     uint32_t devId;
54     uint32_t devType;
55     uint32_t status;
56 } HotPlugEvent;
57 
58 typedef struct {
59     struct IDeviceIoService ioService;
60     uint32_t (*getDeviceCount)(void);
61 } IInputManagerService;
62 
63 typedef struct {
64     unsigned long devProp[BITS_TO_UINT64(INPUT_PROP_CNT)];
65     unsigned long eventType[BITS_TO_UINT64(EV_CNT)];
66     unsigned long absCode[BITS_TO_UINT64(ABS_CNT)];
67     unsigned long relCode[BITS_TO_UINT64(REL_CNT)];
68     unsigned long keyCode[BITS_TO_UINT64(KEY_CNT)];
69     unsigned long ledCode[BITS_TO_UINT64(LED_CNT)];
70     unsigned long miscCode[BITS_TO_UINT64(MSC_CNT)];
71     unsigned long soundCode[BITS_TO_UINT64(SND_CNT)];
72     unsigned long forceCode[BITS_TO_UINT64(FF_CNT)];
73     unsigned long switchCode[BITS_TO_UINT64(SW_CNT)];
74     unsigned long keyType[BITS_TO_UINT64(KEY_CNT)];
75     unsigned long ledType[BITS_TO_UINT64(LED_CNT)];
76     unsigned long soundType[BITS_TO_UINT64(SND_CNT)];
77     unsigned long switchType[BITS_TO_UINT64(SW_CNT)];
78 } DevAbility;
79 
80 typedef struct {
81     int32_t axis;
82     int32_t min;
83     int32_t max;
84     int32_t fuzz;
85     int32_t flat;
86     int32_t range;
87 } DimensionInfo;
88 
89 typedef struct {
90     uint16_t busType;
91     uint16_t vendor;
92     uint16_t product;
93     uint16_t version;
94 } InputDevIdentify;
95 
96 typedef struct {
97     char devName[DEV_NAME_LEN];
98     InputDevIdentify id;
99     DimensionInfo axisInfo[ABS_CNT];
100 } DevAttr;
101 
102 typedef struct InputDeviceInfo {
103     struct HdfDeviceObject *hdfDevObj;
104     uint32_t devId;
105     uint32_t devType;
106     const char *devName;
107     uint16_t pkgNum;
108     uint16_t pkgCount;
109     bool errFrameFlag;
110     struct HdfSBuf *pkgBuf;
111     struct HdfSBuf *eventBuf;
112     void *pvtData;
113     DevAttr attrSet;
114     DevAbility abilitySet;
115     struct OsalMutex mutex;
116     struct InputDeviceInfo *next;
117 } InputDevice;
118 
119 typedef struct {
120     struct HdfDeviceObject *hdfDevObj;
121     uint32_t devCount;
122     struct OsalMutex mutex;
123     bool initialized;
124     InputDevice *inputDevList;
125 } InputManager;
126 
127 enum InputDevType {
128     INDEV_TYPE_TOUCH,               /* Touchscreen */
129     INDEV_TYPE_KEY,                 /* Physical key */
130     INDEV_TYPE_BUTTON,              /* Virtual button */
131     INDEV_TYPE_CROWN,               /* Watch crown */
132     INDEV_TYPE_HID_BEGIN_POS = 33,  /* HID type start position */
133     INDEV_TYPE_ENCODER,             /* Customized type of a specific function or event */
134     INDEV_TYPE_MOUSE,               /* Mouse */
135     INDEV_TYPE_KEYBOARD,            /* Keyboard */
136     INDEV_TYPE_ROCKER,              /* ROCKER */
137     INDEV_TYPE_TRACKBALL,           /* TRACKBALL */
138     INDEV_TYPE_UNKNOWN,             /* Unknown input device type */
139 };
140 
141 enum InputIOsvcCmdId {
142     GET_DEV_TYPE,
143     SET_PWR_STATUS,
144     GET_PWR_STATUS,
145     GET_CHIP_INFO,
146     GET_VENDOR_NAME,
147     GET_CHIP_NAME,
148     GET_DEV_ATTR,
149     GET_DEV_ABILITY,
150     SET_GESTURE_MODE,
151     RUN_CAPAC_TEST,
152     RUN_EXTRA_CMD,
153 };
154 
155 enum TouchIoctlCmd {
156     INPUT_IOCTL_GET_EVENT_DATA,
157     INPUT_IOCTL_SET_POWER_STATUS,
158     INPUT_IOCTL_GET_POWER_STATUS,
159     INPUT_IOCTL_GET_DEVICE_TYPE,
160     INPUT_IOCTL_GET_CHIP_INFO,
161     INPUT_IOCTL_GET_VENDOR_NAME,
162     INPUT_IOCTL_GET_CHIP_NAME,
163     INPUT_IOCTL_SET_GESTURE_MODE,
164     INPUT_IOCTL_RUN_CAPACITANCE_TEST,
165     INPUT_IOCTL_RUN_EXTRA_CMD,
166 };
167 InputManager* GetInputManager(void);
168 int32_t RegisterInputDevice(InputDevice *device);
169 void UnregisterInputDevice(InputDevice *inputDev);
170 
171 #endif