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