1 /* 2 * Copyright (c) 2021-2022 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 Input 18 * @{ 19 * 20 * @brief Provides driver interfaces for the input service. 21 * 22 * These driver interfaces can be used to open and close input device files, get input events, query device information, 23 * register callback functions, and control the feature status. 24 * 25 * @since 1.0 26 * @version 1.0 27 */ 28 29 /** 30 * @file input_type.h 31 * 32 * @brief Declares types of input devices as well as the structure and enumeration types used by driver interfaces. 33 * 34 * @since 1.0 35 * @version 1.0 36 */ 37 38 #ifndef INPUT_TYPES_H 39 #define INPUT_TYPES_H 40 41 #include <stdint.h> 42 #include <stdbool.h> 43 #include <sys/time.h> 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 #ifndef _UAPI_INPUT_H 50 #define INPUT_PROP_MAX 0x1f 51 #define INPUT_PROP_CNT (INPUT_PROP_MAX + 1) 52 #define EV_SYN 0x00 53 #define EV_KEY 0x01 54 #define EV_REL 0x02 55 #define EV_ABS 0x03 56 #define EV_MAX 0x1f 57 #define EV_CNT (EV_MAX + 1) 58 #define ABS_X 0x00 59 #define ABS_Y 0x01 60 #define ABS_MAX 0x3f 61 #define ABS_CNT (ABS_MAX + 1) 62 #define REL_X 0x00 63 #define REL_Y 0x01 64 #define REL_MAX 0x0f 65 #define REL_CNT (REL_MAX + 1) 66 #define KEY_MAX 0x2ff 67 #define KEY_CNT (KEY_MAX + 1) 68 #define LED_MAX 0x0f 69 #define LED_CNT (LED_MAX + 1) 70 #define MSC_MAX 0x07 71 #define MSC_CNT (MSC_MAX + 1) 72 #define SND_MAX 0x07 73 #define SND_CNT (SND_MAX + 1) 74 #define SW_MAX 0x0f 75 #define SW_CNT (SW_MAX + 1) 76 #define BTN_MOUSE 0x110 77 #define BTN_TOUCH 0x14a 78 #define SYN_REPORT 0 79 #endif 80 81 /** Maximum number of input devices */ 82 #define MAX_INPUT_DEV_NUM 32 83 /** Length of chip information */ 84 #define CHIP_INFO_LEN 10 85 /** Length of the chip name */ 86 #define CHIP_NAME_LEN 10 87 /** Length of the vendor name */ 88 #define VENDOR_NAME_LEN 10 89 /** Length of the input device name */ 90 #define DEV_NAME_LEN 64 91 /** Length of the self-test result name */ 92 #define SELF_TEST_RESULT_LEN 20 93 /** Name of the input device manager service */ 94 #define DEV_MANAGER_SERVICE_NAME "hdf_input_host" 95 #ifdef DIV_ROUND_UP 96 #undef DIV_ROUND_UP 97 #endif 98 /** Formula for round-up calculation */ 99 #define DIV_ROUND_UP(nr, d) (((nr) + (d) - 1) / (d)) 100 /** Number of bits contained in a byte */ 101 #define BYTE_HAS_BITS 8 102 /** Formula for conversion between bits and 64-bit unsigned integers */ 103 #define BITS_TO_UINT64(count) DIV_ROUND_UP(count, BYTE_HAS_BITS * sizeof(uint64_t)) 104 /** Formula for calculating the maximum number of force feedback commands sent by the input device */ 105 #define HDF_FF_CNT (0x7f + 1) 106 107 /** 108 * @brief Enumerates return values. 109 */ 110 enum RetStatus { 111 INPUT_SUCCESS = 0, /**< Success */ 112 INPUT_FAILURE = -1, /**< Failure */ 113 INPUT_INVALID_PARAM = -2, /**< Invalid parameter */ 114 INPUT_NOMEM = -3, /**< Insufficient memory */ 115 INPUT_NULL_PTR = -4, /**< Null pointer */ 116 INPUT_TIMEOUT = -5, /**< Execution timed out */ 117 INPUT_UNSUPPORTED = -6, /**< Unsupported feature */ 118 }; 119 120 /** 121 * @brief Enumerates input device types. 122 */ 123 enum InputDevType { 124 INDEV_TYPE_TOUCH, /**< Touchscreen */ 125 INDEV_TYPE_KEY, /**< Physical key */ 126 INDEV_TYPE_BUTTON, /**< Virtual button */ 127 INDEV_TYPE_CROWN, /**< Watch crown */ 128 INDEV_TYPE_HID_BEGIN_POS = 33, /**< HID type start position */ 129 INDEV_TYPE_ENCODER, /**< Encoder */ 130 INDEV_TYPE_MOUSE, /**< Mouse */ 131 INDEV_TYPE_KEYBOARD, /**< Keyboard */ 132 INDEV_TYPE_ROCKER, /**< ROCKER */ 133 INDEV_TYPE_TRACKBALL, /**< TRACKBALL */ 134 INDEV_TYPE_TOUCHPAD, /**< Touchpad */ 135 INDEV_TYPE_UNKNOWN, /**< Unknown input device type */ 136 }; 137 138 /** 139 * @brief Enumerates power statuses. 140 */ 141 enum PowerStatus { 142 INPUT_RESUME, /**< Resume status */ 143 INPUT_SUSPEND, /**< Suspend status */ 144 INPUT_LOW_POWER, /**< Low-power status */ 145 INPUT_POWER_STATUS_UNKNOWN, /**< Unknown power status */ 146 }; 147 148 /** 149 * @brief Enumerates types of capacitance tests. 150 */ 151 enum CapacitanceTest { 152 BASE_TEST, /**< Basic capacitance test */ 153 FULL_TEST, /**< Full capacitance self-test */ 154 MMI_TEST, /**< Man-Machine Interface (MMI) capacitance test */ 155 RUNNING_TEST, /**< Running capacitance test */ 156 TEST_TYPE_UNKNOWN, /**< Unknown test type */ 157 }; 158 159 /** 160 * @brief Describes the input event data package. 161 */ 162 typedef struct { 163 uint32_t type; /**< Type of the input event */ 164 uint32_t code; /**< Specific code item of the input event */ 165 int32_t value; /**< Value of the input event code item */ 166 uint64_t timestamp; /**< Timestamp of the input event */ 167 } InputEventPackage; 168 169 /** 170 * @brief Defines the data packet structure for hot plug events. 171 */ 172 typedef struct { 173 uint32_t devIndex; /**< Device index */ 174 uint32_t devType; /**< Device type */ 175 uint32_t status; /**< Device status 1: offline 0: online*/ 176 } InputHotPlugEvent; 177 178 /** 179 * @brief Defines the input device. 180 */ 181 typedef struct { 182 uint32_t devIndex; /**< Device index */ 183 uint32_t devType; /**< Device type */ 184 } InputDevDesc; 185 186 /** 187 * @brief Defines the input event callback for the input service. 188 */ 189 typedef struct { 190 /** 191 * @brief Reports input event data by the registered callback. 192 * 193 * @param pkgs Input event data package. 194 * @param count Number of input event data packets. 195 * @param devIndex Index of an input device. 196 * @since 1.0 197 * @version 1.0 198 */ 199 void (*EventPkgCallback)(const InputEventPackage **pkgs, uint32_t count, uint32_t devIndex); 200 } InputEventCb; 201 202 /** 203 * @brief Defines the hot plug event callback for the input service. 204 */ 205 typedef struct { 206 /** 207 * @brief Reports hot plug event data by the registered callback. 208 * 209 * @param event Pointer to the hot plug event data reported by the input driver. 210 * @since 1.0 211 * @version 1.0 212 */ 213 void (*HotPlugCallback)(const InputHotPlugEvent *event); 214 } InputHostCb; 215 216 /** 217 * @brief Defines the input device ability for storing bitmaps that record supported event types. 218 * 219 * A bit is used to indicate the type of events that can be reported by the input device. 220 * 221 */ 222 typedef struct { 223 uint64_t devProp[BITS_TO_UINT64(INPUT_PROP_CNT)]; /**< Device properties */ 224 uint64_t eventType[BITS_TO_UINT64(EV_CNT)]; /**< Bitmap for recording the supported event types */ 225 uint64_t absCode[BITS_TO_UINT64(ABS_CNT)]; /**< Bitmap for recording the supported absolute coordinates */ 226 uint64_t relCode[BITS_TO_UINT64(REL_CNT)]; /**< Bitmap for recording the supported relative coordinates */ 227 uint64_t keyCode[BITS_TO_UINT64(KEY_CNT)]; /**< Bitmap for recording the supported keycodes */ 228 uint64_t ledCode[BITS_TO_UINT64(LED_CNT)]; /**< Bitmap for recording the supported indicators */ 229 uint64_t miscCode[BITS_TO_UINT64(MSC_CNT)]; /**< Bitmap for recording other supported functions */ 230 uint64_t soundCode[BITS_TO_UINT64(SND_CNT)]; /**< Bitmap for recording supported sounds or alerts */ 231 uint64_t forceCode[BITS_TO_UINT64(HDF_FF_CNT)]; /**< Bitmap for recording the supported force functions */ 232 uint64_t switchCode[BITS_TO_UINT64(SW_CNT)]; /**< Bitmap for recording the supported switch functions */ 233 uint64_t keyType[BITS_TO_UINT64(KEY_CNT)]; /**< Bitmap for recording the key status */ 234 uint64_t ledType[BITS_TO_UINT64(LED_CNT)]; /**< Bitmap for recording the LED status */ 235 uint64_t soundType[BITS_TO_UINT64(SND_CNT)]; /**< Bitmap for recording the sound status */ 236 uint64_t switchType[BITS_TO_UINT64(SW_CNT)]; /**< Bitmap for recording the switch status */ 237 } InputDevAbility; 238 239 /** 240 * @brief Defines dimension information of the input device. 241 */ 242 typedef struct { 243 int32_t axis; /**< Axis */ 244 int32_t min; /**< Minimum value of each coordinate */ 245 int32_t max; /**< Maximum value of each coordinate */ 246 int32_t fuzz; /**< Resolution of each coordinate */ 247 int32_t flat; /**< Reference value of each coordinate */ 248 int32_t range; /**< Range */ 249 } InputDimensionInfo; 250 251 /** 252 * @brief Defines identification information of the input device. 253 */ 254 typedef struct { 255 uint16_t busType; /**< Bus type */ 256 uint16_t vendor; /**< Vendor ID */ 257 uint16_t product; /**< Product ID */ 258 uint16_t version; /**< Version */ 259 } InputDevIdentify; 260 261 /** 262 * @brief Defines input device attributes. 263 */ 264 typedef struct { 265 char devName[DEV_NAME_LEN]; /**< Device name */ 266 InputDevIdentify id; /**< Device identification information */ 267 InputDimensionInfo axisInfo[ABS_CNT]; /**< Device dimension information */ 268 } InputDevAttr; 269 270 /** 271 * @brief Defines basic device information of the input device. 272 */ 273 typedef struct { 274 uint32_t devIndex; /**< Device index */ 275 uint32_t devType; /**< Device type */ 276 char chipInfo[CHIP_INFO_LEN]; /**< Driver chip information */ 277 char vendorName[VENDOR_NAME_LEN]; /**< Module vendor name */ 278 char chipName[CHIP_NAME_LEN]; /**< Driver chip name */ 279 InputDevAttr attrSet; /**< Device attributes */ 280 InputDevAbility abilitySet; /**< Device abilities */ 281 } InputDeviceInfo; 282 283 /** 284 * @brief Defines the extra commands. 285 */ 286 typedef struct { 287 const char *cmdCode; /**< Command code */ 288 const char *cmdValue; /**< Data transmitted in the command */ 289 } InputExtraCmd; 290 291 #ifdef __cplusplus 292 } 293 #endif 294 #endif 295 /** @} */ 296