blob: d6b02c6f3fe4fd6dc7bd2b947f5c0c61e1167aa0 [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 Agopian56f66cc2012-11-08 15:57:38 -080035
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080036/**
37 * The id of this module
38 */
39#define SENSORS_HARDWARE_MODULE_ID "sensors"
40
41/**
42 * Name of the sensors device to open
43 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -070044#define SENSORS_HARDWARE_POLL "poll"
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080045
46/**
47 * Handles must be higher than SENSORS_HANDLE_BASE and must be unique.
48 * A Handle identifies a given sensors. The handle is used to activate
49 * and/or deactivate sensors.
50 * In this version of the API there can only be 256 handles.
51 */
52#define SENSORS_HANDLE_BASE 0
53#define SENSORS_HANDLE_BITS 8
54#define SENSORS_HANDLE_COUNT (1<<SENSORS_HANDLE_BITS)
55
56
Mathias Agopiana4557722012-11-28 17:21:55 -080057/* attributes queriable with query() */
58enum {
59 /*
60 * Availability: SENSORS_DEVICE_API_VERSION_1_0
61 * return the maximum number of events that can be returned
62 * in a single call to (*poll)(). This value is used by the
63 * framework to adequately dimension the buffer passed to
64 * (*poll)(), note that (*poll)() still needs to pay attention to
65 * the count parameter passed to it, it cannot blindly expect that
66 * this value will be used for all calls to (*poll)().
67 *
68 * Generally this value should be set to match the sum of the internal
69 * FIFOs of all available sensors.
70 */
71 SENSORS_QUERY_MAX_EVENTS_BATCH_COUNT = 0
72};
73
74/*
75 * flags for (*batch)()
76 * Availability: SENSORS_DEVICE_API_VERSION_1_0
77 * see (*batch)() documentation for details
78 */
79enum {
80 SENSORS_BATCH_DRY_RUN = 0x00000001,
81 SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002
82};
83
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080084/**
Mathias Agopian56f66cc2012-11-08 15:57:38 -080085 * Definition of the axis used by the sensor HAL API
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080086 *
87 * This API is relative to the screen of the device in its default orientation,
88 * that is, if the device can be used in portrait or landscape, this API
89 * is only relative to the NATURAL orientation of the screen. In other words,
90 * the axis are not swapped when the device's screen orientation changes.
91 * Higher level services /may/ perform this transformation.
92 *
93 * x<0 x>0
94 * ^
95 * |
96 * +-----------+--> y>0
97 * | |
98 * | |
99 * | |
100 * | | / z<0
101 * | | /
102 * | | /
103 * O-----------+/
104 * |[] [ ] []/
105 * +----------/+ y<0
106 * /
107 * /
108 * |/ z>0 (toward the sky)
109 *
110 * O: Origin (x=0,y=0,z=0)
111 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800112 */
113
Mathias Agopiana4557722012-11-28 17:21:55 -0800114/*
115 * Interaction with suspend mode
116 *
117 * Unless otherwise noted, an enabled sensor shall not prevent the
118 * SoC to go into suspend mode. It is the responsibility of applications
119 * to keep a partial wake-lock should they wish to receive sensor
120 * events while the screen is off. While in suspend mode, and unless
121 * otherwise noted, enabled sensors' events are lost.
122 *
123 * Note that conceptually, the sensor itself is not de-activated while in
124 * suspend mode -- it's just that the data it returns are lost. As soon as
125 * the SoC gets out of suspend mode, operations resume as usual. Of course,
126 * in practice sensors shall be disabled while in suspend mode to
127 * save power, unless batch mode is active, in which case they must
128 * continue fill their internal FIFO (see the documentation of batch() to
129 * learn how suspend interacts with batch mode).
130 *
131 * In batch mode and only when the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is
Mathias Agopian1144bea2013-01-29 15:52:10 -0800132 * set and supported, the specified sensor must be able to wake-up the SoC and
133 * be able to buffer at least 10 seconds worth of the requested sensor events.
Mathias Agopiana4557722012-11-28 17:21:55 -0800134 *
135 * There are notable exceptions to this behavior, which are sensor-dependent
136 * (see sensor types definitions below)
137 *
138 *
139 * The sensor type documentation below specifies the wake-up behavior of
140 * each sensor:
141 * wake-up: yes this sensor must wake-up the SoC to deliver events
142 * wake-up: no this sensor shall not wake-up the SoC, events are dropped
143 *
144 */
145
146/*
147 * Sensor type
148 *
149 * Each sensor has a type which defines what this sensor measures and how
150 * measures are reported. All types are defined below.
151 */
152
153/*
154 * Sensor fusion and virtual sensors
155 *
156 * Many sensor types are or can be implemented as virtual sensors from
157 * physical sensors on the device. For instance the rotation vector sensor,
Mathias Agopian2f276f52013-01-28 17:54:41 -0800158 * orientation sensor, step-detector, step-counter, etc...
Mathias Agopiana4557722012-11-28 17:21:55 -0800159 *
160 * From the point of view of this API these virtual sensors MUST appear as
161 * real, individual sensors. It is the responsibility of the driver and HAL
162 * to make sure this is the case.
163 *
164 * In particular, all sensors must be able to function concurrently.
165 * For example, if defining both an accelerometer and a step counter,
166 * then both must be able to work concurrently.
167 */
168
169/*
170 * Trigger modes
171 *
172 * Sensors can report events in different ways called trigger modes,
173 * each sensor type has one and only one trigger mode associated to it.
174 * Currently there are four trigger modes defined:
175 *
176 * continuous: events are reported at a constant rate defined by setDelay().
177 * eg: accelerometers, gyroscopes.
178 * on-change: events are reported only if the sensor's value has changed.
179 * setDelay() is used to set a lower limit to the reporting
180 * period (minimum time between two events).
181 * The HAL must return an event immediately when an on-change
182 * sensor is activated.
183 * eg: proximity, light sensors
Etienne Le Grandca858142013-02-26 19:17:20 -0800184 * one-shot: upon detection of an event, the sensor deactivates itself and
185 * then sends a single event. Order matters to avoid race
186 * conditions. No other event is sent until the sensor get
187 * reactivated. setDelay() is ignored.
Mathias Agopiana4557722012-11-28 17:21:55 -0800188 * eg: significant motion sensor
189 * special: see details in the sensor type specification below
190 *
191 */
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800192
193/*
194 * SENSOR_TYPE_ACCELEROMETER
Mathias Agopiana4557722012-11-28 17:21:55 -0800195 * trigger-mode: continuous
196 * wake-up sensor: no
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800197 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800198 * All values are in SI units (m/s^2) and measure the acceleration of the
199 * device minus the force of gravity.
200 *
201 * Acceleration sensors return sensor events for all 3 axes at a constant
202 * rate defined by setDelay().
203 *
204 * x: Acceleration on the x-axis
205 * y: Acceleration on the y-axis
206 * z: Acceleration on the z-axis
207 *
208 * Note that the readings from the accelerometer include the acceleration
209 * due to gravity (which is opposite to the direction of the gravity vector).
210 *
211 * Examples:
212 * The norm of <x, y, z> should be close to 0 when in free fall.
213 *
214 * When the device lies flat on a table and is pushed on its left side
215 * toward the right, the x acceleration value is positive.
216 *
217 * When the device lies flat on a table, the acceleration value is +9.81,
218 * which correspond to the acceleration of the device (0 m/s^2) minus the
219 * force of gravity (-9.81 m/s^2).
220 *
221 * When the device lies flat on a table and is pushed toward the sky, the
222 * acceleration value is greater than +9.81, which correspond to the
223 * acceleration of the device (+A m/s^2) minus the force of
224 * gravity (-9.81 m/s^2).
225 */
226#define SENSOR_TYPE_ACCELEROMETER (1)
227
228/*
229 * SENSOR_TYPE_GEOMAGNETIC_FIELD
Mathias Agopiana4557722012-11-28 17:21:55 -0800230 * trigger-mode: continuous
231 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800232 *
233 * All values are in micro-Tesla (uT) and measure the geomagnetic
234 * field in the X, Y and Z axis.
235 *
236 * Returned values include calibration mechanisms such that the vector is
237 * aligned with the magnetic declination and heading of the earth's
238 * geomagnetic field.
239 *
240 * Magnetic Field sensors return sensor events for all 3 axes at a constant
241 * rate defined by setDelay().
242 */
243#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2)
244#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
245
246/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800247 * SENSOR_TYPE_ORIENTATION
Mathias Agopiana4557722012-11-28 17:21:55 -0800248 * trigger-mode: continuous
249 * wake-up sensor: no
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800250 *
251 * All values are angles in degrees.
252 *
Mathias Agopian66a40952010-07-22 17:11:50 -0700253 * Orientation sensors return sensor events for all 3 axes at a constant
254 * rate defined by setDelay().
255 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800256 * azimuth: angle between the magnetic north direction and the Y axis, around
257 * the Z axis (0<=azimuth<360).
258 * 0=North, 90=East, 180=South, 270=West
259 *
260 * pitch: Rotation around X axis (-180<=pitch<=180), with positive values when
261 * the z-axis moves toward the y-axis.
262 *
263 * roll: Rotation around Y axis (-90<=roll<=90), with positive values when
Mathias Agopian19ea59f2010-02-26 13:15:18 -0800264 * the x-axis moves towards the z-axis.
265 *
266 * Note: For historical reasons the roll angle is positive in the clockwise
267 * direction (mathematically speaking, it should be positive in the
268 * counter-clockwise direction):
269 *
270 * Z
271 * ^
272 * (+roll) .--> |
273 * / |
274 * | | roll: rotation around Y axis
275 * X <-------(.)
276 * Y
277 * note that +Y == -roll
278 *
279 *
280 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800281 * Note: This definition is different from yaw, pitch and roll used in aviation
282 * where the X axis is along the long side of the plane (tail to nose).
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800283 */
284#define SENSOR_TYPE_ORIENTATION (3)
285
286/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800287 * SENSOR_TYPE_GYROSCOPE
Mathias Agopiana4557722012-11-28 17:21:55 -0800288 * trigger-mode: continuous
289 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800290 *
Kevin Powellb01a0432010-07-19 19:12:15 -0700291 * All values are in radians/second and measure the rate of rotation
292 * around the X, Y and Z axis. The coordinate system is the same as is
Mathias Agopianc04e5f62010-09-14 10:53:55 -0700293 * used for the acceleration sensor. Rotation is positive in the
294 * counter-clockwise direction (right-hand rule). That is, an observer
295 * looking from some positive location on the x, y or z axis at a device
296 * positioned on the origin would report positive rotation if the device
297 * appeared to be rotating counter clockwise. Note that this is the
298 * standard mathematical definition of positive rotation and does not agree
299 * with the definition of roll given earlier.
300 * The range should at least be 17.45 rad/s (ie: ~1000 deg/s).
Kevin Powellb01a0432010-07-19 19:12:15 -0700301 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800302 * automatic gyro-drift compensation is allowed but not required.
303 */
304#define SENSOR_TYPE_GYROSCOPE (4)
305
306/*
307 * SENSOR_TYPE_LIGHT
Mathias Agopiana4557722012-11-28 17:21:55 -0800308 * trigger-mode: on-change
309 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800310 *
311 * The light sensor value is returned in SI lux units.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800312 */
313#define SENSOR_TYPE_LIGHT (5)
314
315/*
316 * SENSOR_TYPE_PRESSURE
Mathias Agopiana4557722012-11-28 17:21:55 -0800317 * trigger-mode: continuous
318 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800319 *
320 * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800321 */
322#define SENSOR_TYPE_PRESSURE (6)
323
324/* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */
325#define SENSOR_TYPE_TEMPERATURE (7)
326
327/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800328 * SENSOR_TYPE_PROXIMITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800329 * trigger-mode: on-change
330 * wake-up sensor: yes
Mike Lockwooda2414312009-11-03 10:29:50 -0500331 *
332 * The distance value is measured in centimeters. Note that some proximity
333 * sensors only support a binary "close" or "far" measurement. In this case,
334 * the sensor should report its maxRange value in the "far" state and a value
335 * less than maxRange in the "near" state.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800336 */
337#define SENSOR_TYPE_PROXIMITY (8)
338
339/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800340 * SENSOR_TYPE_GRAVITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800341 * trigger-mode: continuous
342 * wake-up sensor: no
Mathias Agopian42b743c2010-11-22 15:55:32 -0800343 *
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800344 * A gravity output indicates the direction of and magnitude of gravity in
345 * the devices's coordinates. On Earth, the magnitude is 9.8 m/s^2.
346 * Units are m/s^2. The coordinate system is the same as is used for the
347 * acceleration sensor. When the device is at rest, the output of the
348 * gravity sensor should be identical to that of the accelerometer.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800349 */
350#define SENSOR_TYPE_GRAVITY (9)
351
352/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800353 * SENSOR_TYPE_LINEAR_ACCELERATION
Mathias Agopiana4557722012-11-28 17:21:55 -0800354 * trigger-mode: continuous
355 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800356 *
357 * Indicates the linear acceleration of the device in device coordinates,
358 * not including gravity.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800359 *
360 * The output is conceptually:
361 * output of TYPE_ACCELERATION - output of TYPE_GRAVITY
362 *
363 * Readings on all axes should be close to 0 when device lies on a table.
364 * Units are m/s^2.
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800365 * The coordinate system is the same as is used for the acceleration sensor.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800366 */
367#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
368
369
370/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800371 * SENSOR_TYPE_ROTATION_VECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800372 * trigger-mode: continuous
373 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800374 *
Kevin Powellb01a0432010-07-19 19:12:15 -0700375 * A rotation vector represents the orientation of the device as a combination
376 * of an angle and an axis, in which the device has rotated through an angle
377 * theta around an axis <x, y, z>. The three elements of the rotation vector
378 * are <x*sin(theta/2), y*sin(theta/2), z*sin(theta/2)>, such that the magnitude
379 * of the rotation vector is equal to sin(theta/2), and the direction of the
380 * rotation vector is equal to the direction of the axis of rotation. The three
381 * elements of the rotation vector are equal to the last three components of a
Etienne Le Grandca858142013-02-26 19:17:20 -0800382 * unit quaternion
383 * <cos(theta/2), x*sin(theta/2), y*sin(theta/2), z*sin(theta/2)>.
384 * Elements of the rotation vector are unitless. The x, y, and z axis are
385 * defined in the same way as for the acceleration sensor.
Mathias Agopian42b743c2010-11-22 15:55:32 -0800386 *
Mathias Agopiand93ff972011-05-02 19:10:31 -0700387 * The reference coordinate system is defined as a direct orthonormal basis,
388 * where:
389 *
390 * - X is defined as the vector product Y.Z (It is tangential to
391 * the ground at the device's current location and roughly points East).
392 *
393 * - Y is tangential to the ground at the device's current location and
394 * points towards the magnetic North Pole.
395 *
396 * - Z points towards the sky and is perpendicular to the ground.
397 *
398 *
Mathias Agopian42b743c2010-11-22 15:55:32 -0800399 * The rotation-vector is stored as:
400 *
401 * sensors_event_t.data[0] = x*sin(theta/2)
402 * sensors_event_t.data[1] = y*sin(theta/2)
403 * sensors_event_t.data[2] = z*sin(theta/2)
Etienne Le Grandca858142013-02-26 19:17:20 -0800404 *
405 * In addition, this sensor reports an estimated heading accuracy.
406 * sensors_event_t.data[3] = estimated_accuracy (in radians)
407 * The heading error must be less than estimated_accuracy 95% of the time
408 *
409 * This sensor must use a gyroscope and an accelerometer as main orientation
410 * change input.
411 *
412 * This sensor can also include magnetometer input to make up for gyro drift,
413 * but it cannot be implemented using only a magnetometer.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800414 */
415#define SENSOR_TYPE_ROTATION_VECTOR (11)
416
417/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800418 * SENSOR_TYPE_RELATIVE_HUMIDITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800419 * trigger-mode: on-change
420 * wake-up sensor: no
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100421 *
422 * A relative humidity sensor measures relative ambient air humidity and
423 * returns a value in percent.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800424 */
425#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
426
427/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800428 * SENSOR_TYPE_AMBIENT_TEMPERATURE
Mathias Agopiana4557722012-11-28 17:21:55 -0800429 * trigger-mode: on-change
430 * wake-up sensor: no
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700431 *
432 * The ambient (room) temperature in degree Celsius.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800433 */
434#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
435
436/*
437 * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
Mathias Agopiana4557722012-11-28 17:21:55 -0800438 * trigger-mode: continuous
439 * wake-up sensor: no
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700440 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800441 * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is
442 * reported separately instead of being included in the measurement.
443 * Factory calibration and temperature compensation should still be applied to
444 * the "uncalibrated" measurement.
445 * Separating away the hard iron calibration estimation allows the system to
446 * better recover from bad hard iron estimation.
447 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800448 * All values are in micro-Tesla (uT) and measure the ambient magnetic
Etienne Le Grandca858142013-02-26 19:17:20 -0800449 * field in the X, Y and Z axis. Assumptions that the the magnetic field
450 * is due to the Earth's poles should be avoided.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800451 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800452 * The uncalibrated_magnetic event contains
453 * - 3 fields for uncalibrated measurement: x_uncalib, y_uncalib, z_uncalib.
454 * Each is a component of the measured magnetic field, with soft iron
455 * and temperature compensation applied, but not hard iron calibration.
456 * These values should be continuous (no re-calibration should cause a jump).
457 * - 3 fields for hard iron bias estimates: x_bias, y_bias, z_bias.
458 * Each field is a component of the estimated hard iron calibration.
459 * They represent the offsets to apply to the uncalibrated readings to obtain
460 * calibrated readings (x_calibrated = x_uncalib + x_bias)
461 * These values are expected to jump as soon as the estimate of the hard iron
462 * changes.
Mathias Agopian1144bea2013-01-29 15:52:10 -0800463 *
464 * If this sensor is present, then the corresponding
465 * SENSOR_TYPE_MAGNETIC_FIELD must be present and both must return the
466 * same sensor_t::name and sensor_t::vendor.
Etienne Le Grandca858142013-02-26 19:17:20 -0800467 *
468 * See SENSOR_TYPE_MAGNETIC_FIELD for more information
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800469 */
470#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
471
472/*
473 * SENSOR_TYPE_GAME_ROTATION_VECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800474 * trigger-mode: continuous
475 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800476 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800477 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic
478 * field. Therefore the Y axis doesn't point north, but instead to some other
479 * reference. That reference is allowed to drift by the same order of
480 * magnitude than the gyroscope drift around the Z axis.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800481 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800482 * This sensor does not report an estimated heading accuracy:
483 * sensors_event_t.data[3] is reserved and should be set to 0
484 *
485 * In the ideal case, a phone rotated and returning to the same real-world
486 * orientation should report the same game rotation vector
487 * (without using the earth's geomagnetic field).
488 *
489 * This sensor must be based on a gyroscope. It cannot be implemented using
490 * a magnetometer.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800491 *
492 * see SENSOR_TYPE_ROTATION_VECTOR for more details
493 */
494#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
495
496/*
497 * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
Mathias Agopiana4557722012-11-28 17:21:55 -0800498 * trigger-mode: continuous
499 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800500 *
501 * All values are in radians/second and measure the rate of rotation
Mathias Agopian1144bea2013-01-29 15:52:10 -0800502 * around the X, Y and Z axis. An estimation of the drift on each axis is
503 * reported as well.
504 *
505 * No gyro-drift compensation shall be performed.
506 * Factory calibration and temperature compensation should still be applied
507 * to the rate of rotation (angular speeds).
508 *
509 * The coordinate system is the same as is
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800510 * used for the acceleration sensor. Rotation is positive in the
511 * counter-clockwise direction (right-hand rule). That is, an observer
512 * looking from some positive location on the x, y or z axis at a device
513 * positioned on the origin would report positive rotation if the device
514 * appeared to be rotating counter clockwise. Note that this is the
515 * standard mathematical definition of positive rotation and does not agree
516 * with the definition of roll given earlier.
517 * The range should at least be 17.45 rad/s (ie: ~1000 deg/s).
518 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800519 * Content of an uncalibrated_gyro event: (units are rad/sec)
520 * x_uncalib : angular speed (w/o drift compensation) around the X axis
521 * y_uncalib : angular speed (w/o drift compensation) around the Y axis
522 * z_uncalib : angular speed (w/o drift compensation) around the Z axis
523 * x_bias : estimated drift around X axis in rad/s
524 * y_bias : estimated drift around Y axis in rad/s
525 * z_bias : estimated drift around Z axis in rad/s
Mathias Agopian1144bea2013-01-29 15:52:10 -0800526 *
527 * IMPLEMENTATION NOTES:
528 *
529 * If the implementation is not able to estimate the drift, then this
530 * sensor MUST NOT be reported by this HAL. Instead, the regular
531 * SENSOR_TYPE_GYROSCOPE is used without drift compensation.
532 *
533 * If this sensor is present, then the corresponding
534 * SENSOR_TYPE_GYROSCOPE must be present and both must return the
535 * same sensor_t::name and sensor_t::vendor.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800536 */
537#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
538
Mathias Agopiana4557722012-11-28 17:21:55 -0800539
540/*
541 * SENSOR_TYPE_SIGNIFICANT_MOTION
542 * trigger-mode: one-shot
543 * wake-up sensor: yes
544 *
545 * A sensor of this type triggers an event each time significant motion
546 * is detected and automatically disables itself.
547 * The only allowed value to return is 1.0.
548 *
549 *
550 * TODO: give more details about what constitute significant motion
551 * and/or what algorithm is to be used
552 *
553 *
554 * IMPORTANT NOTE: this sensor type is very different from other types
555 * in that it must work when the screen is off without the need of
556 * holding a partial wake-lock and MUST allow the SoC to go into suspend.
557 * When significant motion is detected, the sensor must awaken the SoC and
558 * the event be reported.
559 *
560 * If a particular hardware cannot support this mode of operation then this
561 * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable
562 * to "emulate" this sensor in the HAL.
563 *
564 * The whole point of this sensor type is to save power by keeping the
565 * SoC in suspend mode when the device is at rest.
566 *
567 * When the sensor is not activated, it must also be deactivated in the
568 * hardware: it must not wake up the SoC anymore, even in case of
569 * significant motion.
570 *
571 * setDelay() has no effect and is ignored.
572 * Once a "significant motion" event is returned, a sensor of this type
573 * must disables itself automatically, as if activate(..., 0) had been called.
574 */
575
576#define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
577
578
579/*
Mathias Agopian2f276f52013-01-28 17:54:41 -0800580 * SENSOR_TYPE_STEP_DETECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800581 * trigger-mode: special
582 * wake-up sensor: no
583 *
584 * A sensor of this type triggers an event each time a step is taken
585 * by the user. The only allowed value to return is 1.0 and an event is
586 * generated for each step. Like with any other event, the timestamp
587 * indicates when the event (here the step) occurred, this corresponds to when
588 * the foot hit the ground, generating a high variation in acceleration.
589 *
590 * While this sensor operates, it shall not disrupt any other sensors, in
591 * particular, but not limited to, the accelerometer; which might very well
592 * be in use as well.
593 *
594 * This sensor must be low power. That is, if the step detection cannot be
595 * done in hardware, this sensor should not be defined. Also, when the
Mathias Agopian2f276f52013-01-28 17:54:41 -0800596 * step detector is activated and the accelerometer is not, only steps should
Mathias Agopiana4557722012-11-28 17:21:55 -0800597 * trigger interrupts (not accelerometer data).
598 *
599 * setDelay() has no impact on this sensor type
600 */
601
Mathias Agopian2f276f52013-01-28 17:54:41 -0800602#define SENSOR_TYPE_STEP_DETECTOR (18)
Mathias Agopiana4557722012-11-28 17:21:55 -0800603
604
605/*
606 * SENSOR_TYPE_STEP_COUNTER
607 * trigger-mode: on-change
608 * wake-up sensor: no
609 *
610 * A sensor of this type returns the number of steps taken by the user since
Mathias Agopian1144bea2013-01-29 15:52:10 -0800611 * the last reboot while activated. The value is returned as a uint64_t and is
612 * reset to zero only on a system reboot.
Mathias Agopiana4557722012-11-28 17:21:55 -0800613 *
614 * The timestamp of the event is set to the time when the first step
615 * for that event was taken.
Mathias Agopian2f276f52013-01-28 17:54:41 -0800616 * See SENSOR_TYPE_STEP_DETECTOR for the signification of the time of a step.
Mathias Agopiana4557722012-11-28 17:21:55 -0800617 *
618 * The minimum size of the hardware's internal counter shall be 16 bits
619 * (this restriction is here to avoid too frequent wake-ups when the
620 * delay is very large).
621 *
622 * IMPORTANT NOTE: this sensor type is different from other types
623 * in that it must work when the screen is off without the need of
624 * holding a partial wake-lock and MUST allow the SoC to go into suspend.
625 * Unlike other sensors, while in suspend mode this sensor must stay active,
626 * no events are reported during that time but, steps continue to be
627 * accounted for; an event will be reported as soon as the SoC resumes if
628 * the timeout has expired.
629 *
630 * In other words, when the screen is off and the device allowed to
631 * go into suspend mode, we don't want to be woken up, regardless of the
632 * setDelay() value, but the steps shall continue to be counted.
633 *
634 * The driver must however ensure that the internal step count never
635 * overflows. It is allowed in this situation to wake the SoC up so the
636 * driver can do the counter maintenance.
637 *
638 * While this sensor operates, it shall not disrupt any other sensors, in
639 * particular, but not limited to, the accelerometer; which might very well
640 * be in use as well.
641 *
642 * If a particular hardware cannot support these modes of operation then this
643 * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable
644 * to "emulate" this sensor in the HAL.
645 *
646 * This sensor must be low power. That is, if the step detection cannot be
647 * done in hardware, this sensor should not be defined. Also, when the
648 * step counter is activated and the accelerometer is not, only steps should
649 * trigger interrupts (not accelerometer data).
650 *
651 * The whole point of this sensor type is to save power by keeping the
652 * SoC in suspend mode when the device is at rest.
653 */
654
655#define SENSOR_TYPE_STEP_COUNTER (19)
656
Etienne Le Grandca858142013-02-26 19:17:20 -0800657/*
658 * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
659 * trigger-mode: continuous
660 * wake-up sensor: no
661 *
662 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead
663 * of using a gyroscope.
664 *
665 * This sensor must be based on a magnetometer. It cannot be implemented using
666 * a gyroscope, and gyroscope input cannot be used by this sensor.
667 *
668 * Just like SENSOR_TYPE_ROTATION_VECTOR, this sensor reports an estimated
669 * heading accuracy:
670 * sensors_event_t.data[3] = estimated_accuracy (in radians)
671 * The heading error must be less than estimated_accuracy 95% of the time
672 *
673 * see SENSOR_TYPE_ROTATION_VECTOR for more details
674 */
675#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20)
Mathias Agopiana4557722012-11-28 17:21:55 -0800676
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800677/**
678 * Values returned by the accelerometer in various locations in the universe.
679 * all values are in SI units (m/s^2)
680 */
681#define GRAVITY_SUN (275.0f)
682#define GRAVITY_EARTH (9.80665f)
683
684/** Maximum magnetic field on Earth's surface */
685#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
686
687/** Minimum magnetic field on Earth's surface */
688#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
689
690
691/**
692 * status of orientation sensor
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800693 */
Kevin Powellb01a0432010-07-19 19:12:15 -0700694
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800695#define SENSOR_STATUS_UNRELIABLE 0
696#define SENSOR_STATUS_ACCURACY_LOW 1
697#define SENSOR_STATUS_ACCURACY_MEDIUM 2
698#define SENSOR_STATUS_ACCURACY_HIGH 3
699
700
701/**
702 * sensor event data
703 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800704typedef struct {
705 union {
706 float v[3];
707 struct {
708 float x;
709 float y;
710 float z;
711 };
712 struct {
713 float azimuth;
714 float pitch;
715 float roll;
716 };
717 };
718 int8_t status;
719 uint8_t reserved[3];
720} sensors_vec_t;
721
722/**
Etienne Le Grandca858142013-02-26 19:17:20 -0800723 * uncalibrated gyroscope and magnetometer event data
724 */
725typedef struct {
726 float x_uncalib;
727 float y_uncalib;
728 float z_uncalib;
729 float x_bias;
730 float y_bias;
731 float z_bias;
732} uncalibrated_event_t;
733
734/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800735 * Union of the various types of sensor data
736 * that can be returned.
737 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700738typedef struct sensors_event_t {
739 /* must be sizeof(struct sensors_event_t) */
740 int32_t version;
741
742 /* sensor identifier */
743 int32_t sensor;
744
745 /* sensor type */
746 int32_t type;
747
748 /* reserved */
749 int32_t reserved0;
750
751 /* time is in nanosecond */
752 int64_t timestamp;
753
754 union {
755 float data[16];
756
757 /* acceleration values are in meter per second per second (m/s^2) */
Jeff Brown296cf932013-02-09 02:46:33 +0000758 sensors_vec_t acceleration;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700759
760 /* magnetic vector values are in micro-Tesla (uT) */
761 sensors_vec_t magnetic;
762
763 /* orientation values are in degrees */
764 sensors_vec_t orientation;
765
Mathias Agopianc04e5f62010-09-14 10:53:55 -0700766 /* gyroscope values are in rad/s */
Jeff Brown296cf932013-02-09 02:46:33 +0000767 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -0700768
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700769 /* temperature is in degrees centigrade (Celsius) */
770 float temperature;
771
772 /* distance in centimeters */
773 float distance;
774
775 /* light in SI lux units */
776 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -0700777
778 /* pressure in hectopascal (hPa) */
779 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100780
781 /* relative humidity in percent */
782 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -0800783
784 /* step-counter */
785 uint64_t step_counter;
Etienne Le Grandca858142013-02-26 19:17:20 -0800786
787 /* uncalibrated gyroscope values are in rad/s */
788 uncalibrated_event_t uncalibrated_gyro;
789
790 /* uncalibrated magnetometer values are in micro-Teslas */
791 uncalibrated_event_t uncalibrated_magnetic;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700792 };
793 uint32_t reserved1[4];
794} sensors_event_t;
795
796
797
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800798struct sensor_t;
799
800/**
801 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
802 * and the fields of this data structure must begin with hw_module_t
803 * followed by module specific information.
804 */
805struct sensors_module_t {
806 struct hw_module_t common;
807
808 /**
809 * Enumerate all available sensors. The list is returned in "list".
810 * @return number of sensors in the list
811 */
812 int (*get_sensors_list)(struct sensors_module_t* module,
813 struct sensor_t const** list);
814};
815
816struct sensor_t {
Mathias Agopian1144bea2013-01-29 15:52:10 -0800817
818 /* Name of this sensor.
819 * All sensors of the same "type" must have a different "name".
820 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800821 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -0800822
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800823 /* vendor of the hardware part */
824 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -0800825
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800826 /* version of the hardware part + driver. The value of this field
827 * must increase when the driver is updated in a way that changes the
828 * output of this sensor. This is important for fused sensors when the
829 * fusion algorithm is updated.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800830 */
831 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -0800832
833 /* handle that identifies this sensors. This handle is used to reference
834 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800835 */
836 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -0800837
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800838 /* this sensor's type. */
839 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -0800840
841 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800842 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -0800843
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800844 /* smallest difference between two values reported by this sensor */
845 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -0800846
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800847 /* rough estimate of this sensor's power consumption in mA */
848 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -0800849
850 /* this value depends on the trigger mode:
851 *
852 * continuous: minimum sample period allowed in microseconds
853 * on-change : 0
854 * one-shot :-1
855 * special : 0, unless otherwise noted
856 */
Mathias Agopian1511e202010-07-29 15:33:22 -0700857 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -0800858
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800859 /* reserved fields, must be zero */
Mathias Agopian1511e202010-07-29 15:33:22 -0700860 void* reserved[8];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800861};
862
863
Mathias Agopiana4557722012-11-28 17:21:55 -0800864/*
865 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
866 * and is present for backward binary and source compatibility.
867 * (see documentation of the hooks in struct sensors_poll_device_1 below)
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800868 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700869struct sensors_poll_device_t {
870 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700871 int (*activate)(struct sensors_poll_device_t *dev,
872 int handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700873 int (*setDelay)(struct sensors_poll_device_t *dev,
874 int handle, int64_t ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700875 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700876 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700877};
878
Mathias Agopiana4557722012-11-28 17:21:55 -0800879/*
880 * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0
881 */
882typedef struct sensors_poll_device_1 {
883 union {
884 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
885 * and can be down-cast to it
886 */
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800887 struct sensors_poll_device_t v0;
Mathias Agopiana4557722012-11-28 17:21:55 -0800888
889 struct {
890 struct hw_device_t common;
891
892 /* Activate/de-activate one sensor.
893 *
894 * handle is the handle of the sensor to change.
895 * enabled set to 1 to enable, or 0 to disable the sensor.
896 *
897 * unless otherwise noted in the sensor types definitions, an
898 * activated sensor never prevents the SoC to go into suspend
899 * mode; that is, the HAL shall not hold a partial wake-lock on
900 * behalf of applications.
901 *
902 * one-shot sensors de-activate themselves automatically upon
903 * receiving an event and they must still accept to be deactivated
904 * through a call to activate(..., ..., 0).
905 *
906 * if "enabled" is true and the sensor is already activated, this
907 * function is a no-op and succeeds.
908 *
909 * if "enabled" is false and the sensor is already de-activated,
910 * this function is a no-op and succeeds.
911 *
912 * return 0 on success, negative errno code otherwise
913 */
914 int (*activate)(struct sensors_poll_device_t *dev,
915 int handle, int enabled);
916
917 /**
Mathias Agopian1144bea2013-01-29 15:52:10 -0800918 * Set the events's period in nanoseconds for a given sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -0800919 *
Mathias Agopian1144bea2013-01-29 15:52:10 -0800920 * What the period_ns parameter means depends on the specified
Mathias Agopiana4557722012-11-28 17:21:55 -0800921 * sensor's trigger mode:
922 *
923 * continuous: setDelay() sets the sampling rate.
924 * on-change: setDelay() limits the delivery rate of events
925 * one-shot: setDelay() is ignored. it has no effect.
926 * special: see specific sensor type definitions
927 *
928 * For continuous and on-change sensors, if the requested value is
929 * less than sensor_t::minDelay, then it's silently clamped to
930 * sensor_t::minDelay unless sensor_t::minDelay is 0, in which
931 * case it is clamped to >= 1ms.
932 *
933 * @return 0 if successful, < 0 on error
934 */
935 int (*setDelay)(struct sensors_poll_device_t *dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -0800936 int handle, int64_t period_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -0800937
938 /**
939 * Returns an array of sensor data.
940 * This function must block until events are available.
941 *
942 * return the number of events read on success, or -errno in case
943 * of an error.
944 *
945 * The number of events returned in data must be less or equal
946 * to SENSORS_QUERY_MAX_EVENTS_BATCH_COUNT.
947 *
948 * This function shall never return 0 (no event).
949 */
950 int (*poll)(struct sensors_poll_device_t *dev,
951 sensors_event_t* data, int count);
952 };
953 };
954
955 /*
956 * Used to retrieve information about the sensor HAL
957 *
958 * Returns 0 on success or -errno on error.
959 */
960 int (*query)(struct sensors_poll_device_1* dev, int what, int* value);
961
962
963 /*
Mathias Agopian1144bea2013-01-29 15:52:10 -0800964 * Enables batch mode for the given sensor and sets the delay between events
Mathias Agopiana4557722012-11-28 17:21:55 -0800965 *
966 * A timeout value of zero disables batch mode for the given sensor.
967 *
Mathias Agopian1144bea2013-01-29 15:52:10 -0800968 * The period_ns parameter is equivalent to calling setDelay() -- this
969 * function both enables or disables the batch mode AND sets the events's
970 * period in nanosecond. See setDelay() above for a detailed explanation of
971 * the period_ns parameter.
972 *
Mathias Agopiana4557722012-11-28 17:21:55 -0800973 * While in batch mode sensor events are reported in batches at least
974 * every "timeout" nanosecond; that is all events since the previous batch
975 * are recorded and returned all at once. Batches can be interleaved and
976 * split, and as usual events of the same sensor type are time-ordered.
977 *
978 * setDelay() is not affected and it behaves as usual.
979 *
980 * Each event has a timestamp associated with it, the timestamp
981 * must be accurate and correspond to the time at which the event
982 * physically happened.
983 *
984 * If internal h/w FIFOs fill-up before the timeout, then events are
Mathias Agopian1144bea2013-01-29 15:52:10 -0800985 * reported at that point. No event shall be dropped or lost.
986 *
987 *
988 * INTERACTION WITH SUSPEND MODE:
989 * ------------------------------
Mathias Agopiana4557722012-11-28 17:21:55 -0800990 *
991 * By default batch mode doesn't significantly change the interaction with
992 * suspend mode, that is, sensors must continue to allow the SoC to
993 * go into suspend mode and sensors must stay active to fill their
994 * internal FIFO, in this mode, when the FIFO fills-up, it shall wrap
995 * around (basically behave like a circular buffer, overwriting events).
996 * As soon as the SoC comes out of suspend mode, a batch is produced with
997 * as much as the recent history as possible, and batch operation
998 * resumes as usual.
999 *
1000 * The behavior described above allows applications to record the recent
1001 * history of a set of sensor while keeping the SoC into suspend. It
1002 * also allows the hardware to not have to rely on a wake-up interrupt line.
1003 *
1004 * There are cases however where an application cannot afford to lose
1005 * any events, even when the device goes into suspend mode. The behavior
1006 * specified above can be altered by setting the
1007 * SENSORS_BATCH_WAKE_UPON_FIFO_FULL flag. If this flag is set, the SoC
1008 * must be woken up from suspend and a batch must be returned before
1009 * the FIFO fills-up. Enough head room must be allocated in the FIFO to allow
1010 * the device to entirely come out of suspend (which might take a while and
1011 * is device dependent) such that no event are lost.
1012 *
1013 * If the hardware cannot support this mode, or, if the physical
1014 * FIFO is so small that the device would never be allowed to go into
Mathias Agopian1144bea2013-01-29 15:52:10 -08001015 * suspend for at least 10 seconds, then this function MUST fail when
1016 * the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is set, regardless of
1017 * the value of the timeout parameter.
Mathias Agopiana4557722012-11-28 17:21:55 -08001018 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001019 * DRY RUN:
1020 * --------
Mathias Agopiana4557722012-11-28 17:21:55 -08001021 *
1022 * If the flag SENSORS_BATCH_DRY_RUN is set, this function returns
Mathias Agopian1144bea2013-01-29 15:52:10 -08001023 * without modifying the batch mode or the event period and has no side
1024 * effects, but returns errors as usual (as it would if this flag was
1025 * not set). This flag is used to check if batch mode is available for a
1026 * given configuration -- in particular for a given sensor at a given rate.
1027 *
Mathias Agopiana4557722012-11-28 17:21:55 -08001028 *
1029 * Return values:
Mathias Agopian1144bea2013-01-29 15:52:10 -08001030 * --------------
1031 *
1032 * Because sensors must be independent, the return value must not depend
1033 * on the state of the system (whether another sensor is on or not),
1034 * nor on whether the flag SENSORS_BATCH_DRY_RUN is set (in other words,
1035 * if a batch call with SENSORS_BATCH_DRY_RUN is successful,
1036 * the same call without SENSORS_BATCH_DRY_RUN must succeed as well).
Mathias Agopiana4557722012-11-28 17:21:55 -08001037 *
1038 * If successful, 0 is returned.
1039 * If the specified sensor doesn't support batch mode, -EINVAL is returned.
1040 * If the specified sensor's trigger-mode is one-shot, -EINVAL is returned.
1041 * If any of the constraint above cannot be satisfied, -EINVAL is returned.
1042 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001043 * Note: the timeout parameter, when > 0, has no impact on whether this
1044 * function succeeds or fails.
1045 *
Mathias Agopiana4557722012-11-28 17:21:55 -08001046 * If timeout is set to 0, this function must succeed.
1047 *
1048 *
1049 * IMPLEMENTATION NOTES:
Mathias Agopian1144bea2013-01-29 15:52:10 -08001050 * ---------------------
Mathias Agopiana4557722012-11-28 17:21:55 -08001051 *
1052 * batch mode, if supported, should happen at the hardware level,
1053 * typically using hardware FIFOs. In particular, it SHALL NOT be
1054 * implemented in the HAL, as this would be counter productive.
1055 * The goal here is to save significant amounts of power.
1056 *
Mathias Agopiana4557722012-11-28 17:21:55 -08001057 * batch mode can be enabled or disabled at any time, in particular
1058 * while the specified sensor is already enabled and this shall not
1059 * result in the loss of events.
1060 *
Etienne Le Grandca858142013-02-26 19:17:20 -08001061 * COMPARATIVE IMPORTANCE OF BATCHING FOR DIFFERENT SENSORS:
1062 * ---------------------------------------------------------
1063 *
1064 * On platforms on which hardware fifo size is limited, the system designers
1065 * might have to choose how much fifo to reserve for each sensor. To help
1066 * with this choice, Here is a list of applications made possible when
1067 * batching is implemented on the different sensors.
1068 *
1069 * High value: Low power pedestrian dead reckoning
1070 * Target batching time: 20 seconds to 1 minute
1071 * Sensors to batch:
1072 * - Step detector
1073 * - Rotation vector or game rotation vector at 5Hz
1074 * Gives us step and heading while letting the AP go to Suspend.
1075 *
1076 * High value: Medium power activity/gesture recognition
1077 * Target batching time: 3 seconds
1078 * Sensors to batch: accelerometer between 20Hz and 50Hz
1079 * Allows recognizing arbitrary activities and gestures without having
1080 * to keep the AP fully awake while the data is collected.
1081 *
1082 * Medium-high value: Interrupt load reduction
1083 * Target batching time: < 1 second
1084 * Sensors to batch: any high frequency sensor.
1085 * If the gyroscope is set at 800Hz, even batching just 10 gyro events can
1086 * reduce the number of interrupts from 800/second to 80/second.
1087 *
1088 * Medium value: Continuous low frequency data collection
1089 * Target batching time: > 1 minute
1090 * Sensors to batch: barometer, humidity sensor, other low frequency
1091 * sensors.
1092 * Allows creating monitoring applications at low power.
1093 *
1094 * Medium value: Continuous full-sensors collection
1095 * Target batching time: > 1 minute
1096 * Sensors to batch: all, at high frequencies
1097 * Allows full collection of sensor data while leaving the AP in
1098 * suspend mode. Only to consider if fifo space is not an issue.
Mathias Agopiana4557722012-11-28 17:21:55 -08001099 */
1100 int (*batch)(struct sensors_poll_device_1* dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -08001101 int handle, int flags, int64_t period_ns, int64_t timeout);
Mathias Agopiana4557722012-11-28 17:21:55 -08001102
1103 void (*reserved_procs[8])(void);
1104
1105} sensors_poll_device_1_t;
1106
1107
1108
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001109/** convenience API for opening and closing a device */
1110
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001111static inline int sensors_open(const struct hw_module_t* module,
1112 struct sensors_poll_device_t** device) {
1113 return module->methods->open(module,
1114 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1115}
1116
1117static inline int sensors_close(struct sensors_poll_device_t* device) {
1118 return device->common.close(&device->common);
1119}
1120
Mathias Agopiana4557722012-11-28 17:21:55 -08001121static inline int sensors_open_1(const struct hw_module_t* module,
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001122 sensors_poll_device_1_t** device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001123 return module->methods->open(module,
1124 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1125}
1126
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001127static inline int sensors_close_1(sensors_poll_device_1_t* device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001128 return device->common.close(&device->common);
1129}
1130
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001131__END_DECLS
1132
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001133#endif // ANDROID_SENSORS_INTERFACE_H