blob: 6e7ac5d0d8cd39e1d6c22e6a1d9294af53cad55d [file] [log] [blame]
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001/*
Mathias Agopiana4557722012-11-28 17:21:55 -08002 * Copyright (C) 2012 The Android Open Source Project
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08003 *
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_SENSORS_INTERFACE_H
18#define ANDROID_SENSORS_INTERFACE_H
19
20#include <stdint.h>
21#include <sys/cdefs.h>
22#include <sys/types.h>
23
24#include <hardware/hardware.h>
Mike Lockwood21b652f2009-05-22 10:05:48 -040025#include <cutils/native_handle.h>
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080026
27__BEGIN_DECLS
28
Mathias Agopian56f66cc2012-11-08 15:57:38 -080029/*****************************************************************************/
30
31#define SENSORS_HEADER_VERSION 1
32#define SENSORS_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
33#define SENSORS_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, SENSORS_HEADER_VERSION)
Mathias Agopiana4557722012-11-28 17:21:55 -080034#define SENSORS_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION_2(1, 0, SENSORS_HEADER_VERSION)
Mathias Agopian16671c52013-07-24 21:07:40 -070035#define SENSORS_DEVICE_API_VERSION_1_1 HARDWARE_DEVICE_API_VERSION_2(1, 1, SENSORS_HEADER_VERSION)
Mathias Agopian56f66cc2012-11-08 15:57:38 -080036
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080037/**
38 * The id of this module
39 */
40#define SENSORS_HARDWARE_MODULE_ID "sensors"
41
42/**
43 * Name of the sensors device to open
44 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -070045#define SENSORS_HARDWARE_POLL "poll"
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080046
47/**
48 * Handles must be higher than SENSORS_HANDLE_BASE and must be unique.
49 * A Handle identifies a given sensors. The handle is used to activate
50 * and/or deactivate sensors.
51 * In this version of the API there can only be 256 handles.
52 */
53#define SENSORS_HANDLE_BASE 0
54#define SENSORS_HANDLE_BITS 8
55#define SENSORS_HANDLE_COUNT (1<<SENSORS_HANDLE_BITS)
56
57
Mathias Agopiana4557722012-11-28 17:21:55 -080058/*
59 * flags for (*batch)()
60 * Availability: SENSORS_DEVICE_API_VERSION_1_0
61 * see (*batch)() documentation for details
62 */
63enum {
64 SENSORS_BATCH_DRY_RUN = 0x00000001,
65 SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002
66};
67
Mathias Agopian16671c52013-07-24 21:07:40 -070068/*
69 * what field for meta_data_event_t
70 */
71enum {
72 /* a previous flush operation has completed */
Mathias Agopianaf32a8d2013-08-06 20:33:38 -070073 META_DATA_FLUSH_COMPLETE = 1,
74 META_DATA_VERSION /* always last, leave auto-assigned */
Mathias Agopian16671c52013-07-24 21:07:40 -070075};
76
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080077/**
Mathias Agopian56f66cc2012-11-08 15:57:38 -080078 * Definition of the axis used by the sensor HAL API
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080079 *
80 * This API is relative to the screen of the device in its default orientation,
81 * that is, if the device can be used in portrait or landscape, this API
82 * is only relative to the NATURAL orientation of the screen. In other words,
83 * the axis are not swapped when the device's screen orientation changes.
84 * Higher level services /may/ perform this transformation.
85 *
86 * x<0 x>0
87 * ^
88 * |
89 * +-----------+--> y>0
90 * | |
91 * | |
92 * | |
93 * | | / z<0
94 * | | /
95 * | | /
96 * O-----------+/
97 * |[] [ ] []/
98 * +----------/+ y<0
99 * /
100 * /
101 * |/ z>0 (toward the sky)
102 *
103 * O: Origin (x=0,y=0,z=0)
104 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800105 */
106
Mathias Agopiana4557722012-11-28 17:21:55 -0800107/*
108 * Interaction with suspend mode
109 *
110 * Unless otherwise noted, an enabled sensor shall not prevent the
111 * SoC to go into suspend mode. It is the responsibility of applications
112 * to keep a partial wake-lock should they wish to receive sensor
113 * events while the screen is off. While in suspend mode, and unless
Etienne Le Grand28f04112013-03-27 18:59:10 -0700114 * otherwise noted (batch mode, sensor particularities, ...), enabled sensors'
115 * events are lost.
Mathias Agopiana4557722012-11-28 17:21:55 -0800116 *
117 * Note that conceptually, the sensor itself is not de-activated while in
118 * suspend mode -- it's just that the data it returns are lost. As soon as
119 * the SoC gets out of suspend mode, operations resume as usual. Of course,
120 * in practice sensors shall be disabled while in suspend mode to
121 * save power, unless batch mode is active, in which case they must
122 * continue fill their internal FIFO (see the documentation of batch() to
123 * learn how suspend interacts with batch mode).
124 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700125 * In batch mode, and only when the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is
Mathias Agopian1144bea2013-01-29 15:52:10 -0800126 * set and supported, the specified sensor must be able to wake-up the SoC and
127 * be able to buffer at least 10 seconds worth of the requested sensor events.
Mathias Agopiana4557722012-11-28 17:21:55 -0800128 *
129 * There are notable exceptions to this behavior, which are sensor-dependent
130 * (see sensor types definitions below)
131 *
132 *
133 * The sensor type documentation below specifies the wake-up behavior of
134 * each sensor:
135 * wake-up: yes this sensor must wake-up the SoC to deliver events
136 * wake-up: no this sensor shall not wake-up the SoC, events are dropped
137 *
138 */
139
140/*
141 * Sensor type
142 *
143 * Each sensor has a type which defines what this sensor measures and how
144 * measures are reported. All types are defined below.
145 */
146
147/*
148 * Sensor fusion and virtual sensors
149 *
150 * Many sensor types are or can be implemented as virtual sensors from
151 * physical sensors on the device. For instance the rotation vector sensor,
Mathias Agopian2f276f52013-01-28 17:54:41 -0800152 * orientation sensor, step-detector, step-counter, etc...
Mathias Agopiana4557722012-11-28 17:21:55 -0800153 *
154 * From the point of view of this API these virtual sensors MUST appear as
155 * real, individual sensors. It is the responsibility of the driver and HAL
156 * to make sure this is the case.
157 *
158 * In particular, all sensors must be able to function concurrently.
159 * For example, if defining both an accelerometer and a step counter,
160 * then both must be able to work concurrently.
161 */
162
163/*
164 * Trigger modes
165 *
166 * Sensors can report events in different ways called trigger modes,
167 * each sensor type has one and only one trigger mode associated to it.
168 * Currently there are four trigger modes defined:
169 *
170 * continuous: events are reported at a constant rate defined by setDelay().
171 * eg: accelerometers, gyroscopes.
172 * on-change: events are reported only if the sensor's value has changed.
173 * setDelay() is used to set a lower limit to the reporting
174 * period (minimum time between two events).
175 * The HAL must return an event immediately when an on-change
176 * sensor is activated.
177 * eg: proximity, light sensors
Etienne Le Grandca858142013-02-26 19:17:20 -0800178 * one-shot: upon detection of an event, the sensor deactivates itself and
179 * then sends a single event. Order matters to avoid race
180 * conditions. No other event is sent until the sensor get
181 * reactivated. setDelay() is ignored.
Mathias Agopiana4557722012-11-28 17:21:55 -0800182 * eg: significant motion sensor
183 * special: see details in the sensor type specification below
184 *
185 */
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800186
Mathias Agopian16671c52013-07-24 21:07:40 -0700187
188/*
189 * SENSOR_TYPE_META_DATA
190 * trigger-mode: n/a
191 * wake-up sensor: n/a
192 *
193 * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)()
194 *
195 * SENSOR_TYPE_META_DATA is a special token used to populate the
196 * sensors_meta_data_event structure. It doesn't correspond to a physical
197 * sensor. sensors_meta_data_event are special, they exist only inside
198 * the HAL and are generated spontaneously, as opposed to be related to
199 * a physical sensor.
200 *
Mathias Agopianaf32a8d2013-08-06 20:33:38 -0700201 * sensors_meta_data_event_t.version must be META_DATA_VERSION
202 * sensors_meta_data_event_t.sensor must be 0
203 * sensors_meta_data_event_t.type must be SENSOR_TYPE_META_DATA
204 * sensors_meta_data_event_t.reserved must be 0
205 * sensors_meta_data_event_t.timestamp must be 0
Mathias Agopian16671c52013-07-24 21:07:40 -0700206 *
207 * The payload is a meta_data_event_t, where:
208 * meta_data_event_t.what can take the following values:
209 *
210 * META_DATA_FLUSH_COMPLETE
211 * This event indicates that a previous (*flush)() call has completed for the sensor
212 * handle specified in meta_data_event_t.sensor.
213 * see (*flush)() for more details
214 *
215 * All other values for meta_data_event_t.what are reserved and
216 * must not be used.
217 *
218 */
219#define SENSOR_TYPE_META_DATA (0)
220
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800221/*
222 * SENSOR_TYPE_ACCELEROMETER
Mathias Agopiana4557722012-11-28 17:21:55 -0800223 * trigger-mode: continuous
224 * wake-up sensor: no
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800225 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800226 * All values are in SI units (m/s^2) and measure the acceleration of the
227 * device minus the force of gravity.
228 *
229 * Acceleration sensors return sensor events for all 3 axes at a constant
230 * rate defined by setDelay().
231 *
232 * x: Acceleration on the x-axis
233 * y: Acceleration on the y-axis
234 * z: Acceleration on the z-axis
235 *
236 * Note that the readings from the accelerometer include the acceleration
237 * due to gravity (which is opposite to the direction of the gravity vector).
238 *
239 * Examples:
240 * The norm of <x, y, z> should be close to 0 when in free fall.
241 *
242 * When the device lies flat on a table and is pushed on its left side
243 * toward the right, the x acceleration value is positive.
244 *
245 * When the device lies flat on a table, the acceleration value is +9.81,
246 * which correspond to the acceleration of the device (0 m/s^2) minus the
247 * force of gravity (-9.81 m/s^2).
248 *
249 * When the device lies flat on a table and is pushed toward the sky, the
250 * acceleration value is greater than +9.81, which correspond to the
251 * acceleration of the device (+A m/s^2) minus the force of
252 * gravity (-9.81 m/s^2).
253 */
254#define SENSOR_TYPE_ACCELEROMETER (1)
255
256/*
257 * SENSOR_TYPE_GEOMAGNETIC_FIELD
Mathias Agopiana4557722012-11-28 17:21:55 -0800258 * trigger-mode: continuous
259 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800260 *
261 * All values are in micro-Tesla (uT) and measure the geomagnetic
262 * field in the X, Y and Z axis.
263 *
264 * Returned values include calibration mechanisms such that the vector is
265 * aligned with the magnetic declination and heading of the earth's
266 * geomagnetic field.
267 *
268 * Magnetic Field sensors return sensor events for all 3 axes at a constant
269 * rate defined by setDelay().
270 */
271#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2)
272#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
273
274/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800275 * SENSOR_TYPE_ORIENTATION
Mathias Agopiana4557722012-11-28 17:21:55 -0800276 * trigger-mode: continuous
277 * wake-up sensor: no
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800278 *
279 * All values are angles in degrees.
280 *
Mathias Agopian66a40952010-07-22 17:11:50 -0700281 * Orientation sensors return sensor events for all 3 axes at a constant
282 * rate defined by setDelay().
283 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800284 * azimuth: angle between the magnetic north direction and the Y axis, around
285 * the Z axis (0<=azimuth<360).
286 * 0=North, 90=East, 180=South, 270=West
287 *
288 * pitch: Rotation around X axis (-180<=pitch<=180), with positive values when
289 * the z-axis moves toward the y-axis.
290 *
291 * roll: Rotation around Y axis (-90<=roll<=90), with positive values when
Mathias Agopian19ea59f2010-02-26 13:15:18 -0800292 * the x-axis moves towards the z-axis.
293 *
294 * Note: For historical reasons the roll angle is positive in the clockwise
295 * direction (mathematically speaking, it should be positive in the
296 * counter-clockwise direction):
297 *
298 * Z
299 * ^
300 * (+roll) .--> |
301 * / |
302 * | | roll: rotation around Y axis
303 * X <-------(.)
304 * Y
305 * note that +Y == -roll
306 *
307 *
308 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800309 * Note: This definition is different from yaw, pitch and roll used in aviation
310 * where the X axis is along the long side of the plane (tail to nose).
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800311 */
312#define SENSOR_TYPE_ORIENTATION (3)
313
314/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800315 * SENSOR_TYPE_GYROSCOPE
Mathias Agopiana4557722012-11-28 17:21:55 -0800316 * trigger-mode: continuous
317 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800318 *
Kevin Powellb01a0432010-07-19 19:12:15 -0700319 * All values are in radians/second and measure the rate of rotation
320 * around the X, Y and Z axis. The coordinate system is the same as is
Mathias Agopianc04e5f62010-09-14 10:53:55 -0700321 * used for the acceleration sensor. Rotation is positive in the
322 * counter-clockwise direction (right-hand rule). That is, an observer
323 * looking from some positive location on the x, y or z axis at a device
324 * positioned on the origin would report positive rotation if the device
325 * appeared to be rotating counter clockwise. Note that this is the
326 * standard mathematical definition of positive rotation and does not agree
327 * with the definition of roll given earlier.
328 * The range should at least be 17.45 rad/s (ie: ~1000 deg/s).
Kevin Powellb01a0432010-07-19 19:12:15 -0700329 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800330 * automatic gyro-drift compensation is allowed but not required.
331 */
332#define SENSOR_TYPE_GYROSCOPE (4)
333
334/*
335 * SENSOR_TYPE_LIGHT
Mathias Agopiana4557722012-11-28 17:21:55 -0800336 * trigger-mode: on-change
337 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800338 *
339 * The light sensor value is returned in SI lux units.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800340 */
341#define SENSOR_TYPE_LIGHT (5)
342
343/*
344 * SENSOR_TYPE_PRESSURE
Mathias Agopiana4557722012-11-28 17:21:55 -0800345 * trigger-mode: continuous
346 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800347 *
348 * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800349 */
350#define SENSOR_TYPE_PRESSURE (6)
351
352/* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */
353#define SENSOR_TYPE_TEMPERATURE (7)
354
355/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800356 * SENSOR_TYPE_PROXIMITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800357 * trigger-mode: on-change
358 * wake-up sensor: yes
Mike Lockwooda2414312009-11-03 10:29:50 -0500359 *
360 * The distance value is measured in centimeters. Note that some proximity
361 * sensors only support a binary "close" or "far" measurement. In this case,
362 * the sensor should report its maxRange value in the "far" state and a value
363 * less than maxRange in the "near" state.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800364 */
365#define SENSOR_TYPE_PROXIMITY (8)
366
367/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800368 * SENSOR_TYPE_GRAVITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800369 * trigger-mode: continuous
370 * wake-up sensor: no
Mathias Agopian42b743c2010-11-22 15:55:32 -0800371 *
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800372 * A gravity output indicates the direction of and magnitude of gravity in
373 * the devices's coordinates. On Earth, the magnitude is 9.8 m/s^2.
374 * Units are m/s^2. The coordinate system is the same as is used for the
375 * acceleration sensor. When the device is at rest, the output of the
376 * gravity sensor should be identical to that of the accelerometer.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800377 */
378#define SENSOR_TYPE_GRAVITY (9)
379
380/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800381 * SENSOR_TYPE_LINEAR_ACCELERATION
Mathias Agopiana4557722012-11-28 17:21:55 -0800382 * trigger-mode: continuous
383 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800384 *
385 * Indicates the linear acceleration of the device in device coordinates,
386 * not including gravity.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800387 *
388 * The output is conceptually:
389 * output of TYPE_ACCELERATION - output of TYPE_GRAVITY
390 *
391 * Readings on all axes should be close to 0 when device lies on a table.
392 * Units are m/s^2.
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800393 * The coordinate system is the same as is used for the acceleration sensor.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800394 */
395#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
396
397
398/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800399 * SENSOR_TYPE_ROTATION_VECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800400 * trigger-mode: continuous
401 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800402 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700403 * The rotation vector symbolizes the orientation of the device relative to the
404 * East-North-Up coordinates frame. It is usually obtained by integration of
405 * accelerometer, gyroscope and magnetometer readings.
Mathias Agopian42b743c2010-11-22 15:55:32 -0800406 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700407 * The East-North-Up coordinate system is defined as a direct orthonormal basis
Mathias Agopiand93ff972011-05-02 19:10:31 -0700408 * where:
Etienne Le Grand28f04112013-03-27 18:59:10 -0700409 * - X points east and is tangential to the ground.
410 * - Y points north and is tangential to the ground.
Mathias Agopiand93ff972011-05-02 19:10:31 -0700411 * - Z points towards the sky and is perpendicular to the ground.
412 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700413 * The orientation of the phone is represented by the rotation necessary to
414 * align the East-North-Up coordinates with the phone's coordinates. That is,
415 * applying the rotation to the world frame (X,Y,Z) would align them with the
416 * phone coordinates (x,y,z).
Mathias Agopiand93ff972011-05-02 19:10:31 -0700417 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700418 * The rotation can be seen as rotating the phone by an angle theta around
419 * an axis rot_axis to go from the reference (East-North-Up aligned) device
420 * orientation to the current device orientation.
Mathias Agopian42b743c2010-11-22 15:55:32 -0800421 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700422 * The rotation is encoded as the 4 (reordered) components of a unit quaternion:
423 * sensors_event_t.data[0] = rot_axis.x*sin(theta/2)
424 * sensors_event_t.data[1] = rot_axis.y*sin(theta/2)
425 * sensors_event_t.data[2] = rot_axis.z*sin(theta/2)
426 * sensors_event_t.data[3] = cos(theta/2)
427 * where
428 * - rot_axis.x,y,z are the North-East-Up coordinates of a unit length vector
429 * representing the rotation axis
430 * - theta is the rotation angle
431 *
432 * The quaternion must be of norm 1 (it is a unit quaternion). Failure to ensure
433 * this will cause erratic client behaviour.
Etienne Le Grandca858142013-02-26 19:17:20 -0800434 *
435 * In addition, this sensor reports an estimated heading accuracy.
Etienne Le Grand28f04112013-03-27 18:59:10 -0700436 * sensors_event_t.data[4] = estimated_accuracy (in radians)
Etienne Le Grandca858142013-02-26 19:17:20 -0800437 * The heading error must be less than estimated_accuracy 95% of the time
438 *
439 * This sensor must use a gyroscope and an accelerometer as main orientation
440 * change input.
441 *
442 * This sensor can also include magnetometer input to make up for gyro drift,
443 * but it cannot be implemented using only a magnetometer.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800444 */
445#define SENSOR_TYPE_ROTATION_VECTOR (11)
446
447/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800448 * SENSOR_TYPE_RELATIVE_HUMIDITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800449 * trigger-mode: on-change
450 * wake-up sensor: no
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100451 *
452 * A relative humidity sensor measures relative ambient air humidity and
453 * returns a value in percent.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800454 */
455#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
456
457/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800458 * SENSOR_TYPE_AMBIENT_TEMPERATURE
Mathias Agopiana4557722012-11-28 17:21:55 -0800459 * trigger-mode: on-change
460 * wake-up sensor: no
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700461 *
462 * The ambient (room) temperature in degree Celsius.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800463 */
464#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
465
466/*
467 * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
Mathias Agopiana4557722012-11-28 17:21:55 -0800468 * trigger-mode: continuous
469 * wake-up sensor: no
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700470 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800471 * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is
472 * reported separately instead of being included in the measurement.
473 * Factory calibration and temperature compensation should still be applied to
474 * the "uncalibrated" measurement.
475 * Separating away the hard iron calibration estimation allows the system to
476 * better recover from bad hard iron estimation.
477 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800478 * All values are in micro-Tesla (uT) and measure the ambient magnetic
Etienne Le Grandca858142013-02-26 19:17:20 -0800479 * field in the X, Y and Z axis. Assumptions that the the magnetic field
480 * is due to the Earth's poles should be avoided.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800481 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800482 * The uncalibrated_magnetic event contains
483 * - 3 fields for uncalibrated measurement: x_uncalib, y_uncalib, z_uncalib.
484 * Each is a component of the measured magnetic field, with soft iron
485 * and temperature compensation applied, but not hard iron calibration.
486 * These values should be continuous (no re-calibration should cause a jump).
487 * - 3 fields for hard iron bias estimates: x_bias, y_bias, z_bias.
488 * Each field is a component of the estimated hard iron calibration.
Etienne Le Grand7a813e82013-04-23 14:22:23 -0700489 * They represent the offsets to apply to the calibrated readings to obtain
490 * uncalibrated readings (x_uncalib ~= x_calibrated + x_bias)
Etienne Le Grandca858142013-02-26 19:17:20 -0800491 * These values are expected to jump as soon as the estimate of the hard iron
Etienne Le Grand7a813e82013-04-23 14:22:23 -0700492 * changes, and they should be stable the rest of the time.
Mathias Agopian1144bea2013-01-29 15:52:10 -0800493 *
494 * If this sensor is present, then the corresponding
495 * SENSOR_TYPE_MAGNETIC_FIELD must be present and both must return the
496 * same sensor_t::name and sensor_t::vendor.
Etienne Le Grandca858142013-02-26 19:17:20 -0800497 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700498 * Minimum filtering should be applied to this sensor. In particular, low pass
499 * filters should be avoided.
500 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800501 * See SENSOR_TYPE_MAGNETIC_FIELD for more information
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800502 */
503#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
504
505/*
506 * SENSOR_TYPE_GAME_ROTATION_VECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800507 * trigger-mode: continuous
508 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800509 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800510 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic
511 * field. Therefore the Y axis doesn't point north, but instead to some other
512 * reference. That reference is allowed to drift by the same order of
513 * magnitude than the gyroscope drift around the Z axis.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800514 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800515 * This sensor does not report an estimated heading accuracy:
Etienne Le Grand28f04112013-03-27 18:59:10 -0700516 * sensors_event_t.data[4] is reserved and should be set to 0
Etienne Le Grandca858142013-02-26 19:17:20 -0800517 *
518 * In the ideal case, a phone rotated and returning to the same real-world
519 * orientation should report the same game rotation vector
520 * (without using the earth's geomagnetic field).
521 *
522 * This sensor must be based on a gyroscope. It cannot be implemented using
523 * a magnetometer.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800524 *
525 * see SENSOR_TYPE_ROTATION_VECTOR for more details
526 */
527#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
528
529/*
530 * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
Mathias Agopiana4557722012-11-28 17:21:55 -0800531 * trigger-mode: continuous
532 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800533 *
534 * All values are in radians/second and measure the rate of rotation
Mathias Agopian1144bea2013-01-29 15:52:10 -0800535 * around the X, Y and Z axis. An estimation of the drift on each axis is
536 * reported as well.
537 *
538 * No gyro-drift compensation shall be performed.
539 * Factory calibration and temperature compensation should still be applied
540 * to the rate of rotation (angular speeds).
541 *
542 * The coordinate system is the same as is
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800543 * used for the acceleration sensor. Rotation is positive in the
544 * counter-clockwise direction (right-hand rule). That is, an observer
545 * looking from some positive location on the x, y or z axis at a device
546 * positioned on the origin would report positive rotation if the device
547 * appeared to be rotating counter clockwise. Note that this is the
548 * standard mathematical definition of positive rotation and does not agree
549 * with the definition of roll given earlier.
550 * The range should at least be 17.45 rad/s (ie: ~1000 deg/s).
551 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800552 * Content of an uncalibrated_gyro event: (units are rad/sec)
553 * x_uncalib : angular speed (w/o drift compensation) around the X axis
554 * y_uncalib : angular speed (w/o drift compensation) around the Y axis
555 * z_uncalib : angular speed (w/o drift compensation) around the Z axis
556 * x_bias : estimated drift around X axis in rad/s
557 * y_bias : estimated drift around Y axis in rad/s
558 * z_bias : estimated drift around Z axis in rad/s
Mathias Agopian1144bea2013-01-29 15:52:10 -0800559 *
560 * IMPLEMENTATION NOTES:
561 *
562 * If the implementation is not able to estimate the drift, then this
563 * sensor MUST NOT be reported by this HAL. Instead, the regular
564 * SENSOR_TYPE_GYROSCOPE is used without drift compensation.
565 *
566 * If this sensor is present, then the corresponding
567 * SENSOR_TYPE_GYROSCOPE must be present and both must return the
568 * same sensor_t::name and sensor_t::vendor.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800569 */
570#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
571
Mathias Agopiana4557722012-11-28 17:21:55 -0800572
573/*
574 * SENSOR_TYPE_SIGNIFICANT_MOTION
575 * trigger-mode: one-shot
576 * wake-up sensor: yes
577 *
578 * A sensor of this type triggers an event each time significant motion
579 * is detected and automatically disables itself.
580 * The only allowed value to return is 1.0.
581 *
Etienne Le Grand1461f282013-03-05 22:00:33 -0800582 * A significant motion is a motion that might lead to a change in the user
583 * location.
584 * Examples of such motions are:
585 * walking, biking, sitting in a moving car, coach or train.
586 * Examples of situations that should not trigger significant motion:
587 * - phone in pocket and person is not moving
588 * - phone is on a table, even if the table shakes a bit due to nearby traffic
589 * or washing machine
Mathias Agopiana4557722012-11-28 17:21:55 -0800590 *
Etienne Le Grand1461f282013-03-05 22:00:33 -0800591 * A note on false positive / false negative / power consumption tradeoff
592 * - The goal of this sensor is to save power.
593 * - Triggering an event when the user is not moving (false positive) is costly
594 * in terms of power, so it should be avoided.
595 * - Not triggering an event when the user is moving (false negative) is
Etienne Le Grand2e7d3cd2013-03-07 12:22:32 -0800596 * acceptable as long as it is not done repeatedly. If the user has been
Etienne Le Grand1461f282013-03-05 22:00:33 -0800597 * walking for 10 seconds, not triggering an event within those 10 seconds
598 * is not acceptable.
Mathias Agopiana4557722012-11-28 17:21:55 -0800599 *
600 * IMPORTANT NOTE: this sensor type is very different from other types
601 * in that it must work when the screen is off without the need of
602 * holding a partial wake-lock and MUST allow the SoC to go into suspend.
603 * When significant motion is detected, the sensor must awaken the SoC and
604 * the event be reported.
605 *
606 * If a particular hardware cannot support this mode of operation then this
607 * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable
608 * to "emulate" this sensor in the HAL.
609 *
610 * The whole point of this sensor type is to save power by keeping the
611 * SoC in suspend mode when the device is at rest.
612 *
613 * When the sensor is not activated, it must also be deactivated in the
614 * hardware: it must not wake up the SoC anymore, even in case of
615 * significant motion.
616 *
617 * setDelay() has no effect and is ignored.
618 * Once a "significant motion" event is returned, a sensor of this type
619 * must disables itself automatically, as if activate(..., 0) had been called.
620 */
621
622#define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
623
624
625/*
Mathias Agopian2f276f52013-01-28 17:54:41 -0800626 * SENSOR_TYPE_STEP_DETECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800627 * trigger-mode: special
628 * wake-up sensor: no
629 *
630 * A sensor of this type triggers an event each time a step is taken
631 * by the user. The only allowed value to return is 1.0 and an event is
632 * generated for each step. Like with any other event, the timestamp
633 * indicates when the event (here the step) occurred, this corresponds to when
634 * the foot hit the ground, generating a high variation in acceleration.
635 *
636 * While this sensor operates, it shall not disrupt any other sensors, in
637 * particular, but not limited to, the accelerometer; which might very well
638 * be in use as well.
639 *
640 * This sensor must be low power. That is, if the step detection cannot be
641 * done in hardware, this sensor should not be defined. Also, when the
Mathias Agopian2f276f52013-01-28 17:54:41 -0800642 * step detector is activated and the accelerometer is not, only steps should
Mathias Agopiana4557722012-11-28 17:21:55 -0800643 * trigger interrupts (not accelerometer data).
644 *
645 * setDelay() has no impact on this sensor type
646 */
647
Mathias Agopian2f276f52013-01-28 17:54:41 -0800648#define SENSOR_TYPE_STEP_DETECTOR (18)
Mathias Agopiana4557722012-11-28 17:21:55 -0800649
650
651/*
652 * SENSOR_TYPE_STEP_COUNTER
653 * trigger-mode: on-change
654 * wake-up sensor: no
655 *
656 * A sensor of this type returns the number of steps taken by the user since
Mathias Agopian1144bea2013-01-29 15:52:10 -0800657 * the last reboot while activated. The value is returned as a uint64_t and is
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700658 * reset to zero only on a system / android reboot.
Mathias Agopiana4557722012-11-28 17:21:55 -0800659 *
660 * The timestamp of the event is set to the time when the first step
661 * for that event was taken.
Mathias Agopian2f276f52013-01-28 17:54:41 -0800662 * See SENSOR_TYPE_STEP_DETECTOR for the signification of the time of a step.
Mathias Agopiana4557722012-11-28 17:21:55 -0800663 *
664 * The minimum size of the hardware's internal counter shall be 16 bits
665 * (this restriction is here to avoid too frequent wake-ups when the
666 * delay is very large).
667 *
668 * IMPORTANT NOTE: this sensor type is different from other types
669 * in that it must work when the screen is off without the need of
670 * holding a partial wake-lock and MUST allow the SoC to go into suspend.
671 * Unlike other sensors, while in suspend mode this sensor must stay active,
672 * no events are reported during that time but, steps continue to be
673 * accounted for; an event will be reported as soon as the SoC resumes if
674 * the timeout has expired.
675 *
676 * In other words, when the screen is off and the device allowed to
677 * go into suspend mode, we don't want to be woken up, regardless of the
678 * setDelay() value, but the steps shall continue to be counted.
679 *
680 * The driver must however ensure that the internal step count never
681 * overflows. It is allowed in this situation to wake the SoC up so the
682 * driver can do the counter maintenance.
683 *
684 * While this sensor operates, it shall not disrupt any other sensors, in
685 * particular, but not limited to, the accelerometer; which might very well
686 * be in use as well.
687 *
688 * If a particular hardware cannot support these modes of operation then this
689 * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable
690 * to "emulate" this sensor in the HAL.
691 *
692 * This sensor must be low power. That is, if the step detection cannot be
693 * done in hardware, this sensor should not be defined. Also, when the
694 * step counter is activated and the accelerometer is not, only steps should
695 * trigger interrupts (not accelerometer data).
696 *
697 * The whole point of this sensor type is to save power by keeping the
698 * SoC in suspend mode when the device is at rest.
699 */
700
701#define SENSOR_TYPE_STEP_COUNTER (19)
702
Etienne Le Grandca858142013-02-26 19:17:20 -0800703/*
704 * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
705 * trigger-mode: continuous
706 * wake-up sensor: no
707 *
708 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead
709 * of using a gyroscope.
710 *
711 * This sensor must be based on a magnetometer. It cannot be implemented using
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700712 * a gyroscope, and gyroscope input cannot be used by this sensor, as the
713 * goal of this sensor is to be low power.
714 * The accelerometer can be (and usually is) used.
Etienne Le Grandca858142013-02-26 19:17:20 -0800715 *
716 * Just like SENSOR_TYPE_ROTATION_VECTOR, this sensor reports an estimated
717 * heading accuracy:
Etienne Le Grand28f04112013-03-27 18:59:10 -0700718 * sensors_event_t.data[4] = estimated_accuracy (in radians)
Etienne Le Grandca858142013-02-26 19:17:20 -0800719 * The heading error must be less than estimated_accuracy 95% of the time
720 *
721 * see SENSOR_TYPE_ROTATION_VECTOR for more details
722 */
723#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20)
Mathias Agopiana4557722012-11-28 17:21:55 -0800724
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800725/**
726 * Values returned by the accelerometer in various locations in the universe.
727 * all values are in SI units (m/s^2)
728 */
729#define GRAVITY_SUN (275.0f)
730#define GRAVITY_EARTH (9.80665f)
731
732/** Maximum magnetic field on Earth's surface */
733#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
734
735/** Minimum magnetic field on Earth's surface */
736#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
737
738
739/**
740 * status of orientation sensor
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800741 */
Kevin Powellb01a0432010-07-19 19:12:15 -0700742
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800743#define SENSOR_STATUS_UNRELIABLE 0
744#define SENSOR_STATUS_ACCURACY_LOW 1
745#define SENSOR_STATUS_ACCURACY_MEDIUM 2
746#define SENSOR_STATUS_ACCURACY_HIGH 3
747
748
749/**
750 * sensor event data
751 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800752typedef struct {
753 union {
754 float v[3];
755 struct {
756 float x;
757 float y;
758 float z;
759 };
760 struct {
761 float azimuth;
762 float pitch;
763 float roll;
764 };
765 };
766 int8_t status;
767 uint8_t reserved[3];
768} sensors_vec_t;
769
770/**
Etienne Le Grandca858142013-02-26 19:17:20 -0800771 * uncalibrated gyroscope and magnetometer event data
772 */
773typedef struct {
Etienne Le Grand28f04112013-03-27 18:59:10 -0700774 union {
775 float uncalib[3];
776 struct {
777 float x_uncalib;
778 float y_uncalib;
779 float z_uncalib;
780 };
781 };
782 union {
783 float bias[3];
784 struct {
785 float x_bias;
786 float y_bias;
787 float z_bias;
788 };
789 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800790} uncalibrated_event_t;
791
Mathias Agopian16671c52013-07-24 21:07:40 -0700792typedef struct meta_data_event {
793 int32_t what;
794 int32_t sensor;
795} meta_data_event_t;
796
Etienne Le Grandca858142013-02-26 19:17:20 -0800797/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800798 * Union of the various types of sensor data
799 * that can be returned.
800 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700801typedef struct sensors_event_t {
802 /* must be sizeof(struct sensors_event_t) */
803 int32_t version;
804
805 /* sensor identifier */
806 int32_t sensor;
807
808 /* sensor type */
809 int32_t type;
810
811 /* reserved */
812 int32_t reserved0;
813
814 /* time is in nanosecond */
815 int64_t timestamp;
816
817 union {
Mathias Agopian27e16682013-07-08 14:00:54 -0700818 union {
819 float data[16];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700820
Mathias Agopian27e16682013-07-08 14:00:54 -0700821 /* acceleration values are in meter per second per second (m/s^2) */
822 sensors_vec_t acceleration;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700823
Mathias Agopian27e16682013-07-08 14:00:54 -0700824 /* magnetic vector values are in micro-Tesla (uT) */
825 sensors_vec_t magnetic;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700826
Mathias Agopian27e16682013-07-08 14:00:54 -0700827 /* orientation values are in degrees */
828 sensors_vec_t orientation;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700829
Mathias Agopian27e16682013-07-08 14:00:54 -0700830 /* gyroscope values are in rad/s */
831 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -0700832
Mathias Agopian27e16682013-07-08 14:00:54 -0700833 /* temperature is in degrees centigrade (Celsius) */
834 float temperature;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700835
Mathias Agopian27e16682013-07-08 14:00:54 -0700836 /* distance in centimeters */
837 float distance;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700838
Mathias Agopian27e16682013-07-08 14:00:54 -0700839 /* light in SI lux units */
840 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -0700841
Mathias Agopian27e16682013-07-08 14:00:54 -0700842 /* pressure in hectopascal (hPa) */
843 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100844
Mathias Agopian27e16682013-07-08 14:00:54 -0700845 /* relative humidity in percent */
846 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -0800847
Mathias Agopian27e16682013-07-08 14:00:54 -0700848 /* uncalibrated gyroscope values are in rad/s */
849 uncalibrated_event_t uncalibrated_gyro;
Etienne Le Grandca858142013-02-26 19:17:20 -0800850
Mathias Agopian27e16682013-07-08 14:00:54 -0700851 /* uncalibrated magnetometer values are in micro-Teslas */
852 uncalibrated_event_t uncalibrated_magnetic;
Mathias Agopian16671c52013-07-24 21:07:40 -0700853
854 /* this is a special event. see SENSOR_TYPE_META_DATA above.
855 * sensors_meta_data_event_t events are all reported with a type of
856 * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
857 */
858 meta_data_event_t meta_data;
Mathias Agopian27e16682013-07-08 14:00:54 -0700859 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800860
Mathias Agopian27e16682013-07-08 14:00:54 -0700861 union {
862 uint64_t data[8];
863
864 /* step-counter */
865 uint64_t step_counter;
866 } u64;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700867 };
Mathias Agopian27e16682013-07-08 14:00:54 -0700868 uint32_t reserved1[4];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700869} sensors_event_t;
870
871
Mathias Agopian16671c52013-07-24 21:07:40 -0700872/* see SENSOR_TYPE_META_DATA */
873typedef sensors_event_t sensors_meta_data_event_t;
874
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700875
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800876struct sensor_t;
877
878/**
879 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
880 * and the fields of this data structure must begin with hw_module_t
881 * followed by module specific information.
882 */
883struct sensors_module_t {
884 struct hw_module_t common;
885
886 /**
887 * Enumerate all available sensors. The list is returned in "list".
888 * @return number of sensors in the list
889 */
890 int (*get_sensors_list)(struct sensors_module_t* module,
891 struct sensor_t const** list);
892};
893
894struct sensor_t {
Mathias Agopian1144bea2013-01-29 15:52:10 -0800895
896 /* Name of this sensor.
897 * All sensors of the same "type" must have a different "name".
898 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800899 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -0800900
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800901 /* vendor of the hardware part */
902 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -0800903
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800904 /* version of the hardware part + driver. The value of this field
905 * must increase when the driver is updated in a way that changes the
906 * output of this sensor. This is important for fused sensors when the
907 * fusion algorithm is updated.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800908 */
909 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -0800910
911 /* handle that identifies this sensors. This handle is used to reference
912 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800913 */
914 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -0800915
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800916 /* this sensor's type. */
917 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -0800918
919 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800920 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -0800921
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800922 /* smallest difference between two values reported by this sensor */
923 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -0800924
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800925 /* rough estimate of this sensor's power consumption in mA */
926 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -0800927
928 /* this value depends on the trigger mode:
929 *
930 * continuous: minimum sample period allowed in microseconds
931 * on-change : 0
932 * one-shot :-1
933 * special : 0, unless otherwise noted
934 */
Mathias Agopian1511e202010-07-29 15:33:22 -0700935 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -0800936
Mathias Agopian16671c52013-07-24 21:07:40 -0700937 /* number of events reserved for this sensor in the batch mode FIFO.
938 * If there is a dedicated FIFO for this sensor, then this is the
939 * size of this FIFO. If the FIFO is shared with other sensors,
940 * this is the size reserved for that sensor and it can be zero.
941 */
942 uint32_t fifoReservedEventCount;
943
944 /* maximum number of events of this sensor that could be batched.
945 * This is especially relevant when the FIFO is shared between
946 * several sensors; this value is then set to the size of that FIFO.
947 */
948 uint32_t fifoMaxEventCount;
949
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800950 /* reserved fields, must be zero */
Mathias Agopian16671c52013-07-24 21:07:40 -0700951 void* reserved[6];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800952};
953
954
Mathias Agopiana4557722012-11-28 17:21:55 -0800955/*
956 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
957 * and is present for backward binary and source compatibility.
958 * (see documentation of the hooks in struct sensors_poll_device_1 below)
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800959 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700960struct sensors_poll_device_t {
961 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700962 int (*activate)(struct sensors_poll_device_t *dev,
963 int handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700964 int (*setDelay)(struct sensors_poll_device_t *dev,
965 int handle, int64_t ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700966 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700967 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700968};
969
Mathias Agopiana4557722012-11-28 17:21:55 -0800970/*
971 * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0
972 */
973typedef struct sensors_poll_device_1 {
974 union {
975 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
976 * and can be down-cast to it
977 */
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800978 struct sensors_poll_device_t v0;
Mathias Agopiana4557722012-11-28 17:21:55 -0800979
980 struct {
981 struct hw_device_t common;
982
983 /* Activate/de-activate one sensor.
984 *
985 * handle is the handle of the sensor to change.
986 * enabled set to 1 to enable, or 0 to disable the sensor.
987 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700988 * if enabled is set to 1, the sensor is activated even if
989 * setDelay() wasn't called before. In this case, a default rate
990 * should be used.
991 *
Mathias Agopiana4557722012-11-28 17:21:55 -0800992 * unless otherwise noted in the sensor types definitions, an
993 * activated sensor never prevents the SoC to go into suspend
994 * mode; that is, the HAL shall not hold a partial wake-lock on
995 * behalf of applications.
996 *
997 * one-shot sensors de-activate themselves automatically upon
998 * receiving an event and they must still accept to be deactivated
999 * through a call to activate(..., ..., 0).
1000 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001001 * if "enabled" is 1 and the sensor is already activated, this
Mathias Agopiana4557722012-11-28 17:21:55 -08001002 * function is a no-op and succeeds.
1003 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001004 * if "enabled" is 0 and the sensor is already de-activated,
Mathias Agopiana4557722012-11-28 17:21:55 -08001005 * this function is a no-op and succeeds.
1006 *
1007 * return 0 on success, negative errno code otherwise
1008 */
1009 int (*activate)(struct sensors_poll_device_t *dev,
1010 int handle, int enabled);
1011
1012 /**
Mathias Agopian1144bea2013-01-29 15:52:10 -08001013 * Set the events's period in nanoseconds for a given sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -08001014 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001015 * What the period_ns parameter means depends on the specified
Mathias Agopiana4557722012-11-28 17:21:55 -08001016 * sensor's trigger mode:
1017 *
1018 * continuous: setDelay() sets the sampling rate.
1019 * on-change: setDelay() limits the delivery rate of events
1020 * one-shot: setDelay() is ignored. it has no effect.
1021 * special: see specific sensor type definitions
1022 *
1023 * For continuous and on-change sensors, if the requested value is
1024 * less than sensor_t::minDelay, then it's silently clamped to
1025 * sensor_t::minDelay unless sensor_t::minDelay is 0, in which
1026 * case it is clamped to >= 1ms.
1027 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001028 * setDelay will not be called when the sensor is in batching mode.
1029 * In this case, batch() will be called with the new period.
1030 *
Mathias Agopiana4557722012-11-28 17:21:55 -08001031 * @return 0 if successful, < 0 on error
1032 */
1033 int (*setDelay)(struct sensors_poll_device_t *dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -08001034 int handle, int64_t period_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -08001035
1036 /**
1037 * Returns an array of sensor data.
1038 * This function must block until events are available.
1039 *
1040 * return the number of events read on success, or -errno in case
1041 * of an error.
1042 *
1043 * The number of events returned in data must be less or equal
Etienne Le Grand28f04112013-03-27 18:59:10 -07001044 * to the "count" argument.
Mathias Agopiana4557722012-11-28 17:21:55 -08001045 *
1046 * This function shall never return 0 (no event).
1047 */
1048 int (*poll)(struct sensors_poll_device_t *dev,
1049 sensors_event_t* data, int count);
1050 };
1051 };
1052
Mathias Agopiana4557722012-11-28 17:21:55 -08001053
1054 /*
Mathias Agopian1144bea2013-01-29 15:52:10 -08001055 * Enables batch mode for the given sensor and sets the delay between events
Mathias Agopiana4557722012-11-28 17:21:55 -08001056 *
1057 * A timeout value of zero disables batch mode for the given sensor.
1058 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001059 * The period_ns parameter is equivalent to calling setDelay() -- this
1060 * function both enables or disables the batch mode AND sets the events's
1061 * period in nanosecond. See setDelay() above for a detailed explanation of
1062 * the period_ns parameter.
1063 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001064 * BATCH MODE:
1065 * -----------
1066 * In non-batch mode, all sensor events must be reported as soon as they
1067 * are detected. For example, an accelerometer activated at 50Hz will
1068 * trigger interrupts 50 times per second.
1069 * While in batch mode, sensor events do not need to be reported as soon
1070 * as they are detected. They can be temporarily stored in batches and
1071 * reported in batches, as long as no event is delayed by more than
1072 * "timeout" nanoseconds. That is, all events since the previous batch
1073 * are recorded and returned all at once. This allows to reduce the amount
1074 * of interrupts sent to the SoC, and allow the SoC to switch to a lower
1075 * power state (Idle) while the sensor is capturing and batching data.
Mathias Agopiana4557722012-11-28 17:21:55 -08001076 *
1077 * setDelay() is not affected and it behaves as usual.
1078 *
1079 * Each event has a timestamp associated with it, the timestamp
1080 * must be accurate and correspond to the time at which the event
1081 * physically happened.
1082 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001083 * Batching does not modify the behavior of poll(): batches from different
1084 * sensors can be interleaved and split. As usual, all events from the same
1085 * sensor are time-ordered.
1086 *
1087 * BEHAVIOUR OUTSIDE OF SUSPEND MODE:
1088 * ----------------------------------
1089 *
1090 * When the SoC is awake (not in suspend mode), events must be reported in
1091 * batches at least every "timeout". No event shall be dropped or lost.
Mathias Agopiana4557722012-11-28 17:21:55 -08001092 * If internal h/w FIFOs fill-up before the timeout, then events are
Etienne Le Grand28f04112013-03-27 18:59:10 -07001093 * reported at that point to ensure no event is lost.
Mathias Agopian1144bea2013-01-29 15:52:10 -08001094 *
1095 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001096 * NORMAL BEHAVIOR IN SUSPEND MODE:
1097 * ---------------------------------
Mathias Agopiana4557722012-11-28 17:21:55 -08001098 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001099 * By default, batch mode doesn't significantly change the interaction with
1100 * suspend mode. That is, sensors must continue to allow the SoC to
Mathias Agopiana4557722012-11-28 17:21:55 -08001101 * go into suspend mode and sensors must stay active to fill their
Etienne Le Grand28f04112013-03-27 18:59:10 -07001102 * internal FIFO. In this mode, when the FIFO fills up, it shall wrap
Mathias Agopiana4557722012-11-28 17:21:55 -08001103 * around (basically behave like a circular buffer, overwriting events).
1104 * As soon as the SoC comes out of suspend mode, a batch is produced with
1105 * as much as the recent history as possible, and batch operation
1106 * resumes as usual.
1107 *
1108 * The behavior described above allows applications to record the recent
1109 * history of a set of sensor while keeping the SoC into suspend. It
1110 * also allows the hardware to not have to rely on a wake-up interrupt line.
1111 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001112 * WAKE_UPON_FIFO_FULL BEHAVIOR IN SUSPEND MODE:
1113 * ----------------------------------------------
Mathias Agopiana4557722012-11-28 17:21:55 -08001114 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001115 * There are cases, however, where an application cannot afford to lose
1116 * any events, even when the device goes into suspend mode.
1117 * For a given rate, if a sensor has the capability to store at least 10
1118 * seconds worth of events in its FIFO and is able to wake up the Soc, it
1119 * can implement an optional secondary mode: the WAKE_UPON_FIFO_FULL mode.
1120 *
1121 * The caller will set the SENSORS_BATCH_WAKE_UPON_FIFO_FULL flag to
1122 * activate this mode. If the sensor does not support this mode, batch()
1123 * will fail when the flag is set.
1124 *
1125 * When running with the WAKE_UPON_FIFO_FULL flag set, no events can be
1126 * lost. When the FIFO is getting full, the sensor must wake up the SoC from
1127 * suspend and return a batch before the FIFO fills-up.
1128 * Depending on the device, it might take a few miliseconds for the SoC to
1129 * entirely come out of suspend and start flushing the FIFO. Enough head
1130 * room must be allocated in the FIFO to allow the device to entirely come
1131 * out of suspend without the FIFO overflowing (no events shall be lost).
1132 *
1133 * Implementing the WAKE_UPON_FIFO_FULL mode is optional.
1134 * If the hardware cannot support this mode, or if the physical
Mathias Agopiana4557722012-11-28 17:21:55 -08001135 * FIFO is so small that the device would never be allowed to go into
Mathias Agopian1144bea2013-01-29 15:52:10 -08001136 * suspend for at least 10 seconds, then this function MUST fail when
1137 * the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is set, regardless of
1138 * the value of the timeout parameter.
Mathias Agopiana4557722012-11-28 17:21:55 -08001139 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001140 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001141 * DRY RUN:
1142 * --------
Mathias Agopiana4557722012-11-28 17:21:55 -08001143 *
1144 * If the flag SENSORS_BATCH_DRY_RUN is set, this function returns
Mathias Agopian1144bea2013-01-29 15:52:10 -08001145 * without modifying the batch mode or the event period and has no side
1146 * effects, but returns errors as usual (as it would if this flag was
1147 * not set). This flag is used to check if batch mode is available for a
1148 * given configuration -- in particular for a given sensor at a given rate.
1149 *
Mathias Agopiana4557722012-11-28 17:21:55 -08001150 *
1151 * Return values:
Mathias Agopian1144bea2013-01-29 15:52:10 -08001152 * --------------
1153 *
1154 * Because sensors must be independent, the return value must not depend
1155 * on the state of the system (whether another sensor is on or not),
1156 * nor on whether the flag SENSORS_BATCH_DRY_RUN is set (in other words,
1157 * if a batch call with SENSORS_BATCH_DRY_RUN is successful,
1158 * the same call without SENSORS_BATCH_DRY_RUN must succeed as well).
Mathias Agopiana4557722012-11-28 17:21:55 -08001159 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001160 * When timeout is not 0:
1161 * If successful, 0 is returned.
1162 * If the specified sensor doesn't support batch mode, return -EINVAL.
1163 * If the specified sensor's trigger-mode is one-shot, return -EINVAL.
1164 * If WAKE_UPON_FIFO_FULL is specified and the specified sensor's internal
1165 * FIFO is too small to store at least 10 seconds worth of data at the
1166 * given rate, -EINVAL is returned. Note that as stated above, this has to
1167 * be determined at compile time, and not based on the state of the
1168 * system.
1169 * If some other constraints above cannot be satisfied, return -EINVAL.
Mathias Agopiana4557722012-11-28 17:21:55 -08001170 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001171 * Note: the timeout parameter, when > 0, has no impact on whether this
1172 * function succeeds or fails.
1173 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001174 * When timeout is 0:
1175 * The caller will never set the wake_upon_fifo_full flag.
1176 * The function must succeed, and batch mode must be deactivated.
1177 *
1178 * Independently of whether DRY_RUN is specified, When the call to batch()
1179 * fails, no state should be changed. In particular, a failed call to
1180 * batch() should not change the rate of the sensor. Example:
1181 * setDelay(..., 10ms)
1182 * batch(..., 20ms, ...) fails
1183 * rate should stay 10ms.
Mathias Agopiana4557722012-11-28 17:21:55 -08001184 *
1185 *
1186 * IMPLEMENTATION NOTES:
Mathias Agopian1144bea2013-01-29 15:52:10 -08001187 * ---------------------
Mathias Agopiana4557722012-11-28 17:21:55 -08001188 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001189 * Batch mode, if supported, should happen at the hardware level,
Mathias Agopiana4557722012-11-28 17:21:55 -08001190 * typically using hardware FIFOs. In particular, it SHALL NOT be
1191 * implemented in the HAL, as this would be counter productive.
1192 * The goal here is to save significant amounts of power.
1193 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001194 * In some implementations, events from several sensors can share the
1195 * same physical FIFO. In that case, all events in the FIFO can be sent and
1196 * processed by the HAL as soon as one batch must be reported.
1197 * For example, if the following sensors are activated:
1198 * - accelerometer batched with timeout = 20s
1199 * - gyroscope batched with timeout = 5s
1200 * then the accelerometer batches can be reported at the same time the
1201 * gyroscope batches are reported (every 5 seconds)
1202 *
1203 * Batch mode can be enabled or disabled at any time, in particular
1204 * while the specified sensor is already enabled, and this shall not
Mathias Agopiana4557722012-11-28 17:21:55 -08001205 * result in the loss of events.
1206 *
Etienne Le Grandca858142013-02-26 19:17:20 -08001207 * COMPARATIVE IMPORTANCE OF BATCHING FOR DIFFERENT SENSORS:
1208 * ---------------------------------------------------------
1209 *
1210 * On platforms on which hardware fifo size is limited, the system designers
1211 * might have to choose how much fifo to reserve for each sensor. To help
Etienne Le Grand28f04112013-03-27 18:59:10 -07001212 * with this choice, here is a list of applications made possible when
Etienne Le Grandca858142013-02-26 19:17:20 -08001213 * batching is implemented on the different sensors.
1214 *
1215 * High value: Low power pedestrian dead reckoning
1216 * Target batching time: 20 seconds to 1 minute
1217 * Sensors to batch:
1218 * - Step detector
1219 * - Rotation vector or game rotation vector at 5Hz
Etienne Le Grand28f04112013-03-27 18:59:10 -07001220 * Gives us step and heading while letting the SoC go to Suspend.
Etienne Le Grandca858142013-02-26 19:17:20 -08001221 *
1222 * High value: Medium power activity/gesture recognition
1223 * Target batching time: 3 seconds
1224 * Sensors to batch: accelerometer between 20Hz and 50Hz
1225 * Allows recognizing arbitrary activities and gestures without having
Etienne Le Grand28f04112013-03-27 18:59:10 -07001226 * to keep the SoC fully awake while the data is collected.
Etienne Le Grandca858142013-02-26 19:17:20 -08001227 *
1228 * Medium-high value: Interrupt load reduction
1229 * Target batching time: < 1 second
1230 * Sensors to batch: any high frequency sensor.
1231 * If the gyroscope is set at 800Hz, even batching just 10 gyro events can
1232 * reduce the number of interrupts from 800/second to 80/second.
1233 *
1234 * Medium value: Continuous low frequency data collection
1235 * Target batching time: > 1 minute
1236 * Sensors to batch: barometer, humidity sensor, other low frequency
1237 * sensors.
1238 * Allows creating monitoring applications at low power.
1239 *
1240 * Medium value: Continuous full-sensors collection
1241 * Target batching time: > 1 minute
1242 * Sensors to batch: all, at high frequencies
Etienne Le Grand28f04112013-03-27 18:59:10 -07001243 * Allows full collection of sensor data while leaving the SoC in
Etienne Le Grandca858142013-02-26 19:17:20 -08001244 * suspend mode. Only to consider if fifo space is not an issue.
Etienne Le Grand28f04112013-03-27 18:59:10 -07001245 *
1246 * In each of the cases above, if WAKE_UPON_FIFO_FULL is implemented, the
1247 * applications might decide to let the SoC go to suspend, allowing for even
1248 * more power savings.
Mathias Agopiana4557722012-11-28 17:21:55 -08001249 */
1250 int (*batch)(struct sensors_poll_device_1* dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -08001251 int handle, int flags, int64_t period_ns, int64_t timeout);
Mathias Agopiana4557722012-11-28 17:21:55 -08001252
Mathias Agopian16671c52013-07-24 21:07:40 -07001253 /*
1254 * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
1255 * to the end of the "batch mode" FIFO for the specified sensor and flushes
1256 * the FIFO; those events are delivered as usual (i.e.: as if the batch
1257 * timeout had expired) and removed from the FIFO.
1258 *
1259 * See the META_DATA_FLUSH_COMPLETE section for details about the
1260 * META_DATA_FLUSH_COMPLETE event.
1261 *
1262 * The flush happens asynchronously (i.e.: this function must return
1263 * immediately).
1264 *
1265 * If the implementation uses a single FIFO for several sensors, that
1266 * FIFO is flushed and the META_DATA_FLUSH_COMPLETE event is added only
1267 * for the specified sensor.
1268 *
1269 * If the specified sensor wasn't in batch mode, flush succeeds and
1270 * promptly sends a META_DATA_FLUSH_COMPLETE event for that sensor.
1271 *
1272 * If the FIFO was empty at the time of the call, flush returns
1273 * 0 (success) and promptly sends a META_DATA_FLUSH_COMPLETE event
1274 * for that sensor.
1275 *
1276 * If the specified sensor wasn't enabled, flush returns -EINVAL.
1277 *
1278 * return 0 on success, negative errno code otherwise.
1279 */
1280 int (*flush)(struct sensors_poll_device_1* dev, int handle);
1281
Mathias Agopiana4557722012-11-28 17:21:55 -08001282 void (*reserved_procs[8])(void);
1283
1284} sensors_poll_device_1_t;
1285
1286
1287
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001288/** convenience API for opening and closing a device */
1289
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001290static inline int sensors_open(const struct hw_module_t* module,
1291 struct sensors_poll_device_t** device) {
1292 return module->methods->open(module,
1293 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1294}
1295
1296static inline int sensors_close(struct sensors_poll_device_t* device) {
1297 return device->common.close(&device->common);
1298}
1299
Mathias Agopiana4557722012-11-28 17:21:55 -08001300static inline int sensors_open_1(const struct hw_module_t* module,
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001301 sensors_poll_device_1_t** device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001302 return module->methods->open(module,
1303 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1304}
1305
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001306static inline int sensors_close_1(sensors_poll_device_1_t* device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001307 return device->common.close(&device->common);
1308}
1309
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001310__END_DECLS
1311
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001312#endif // ANDROID_SENSORS_INTERFACE_H