blob: dad1bc09751a38506a32623a0d52ecc1feb60c1e [file] [log] [blame]
Michael Wright5113aff2015-02-13 17:31:41 -08001/*
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
30typedef enum input_bus {
31 INPUT_BUS_BT,
32 INPUT_BUS_USB,
33 INPUT_BUS_SERIAL,
34 INPUT_BUS_BUILTIN
35} input_bus_t;
36
37typedef struct input_host input_host_t;
38
39typedef struct input_device_handle input_device_handle_t;
40
41typedef struct input_device_identifier input_device_identifier_t;
42
43typedef struct input_device_definition input_device_definition_t;
44
45typedef struct input_report_definition input_report_definition_t;
46
47typedef struct input_report input_report_t;
48
49typedef struct input_collection input_collection_t;
50
51typedef enum {
52 INPUT_USAGE_TOUCHPAD_X,
53 INPUT_USAGE_TOUCHPAD_Y,
54 // etc
55} input_usage_t;
56
57typedef enum {
58 INPUT_COLLECTION_ID_TOUCH,
59 INPUT_COLLECTION_ID_KEYBOARD,
60 INPUT_COLLECTION_ID_MOUSE,
61 INPUT_COLLECTION_ID_TOUCHPAD,
62 // etc
63} input_collection_id_t;
64
65typedef struct input_message input_message_t;
66
67typedef struct input_host_callbacks {
68
69 /**
70 * Creates a device identifier with the given properties.
71 * The unique ID should be a string that precisely identifies a given piece of hardware. For
72 * example, an input device connected via Bluetooth could use its MAC address as its unique ID.
73 */
74 input_device_identifier_t* (*create_device_identifier)(input_host_t* host,
75 const char* name, int32_t product_id, int32_t vendor_id,
76 input_bus_t bus, const char* unique_id);
77
78 /**
79 * Allocates the device definition which will describe the input capabilities of a device. A
80 * device definition may be used to register as many devices as desired.
81 */
82 input_device_definition_t* (*create_device_definition)(input_host_t* host);
83
84 /**
85 * Allocate either an input report, which the HAL will use to tell the host of incoming input
86 * events, or an output report, which the host will use to tell the HAL of desired state
87 * changes (e.g. setting an LED).
88 */
89 input_report_definition_t* (*create_input_report_definition)(input_host_t* host);
90 input_report_definition_t* (*create_output_report_definition)(input_host_t* host);
91
92 /**
93 * Append the report to the given input device.
94 */
95 void (*input_device_definition_add_report)(input_host_t* host,
96 input_device_definition_t* d, input_report_definition_t* r);
97
98 /**
99 * Add a collection with the given arity and ID. A collection describes a set
100 * of logically grouped properties such as the X and Y coordinates of a single finger touch or
101 * the set of keys on a keyboard. The arity declares how many repeated instances of this
102 * collection will appear in whatever report it is attached to. The ID describes the type of
103 * grouping being represented by the collection. For example, a touchscreen capable of
104 * reporting up to 2 fingers simultaneously might have a collection with the X and Y
105 * coordinates, an arity of 2, and an ID of INPUT_COLLECTION_USAGE_TOUCHSCREEN. Any given ID
106 * may only be present once for a given report.
107 */
108 void (*input_report_definition_add_collection)(input_host_t* host,
109 input_report_definition_t* report, input_collection_id_t id, int32_t arity);
110
111 /**
112 * Declare an int usage with the given properties. The report and collection defines where the
113 * usage is being declared.
114 */
115 void (*input_report_definition_declare_usage_int)(input_host_t* host,
116 input_report_definition_t* report, input_collection_id_t id,
117 input_usage_t usage, int32_t min, int32_t max, float resolution);
118
119 /**
120 * Declare a set of boolean usages with the given properties. The report and collection
121 * defines where the usages are being declared.
122 */
123 void (*input_report_definition_declare_usages_bool)(input_host_t* host,
124 input_report_definition_t* report, input_collection_id_t id,
125 input_usage_t* usage, size_t usage_count);
126
127
128 /**
129 * Register a given input device definition. This notifies the host that an input device has
130 * been connected and gives a description of all its capabilities.
131 */
132 input_device_handle_t* (*register_device)(input_host_t* host,
133 input_device_identifier_t* id, input_device_definition_t* d);
134
135 /** Unregister the given device */
136 void (*unregister_device)(input_host_t* host, input_device_handle_t* handle);
137
138 /**
139 * Allocate a report that will contain all of the state as described by the given report.
140 */
141 input_report_t* (*input_allocate_report)(input_host_t* host, input_report_definition_t* r);
142
143 void (*report_event)(input_host_t* host, input_device_handle_t* d, input_report_t* report);
144} input_host_callbacks_t;
145
146typedef struct input_module input_module_t;
147
148struct input_module {
149 /**
150 * Common methods of the input module. This *must* be the first member
151 * of input_module as users of this structure will cast a hw_module_t
152 * to input_module pointer in contexts where it's known
153 * the hw_module_t references a input_module.
154 */
155 struct hw_module_t common;
156
157 /**
158 * Initialize the module with host callbacks. At this point the HAL should start up whatever
159 * infrastructure it needs to in order to process input events.
160 */
161 void (*init)(const input_module_t* module, input_host_t* host, input_host_callbacks_t cb);
162
163 /**
164 * Sends an output report with a new set of state the host would like the given device to
165 * assume.
166 */
167 void (*notify_report)(input_report_t* report);
168};
169
170static inline int input_open(const struct hw_module_t** module, const char* type) {
171 return hw_get_module_by_class(INPUT_HARDWARE_MODULE_ID, type, module);
172}
173
174__END_DECLS
175
176#endif /* ANDROID_INCLUDE_HARDWARE_INPUT_H */