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