blob: 4fd44687e72b4dd3aed9af943b8eb5774129a3b3 [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 */
73 META_DATA_FLUSH_COMPLETE = 1
74};
75
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080076/**
Mathias Agopian56f66cc2012-11-08 15:57:38 -080077 * Definition of the axis used by the sensor HAL API
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080078 *
79 * This API is relative to the screen of the device in its default orientation,
80 * that is, if the device can be used in portrait or landscape, this API
81 * is only relative to the NATURAL orientation of the screen. In other words,
82 * the axis are not swapped when the device's screen orientation changes.
83 * Higher level services /may/ perform this transformation.
84 *
85 * x<0 x>0
86 * ^
87 * |
88 * +-----------+--> y>0
89 * | |
90 * | |
91 * | |
92 * | | / z<0
93 * | | /
94 * | | /
95 * O-----------+/
96 * |[] [ ] []/
97 * +----------/+ y<0
98 * /
99 * /
100 * |/ z>0 (toward the sky)
101 *
102 * O: Origin (x=0,y=0,z=0)
103 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800104 */
105
Mathias Agopiana4557722012-11-28 17:21:55 -0800106/*
107 * Interaction with suspend mode
108 *
109 * Unless otherwise noted, an enabled sensor shall not prevent the
110 * SoC to go into suspend mode. It is the responsibility of applications
111 * to keep a partial wake-lock should they wish to receive sensor
112 * events while the screen is off. While in suspend mode, and unless
Etienne Le Grand28f04112013-03-27 18:59:10 -0700113 * otherwise noted (batch mode, sensor particularities, ...), enabled sensors'
114 * events are lost.
Mathias Agopiana4557722012-11-28 17:21:55 -0800115 *
116 * Note that conceptually, the sensor itself is not de-activated while in
117 * suspend mode -- it's just that the data it returns are lost. As soon as
118 * the SoC gets out of suspend mode, operations resume as usual. Of course,
119 * in practice sensors shall be disabled while in suspend mode to
120 * save power, unless batch mode is active, in which case they must
121 * continue fill their internal FIFO (see the documentation of batch() to
122 * learn how suspend interacts with batch mode).
123 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700124 * In batch mode, and only when the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is
Mathias Agopian1144bea2013-01-29 15:52:10 -0800125 * set and supported, the specified sensor must be able to wake-up the SoC and
126 * be able to buffer at least 10 seconds worth of the requested sensor events.
Mathias Agopiana4557722012-11-28 17:21:55 -0800127 *
128 * There are notable exceptions to this behavior, which are sensor-dependent
129 * (see sensor types definitions below)
130 *
131 *
132 * The sensor type documentation below specifies the wake-up behavior of
133 * each sensor:
134 * wake-up: yes this sensor must wake-up the SoC to deliver events
135 * wake-up: no this sensor shall not wake-up the SoC, events are dropped
136 *
137 */
138
139/*
140 * Sensor type
141 *
142 * Each sensor has a type which defines what this sensor measures and how
143 * measures are reported. All types are defined below.
144 */
145
146/*
147 * Sensor fusion and virtual sensors
148 *
149 * Many sensor types are or can be implemented as virtual sensors from
150 * physical sensors on the device. For instance the rotation vector sensor,
Mathias Agopian2f276f52013-01-28 17:54:41 -0800151 * orientation sensor, step-detector, step-counter, etc...
Mathias Agopiana4557722012-11-28 17:21:55 -0800152 *
153 * From the point of view of this API these virtual sensors MUST appear as
154 * real, individual sensors. It is the responsibility of the driver and HAL
155 * to make sure this is the case.
156 *
157 * In particular, all sensors must be able to function concurrently.
158 * For example, if defining both an accelerometer and a step counter,
159 * then both must be able to work concurrently.
160 */
161
162/*
163 * Trigger modes
164 *
165 * Sensors can report events in different ways called trigger modes,
166 * each sensor type has one and only one trigger mode associated to it.
167 * Currently there are four trigger modes defined:
168 *
169 * continuous: events are reported at a constant rate defined by setDelay().
170 * eg: accelerometers, gyroscopes.
171 * on-change: events are reported only if the sensor's value has changed.
172 * setDelay() is used to set a lower limit to the reporting
173 * period (minimum time between two events).
174 * The HAL must return an event immediately when an on-change
175 * sensor is activated.
176 * eg: proximity, light sensors
Etienne Le Grandca858142013-02-26 19:17:20 -0800177 * one-shot: upon detection of an event, the sensor deactivates itself and
178 * then sends a single event. Order matters to avoid race
179 * conditions. No other event is sent until the sensor get
180 * reactivated. setDelay() is ignored.
Mathias Agopiana4557722012-11-28 17:21:55 -0800181 * eg: significant motion sensor
182 * special: see details in the sensor type specification below
183 *
184 */
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800185
Mathias Agopian16671c52013-07-24 21:07:40 -0700186
187/*
188 * SENSOR_TYPE_META_DATA
189 * trigger-mode: n/a
190 * wake-up sensor: n/a
191 *
192 * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)()
193 *
194 * SENSOR_TYPE_META_DATA is a special token used to populate the
195 * sensors_meta_data_event structure. It doesn't correspond to a physical
196 * sensor. sensors_meta_data_event are special, they exist only inside
197 * the HAL and are generated spontaneously, as opposed to be related to
198 * a physical sensor.
199 *
200 * sensors_meta_data_event_t.base.version must be 0
201 * sensors_meta_data_event_t.base.sensor must be 0
202 * sensors_meta_data_event_t.base.type must be SENSOR_TYPE_META_DATA
203 * sensors_meta_data_event_t.base.reserved must be 0
204 * sensors_meta_data_event_t.base.timestamp must be 0
205 *
206 * The payload is a meta_data_event_t, where:
207 * meta_data_event_t.what can take the following values:
208 *
209 * META_DATA_FLUSH_COMPLETE
210 * This event indicates that a previous (*flush)() call has completed for the sensor
211 * handle specified in meta_data_event_t.sensor.
212 * see (*flush)() for more details
213 *
214 * All other values for meta_data_event_t.what are reserved and
215 * must not be used.
216 *
217 */
218#define SENSOR_TYPE_META_DATA (0)
219
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800220/*
221 * SENSOR_TYPE_ACCELEROMETER
Mathias Agopiana4557722012-11-28 17:21:55 -0800222 * trigger-mode: continuous
223 * wake-up sensor: no
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800224 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800225 * All values are in SI units (m/s^2) and measure the acceleration of the
226 * device minus the force of gravity.
227 *
228 * Acceleration sensors return sensor events for all 3 axes at a constant
229 * rate defined by setDelay().
230 *
231 * x: Acceleration on the x-axis
232 * y: Acceleration on the y-axis
233 * z: Acceleration on the z-axis
234 *
235 * Note that the readings from the accelerometer include the acceleration
236 * due to gravity (which is opposite to the direction of the gravity vector).
237 *
238 * Examples:
239 * The norm of <x, y, z> should be close to 0 when in free fall.
240 *
241 * When the device lies flat on a table and is pushed on its left side
242 * toward the right, the x acceleration value is positive.
243 *
244 * When the device lies flat on a table, the acceleration value is +9.81,
245 * which correspond to the acceleration of the device (0 m/s^2) minus the
246 * force of gravity (-9.81 m/s^2).
247 *
248 * When the device lies flat on a table and is pushed toward the sky, the
249 * acceleration value is greater than +9.81, which correspond to the
250 * acceleration of the device (+A m/s^2) minus the force of
251 * gravity (-9.81 m/s^2).
252 */
253#define SENSOR_TYPE_ACCELEROMETER (1)
254
255/*
256 * SENSOR_TYPE_GEOMAGNETIC_FIELD
Mathias Agopiana4557722012-11-28 17:21:55 -0800257 * trigger-mode: continuous
258 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800259 *
260 * All values are in micro-Tesla (uT) and measure the geomagnetic
261 * field in the X, Y and Z axis.
262 *
263 * Returned values include calibration mechanisms such that the vector is
264 * aligned with the magnetic declination and heading of the earth's
265 * geomagnetic field.
266 *
267 * Magnetic Field sensors return sensor events for all 3 axes at a constant
268 * rate defined by setDelay().
269 */
270#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2)
271#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
272
273/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800274 * SENSOR_TYPE_ORIENTATION
Mathias Agopiana4557722012-11-28 17:21:55 -0800275 * trigger-mode: continuous
276 * wake-up sensor: no
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800277 *
278 * All values are angles in degrees.
279 *
Mathias Agopian66a40952010-07-22 17:11:50 -0700280 * Orientation sensors return sensor events for all 3 axes at a constant
281 * rate defined by setDelay().
282 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800283 * azimuth: angle between the magnetic north direction and the Y axis, around
284 * the Z axis (0<=azimuth<360).
285 * 0=North, 90=East, 180=South, 270=West
286 *
287 * pitch: Rotation around X axis (-180<=pitch<=180), with positive values when
288 * the z-axis moves toward the y-axis.
289 *
290 * roll: Rotation around Y axis (-90<=roll<=90), with positive values when
Mathias Agopian19ea59f2010-02-26 13:15:18 -0800291 * the x-axis moves towards the z-axis.
292 *
293 * Note: For historical reasons the roll angle is positive in the clockwise
294 * direction (mathematically speaking, it should be positive in the
295 * counter-clockwise direction):
296 *
297 * Z
298 * ^
299 * (+roll) .--> |
300 * / |
301 * | | roll: rotation around Y axis
302 * X <-------(.)
303 * Y
304 * note that +Y == -roll
305 *
306 *
307 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800308 * Note: This definition is different from yaw, pitch and roll used in aviation
309 * where the X axis is along the long side of the plane (tail to nose).
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800310 */
311#define SENSOR_TYPE_ORIENTATION (3)
312
313/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800314 * SENSOR_TYPE_GYROSCOPE
Mathias Agopiana4557722012-11-28 17:21:55 -0800315 * trigger-mode: continuous
316 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800317 *
Kevin Powellb01a0432010-07-19 19:12:15 -0700318 * All values are in radians/second and measure the rate of rotation
319 * around the X, Y and Z axis. The coordinate system is the same as is
Mathias Agopianc04e5f62010-09-14 10:53:55 -0700320 * used for the acceleration sensor. Rotation is positive in the
321 * counter-clockwise direction (right-hand rule). That is, an observer
322 * looking from some positive location on the x, y or z axis at a device
323 * positioned on the origin would report positive rotation if the device
324 * appeared to be rotating counter clockwise. Note that this is the
325 * standard mathematical definition of positive rotation and does not agree
326 * with the definition of roll given earlier.
327 * The range should at least be 17.45 rad/s (ie: ~1000 deg/s).
Kevin Powellb01a0432010-07-19 19:12:15 -0700328 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800329 * automatic gyro-drift compensation is allowed but not required.
330 */
331#define SENSOR_TYPE_GYROSCOPE (4)
332
333/*
334 * SENSOR_TYPE_LIGHT
Mathias Agopiana4557722012-11-28 17:21:55 -0800335 * trigger-mode: on-change
336 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800337 *
338 * The light sensor value is returned in SI lux units.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800339 */
340#define SENSOR_TYPE_LIGHT (5)
341
342/*
343 * SENSOR_TYPE_PRESSURE
Mathias Agopiana4557722012-11-28 17:21:55 -0800344 * trigger-mode: continuous
345 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800346 *
347 * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800348 */
349#define SENSOR_TYPE_PRESSURE (6)
350
351/* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */
352#define SENSOR_TYPE_TEMPERATURE (7)
353
354/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800355 * SENSOR_TYPE_PROXIMITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800356 * trigger-mode: on-change
357 * wake-up sensor: yes
Mike Lockwooda2414312009-11-03 10:29:50 -0500358 *
359 * The distance value is measured in centimeters. Note that some proximity
360 * sensors only support a binary "close" or "far" measurement. In this case,
361 * the sensor should report its maxRange value in the "far" state and a value
362 * less than maxRange in the "near" state.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800363 */
364#define SENSOR_TYPE_PROXIMITY (8)
365
366/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800367 * SENSOR_TYPE_GRAVITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800368 * trigger-mode: continuous
369 * wake-up sensor: no
Mathias Agopian42b743c2010-11-22 15:55:32 -0800370 *
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800371 * A gravity output indicates the direction of and magnitude of gravity in
372 * the devices's coordinates. On Earth, the magnitude is 9.8 m/s^2.
373 * Units are m/s^2. The coordinate system is the same as is used for the
374 * acceleration sensor. When the device is at rest, the output of the
375 * gravity sensor should be identical to that of the accelerometer.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800376 */
377#define SENSOR_TYPE_GRAVITY (9)
378
379/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800380 * SENSOR_TYPE_LINEAR_ACCELERATION
Mathias Agopiana4557722012-11-28 17:21:55 -0800381 * trigger-mode: continuous
382 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800383 *
384 * Indicates the linear acceleration of the device in device coordinates,
385 * not including gravity.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800386 *
387 * The output is conceptually:
388 * output of TYPE_ACCELERATION - output of TYPE_GRAVITY
389 *
390 * Readings on all axes should be close to 0 when device lies on a table.
391 * Units are m/s^2.
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800392 * The coordinate system is the same as is used for the acceleration sensor.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800393 */
394#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
395
396
397/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800398 * SENSOR_TYPE_ROTATION_VECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800399 * trigger-mode: continuous
400 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800401 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700402 * The rotation vector symbolizes the orientation of the device relative to the
403 * East-North-Up coordinates frame. It is usually obtained by integration of
404 * accelerometer, gyroscope and magnetometer readings.
Mathias Agopian42b743c2010-11-22 15:55:32 -0800405 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700406 * The East-North-Up coordinate system is defined as a direct orthonormal basis
Mathias Agopiand93ff972011-05-02 19:10:31 -0700407 * where:
Etienne Le Grand28f04112013-03-27 18:59:10 -0700408 * - X points east and is tangential to the ground.
409 * - Y points north and is tangential to the ground.
Mathias Agopiand93ff972011-05-02 19:10:31 -0700410 * - Z points towards the sky and is perpendicular to the ground.
411 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700412 * The orientation of the phone is represented by the rotation necessary to
413 * align the East-North-Up coordinates with the phone's coordinates. That is,
414 * applying the rotation to the world frame (X,Y,Z) would align them with the
415 * phone coordinates (x,y,z).
Mathias Agopiand93ff972011-05-02 19:10:31 -0700416 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700417 * The rotation can be seen as rotating the phone by an angle theta around
418 * an axis rot_axis to go from the reference (East-North-Up aligned) device
419 * orientation to the current device orientation.
Mathias Agopian42b743c2010-11-22 15:55:32 -0800420 *
Etienne Le Grand28f04112013-03-27 18:59:10 -0700421 * The rotation is encoded as the 4 (reordered) components of a unit quaternion:
422 * sensors_event_t.data[0] = rot_axis.x*sin(theta/2)
423 * sensors_event_t.data[1] = rot_axis.y*sin(theta/2)
424 * sensors_event_t.data[2] = rot_axis.z*sin(theta/2)
425 * sensors_event_t.data[3] = cos(theta/2)
426 * where
427 * - rot_axis.x,y,z are the North-East-Up coordinates of a unit length vector
428 * representing the rotation axis
429 * - theta is the rotation angle
430 *
431 * The quaternion must be of norm 1 (it is a unit quaternion). Failure to ensure
432 * this will cause erratic client behaviour.
Etienne Le Grandca858142013-02-26 19:17:20 -0800433 *
434 * In addition, this sensor reports an estimated heading accuracy.
Etienne Le Grand28f04112013-03-27 18:59:10 -0700435 * sensors_event_t.data[4] = estimated_accuracy (in radians)
Etienne Le Grandca858142013-02-26 19:17:20 -0800436 * The heading error must be less than estimated_accuracy 95% of the time
437 *
438 * This sensor must use a gyroscope and an accelerometer as main orientation
439 * change input.
440 *
441 * This sensor can also include magnetometer input to make up for gyro drift,
442 * but it cannot be implemented using only a magnetometer.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800443 */
444#define SENSOR_TYPE_ROTATION_VECTOR (11)
445
446/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800447 * SENSOR_TYPE_RELATIVE_HUMIDITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800448 * trigger-mode: on-change
449 * wake-up sensor: no
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100450 *
451 * A relative humidity sensor measures relative ambient air humidity and
452 * returns a value in percent.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800453 */
454#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
455
456/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800457 * SENSOR_TYPE_AMBIENT_TEMPERATURE
Mathias Agopiana4557722012-11-28 17:21:55 -0800458 * trigger-mode: on-change
459 * wake-up sensor: no
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700460 *
461 * The ambient (room) temperature in degree Celsius.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800462 */
463#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
464
465/*
466 * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
Mathias Agopiana4557722012-11-28 17:21:55 -0800467 * trigger-mode: continuous
468 * wake-up sensor: no
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700469 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800470 * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is
471 * reported separately instead of being included in the measurement.
472 * Factory calibration and temperature compensation should still be applied to
473 * the "uncalibrated" measurement.
474 * Separating away the hard iron calibration estimation allows the system to
475 * better recover from bad hard iron estimation.
476 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800477 * All values are in micro-Tesla (uT) and measure the ambient magnetic
Etienne Le Grandca858142013-02-26 19:17:20 -0800478 * field in the X, Y and Z axis. Assumptions that the the magnetic field
479 * is due to the Earth's poles should be avoided.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800480 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800481 * The uncalibrated_magnetic event contains
482 * - 3 fields for uncalibrated measurement: x_uncalib, y_uncalib, z_uncalib.
483 * Each is a component of the measured magnetic field, with soft iron
484 * and temperature compensation applied, but not hard iron calibration.
485 * These values should be continuous (no re-calibration should cause a jump).
486 * - 3 fields for hard iron bias estimates: x_bias, y_bias, z_bias.
487 * Each field is a component of the estimated hard iron calibration.
Etienne Le Grand7a813e82013-04-23 14:22:23 -0700488 * They represent the offsets to apply to the calibrated readings to obtain
489 * uncalibrated readings (x_uncalib ~= x_calibrated + x_bias)
Etienne Le Grandca858142013-02-26 19:17:20 -0800490 * These values are expected to jump as soon as the estimate of the hard iron
Etienne Le Grand7a813e82013-04-23 14:22:23 -0700491 * changes, and they should be stable the rest of the time.
Mathias Agopian1144bea2013-01-29 15:52:10 -0800492 *
493 * If this sensor is present, then the corresponding
494 * SENSOR_TYPE_MAGNETIC_FIELD must be present and both must return the
495 * same sensor_t::name and sensor_t::vendor.
Etienne Le Grandca858142013-02-26 19:17:20 -0800496 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700497 * Minimum filtering should be applied to this sensor. In particular, low pass
498 * filters should be avoided.
499 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800500 * See SENSOR_TYPE_MAGNETIC_FIELD for more information
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800501 */
502#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
503
504/*
505 * SENSOR_TYPE_GAME_ROTATION_VECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800506 * trigger-mode: continuous
507 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800508 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800509 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic
510 * field. Therefore the Y axis doesn't point north, but instead to some other
511 * reference. That reference is allowed to drift by the same order of
512 * magnitude than the gyroscope drift around the Z axis.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800513 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800514 * This sensor does not report an estimated heading accuracy:
Etienne Le Grand28f04112013-03-27 18:59:10 -0700515 * sensors_event_t.data[4] is reserved and should be set to 0
Etienne Le Grandca858142013-02-26 19:17:20 -0800516 *
517 * In the ideal case, a phone rotated and returning to the same real-world
518 * orientation should report the same game rotation vector
519 * (without using the earth's geomagnetic field).
520 *
521 * This sensor must be based on a gyroscope. It cannot be implemented using
522 * a magnetometer.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800523 *
524 * see SENSOR_TYPE_ROTATION_VECTOR for more details
525 */
526#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
527
528/*
529 * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
Mathias Agopiana4557722012-11-28 17:21:55 -0800530 * trigger-mode: continuous
531 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800532 *
533 * All values are in radians/second and measure the rate of rotation
Mathias Agopian1144bea2013-01-29 15:52:10 -0800534 * around the X, Y and Z axis. An estimation of the drift on each axis is
535 * reported as well.
536 *
537 * No gyro-drift compensation shall be performed.
538 * Factory calibration and temperature compensation should still be applied
539 * to the rate of rotation (angular speeds).
540 *
541 * The coordinate system is the same as is
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800542 * used for the acceleration sensor. Rotation is positive in the
543 * counter-clockwise direction (right-hand rule). That is, an observer
544 * looking from some positive location on the x, y or z axis at a device
545 * positioned on the origin would report positive rotation if the device
546 * appeared to be rotating counter clockwise. Note that this is the
547 * standard mathematical definition of positive rotation and does not agree
548 * with the definition of roll given earlier.
549 * The range should at least be 17.45 rad/s (ie: ~1000 deg/s).
550 *
Etienne Le Grandca858142013-02-26 19:17:20 -0800551 * Content of an uncalibrated_gyro event: (units are rad/sec)
552 * x_uncalib : angular speed (w/o drift compensation) around the X axis
553 * y_uncalib : angular speed (w/o drift compensation) around the Y axis
554 * z_uncalib : angular speed (w/o drift compensation) around the Z axis
555 * x_bias : estimated drift around X axis in rad/s
556 * y_bias : estimated drift around Y axis in rad/s
557 * z_bias : estimated drift around Z axis in rad/s
Mathias Agopian1144bea2013-01-29 15:52:10 -0800558 *
559 * IMPLEMENTATION NOTES:
560 *
561 * If the implementation is not able to estimate the drift, then this
562 * sensor MUST NOT be reported by this HAL. Instead, the regular
563 * SENSOR_TYPE_GYROSCOPE is used without drift compensation.
564 *
565 * If this sensor is present, then the corresponding
566 * SENSOR_TYPE_GYROSCOPE must be present and both must return the
567 * same sensor_t::name and sensor_t::vendor.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800568 */
569#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
570
Mathias Agopiana4557722012-11-28 17:21:55 -0800571
572/*
573 * SENSOR_TYPE_SIGNIFICANT_MOTION
574 * trigger-mode: one-shot
575 * wake-up sensor: yes
576 *
577 * A sensor of this type triggers an event each time significant motion
578 * is detected and automatically disables itself.
579 * The only allowed value to return is 1.0.
580 *
Etienne Le Grand1461f282013-03-05 22:00:33 -0800581 * A significant motion is a motion that might lead to a change in the user
582 * location.
583 * Examples of such motions are:
584 * walking, biking, sitting in a moving car, coach or train.
585 * Examples of situations that should not trigger significant motion:
586 * - phone in pocket and person is not moving
587 * - phone is on a table, even if the table shakes a bit due to nearby traffic
588 * or washing machine
Mathias Agopiana4557722012-11-28 17:21:55 -0800589 *
Etienne Le Grand1461f282013-03-05 22:00:33 -0800590 * A note on false positive / false negative / power consumption tradeoff
591 * - The goal of this sensor is to save power.
592 * - Triggering an event when the user is not moving (false positive) is costly
593 * in terms of power, so it should be avoided.
594 * - Not triggering an event when the user is moving (false negative) is
Etienne Le Grand2e7d3cd2013-03-07 12:22:32 -0800595 * acceptable as long as it is not done repeatedly. If the user has been
Etienne Le Grand1461f282013-03-05 22:00:33 -0800596 * walking for 10 seconds, not triggering an event within those 10 seconds
597 * is not acceptable.
Mathias Agopiana4557722012-11-28 17:21:55 -0800598 *
599 * IMPORTANT NOTE: this sensor type is very different from other types
600 * in that it must work when the screen is off without the need of
601 * holding a partial wake-lock and MUST allow the SoC to go into suspend.
602 * When significant motion is detected, the sensor must awaken the SoC and
603 * the event be reported.
604 *
605 * If a particular hardware cannot support this mode of operation then this
606 * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable
607 * to "emulate" this sensor in the HAL.
608 *
609 * The whole point of this sensor type is to save power by keeping the
610 * SoC in suspend mode when the device is at rest.
611 *
612 * When the sensor is not activated, it must also be deactivated in the
613 * hardware: it must not wake up the SoC anymore, even in case of
614 * significant motion.
615 *
616 * setDelay() has no effect and is ignored.
617 * Once a "significant motion" event is returned, a sensor of this type
618 * must disables itself automatically, as if activate(..., 0) had been called.
619 */
620
621#define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
622
623
624/*
Mathias Agopian2f276f52013-01-28 17:54:41 -0800625 * SENSOR_TYPE_STEP_DETECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800626 * trigger-mode: special
627 * wake-up sensor: no
628 *
629 * A sensor of this type triggers an event each time a step is taken
630 * by the user. The only allowed value to return is 1.0 and an event is
631 * generated for each step. Like with any other event, the timestamp
632 * indicates when the event (here the step) occurred, this corresponds to when
633 * the foot hit the ground, generating a high variation in acceleration.
634 *
635 * While this sensor operates, it shall not disrupt any other sensors, in
636 * particular, but not limited to, the accelerometer; which might very well
637 * be in use as well.
638 *
639 * This sensor must be low power. That is, if the step detection cannot be
640 * done in hardware, this sensor should not be defined. Also, when the
Mathias Agopian2f276f52013-01-28 17:54:41 -0800641 * step detector is activated and the accelerometer is not, only steps should
Mathias Agopiana4557722012-11-28 17:21:55 -0800642 * trigger interrupts (not accelerometer data).
643 *
644 * setDelay() has no impact on this sensor type
645 */
646
Mathias Agopian2f276f52013-01-28 17:54:41 -0800647#define SENSOR_TYPE_STEP_DETECTOR (18)
Mathias Agopiana4557722012-11-28 17:21:55 -0800648
649
650/*
651 * SENSOR_TYPE_STEP_COUNTER
652 * trigger-mode: on-change
653 * wake-up sensor: no
654 *
655 * A sensor of this type returns the number of steps taken by the user since
Mathias Agopian1144bea2013-01-29 15:52:10 -0800656 * the last reboot while activated. The value is returned as a uint64_t and is
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700657 * reset to zero only on a system / android reboot.
Mathias Agopiana4557722012-11-28 17:21:55 -0800658 *
659 * The timestamp of the event is set to the time when the first step
660 * for that event was taken.
Mathias Agopian2f276f52013-01-28 17:54:41 -0800661 * See SENSOR_TYPE_STEP_DETECTOR for the signification of the time of a step.
Mathias Agopiana4557722012-11-28 17:21:55 -0800662 *
663 * The minimum size of the hardware's internal counter shall be 16 bits
664 * (this restriction is here to avoid too frequent wake-ups when the
665 * delay is very large).
666 *
667 * IMPORTANT NOTE: this sensor type is different from other types
668 * in that it must work when the screen is off without the need of
669 * holding a partial wake-lock and MUST allow the SoC to go into suspend.
670 * Unlike other sensors, while in suspend mode this sensor must stay active,
671 * no events are reported during that time but, steps continue to be
672 * accounted for; an event will be reported as soon as the SoC resumes if
673 * the timeout has expired.
674 *
675 * In other words, when the screen is off and the device allowed to
676 * go into suspend mode, we don't want to be woken up, regardless of the
677 * setDelay() value, but the steps shall continue to be counted.
678 *
679 * The driver must however ensure that the internal step count never
680 * overflows. It is allowed in this situation to wake the SoC up so the
681 * driver can do the counter maintenance.
682 *
683 * While this sensor operates, it shall not disrupt any other sensors, in
684 * particular, but not limited to, the accelerometer; which might very well
685 * be in use as well.
686 *
687 * If a particular hardware cannot support these modes of operation then this
688 * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable
689 * to "emulate" this sensor in the HAL.
690 *
691 * This sensor must be low power. That is, if the step detection cannot be
692 * done in hardware, this sensor should not be defined. Also, when the
693 * step counter is activated and the accelerometer is not, only steps should
694 * trigger interrupts (not accelerometer data).
695 *
696 * The whole point of this sensor type is to save power by keeping the
697 * SoC in suspend mode when the device is at rest.
698 */
699
700#define SENSOR_TYPE_STEP_COUNTER (19)
701
Etienne Le Grandca858142013-02-26 19:17:20 -0800702/*
703 * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
704 * trigger-mode: continuous
705 * wake-up sensor: no
706 *
707 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead
708 * of using a gyroscope.
709 *
710 * This sensor must be based on a magnetometer. It cannot be implemented using
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700711 * a gyroscope, and gyroscope input cannot be used by this sensor, as the
712 * goal of this sensor is to be low power.
713 * The accelerometer can be (and usually is) used.
Etienne Le Grandca858142013-02-26 19:17:20 -0800714 *
715 * Just like SENSOR_TYPE_ROTATION_VECTOR, this sensor reports an estimated
716 * heading accuracy:
Etienne Le Grand28f04112013-03-27 18:59:10 -0700717 * sensors_event_t.data[4] = estimated_accuracy (in radians)
Etienne Le Grandca858142013-02-26 19:17:20 -0800718 * The heading error must be less than estimated_accuracy 95% of the time
719 *
720 * see SENSOR_TYPE_ROTATION_VECTOR for more details
721 */
722#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20)
Mathias Agopiana4557722012-11-28 17:21:55 -0800723
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800724/**
725 * Values returned by the accelerometer in various locations in the universe.
726 * all values are in SI units (m/s^2)
727 */
728#define GRAVITY_SUN (275.0f)
729#define GRAVITY_EARTH (9.80665f)
730
731/** Maximum magnetic field on Earth's surface */
732#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
733
734/** Minimum magnetic field on Earth's surface */
735#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
736
737
738/**
739 * status of orientation sensor
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800740 */
Kevin Powellb01a0432010-07-19 19:12:15 -0700741
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800742#define SENSOR_STATUS_UNRELIABLE 0
743#define SENSOR_STATUS_ACCURACY_LOW 1
744#define SENSOR_STATUS_ACCURACY_MEDIUM 2
745#define SENSOR_STATUS_ACCURACY_HIGH 3
746
747
748/**
749 * sensor event data
750 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800751typedef struct {
752 union {
753 float v[3];
754 struct {
755 float x;
756 float y;
757 float z;
758 };
759 struct {
760 float azimuth;
761 float pitch;
762 float roll;
763 };
764 };
765 int8_t status;
766 uint8_t reserved[3];
767} sensors_vec_t;
768
769/**
Etienne Le Grandca858142013-02-26 19:17:20 -0800770 * uncalibrated gyroscope and magnetometer event data
771 */
772typedef struct {
Etienne Le Grand28f04112013-03-27 18:59:10 -0700773 union {
774 float uncalib[3];
775 struct {
776 float x_uncalib;
777 float y_uncalib;
778 float z_uncalib;
779 };
780 };
781 union {
782 float bias[3];
783 struct {
784 float x_bias;
785 float y_bias;
786 float z_bias;
787 };
788 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800789} uncalibrated_event_t;
790
Mathias Agopian16671c52013-07-24 21:07:40 -0700791typedef struct meta_data_event {
792 int32_t what;
793 int32_t sensor;
794} meta_data_event_t;
795
Etienne Le Grandca858142013-02-26 19:17:20 -0800796/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800797 * Union of the various types of sensor data
798 * that can be returned.
799 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700800typedef struct sensors_event_t {
801 /* must be sizeof(struct sensors_event_t) */
802 int32_t version;
803
804 /* sensor identifier */
805 int32_t sensor;
806
807 /* sensor type */
808 int32_t type;
809
810 /* reserved */
811 int32_t reserved0;
812
813 /* time is in nanosecond */
814 int64_t timestamp;
815
816 union {
Mathias Agopian27e16682013-07-08 14:00:54 -0700817 union {
818 float data[16];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700819
Mathias Agopian27e16682013-07-08 14:00:54 -0700820 /* acceleration values are in meter per second per second (m/s^2) */
821 sensors_vec_t acceleration;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700822
Mathias Agopian27e16682013-07-08 14:00:54 -0700823 /* magnetic vector values are in micro-Tesla (uT) */
824 sensors_vec_t magnetic;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700825
Mathias Agopian27e16682013-07-08 14:00:54 -0700826 /* orientation values are in degrees */
827 sensors_vec_t orientation;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700828
Mathias Agopian27e16682013-07-08 14:00:54 -0700829 /* gyroscope values are in rad/s */
830 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -0700831
Mathias Agopian27e16682013-07-08 14:00:54 -0700832 /* temperature is in degrees centigrade (Celsius) */
833 float temperature;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700834
Mathias Agopian27e16682013-07-08 14:00:54 -0700835 /* distance in centimeters */
836 float distance;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700837
Mathias Agopian27e16682013-07-08 14:00:54 -0700838 /* light in SI lux units */
839 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -0700840
Mathias Agopian27e16682013-07-08 14:00:54 -0700841 /* pressure in hectopascal (hPa) */
842 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100843
Mathias Agopian27e16682013-07-08 14:00:54 -0700844 /* relative humidity in percent */
845 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -0800846
Mathias Agopian27e16682013-07-08 14:00:54 -0700847 /* uncalibrated gyroscope values are in rad/s */
848 uncalibrated_event_t uncalibrated_gyro;
Etienne Le Grandca858142013-02-26 19:17:20 -0800849
Mathias Agopian27e16682013-07-08 14:00:54 -0700850 /* uncalibrated magnetometer values are in micro-Teslas */
851 uncalibrated_event_t uncalibrated_magnetic;
Mathias Agopian16671c52013-07-24 21:07:40 -0700852
853 /* this is a special event. see SENSOR_TYPE_META_DATA above.
854 * sensors_meta_data_event_t events are all reported with a type of
855 * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
856 */
857 meta_data_event_t meta_data;
Mathias Agopian27e16682013-07-08 14:00:54 -0700858 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800859
Mathias Agopian27e16682013-07-08 14:00:54 -0700860 union {
861 uint64_t data[8];
862
863 /* step-counter */
864 uint64_t step_counter;
865 } u64;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700866 };
Mathias Agopian27e16682013-07-08 14:00:54 -0700867 uint32_t reserved1[4];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700868} sensors_event_t;
869
870
Mathias Agopian16671c52013-07-24 21:07:40 -0700871/* see SENSOR_TYPE_META_DATA */
872typedef sensors_event_t sensors_meta_data_event_t;
873
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700874
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800875struct sensor_t;
876
877/**
878 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
879 * and the fields of this data structure must begin with hw_module_t
880 * followed by module specific information.
881 */
882struct sensors_module_t {
883 struct hw_module_t common;
884
885 /**
886 * Enumerate all available sensors. The list is returned in "list".
887 * @return number of sensors in the list
888 */
889 int (*get_sensors_list)(struct sensors_module_t* module,
890 struct sensor_t const** list);
891};
892
893struct sensor_t {
Mathias Agopian1144bea2013-01-29 15:52:10 -0800894
895 /* Name of this sensor.
896 * All sensors of the same "type" must have a different "name".
897 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800898 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -0800899
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800900 /* vendor of the hardware part */
901 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -0800902
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800903 /* version of the hardware part + driver. The value of this field
904 * must increase when the driver is updated in a way that changes the
905 * output of this sensor. This is important for fused sensors when the
906 * fusion algorithm is updated.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800907 */
908 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -0800909
910 /* handle that identifies this sensors. This handle is used to reference
911 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800912 */
913 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -0800914
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800915 /* this sensor's type. */
916 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -0800917
918 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800919 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -0800920
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800921 /* smallest difference between two values reported by this sensor */
922 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -0800923
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800924 /* rough estimate of this sensor's power consumption in mA */
925 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -0800926
927 /* this value depends on the trigger mode:
928 *
929 * continuous: minimum sample period allowed in microseconds
930 * on-change : 0
931 * one-shot :-1
932 * special : 0, unless otherwise noted
933 */
Mathias Agopian1511e202010-07-29 15:33:22 -0700934 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -0800935
Mathias Agopian16671c52013-07-24 21:07:40 -0700936 /* number of events reserved for this sensor in the batch mode FIFO.
937 * If there is a dedicated FIFO for this sensor, then this is the
938 * size of this FIFO. If the FIFO is shared with other sensors,
939 * this is the size reserved for that sensor and it can be zero.
940 */
941 uint32_t fifoReservedEventCount;
942
943 /* maximum number of events of this sensor that could be batched.
944 * This is especially relevant when the FIFO is shared between
945 * several sensors; this value is then set to the size of that FIFO.
946 */
947 uint32_t fifoMaxEventCount;
948
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800949 /* reserved fields, must be zero */
Mathias Agopian16671c52013-07-24 21:07:40 -0700950 void* reserved[6];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800951};
952
953
Mathias Agopiana4557722012-11-28 17:21:55 -0800954/*
955 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
956 * and is present for backward binary and source compatibility.
957 * (see documentation of the hooks in struct sensors_poll_device_1 below)
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800958 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700959struct sensors_poll_device_t {
960 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700961 int (*activate)(struct sensors_poll_device_t *dev,
962 int handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700963 int (*setDelay)(struct sensors_poll_device_t *dev,
964 int handle, int64_t ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700965 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700966 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700967};
968
Mathias Agopiana4557722012-11-28 17:21:55 -0800969/*
970 * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0
971 */
972typedef struct sensors_poll_device_1 {
973 union {
974 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
975 * and can be down-cast to it
976 */
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800977 struct sensors_poll_device_t v0;
Mathias Agopiana4557722012-11-28 17:21:55 -0800978
979 struct {
980 struct hw_device_t common;
981
982 /* Activate/de-activate one sensor.
983 *
984 * handle is the handle of the sensor to change.
985 * enabled set to 1 to enable, or 0 to disable the sensor.
986 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -0700987 * if enabled is set to 1, the sensor is activated even if
988 * setDelay() wasn't called before. In this case, a default rate
989 * should be used.
990 *
Mathias Agopiana4557722012-11-28 17:21:55 -0800991 * unless otherwise noted in the sensor types definitions, an
992 * activated sensor never prevents the SoC to go into suspend
993 * mode; that is, the HAL shall not hold a partial wake-lock on
994 * behalf of applications.
995 *
996 * one-shot sensors de-activate themselves automatically upon
997 * receiving an event and they must still accept to be deactivated
998 * through a call to activate(..., ..., 0).
999 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001000 * if "enabled" is 1 and the sensor is already activated, this
Mathias Agopiana4557722012-11-28 17:21:55 -08001001 * function is a no-op and succeeds.
1002 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001003 * if "enabled" is 0 and the sensor is already de-activated,
Mathias Agopiana4557722012-11-28 17:21:55 -08001004 * this function is a no-op and succeeds.
1005 *
1006 * return 0 on success, negative errno code otherwise
1007 */
1008 int (*activate)(struct sensors_poll_device_t *dev,
1009 int handle, int enabled);
1010
1011 /**
Mathias Agopian1144bea2013-01-29 15:52:10 -08001012 * Set the events's period in nanoseconds for a given sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -08001013 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001014 * What the period_ns parameter means depends on the specified
Mathias Agopiana4557722012-11-28 17:21:55 -08001015 * sensor's trigger mode:
1016 *
1017 * continuous: setDelay() sets the sampling rate.
1018 * on-change: setDelay() limits the delivery rate of events
1019 * one-shot: setDelay() is ignored. it has no effect.
1020 * special: see specific sensor type definitions
1021 *
1022 * For continuous and on-change sensors, if the requested value is
1023 * less than sensor_t::minDelay, then it's silently clamped to
1024 * sensor_t::minDelay unless sensor_t::minDelay is 0, in which
1025 * case it is clamped to >= 1ms.
1026 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001027 * setDelay will not be called when the sensor is in batching mode.
1028 * In this case, batch() will be called with the new period.
1029 *
Mathias Agopiana4557722012-11-28 17:21:55 -08001030 * @return 0 if successful, < 0 on error
1031 */
1032 int (*setDelay)(struct sensors_poll_device_t *dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -08001033 int handle, int64_t period_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -08001034
1035 /**
1036 * Returns an array of sensor data.
1037 * This function must block until events are available.
1038 *
1039 * return the number of events read on success, or -errno in case
1040 * of an error.
1041 *
1042 * The number of events returned in data must be less or equal
Etienne Le Grand28f04112013-03-27 18:59:10 -07001043 * to the "count" argument.
Mathias Agopiana4557722012-11-28 17:21:55 -08001044 *
1045 * This function shall never return 0 (no event).
1046 */
1047 int (*poll)(struct sensors_poll_device_t *dev,
1048 sensors_event_t* data, int count);
1049 };
1050 };
1051
Mathias Agopiana4557722012-11-28 17:21:55 -08001052
1053 /*
Mathias Agopian1144bea2013-01-29 15:52:10 -08001054 * Enables batch mode for the given sensor and sets the delay between events
Mathias Agopiana4557722012-11-28 17:21:55 -08001055 *
1056 * A timeout value of zero disables batch mode for the given sensor.
1057 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001058 * The period_ns parameter is equivalent to calling setDelay() -- this
1059 * function both enables or disables the batch mode AND sets the events's
1060 * period in nanosecond. See setDelay() above for a detailed explanation of
1061 * the period_ns parameter.
1062 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001063 * BATCH MODE:
1064 * -----------
1065 * In non-batch mode, all sensor events must be reported as soon as they
1066 * are detected. For example, an accelerometer activated at 50Hz will
1067 * trigger interrupts 50 times per second.
1068 * While in batch mode, sensor events do not need to be reported as soon
1069 * as they are detected. They can be temporarily stored in batches and
1070 * reported in batches, as long as no event is delayed by more than
1071 * "timeout" nanoseconds. That is, all events since the previous batch
1072 * are recorded and returned all at once. This allows to reduce the amount
1073 * of interrupts sent to the SoC, and allow the SoC to switch to a lower
1074 * power state (Idle) while the sensor is capturing and batching data.
Mathias Agopiana4557722012-11-28 17:21:55 -08001075 *
1076 * setDelay() is not affected and it behaves as usual.
1077 *
1078 * Each event has a timestamp associated with it, the timestamp
1079 * must be accurate and correspond to the time at which the event
1080 * physically happened.
1081 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001082 * Batching does not modify the behavior of poll(): batches from different
1083 * sensors can be interleaved and split. As usual, all events from the same
1084 * sensor are time-ordered.
1085 *
1086 * BEHAVIOUR OUTSIDE OF SUSPEND MODE:
1087 * ----------------------------------
1088 *
1089 * When the SoC is awake (not in suspend mode), events must be reported in
1090 * batches at least every "timeout". No event shall be dropped or lost.
Mathias Agopiana4557722012-11-28 17:21:55 -08001091 * If internal h/w FIFOs fill-up before the timeout, then events are
Etienne Le Grand28f04112013-03-27 18:59:10 -07001092 * reported at that point to ensure no event is lost.
Mathias Agopian1144bea2013-01-29 15:52:10 -08001093 *
1094 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001095 * NORMAL BEHAVIOR IN SUSPEND MODE:
1096 * ---------------------------------
Mathias Agopiana4557722012-11-28 17:21:55 -08001097 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001098 * By default, batch mode doesn't significantly change the interaction with
1099 * suspend mode. That is, sensors must continue to allow the SoC to
Mathias Agopiana4557722012-11-28 17:21:55 -08001100 * go into suspend mode and sensors must stay active to fill their
Etienne Le Grand28f04112013-03-27 18:59:10 -07001101 * internal FIFO. In this mode, when the FIFO fills up, it shall wrap
Mathias Agopiana4557722012-11-28 17:21:55 -08001102 * around (basically behave like a circular buffer, overwriting events).
1103 * As soon as the SoC comes out of suspend mode, a batch is produced with
1104 * as much as the recent history as possible, and batch operation
1105 * resumes as usual.
1106 *
1107 * The behavior described above allows applications to record the recent
1108 * history of a set of sensor while keeping the SoC into suspend. It
1109 * also allows the hardware to not have to rely on a wake-up interrupt line.
1110 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001111 * WAKE_UPON_FIFO_FULL BEHAVIOR IN SUSPEND MODE:
1112 * ----------------------------------------------
Mathias Agopiana4557722012-11-28 17:21:55 -08001113 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001114 * There are cases, however, where an application cannot afford to lose
1115 * any events, even when the device goes into suspend mode.
1116 * For a given rate, if a sensor has the capability to store at least 10
1117 * seconds worth of events in its FIFO and is able to wake up the Soc, it
1118 * can implement an optional secondary mode: the WAKE_UPON_FIFO_FULL mode.
1119 *
1120 * The caller will set the SENSORS_BATCH_WAKE_UPON_FIFO_FULL flag to
1121 * activate this mode. If the sensor does not support this mode, batch()
1122 * will fail when the flag is set.
1123 *
1124 * When running with the WAKE_UPON_FIFO_FULL flag set, no events can be
1125 * lost. When the FIFO is getting full, the sensor must wake up the SoC from
1126 * suspend and return a batch before the FIFO fills-up.
1127 * Depending on the device, it might take a few miliseconds for the SoC to
1128 * entirely come out of suspend and start flushing the FIFO. Enough head
1129 * room must be allocated in the FIFO to allow the device to entirely come
1130 * out of suspend without the FIFO overflowing (no events shall be lost).
1131 *
1132 * Implementing the WAKE_UPON_FIFO_FULL mode is optional.
1133 * If the hardware cannot support this mode, or if the physical
Mathias Agopiana4557722012-11-28 17:21:55 -08001134 * FIFO is so small that the device would never be allowed to go into
Mathias Agopian1144bea2013-01-29 15:52:10 -08001135 * suspend for at least 10 seconds, then this function MUST fail when
1136 * the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is set, regardless of
1137 * the value of the timeout parameter.
Mathias Agopiana4557722012-11-28 17:21:55 -08001138 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001139 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001140 * DRY RUN:
1141 * --------
Mathias Agopiana4557722012-11-28 17:21:55 -08001142 *
1143 * If the flag SENSORS_BATCH_DRY_RUN is set, this function returns
Mathias Agopian1144bea2013-01-29 15:52:10 -08001144 * without modifying the batch mode or the event period and has no side
1145 * effects, but returns errors as usual (as it would if this flag was
1146 * not set). This flag is used to check if batch mode is available for a
1147 * given configuration -- in particular for a given sensor at a given rate.
1148 *
Mathias Agopiana4557722012-11-28 17:21:55 -08001149 *
1150 * Return values:
Mathias Agopian1144bea2013-01-29 15:52:10 -08001151 * --------------
1152 *
1153 * Because sensors must be independent, the return value must not depend
1154 * on the state of the system (whether another sensor is on or not),
1155 * nor on whether the flag SENSORS_BATCH_DRY_RUN is set (in other words,
1156 * if a batch call with SENSORS_BATCH_DRY_RUN is successful,
1157 * the same call without SENSORS_BATCH_DRY_RUN must succeed as well).
Mathias Agopiana4557722012-11-28 17:21:55 -08001158 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001159 * When timeout is not 0:
1160 * If successful, 0 is returned.
1161 * If the specified sensor doesn't support batch mode, return -EINVAL.
1162 * If the specified sensor's trigger-mode is one-shot, return -EINVAL.
1163 * If WAKE_UPON_FIFO_FULL is specified and the specified sensor's internal
1164 * FIFO is too small to store at least 10 seconds worth of data at the
1165 * given rate, -EINVAL is returned. Note that as stated above, this has to
1166 * be determined at compile time, and not based on the state of the
1167 * system.
1168 * If some other constraints above cannot be satisfied, return -EINVAL.
Mathias Agopiana4557722012-11-28 17:21:55 -08001169 *
Mathias Agopian1144bea2013-01-29 15:52:10 -08001170 * Note: the timeout parameter, when > 0, has no impact on whether this
1171 * function succeeds or fails.
1172 *
Etienne Le Grandf770b7a2013-07-10 14:08:40 -07001173 * When timeout is 0:
1174 * The caller will never set the wake_upon_fifo_full flag.
1175 * The function must succeed, and batch mode must be deactivated.
1176 *
1177 * Independently of whether DRY_RUN is specified, When the call to batch()
1178 * fails, no state should be changed. In particular, a failed call to
1179 * batch() should not change the rate of the sensor. Example:
1180 * setDelay(..., 10ms)
1181 * batch(..., 20ms, ...) fails
1182 * rate should stay 10ms.
Mathias Agopiana4557722012-11-28 17:21:55 -08001183 *
1184 *
1185 * IMPLEMENTATION NOTES:
Mathias Agopian1144bea2013-01-29 15:52:10 -08001186 * ---------------------
Mathias Agopiana4557722012-11-28 17:21:55 -08001187 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001188 * Batch mode, if supported, should happen at the hardware level,
Mathias Agopiana4557722012-11-28 17:21:55 -08001189 * typically using hardware FIFOs. In particular, it SHALL NOT be
1190 * implemented in the HAL, as this would be counter productive.
1191 * The goal here is to save significant amounts of power.
1192 *
Etienne Le Grand28f04112013-03-27 18:59:10 -07001193 * In some implementations, events from several sensors can share the
1194 * same physical FIFO. In that case, all events in the FIFO can be sent and
1195 * processed by the HAL as soon as one batch must be reported.
1196 * For example, if the following sensors are activated:
1197 * - accelerometer batched with timeout = 20s
1198 * - gyroscope batched with timeout = 5s
1199 * then the accelerometer batches can be reported at the same time the
1200 * gyroscope batches are reported (every 5 seconds)
1201 *
1202 * Batch mode can be enabled or disabled at any time, in particular
1203 * while the specified sensor is already enabled, and this shall not
Mathias Agopiana4557722012-11-28 17:21:55 -08001204 * result in the loss of events.
1205 *
Etienne Le Grandca858142013-02-26 19:17:20 -08001206 * COMPARATIVE IMPORTANCE OF BATCHING FOR DIFFERENT SENSORS:
1207 * ---------------------------------------------------------
1208 *
1209 * On platforms on which hardware fifo size is limited, the system designers
1210 * might have to choose how much fifo to reserve for each sensor. To help
Etienne Le Grand28f04112013-03-27 18:59:10 -07001211 * with this choice, here is a list of applications made possible when
Etienne Le Grandca858142013-02-26 19:17:20 -08001212 * batching is implemented on the different sensors.
1213 *
1214 * High value: Low power pedestrian dead reckoning
1215 * Target batching time: 20 seconds to 1 minute
1216 * Sensors to batch:
1217 * - Step detector
1218 * - Rotation vector or game rotation vector at 5Hz
Etienne Le Grand28f04112013-03-27 18:59:10 -07001219 * Gives us step and heading while letting the SoC go to Suspend.
Etienne Le Grandca858142013-02-26 19:17:20 -08001220 *
1221 * High value: Medium power activity/gesture recognition
1222 * Target batching time: 3 seconds
1223 * Sensors to batch: accelerometer between 20Hz and 50Hz
1224 * Allows recognizing arbitrary activities and gestures without having
Etienne Le Grand28f04112013-03-27 18:59:10 -07001225 * to keep the SoC fully awake while the data is collected.
Etienne Le Grandca858142013-02-26 19:17:20 -08001226 *
1227 * Medium-high value: Interrupt load reduction
1228 * Target batching time: < 1 second
1229 * Sensors to batch: any high frequency sensor.
1230 * If the gyroscope is set at 800Hz, even batching just 10 gyro events can
1231 * reduce the number of interrupts from 800/second to 80/second.
1232 *
1233 * Medium value: Continuous low frequency data collection
1234 * Target batching time: > 1 minute
1235 * Sensors to batch: barometer, humidity sensor, other low frequency
1236 * sensors.
1237 * Allows creating monitoring applications at low power.
1238 *
1239 * Medium value: Continuous full-sensors collection
1240 * Target batching time: > 1 minute
1241 * Sensors to batch: all, at high frequencies
Etienne Le Grand28f04112013-03-27 18:59:10 -07001242 * Allows full collection of sensor data while leaving the SoC in
Etienne Le Grandca858142013-02-26 19:17:20 -08001243 * suspend mode. Only to consider if fifo space is not an issue.
Etienne Le Grand28f04112013-03-27 18:59:10 -07001244 *
1245 * In each of the cases above, if WAKE_UPON_FIFO_FULL is implemented, the
1246 * applications might decide to let the SoC go to suspend, allowing for even
1247 * more power savings.
Mathias Agopiana4557722012-11-28 17:21:55 -08001248 */
1249 int (*batch)(struct sensors_poll_device_1* dev,
Mathias Agopian1144bea2013-01-29 15:52:10 -08001250 int handle, int flags, int64_t period_ns, int64_t timeout);
Mathias Agopiana4557722012-11-28 17:21:55 -08001251
Mathias Agopian16671c52013-07-24 21:07:40 -07001252 /*
1253 * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
1254 * to the end of the "batch mode" FIFO for the specified sensor and flushes
1255 * the FIFO; those events are delivered as usual (i.e.: as if the batch
1256 * timeout had expired) and removed from the FIFO.
1257 *
1258 * See the META_DATA_FLUSH_COMPLETE section for details about the
1259 * META_DATA_FLUSH_COMPLETE event.
1260 *
1261 * The flush happens asynchronously (i.e.: this function must return
1262 * immediately).
1263 *
1264 * If the implementation uses a single FIFO for several sensors, that
1265 * FIFO is flushed and the META_DATA_FLUSH_COMPLETE event is added only
1266 * for the specified sensor.
1267 *
1268 * If the specified sensor wasn't in batch mode, flush succeeds and
1269 * promptly sends a META_DATA_FLUSH_COMPLETE event for that sensor.
1270 *
1271 * If the FIFO was empty at the time of the call, flush returns
1272 * 0 (success) and promptly sends a META_DATA_FLUSH_COMPLETE event
1273 * for that sensor.
1274 *
1275 * If the specified sensor wasn't enabled, flush returns -EINVAL.
1276 *
1277 * return 0 on success, negative errno code otherwise.
1278 */
1279 int (*flush)(struct sensors_poll_device_1* dev, int handle);
1280
Mathias Agopiana4557722012-11-28 17:21:55 -08001281 void (*reserved_procs[8])(void);
1282
1283} sensors_poll_device_1_t;
1284
1285
1286
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001287/** convenience API for opening and closing a device */
1288
Mathias Agopianb1e212e2010-07-08 16:44:54 -07001289static inline int sensors_open(const struct hw_module_t* module,
1290 struct sensors_poll_device_t** device) {
1291 return module->methods->open(module,
1292 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1293}
1294
1295static inline int sensors_close(struct sensors_poll_device_t* device) {
1296 return device->common.close(&device->common);
1297}
1298
Mathias Agopiana4557722012-11-28 17:21:55 -08001299static inline int sensors_open_1(const struct hw_module_t* module,
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001300 sensors_poll_device_1_t** device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001301 return module->methods->open(module,
1302 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1303}
1304
Andrew Hsieh1082c0b2012-12-11 20:51:41 -08001305static inline int sensors_close_1(sensors_poll_device_1_t* device) {
Mathias Agopiana4557722012-11-28 17:21:55 -08001306 return device->common.close(&device->common);
1307}
1308
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001309__END_DECLS
1310
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001311#endif // ANDROID_SENSORS_INTERFACE_H