• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_INCLUDE_HARDWARE_INPUT_H
18 #define ANDROID_INCLUDE_HARDWARE_INPUT_H
19 
20 #include <hardware/hardware.h>
21 #include <stdint.h>
22 
23 __BEGIN_DECLS
24 
25 #define INPUT_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
26 #define INPUT_HARDWARE_MODULE_ID "input"
27 
28 #define INPUT_INSTANCE_EVDEV "evdev"
29 
30 typedef enum input_bus {
31     INPUT_BUS_BT,
32     INPUT_BUS_USB,
33     INPUT_BUS_SERIAL,
34     INPUT_BUS_BUILTIN
35 } input_bus_t;
36 
37 typedef struct input_host input_host_t;
38 
39 typedef struct input_device_handle input_device_handle_t;
40 
41 typedef struct input_device_identifier input_device_identifier_t;
42 
43 typedef struct input_device_definition input_device_definition_t;
44 
45 typedef struct input_report_definition input_report_definition_t;
46 
47 typedef struct input_report input_report_t;
48 
49 typedef struct input_collection input_collection_t;
50 
51 typedef struct input_property_map input_property_map_t;
52 
53 typedef struct input_property input_property_t;
54 
55 typedef enum {
56     // keycodes
57     INPUT_USAGE_KEYCODE_UNKNOWN,
58     INPUT_USAGE_KEYCODE_SOFT_LEFT,
59     INPUT_USAGE_KEYCODE_SOFT_RIGHT,
60     INPUT_USAGE_KEYCODE_HOME,
61     INPUT_USAGE_KEYCODE_BACK,
62     INPUT_USAGE_KEYCODE_CALL,
63     INPUT_USAGE_KEYCODE_ENDCALL,
64     INPUT_USAGE_KEYCODE_0,
65     INPUT_USAGE_KEYCODE_1,
66     INPUT_USAGE_KEYCODE_2,
67     INPUT_USAGE_KEYCODE_3,
68     INPUT_USAGE_KEYCODE_4,
69     INPUT_USAGE_KEYCODE_5,
70     INPUT_USAGE_KEYCODE_6,
71     INPUT_USAGE_KEYCODE_7,
72     INPUT_USAGE_KEYCODE_8,
73     INPUT_USAGE_KEYCODE_9,
74     INPUT_USAGE_KEYCODE_STAR,
75     INPUT_USAGE_KEYCODE_POUND,
76     INPUT_USAGE_KEYCODE_DPAD_UP,
77     INPUT_USAGE_KEYCODE_DPAD_DOWN,
78     INPUT_USAGE_KEYCODE_DPAD_LEFT,
79     INPUT_USAGE_KEYCODE_DPAD_RIGHT,
80     INPUT_USAGE_KEYCODE_DPAD_CENTER,
81     INPUT_USAGE_KEYCODE_VOLUME_UP,
82     INPUT_USAGE_KEYCODE_VOLUME_DOWN,
83     INPUT_USAGE_KEYCODE_POWER,
84     INPUT_USAGE_KEYCODE_CAMERA,
85     INPUT_USAGE_KEYCODE_CLEAR,
86     INPUT_USAGE_KEYCODE_A,
87     INPUT_USAGE_KEYCODE_B,
88     INPUT_USAGE_KEYCODE_C,
89     INPUT_USAGE_KEYCODE_D,
90     INPUT_USAGE_KEYCODE_E,
91     INPUT_USAGE_KEYCODE_F,
92     INPUT_USAGE_KEYCODE_G,
93     INPUT_USAGE_KEYCODE_H,
94     INPUT_USAGE_KEYCODE_I,
95     INPUT_USAGE_KEYCODE_J,
96     INPUT_USAGE_KEYCODE_K,
97     INPUT_USAGE_KEYCODE_L,
98     INPUT_USAGE_KEYCODE_M,
99     INPUT_USAGE_KEYCODE_N,
100     INPUT_USAGE_KEYCODE_O,
101     INPUT_USAGE_KEYCODE_P,
102     INPUT_USAGE_KEYCODE_Q,
103     INPUT_USAGE_KEYCODE_R,
104     INPUT_USAGE_KEYCODE_S,
105     INPUT_USAGE_KEYCODE_T,
106     INPUT_USAGE_KEYCODE_U,
107     INPUT_USAGE_KEYCODE_V,
108     INPUT_USAGE_KEYCODE_W,
109     INPUT_USAGE_KEYCODE_X,
110     INPUT_USAGE_KEYCODE_Y,
111     INPUT_USAGE_KEYCODE_Z,
112     INPUT_USAGE_KEYCODE_COMMA,
113     INPUT_USAGE_KEYCODE_PERIOD,
114     INPUT_USAGE_KEYCODE_ALT_LEFT,
115     INPUT_USAGE_KEYCODE_ALT_RIGHT,
116     INPUT_USAGE_KEYCODE_SHIFT_LEFT,
117     INPUT_USAGE_KEYCODE_SHIFT_RIGHT,
118     INPUT_USAGE_KEYCODE_TAB,
119     INPUT_USAGE_KEYCODE_SPACE,
120     INPUT_USAGE_KEYCODE_SYM,
121     INPUT_USAGE_KEYCODE_EXPLORER,
122     INPUT_USAGE_KEYCODE_ENVELOPE,
123     INPUT_USAGE_KEYCODE_ENTER,
124     INPUT_USAGE_KEYCODE_DEL,
125     INPUT_USAGE_KEYCODE_GRAVE,
126     INPUT_USAGE_KEYCODE_MINUS,
127     INPUT_USAGE_KEYCODE_EQUALS,
128     INPUT_USAGE_KEYCODE_LEFT_BRACKET,
129     INPUT_USAGE_KEYCODE_RIGHT_BRACKET,
130     INPUT_USAGE_KEYCODE_BACKSLASH,
131     INPUT_USAGE_KEYCODE_SEMICOLON,
132     INPUT_USAGE_KEYCODE_APOSTROPHE,
133     INPUT_USAGE_KEYCODE_SLASH,
134     INPUT_USAGE_KEYCODE_AT,
135     INPUT_USAGE_KEYCODE_NUM,
136     INPUT_USAGE_KEYCODE_HEADSETHOOK,
137     INPUT_USAGE_KEYCODE_FOCUS,   // *Camera* focus
138     INPUT_USAGE_KEYCODE_PLUS,
139     INPUT_USAGE_KEYCODE_MENU,
140     INPUT_USAGE_KEYCODE_NOTIFICATION,
141     INPUT_USAGE_KEYCODE_SEARCH,
142     INPUT_USAGE_KEYCODE_MEDIA_PLAY_PAUSE,
143     INPUT_USAGE_KEYCODE_MEDIA_STOP,
144     INPUT_USAGE_KEYCODE_MEDIA_NEXT,
145     INPUT_USAGE_KEYCODE_MEDIA_PREVIOUS,
146     INPUT_USAGE_KEYCODE_MEDIA_REWIND,
147     INPUT_USAGE_KEYCODE_MEDIA_FAST_FORWARD,
148     INPUT_USAGE_KEYCODE_MUTE,
149     INPUT_USAGE_KEYCODE_PAGE_UP,
150     INPUT_USAGE_KEYCODE_PAGE_DOWN,
151     INPUT_USAGE_KEYCODE_PICTSYMBOLS,
152     INPUT_USAGE_KEYCODE_SWITCH_CHARSET,
153     INPUT_USAGE_KEYCODE_BUTTON_A,
154     INPUT_USAGE_KEYCODE_BUTTON_B,
155     INPUT_USAGE_KEYCODE_BUTTON_C,
156     INPUT_USAGE_KEYCODE_BUTTON_X,
157     INPUT_USAGE_KEYCODE_BUTTON_Y,
158     INPUT_USAGE_KEYCODE_BUTTON_Z,
159     INPUT_USAGE_KEYCODE_BUTTON_L1,
160     INPUT_USAGE_KEYCODE_BUTTON_R1,
161     INPUT_USAGE_KEYCODE_BUTTON_L2,
162     INPUT_USAGE_KEYCODE_BUTTON_R2,
163     INPUT_USAGE_KEYCODE_BUTTON_THUMBL,
164     INPUT_USAGE_KEYCODE_BUTTON_THUMBR,
165     INPUT_USAGE_KEYCODE_BUTTON_START,
166     INPUT_USAGE_KEYCODE_BUTTON_SELECT,
167     INPUT_USAGE_KEYCODE_BUTTON_MODE,
168     INPUT_USAGE_KEYCODE_ESCAPE,
169     INPUT_USAGE_KEYCODE_FORWARD_DEL,
170     INPUT_USAGE_KEYCODE_CTRL_LEFT,
171     INPUT_USAGE_KEYCODE_CTRL_RIGHT,
172     INPUT_USAGE_KEYCODE_CAPS_LOCK,
173     INPUT_USAGE_KEYCODE_SCROLL_LOCK,
174     INPUT_USAGE_KEYCODE_META_LEFT,
175     INPUT_USAGE_KEYCODE_META_RIGHT,
176     INPUT_USAGE_KEYCODE_FUNCTION,
177     INPUT_USAGE_KEYCODE_SYSRQ,
178     INPUT_USAGE_KEYCODE_BREAK,
179     INPUT_USAGE_KEYCODE_MOVE_HOME,
180     INPUT_USAGE_KEYCODE_MOVE_END,
181     INPUT_USAGE_KEYCODE_INSERT,
182     INPUT_USAGE_KEYCODE_FORWARD,
183     INPUT_USAGE_KEYCODE_MEDIA_PLAY,
184     INPUT_USAGE_KEYCODE_MEDIA_PAUSE,
185     INPUT_USAGE_KEYCODE_MEDIA_CLOSE,
186     INPUT_USAGE_KEYCODE_MEDIA_EJECT,
187     INPUT_USAGE_KEYCODE_MEDIA_RECORD,
188     INPUT_USAGE_KEYCODE_F1,
189     INPUT_USAGE_KEYCODE_F2,
190     INPUT_USAGE_KEYCODE_F3,
191     INPUT_USAGE_KEYCODE_F4,
192     INPUT_USAGE_KEYCODE_F5,
193     INPUT_USAGE_KEYCODE_F6,
194     INPUT_USAGE_KEYCODE_F7,
195     INPUT_USAGE_KEYCODE_F8,
196     INPUT_USAGE_KEYCODE_F9,
197     INPUT_USAGE_KEYCODE_F10,
198     INPUT_USAGE_KEYCODE_F11,
199     INPUT_USAGE_KEYCODE_F12,
200     INPUT_USAGE_KEYCODE_NUM_LOCK,
201     INPUT_USAGE_KEYCODE_NUMPAD_0,
202     INPUT_USAGE_KEYCODE_NUMPAD_1,
203     INPUT_USAGE_KEYCODE_NUMPAD_2,
204     INPUT_USAGE_KEYCODE_NUMPAD_3,
205     INPUT_USAGE_KEYCODE_NUMPAD_4,
206     INPUT_USAGE_KEYCODE_NUMPAD_5,
207     INPUT_USAGE_KEYCODE_NUMPAD_6,
208     INPUT_USAGE_KEYCODE_NUMPAD_7,
209     INPUT_USAGE_KEYCODE_NUMPAD_8,
210     INPUT_USAGE_KEYCODE_NUMPAD_9,
211     INPUT_USAGE_KEYCODE_NUMPAD_DIVIDE,
212     INPUT_USAGE_KEYCODE_NUMPAD_MULTIPLY,
213     INPUT_USAGE_KEYCODE_NUMPAD_SUBTRACT,
214     INPUT_USAGE_KEYCODE_NUMPAD_ADD,
215     INPUT_USAGE_KEYCODE_NUMPAD_DOT,
216     INPUT_USAGE_KEYCODE_NUMPAD_COMMA,
217     INPUT_USAGE_KEYCODE_NUMPAD_ENTER,
218     INPUT_USAGE_KEYCODE_NUMPAD_EQUALS,
219     INPUT_USAGE_KEYCODE_NUMPAD_LEFT_PAREN,
220     INPUT_USAGE_KEYCODE_NUMPAD_RIGHT_PAREN,
221     INPUT_USAGE_KEYCODE_VOLUME_MUTE,
222     INPUT_USAGE_KEYCODE_INFO,
223     INPUT_USAGE_KEYCODE_CHANNEL_UP,
224     INPUT_USAGE_KEYCODE_CHANNEL_DOWN,
225     INPUT_USAGE_KEYCODE_ZOOM_IN,
226     INPUT_USAGE_KEYCODE_ZOOM_OUT,
227     INPUT_USAGE_KEYCODE_TV,
228     INPUT_USAGE_KEYCODE_WINDOW,
229     INPUT_USAGE_KEYCODE_GUIDE,
230     INPUT_USAGE_KEYCODE_DVR,
231     INPUT_USAGE_KEYCODE_BOOKMARK,
232     INPUT_USAGE_KEYCODE_CAPTIONS,
233     INPUT_USAGE_KEYCODE_SETTINGS,
234     INPUT_USAGE_KEYCODE_TV_POWER,
235     INPUT_USAGE_KEYCODE_TV_INPUT,
236     INPUT_USAGE_KEYCODE_STB_POWER,
237     INPUT_USAGE_KEYCODE_STB_INPUT,
238     INPUT_USAGE_KEYCODE_AVR_POWER,
239     INPUT_USAGE_KEYCODE_AVR_INPUT,
240     INPUT_USAGE_KEYCODE_PROG_RED,
241     INPUT_USAGE_KEYCODE_PROG_GREEN,
242     INPUT_USAGE_KEYCODE_PROG_YELLOW,
243     INPUT_USAGE_KEYCODE_PROG_BLUE,
244     INPUT_USAGE_KEYCODE_APP_SWITCH,
245     INPUT_USAGE_KEYCODE_BUTTON_1,
246     INPUT_USAGE_KEYCODE_BUTTON_2,
247     INPUT_USAGE_KEYCODE_BUTTON_3,
248     INPUT_USAGE_KEYCODE_BUTTON_4,
249     INPUT_USAGE_KEYCODE_BUTTON_5,
250     INPUT_USAGE_KEYCODE_BUTTON_6,
251     INPUT_USAGE_KEYCODE_BUTTON_7,
252     INPUT_USAGE_KEYCODE_BUTTON_8,
253     INPUT_USAGE_KEYCODE_BUTTON_9,
254     INPUT_USAGE_KEYCODE_BUTTON_10,
255     INPUT_USAGE_KEYCODE_BUTTON_11,
256     INPUT_USAGE_KEYCODE_BUTTON_12,
257     INPUT_USAGE_KEYCODE_BUTTON_13,
258     INPUT_USAGE_KEYCODE_BUTTON_14,
259     INPUT_USAGE_KEYCODE_BUTTON_15,
260     INPUT_USAGE_KEYCODE_BUTTON_16,
261     INPUT_USAGE_KEYCODE_LANGUAGE_SWITCH,
262     INPUT_USAGE_KEYCODE_MANNER_MODE,
263     INPUT_USAGE_KEYCODE_3D_MODE,
264     INPUT_USAGE_KEYCODE_CONTACTS,
265     INPUT_USAGE_KEYCODE_CALENDAR,
266     INPUT_USAGE_KEYCODE_MUSIC,
267     INPUT_USAGE_KEYCODE_CALCULATOR,
268     INPUT_USAGE_KEYCODE_ZENKAKU_HANKAKU,
269     INPUT_USAGE_KEYCODE_EISU,
270     INPUT_USAGE_KEYCODE_MUHENKAN,
271     INPUT_USAGE_KEYCODE_HENKAN,
272     INPUT_USAGE_KEYCODE_KATAKANA_HIRAGANA,
273     INPUT_USAGE_KEYCODE_YEN,
274     INPUT_USAGE_KEYCODE_RO,
275     INPUT_USAGE_KEYCODE_KANA,
276     INPUT_USAGE_KEYCODE_ASSIST,
277     INPUT_USAGE_KEYCODE_BRIGHTNESS_DOWN,
278     INPUT_USAGE_KEYCODE_BRIGHTNESS_UP,
279     INPUT_USAGE_KEYCODE_MEDIA_AUDIO_TRACK,
280     INPUT_USAGE_KEYCODE_SLEEP,
281     INPUT_USAGE_KEYCODE_WAKEUP,
282     INPUT_USAGE_KEYCODE_PAIRING,
283     INPUT_USAGE_KEYCODE_MEDIA_TOP_MENU,
284     INPUT_USAGE_KEYCODE_11,
285     INPUT_USAGE_KEYCODE_12,
286     INPUT_USAGE_KEYCODE_LAST_CHANNEL,
287     INPUT_USAGE_KEYCODE_TV_DATA_SERVICE,
288     INPUT_USAGE_KEYCODE_VOICE_ASSIST,
289     INPUT_USAGE_KEYCODE_TV_RADIO_SERVICE,
290     INPUT_USAGE_KEYCODE_TV_TELETEXT,
291     INPUT_USAGE_KEYCODE_TV_NUMBER_ENTRY,
292     INPUT_USAGE_KEYCODE_TV_TERRESTRIAL_ANALOG,
293     INPUT_USAGE_KEYCODE_TV_TERRESTRIAL_DIGITAL,
294     INPUT_USAGE_KEYCODE_TV_SATELLITE,
295     INPUT_USAGE_KEYCODE_TV_SATELLITE_BS,
296     INPUT_USAGE_KEYCODE_TV_SATELLITE_CS,
297     INPUT_USAGE_KEYCODE_TV_SATELLITE_SERVICE,
298     INPUT_USAGE_KEYCODE_TV_NETWORK,
299     INPUT_USAGE_KEYCODE_TV_ANTENNA_CABLE,
300     INPUT_USAGE_KEYCODE_TV_INPUT_HDMI_1,
301     INPUT_USAGE_KEYCODE_TV_INPUT_HDMI_2,
302     INPUT_USAGE_KEYCODE_TV_INPUT_HDMI_3,
303     INPUT_USAGE_KEYCODE_TV_INPUT_HDMI_4,
304     INPUT_USAGE_KEYCODE_TV_INPUT_COMPOSITE_1,
305     INPUT_USAGE_KEYCODE_TV_INPUT_COMPOSITE_2,
306     INPUT_USAGE_KEYCODE_TV_INPUT_COMPONENT_1,
307     INPUT_USAGE_KEYCODE_TV_INPUT_COMPONENT_2,
308     INPUT_USAGE_KEYCODE_TV_INPUT_VGA_1,
309     INPUT_USAGE_KEYCODE_TV_AUDIO_DESCRIPTION,
310     INPUT_USAGE_KEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP,
311     INPUT_USAGE_KEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN,
312     INPUT_USAGE_KEYCODE_TV_ZOOM_MODE,
313     INPUT_USAGE_KEYCODE_TV_CONTENTS_MENU,
314     INPUT_USAGE_KEYCODE_TV_MEDIA_CONTEXT_MENU,
315     INPUT_USAGE_KEYCODE_TV_TIMER_PROGRAMMING,
316     INPUT_USAGE_KEYCODE_HELP,
317 
318     // axes
319     INPUT_USAGE_AXIS_X,
320     INPUT_USAGE_AXIS_Y,
321     INPUT_USAGE_AXIS_Z,
322     INPUT_USAGE_AXIS_RX,
323     INPUT_USAGE_AXIS_RY,
324     INPUT_USAGE_AXIS_RZ,
325     INPUT_USAGE_AXIS_HAT_X,
326     INPUT_USAGE_AXIS_HAT_Y,
327     INPUT_USAGE_AXIS_PRESSURE,
328     INPUT_USAGE_AXIS_SIZE,
329     INPUT_USAGE_AXIS_TOUCH_MAJOR,
330     INPUT_USAGE_AXIS_TOUCH_MINOR,
331     INPUT_USAGE_AXIS_TOOL_MAJOR,
332     INPUT_USAGE_AXIS_TOOL_MINOR,
333     INPUT_USAGE_AXIS_ORIENTATION,
334     INPUT_USAGE_AXIS_VSCROLL,
335     INPUT_USAGE_AXIS_HSCROLL,
336     INPUT_USAGE_AXIS_LTRIGGER,
337     INPUT_USAGE_AXIS_RTRIGGER,
338     INPUT_USAGE_AXIS_THROTTLE,
339     INPUT_USAGE_AXIS_RUDDER,
340     INPUT_USAGE_AXIS_WHEEL,
341     INPUT_USAGE_AXIS_GAS,
342     INPUT_USAGE_AXIS_BRAKE,
343     INPUT_USAGE_AXIS_DISTANCE,
344     INPUT_USAGE_AXIS_TILT,
345     INPUT_USAGE_AXIS_GENERIC_1,
346     INPUT_USAGE_AXIS_GENERIC_2,
347     INPUT_USAGE_AXIS_GENERIC_3,
348     INPUT_USAGE_AXIS_GENERIC_4,
349     INPUT_USAGE_AXIS_GENERIC_5,
350     INPUT_USAGE_AXIS_GENERIC_6,
351     INPUT_USAGE_AXIS_GENERIC_7,
352     INPUT_USAGE_AXIS_GENERIC_8,
353     INPUT_USAGE_AXIS_GENERIC_9,
354     INPUT_USAGE_AXIS_GENERIC_10,
355     INPUT_USAGE_AXIS_GENERIC_11,
356     INPUT_USAGE_AXIS_GENERIC_12,
357     INPUT_USAGE_AXIS_GENERIC_13,
358     INPUT_USAGE_AXIS_GENERIC_14,
359     INPUT_USAGE_AXIS_GENERIC_15,
360     INPUT_USAGE_AXIS_GENERIC_16,
361 
362     // leds
363     INPUT_USAGE_LED_NUM_LOCK,
364     INPUT_USAGE_LED_CAPS_LOCK,
365     INPUT_USAGE_LED_SCROLL_LOCK,
366     INPUT_USAGE_LED_COMPOSE,
367     INPUT_USAGE_LED_KANA,
368     INPUT_USAGE_LED_SLEEP,
369     INPUT_USAGE_LED_SUSPEND,
370     INPUT_USAGE_LED_MUTE,
371     INPUT_USAGE_LED_MISC,
372     INPUT_USAGE_LED_MAIL,
373     INPUT_USAGE_LED_CHARGING,
374     INPUT_USAGE_LED_CONTROLLER_1,
375     INPUT_USAGE_LED_CONTROLLER_2,
376     INPUT_USAGE_LED_CONTROLLER_3,
377     INPUT_USAGE_LED_CONTROLLER_4,
378 
379     // switches
380     INPUT_USAGE_SWITCH_UNKNOWN,
381     INPUT_USAGE_SWITCH_LID,
382     INPUT_USAGE_SWITCH_KEYPAD_SLIDE,
383     INPUT_USAGE_SWITCH_HEADPHONE_INSERT,
384     INPUT_USAGE_SWITCH_MICROPHONE_INSERT,
385     INPUT_USAGE_SWITCH_LINEOUT_INSERT,
386     INPUT_USAGE_SWITCH_CAMERA_LENS_COVER,
387 
388     // mouse buttons
389     // (see android.view.MotionEvent)
390     INPUT_USAGE_BUTTON_UNKNOWN,
391     INPUT_USAGE_BUTTON_PRIMARY,   // left
392     INPUT_USAGE_BUTTON_SECONDARY, // right
393     INPUT_USAGE_BUTTON_TERTIARY,  // middle
394     INPUT_USAGE_BUTTON_FORWARD,
395     INPUT_USAGE_BUTTON_BACK,
396 } input_usage_t;
397 
398 typedef enum input_collection_id {
399     INPUT_COLLECTION_ID_TOUCH,
400     INPUT_COLLECTION_ID_KEYBOARD,
401     INPUT_COLLECTION_ID_MOUSE,
402     INPUT_COLLECTION_ID_TOUCHPAD,
403     INPUT_COLLECTION_ID_SWITCH,
404     // etc
405 } input_collection_id_t;
406 
407 typedef struct input_message input_message_t;
408 
409 typedef struct input_host_callbacks {
410 
411     /**
412      * Creates a device identifier with the given properties.
413      * The unique ID should be a string that precisely identifies a given piece of hardware. For
414      * example, an input device connected via Bluetooth could use its MAC address as its unique ID.
415      */
416     input_device_identifier_t* (*create_device_identifier)(input_host_t* host,
417             const char* name, int32_t product_id, int32_t vendor_id,
418             input_bus_t bus, const char* unique_id);
419 
420     /**
421      * Allocates the device definition which will describe the input capabilities of a device. A
422      * device definition may be used to register as many devices as desired.
423      */
424     input_device_definition_t* (*create_device_definition)(input_host_t* host);
425 
426     /**
427      * Allocate either an input report, which the HAL will use to tell the host of incoming input
428      * events, or an output report, which the host will use to tell the HAL of desired state
429      * changes (e.g. setting an LED).
430      */
431     input_report_definition_t* (*create_input_report_definition)(input_host_t* host);
432     input_report_definition_t* (*create_output_report_definition)(input_host_t* host);
433 
434     /**
435      * Frees the report definition.
436      */
437     void (*free_report_definition)(input_host_t* host, input_report_definition_t* report_def);
438 
439     /**
440      * Append the report to the given input device.
441      */
442     void (*input_device_definition_add_report)(input_host_t* host,
443             input_device_definition_t* d, input_report_definition_t* r);
444 
445     /**
446      * Add a collection with the given arity and ID. A collection describes a set
447      * of logically grouped properties such as the X and Y coordinates of a single finger touch or
448      * the set of keys on a keyboard. The arity declares how many repeated instances of this
449      * collection will appear in whatever report it is attached to. The ID describes the type of
450      * grouping being represented by the collection. For example, a touchscreen capable of
451      * reporting up to 2 fingers simultaneously might have a collection with the X and Y
452      * coordinates, an arity of 2, and an ID of INPUT_COLLECTION_USAGE_TOUCHSCREEN. Any given ID
453      * may only be present once for a given report.
454      */
455     void (*input_report_definition_add_collection)(input_host_t* host,
456             input_report_definition_t* report, input_collection_id_t id, int32_t arity);
457 
458     /**
459      * Declare an int usage with the given properties. The report and collection defines where the
460      * usage is being declared.
461      */
462     void (*input_report_definition_declare_usage_int)(input_host_t* host,
463             input_report_definition_t* report, input_collection_id_t id,
464             input_usage_t usage, int32_t min, int32_t max, float resolution);
465 
466     /**
467      * Declare a set of boolean usages with the given properties.  The report and collection
468      * defines where the usages are being declared.
469      */
470     void (*input_report_definition_declare_usages_bool)(input_host_t* host,
471             input_report_definition_t* report, input_collection_id_t id,
472             input_usage_t* usage, size_t usage_count);
473 
474 
475     /**
476      * Register a given input device definition. This notifies the host that an input device has
477      * been connected and gives a description of all its capabilities.
478      */
479     input_device_handle_t* (*register_device)(input_host_t* host,
480             input_device_identifier_t* id, input_device_definition_t* d);
481 
482     /** Unregister the given device */
483     void (*unregister_device)(input_host_t* host, input_device_handle_t* handle);
484 
485     /**
486      * Allocate a report that will contain all of the state as described by the given report.
487      */
488     input_report_t* (*input_allocate_report)(input_host_t* host, input_report_definition_t* r);
489 
490     /**
491      * Add an int usage value to a report.
492      */
493     void (*input_report_set_usage_int)(input_host_t* host, input_report_t* r,
494             input_collection_id_t id, input_usage_t usage, int32_t value, int32_t arity_index);
495 
496     /**
497      * Add a boolean usage value to a report.
498      */
499     void (*input_report_set_usage_bool)(input_host_t* host, input_report_t* r,
500             input_collection_id_t id, input_usage_t usage, bool value, int32_t arity_index);
501 
502     void (*report_event)(input_host_t* host, input_device_handle_t* d, input_report_t* report);
503 
504     /**
505      * Retrieve the set of properties for the device. The returned
506      * input_property_map_t* may be used to query specific properties via the
507      * input_get_device_property callback.
508      */
509     input_property_map_t* (*input_get_device_property_map)(input_host_t* host,
510             input_device_identifier_t* id);
511     /**
512      * Retrieve a property for the device with the given key. Returns NULL if
513      * the key does not exist, or an input_property_t* that must be freed using
514      * input_free_device_property(). Using an input_property_t after the
515      * corresponding input_property_map_t is freed is undefined.
516      */
517     input_property_t* (*input_get_device_property)(input_host_t* host,
518             input_property_map_t* map, const char* key);
519 
520     /**
521      * Get the key for the input property. Returns NULL if the property is NULL.
522      * The returned const char* is owned by the input_property_t.
523      */
524     const char* (*input_get_property_key)(input_host_t* host, input_property_t* property);
525 
526     /**
527      * Get the value for the input property. Returns NULL if the property is
528      * NULL. The returned const char* is owned by the input_property_t.
529      */
530     const char* (*input_get_property_value)(input_host_t* host, input_property_t* property);
531 
532     /**
533      * Frees the input_property_t*.
534      */
535     void (*input_free_device_property)(input_host_t* host, input_property_t* property);
536 
537     /**
538      * Frees the input_property_map_t*.
539      */
540     void (*input_free_device_property_map)(input_host_t* host, input_property_map_t* map);
541 } input_host_callbacks_t;
542 
543 typedef struct input_module input_module_t;
544 
545 struct input_module {
546     /**
547      * Common methods of the input module. This *must* be the first member
548      * of input_module as users of this structure will cast a hw_module_t
549      * to input_module pointer in contexts where it's known
550      * the hw_module_t references a input_module.
551      */
552     struct hw_module_t common;
553 
554     /**
555      * Initialize the module with host callbacks. At this point the HAL should start up whatever
556      * infrastructure it needs to in order to process input events.
557      */
558     void (*init)(const input_module_t* module, input_host_t* host, input_host_callbacks_t cb);
559 
560     /**
561      * Sends an output report with a new set of state the host would like the given device to
562      * assume.
563      */
564     void (*notify_report)(const input_module_t* module, input_report_t* report);
565 };
566 
input_open(const struct hw_module_t ** module,const char * type)567 static inline int input_open(const struct hw_module_t** module, const char* type) {
568     return hw_get_module_by_class(INPUT_HARDWARE_MODULE_ID, type, module);
569 }
570 
571 __END_DECLS
572 
573 #endif  /* ANDROID_INCLUDE_HARDWARE_INPUT_H */
574