• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TOUCHPAD,            /**< Touchpad */
107     INDEV_TYPE_UNKNOWN,             /**< Unknown input device type */
108 };
109 
110 /**
111  * @brief Enumerates power statuses.
112  */
113 enum PowerStatus {
114     INPUT_RESUME,                  /**< Resume status */
115     INPUT_SUSPEND,                 /**< Suspend status */
116     INPUT_LOW_POWER,               /**< Low-power status */
117     INPUT_POWER_STATUS_UNKNOWN,    /**< Unknown power status */
118 };
119 
120 /**
121  * @brief Enumerates types of capacitance tests.
122  */
123 enum CapacitanceTest {
124     BASE_TEST,             /**< Basic capacitance test */
125     FULL_TEST,             /**< Full capacitance self-test */
126     MMI_TEST,              /**< Man-Machine Interface (MMI) capacitance test */
127     RUNNING_TEST,          /**< Running capacitance test */
128     TEST_TYPE_UNKNOWN,     /**< Unknown test type */
129 };
130 
131 /**
132  * @brief Describes the input event data package.
133  */
134 typedef struct {
135     uint32_t type;          /**< Type of the input event */
136     uint32_t code;          /**< Specific code item of the input event */
137     int32_t value;          /**< Value of the input event code item */
138     uint64_t timestamp;     /**< Timestamp of the input event */
139 } InputEventPackage;
140 
141 /**
142  * @brief Defines the data packet structure for hot plug events.
143  */
144 typedef struct {
145     uint32_t devIndex;      /**< Device index */
146     uint32_t devType;       /**< Device type */
147     uint32_t status;        /**< Device status 1: offline 0: online*/
148 } InputHotPlugEvent;
149 
150 /**
151  * @brief Defines the input device.
152  */
153 typedef struct {
154     uint32_t devIndex;      /**< Device index */
155     uint32_t devType;       /**< Device type */
156 } InputDevDesc;
157 
158 /**
159  * @brief Defines the input event callback for the input service.
160  */
161 typedef struct {
162     /**
163      * @brief Reports input event data by the registered callback.
164      *
165      * @param pkgs Input event data package.
166      * @param count Number of input event data packets.
167      * @param devIndex Index of an input device.
168      * @since 1.0
169      * @version 1.0
170      */
171     void (*EventPkgCallback)(const InputEventPackage **pkgs, uint32_t count, uint32_t devIndex);
172 } InputEventCb;
173 
174 /**
175  * @brief Defines the hot plug event callback for the input service.
176  */
177 typedef struct {
178     /**
179      * @brief Reports hot plug event data by the registered callback.
180      *
181      * @param event Pointer to the hot plug event data reported by the input driver.
182      * @since 1.0
183      * @version 1.0
184      */
185     void (*HotPlugCallback)(const InputHotPlugEvent *event);
186 } InputHostCb;
187 
188 /**
189   * @brief Defines the input device ability for storing bitmaps that record supported event types.
190  *
191  * A bit is used to indicate the type of events that can be reported by the input device.
192  *
193  */
194 typedef struct {
195     uint64_t devProp[BITS_TO_UINT64(INPUT_PROP_CNT)];    /**< Device properties */
196     uint64_t eventType[BITS_TO_UINT64(EV_CNT)];          /**< Bitmap for recording the supported event types */
197     uint64_t absCode[BITS_TO_UINT64(ABS_CNT)];           /**< Bitmap for recording the supported absolute coordinates */
198     uint64_t relCode[BITS_TO_UINT64(REL_CNT)];           /**< Bitmap for recording the supported relative coordinates */
199     uint64_t keyCode[BITS_TO_UINT64(KEY_CNT)];           /**< Bitmap for recording the supported keycodes */
200     uint64_t ledCode[BITS_TO_UINT64(LED_CNT)];           /**< Bitmap for recording the supported indicators */
201     uint64_t miscCode[BITS_TO_UINT64(MSC_CNT)];          /**< Bitmap for recording other supported functions */
202     uint64_t soundCode[BITS_TO_UINT64(SND_CNT)];         /**< Bitmap for recording supported sounds or alerts */
203     uint64_t forceCode[BITS_TO_UINT64(HDF_FF_CNT)];      /**< Bitmap for recording the supported force functions */
204     uint64_t switchCode[BITS_TO_UINT64(SW_CNT)];         /**< Bitmap for recording the supported switch functions */
205     uint64_t keyType[BITS_TO_UINT64(KEY_CNT)];           /**< Bitmap for recording the key status */
206     uint64_t ledType[BITS_TO_UINT64(LED_CNT)];           /**< Bitmap for recording the LED status */
207     uint64_t soundType[BITS_TO_UINT64(SND_CNT)];         /**< Bitmap for recording the sound status */
208     uint64_t switchType[BITS_TO_UINT64(SW_CNT)];         /**< Bitmap for recording the switch status */
209 } InputDevAbility;
210 
211 /**
212  * @brief Defines dimension information of the input device.
213  */
214 typedef struct {
215     int32_t axis;        /**< Axis */
216     int32_t min;         /**< Minimum value of each coordinate */
217     int32_t max;         /**< Maximum value of each coordinate */
218     int32_t fuzz;        /**< Resolution of each coordinate */
219     int32_t flat;        /**< Reference value of each coordinate */
220     int32_t range;       /**< Range */
221 } InputDimensionInfo;
222 
223 /**
224  * @brief Defines identification information of the input device.
225  */
226 typedef struct {
227     uint16_t busType;    /**< Bus type */
228     uint16_t vendor;     /**< Vendor ID */
229     uint16_t product;    /**< Product ID */
230     uint16_t version;    /**< Version */
231 } InputDevIdentify;
232 
233 /**
234  * @brief Defines input device attributes.
235  */
236 typedef struct {
237     char devName[DEV_NAME_LEN];               /**< Device name */
238     InputDevIdentify id;                      /**< Device identification information */
239     InputDimensionInfo axisInfo[ABS_CNT];     /**< Device dimension information */
240 } InputDevAttr;
241 
242 /**
243  * @brief Defines basic device information of the input device.
244  */
245 typedef struct {
246     uint32_t devIndex;                   /**< Device index */
247     uint32_t devType;                    /**< Device type */
248     char chipInfo[CHIP_INFO_LEN];        /**< Driver chip information */
249     char vendorName[VENDOR_NAME_LEN];    /**< Module vendor name */
250     char chipName[CHIP_NAME_LEN];        /**< Driver chip name */
251     InputDevAttr attrSet;                /**< Device attributes */
252     InputDevAbility abilitySet;          /**< Device abilities */
253 } InputDeviceInfo;
254 
255 /**
256  * @brief Defines the extra commands.
257  */
258 typedef struct {
259     const char *cmdCode;     /**< Command code */
260     const char *cmdValue;    /**< Data transmitted in the command */
261 } InputExtraCmd;
262 
263 #ifdef __cplusplus
264 }
265 #endif
266 #endif
267 /** @} */
268