blob: c9ff6689d29a8fc30d9b5d3e8bb768a22d5f5339 [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
132 * set and supported, the specified sensor must be able to wake-up the SoC.
133 *
134 * There are notable exceptions to this behavior, which are sensor-dependent
135 * (see sensor types definitions below)
136 *
137 *
138 * The sensor type documentation below specifies the wake-up behavior of
139 * each sensor:
140 * wake-up: yes this sensor must wake-up the SoC to deliver events
141 * wake-up: no this sensor shall not wake-up the SoC, events are dropped
142 *
143 */
144
145/*
146 * Sensor type
147 *
148 * Each sensor has a type which defines what this sensor measures and how
149 * measures are reported. All types are defined below.
150 */
151
152/*
153 * Sensor fusion and virtual sensors
154 *
155 * Many sensor types are or can be implemented as virtual sensors from
156 * physical sensors on the device. For instance the rotation vector sensor,
157 * orientation sensor, pedometer, step-counter, etc...
158 *
159 * From the point of view of this API these virtual sensors MUST appear as
160 * real, individual sensors. It is the responsibility of the driver and HAL
161 * to make sure this is the case.
162 *
163 * In particular, all sensors must be able to function concurrently.
164 * For example, if defining both an accelerometer and a step counter,
165 * then both must be able to work concurrently.
166 */
167
168/*
169 * Trigger modes
170 *
171 * Sensors can report events in different ways called trigger modes,
172 * each sensor type has one and only one trigger mode associated to it.
173 * Currently there are four trigger modes defined:
174 *
175 * continuous: events are reported at a constant rate defined by setDelay().
176 * eg: accelerometers, gyroscopes.
177 * on-change: events are reported only if the sensor's value has changed.
178 * setDelay() is used to set a lower limit to the reporting
179 * period (minimum time between two events).
180 * The HAL must return an event immediately when an on-change
181 * sensor is activated.
182 * eg: proximity, light sensors
183 * one-shot: a single event is reported and the sensor returns to the
184 * disabled state, no further events are reported. setDelay() is
185 * ignored.
186 * eg: significant motion sensor
187 * special: see details in the sensor type specification below
188 *
189 */
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800190
191/*
192 * SENSOR_TYPE_ACCELEROMETER
Mathias Agopiana4557722012-11-28 17:21:55 -0800193 * trigger-mode: continuous
194 * wake-up sensor: no
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800195 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800196 * All values are in SI units (m/s^2) and measure the acceleration of the
197 * device minus the force of gravity.
198 *
199 * Acceleration sensors return sensor events for all 3 axes at a constant
200 * rate defined by setDelay().
201 *
202 * x: Acceleration on the x-axis
203 * y: Acceleration on the y-axis
204 * z: Acceleration on the z-axis
205 *
206 * Note that the readings from the accelerometer include the acceleration
207 * due to gravity (which is opposite to the direction of the gravity vector).
208 *
209 * Examples:
210 * The norm of <x, y, z> should be close to 0 when in free fall.
211 *
212 * When the device lies flat on a table and is pushed on its left side
213 * toward the right, the x acceleration value is positive.
214 *
215 * When the device lies flat on a table, the acceleration value is +9.81,
216 * which correspond to the acceleration of the device (0 m/s^2) minus the
217 * force of gravity (-9.81 m/s^2).
218 *
219 * When the device lies flat on a table and is pushed toward the sky, the
220 * acceleration value is greater than +9.81, which correspond to the
221 * acceleration of the device (+A m/s^2) minus the force of
222 * gravity (-9.81 m/s^2).
223 */
224#define SENSOR_TYPE_ACCELEROMETER (1)
225
226/*
227 * SENSOR_TYPE_GEOMAGNETIC_FIELD
Mathias Agopiana4557722012-11-28 17:21:55 -0800228 * trigger-mode: continuous
229 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800230 *
231 * All values are in micro-Tesla (uT) and measure the geomagnetic
232 * field in the X, Y and Z axis.
233 *
234 * Returned values include calibration mechanisms such that the vector is
235 * aligned with the magnetic declination and heading of the earth's
236 * geomagnetic field.
237 *
238 * Magnetic Field sensors return sensor events for all 3 axes at a constant
239 * rate defined by setDelay().
240 */
241#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2)
242#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
243
244/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800245 * SENSOR_TYPE_ORIENTATION
Mathias Agopiana4557722012-11-28 17:21:55 -0800246 * trigger-mode: continuous
247 * wake-up sensor: no
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800248 *
249 * All values are angles in degrees.
250 *
Mathias Agopian66a40952010-07-22 17:11:50 -0700251 * Orientation sensors return sensor events for all 3 axes at a constant
252 * rate defined by setDelay().
253 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800254 * azimuth: angle between the magnetic north direction and the Y axis, around
255 * the Z axis (0<=azimuth<360).
256 * 0=North, 90=East, 180=South, 270=West
257 *
258 * pitch: Rotation around X axis (-180<=pitch<=180), with positive values when
259 * the z-axis moves toward the y-axis.
260 *
261 * roll: Rotation around Y axis (-90<=roll<=90), with positive values when
Mathias Agopian19ea59f2010-02-26 13:15:18 -0800262 * the x-axis moves towards the z-axis.
263 *
264 * Note: For historical reasons the roll angle is positive in the clockwise
265 * direction (mathematically speaking, it should be positive in the
266 * counter-clockwise direction):
267 *
268 * Z
269 * ^
270 * (+roll) .--> |
271 * / |
272 * | | roll: rotation around Y axis
273 * X <-------(.)
274 * Y
275 * note that +Y == -roll
276 *
277 *
278 *
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800279 * Note: This definition is different from yaw, pitch and roll used in aviation
280 * where the X axis is along the long side of the plane (tail to nose).
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800281 */
282#define SENSOR_TYPE_ORIENTATION (3)
283
284/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800285 * SENSOR_TYPE_GYROSCOPE
Mathias Agopiana4557722012-11-28 17:21:55 -0800286 * trigger-mode: continuous
287 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800288 *
Kevin Powellb01a0432010-07-19 19:12:15 -0700289 * All values are in radians/second and measure the rate of rotation
290 * around the X, Y and Z axis. The coordinate system is the same as is
Mathias Agopianc04e5f62010-09-14 10:53:55 -0700291 * used for the acceleration sensor. Rotation is positive in the
292 * counter-clockwise direction (right-hand rule). That is, an observer
293 * looking from some positive location on the x, y or z axis at a device
294 * positioned on the origin would report positive rotation if the device
295 * appeared to be rotating counter clockwise. Note that this is the
296 * standard mathematical definition of positive rotation and does not agree
297 * with the definition of roll given earlier.
298 * The range should at least be 17.45 rad/s (ie: ~1000 deg/s).
Kevin Powellb01a0432010-07-19 19:12:15 -0700299 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800300 * automatic gyro-drift compensation is allowed but not required.
301 */
302#define SENSOR_TYPE_GYROSCOPE (4)
303
304/*
305 * SENSOR_TYPE_LIGHT
Mathias Agopiana4557722012-11-28 17:21:55 -0800306 * trigger-mode: on-change
307 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800308 *
309 * The light sensor value is returned in SI lux units.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800310 */
311#define SENSOR_TYPE_LIGHT (5)
312
313/*
314 * SENSOR_TYPE_PRESSURE
Mathias Agopiana4557722012-11-28 17:21:55 -0800315 * trigger-mode: continuous
316 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800317 *
318 * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800319 */
320#define SENSOR_TYPE_PRESSURE (6)
321
322/* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */
323#define SENSOR_TYPE_TEMPERATURE (7)
324
325/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800326 * SENSOR_TYPE_PROXIMITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800327 * trigger-mode: on-change
328 * wake-up sensor: yes
Mike Lockwooda2414312009-11-03 10:29:50 -0500329 *
330 * The distance value is measured in centimeters. Note that some proximity
331 * sensors only support a binary "close" or "far" measurement. In this case,
332 * the sensor should report its maxRange value in the "far" state and a value
333 * less than maxRange in the "near" state.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800334 */
335#define SENSOR_TYPE_PROXIMITY (8)
336
337/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800338 * SENSOR_TYPE_GRAVITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800339 * trigger-mode: continuous
340 * wake-up sensor: no
Mathias Agopian42b743c2010-11-22 15:55:32 -0800341 *
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800342 * A gravity output indicates the direction of and magnitude of gravity in
343 * the devices's coordinates. On Earth, the magnitude is 9.8 m/s^2.
344 * Units are m/s^2. The coordinate system is the same as is used for the
345 * acceleration sensor. When the device is at rest, the output of the
346 * gravity sensor should be identical to that of the accelerometer.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800347 */
348#define SENSOR_TYPE_GRAVITY (9)
349
350/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800351 * SENSOR_TYPE_LINEAR_ACCELERATION
Mathias Agopiana4557722012-11-28 17:21:55 -0800352 * trigger-mode: continuous
353 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800354 *
355 * Indicates the linear acceleration of the device in device coordinates,
356 * not including gravity.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800357 *
358 * The output is conceptually:
359 * output of TYPE_ACCELERATION - output of TYPE_GRAVITY
360 *
361 * Readings on all axes should be close to 0 when device lies on a table.
362 * Units are m/s^2.
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800363 * The coordinate system is the same as is used for the acceleration sensor.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800364 */
365#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
366
367
368/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800369 * SENSOR_TYPE_ROTATION_VECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800370 * trigger-mode: continuous
371 * wake-up sensor: no
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800372 *
Kevin Powellb01a0432010-07-19 19:12:15 -0700373 * A rotation vector represents the orientation of the device as a combination
374 * of an angle and an axis, in which the device has rotated through an angle
375 * theta around an axis <x, y, z>. The three elements of the rotation vector
376 * are <x*sin(theta/2), y*sin(theta/2), z*sin(theta/2)>, such that the magnitude
377 * of the rotation vector is equal to sin(theta/2), and the direction of the
378 * rotation vector is equal to the direction of the axis of rotation. The three
379 * elements of the rotation vector are equal to the last three components of a
380 * unit quaternion <cos(theta/2), x*sin(theta/2), y*sin(theta/2), z*sin(theta/2)>.
381 * Elements of the rotation vector are unitless. The x, y, and z axis are defined
382 * in the same was as for the acceleration sensor.
Mathias Agopian42b743c2010-11-22 15:55:32 -0800383 *
Mathias Agopiand93ff972011-05-02 19:10:31 -0700384 * The reference coordinate system is defined as a direct orthonormal basis,
385 * where:
386 *
387 * - X is defined as the vector product Y.Z (It is tangential to
388 * the ground at the device's current location and roughly points East).
389 *
390 * - Y is tangential to the ground at the device's current location and
391 * points towards the magnetic North Pole.
392 *
393 * - Z points towards the sky and is perpendicular to the ground.
394 *
395 *
Mathias Agopian42b743c2010-11-22 15:55:32 -0800396 * The rotation-vector is stored as:
397 *
398 * sensors_event_t.data[0] = x*sin(theta/2)
399 * sensors_event_t.data[1] = y*sin(theta/2)
400 * sensors_event_t.data[2] = z*sin(theta/2)
401 * sensors_event_t.data[3] = cos(theta/2)
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800402 */
403#define SENSOR_TYPE_ROTATION_VECTOR (11)
404
405/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800406 * SENSOR_TYPE_RELATIVE_HUMIDITY
Mathias Agopiana4557722012-11-28 17:21:55 -0800407 * trigger-mode: on-change
408 * wake-up sensor: no
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100409 *
410 * A relative humidity sensor measures relative ambient air humidity and
411 * returns a value in percent.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800412 */
413#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
414
415/*
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800416 * SENSOR_TYPE_AMBIENT_TEMPERATURE
Mathias Agopiana4557722012-11-28 17:21:55 -0800417 * trigger-mode: on-change
418 * wake-up sensor: no
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700419 *
420 * The ambient (room) temperature in degree Celsius.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800421 */
422#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
423
424/*
425 * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
Mathias Agopiana4557722012-11-28 17:21:55 -0800426 * trigger-mode: continuous
427 * wake-up sensor: no
Mathias Agopian54f9dd02011-03-22 18:42:03 -0700428 *
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800429 * All values are in micro-Tesla (uT) and measure the ambient magnetic
430 * field in the X, Y and Z axis.
431 *
432 * No periodic calibration is performed (ie: there are no discontinuities
433 * in the data stream while using this sensor). Assumptions that the the
434 * magnetic field is due to the Earth's poles should be avoided.
435 *
436 * Factory calibration and temperature compensation should still be applied.
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800437 */
438#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
439
440/*
441 * SENSOR_TYPE_GAME_ROTATION_VECTOR
Mathias Agopiana4557722012-11-28 17:21:55 -0800442 * trigger-mode: continuous
443 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800444 *
445 * SENSOR_TYPE_GAME_ROTATION_VECTOR is identical to SENSOR_TYPE_ROTATION_VECTOR,
446 * except that it doesn't use the geomagnetic field. Therefore the Y axis doesn't
447 * point north, but instead to some other reference, that reference is allowed
448 * to drift by the same order of magnitude than the gyroscope drift around
449 * the Z axis.
450 *
451 * In the ideal case, a phone rotated and returning to the same real-world
452 * orientation should report the same game rotation vector
453 * (without using the earth's geomagnetic field).
454 *
455 * see SENSOR_TYPE_ROTATION_VECTOR for more details
456 */
457#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
458
459/*
460 * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
Mathias Agopiana4557722012-11-28 17:21:55 -0800461 * trigger-mode: continuous
462 * wake-up sensor: no
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800463 *
464 * All values are in radians/second and measure the rate of rotation
465 * around the X, Y and Z axis. The coordinate system is the same as is
466 * used for the acceleration sensor. Rotation is positive in the
467 * counter-clockwise direction (right-hand rule). That is, an observer
468 * looking from some positive location on the x, y or z axis at a device
469 * positioned on the origin would report positive rotation if the device
470 * appeared to be rotating counter clockwise. Note that this is the
471 * standard mathematical definition of positive rotation and does not agree
472 * with the definition of roll given earlier.
473 * The range should at least be 17.45 rad/s (ie: ~1000 deg/s).
474 *
475 * No gyro-drift compensation shall be performed.
476 * Factory calibration and temperature compensation should still be applied.
477 */
478#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
479
Mathias Agopiana4557722012-11-28 17:21:55 -0800480
481/*
482 * SENSOR_TYPE_SIGNIFICANT_MOTION
483 * trigger-mode: one-shot
484 * wake-up sensor: yes
485 *
486 * A sensor of this type triggers an event each time significant motion
487 * is detected and automatically disables itself.
488 * The only allowed value to return is 1.0.
489 *
490 *
491 * TODO: give more details about what constitute significant motion
492 * and/or what algorithm is to be used
493 *
494 *
495 * IMPORTANT NOTE: this sensor type is very different from other types
496 * in that it must work when the screen is off without the need of
497 * holding a partial wake-lock and MUST allow the SoC to go into suspend.
498 * When significant motion is detected, the sensor must awaken the SoC and
499 * the event be reported.
500 *
501 * If a particular hardware cannot support this mode of operation then this
502 * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable
503 * to "emulate" this sensor in the HAL.
504 *
505 * The whole point of this sensor type is to save power by keeping the
506 * SoC in suspend mode when the device is at rest.
507 *
508 * When the sensor is not activated, it must also be deactivated in the
509 * hardware: it must not wake up the SoC anymore, even in case of
510 * significant motion.
511 *
512 * setDelay() has no effect and is ignored.
513 * Once a "significant motion" event is returned, a sensor of this type
514 * must disables itself automatically, as if activate(..., 0) had been called.
515 */
516
517#define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
518
519
520/*
521 * SENSOR_TYPE_PEDOMETER
522 * trigger-mode: special
523 * wake-up sensor: no
524 *
525 * A sensor of this type triggers an event each time a step is taken
526 * by the user. The only allowed value to return is 1.0 and an event is
527 * generated for each step. Like with any other event, the timestamp
528 * indicates when the event (here the step) occurred, this corresponds to when
529 * the foot hit the ground, generating a high variation in acceleration.
530 *
531 * While this sensor operates, it shall not disrupt any other sensors, in
532 * particular, but not limited to, the accelerometer; which might very well
533 * be in use as well.
534 *
535 * This sensor must be low power. That is, if the step detection cannot be
536 * done in hardware, this sensor should not be defined. Also, when the
537 * pedometer is activated and the accelerometer is not, only steps should
538 * trigger interrupts (not accelerometer data).
539 *
540 * setDelay() has no impact on this sensor type
541 */
542
543#define SENSOR_TYPE_PEDOMETER (18)
544
545
546/*
547 * SENSOR_TYPE_STEP_COUNTER
548 * trigger-mode: on-change
549 * wake-up sensor: no
550 *
551 * A sensor of this type returns the number of steps taken by the user since
552 * the last reboot. The value is returned as a uint64_t and is reset to
553 * zero only on a system reboot.
554 *
555 * The timestamp of the event is set to the time when the first step
556 * for that event was taken.
557 * See SENSOR_TYPE_PEDOMETER for the signification of the time of a step.
558 *
559 * The minimum size of the hardware's internal counter shall be 16 bits
560 * (this restriction is here to avoid too frequent wake-ups when the
561 * delay is very large).
562 *
563 * IMPORTANT NOTE: this sensor type is different from other types
564 * in that it must work when the screen is off without the need of
565 * holding a partial wake-lock and MUST allow the SoC to go into suspend.
566 * Unlike other sensors, while in suspend mode this sensor must stay active,
567 * no events are reported during that time but, steps continue to be
568 * accounted for; an event will be reported as soon as the SoC resumes if
569 * the timeout has expired.
570 *
571 * In other words, when the screen is off and the device allowed to
572 * go into suspend mode, we don't want to be woken up, regardless of the
573 * setDelay() value, but the steps shall continue to be counted.
574 *
575 * The driver must however ensure that the internal step count never
576 * overflows. It is allowed in this situation to wake the SoC up so the
577 * driver can do the counter maintenance.
578 *
579 * While this sensor operates, it shall not disrupt any other sensors, in
580 * particular, but not limited to, the accelerometer; which might very well
581 * be in use as well.
582 *
583 * If a particular hardware cannot support these modes of operation then this
584 * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable
585 * to "emulate" this sensor in the HAL.
586 *
587 * This sensor must be low power. That is, if the step detection cannot be
588 * done in hardware, this sensor should not be defined. Also, when the
589 * step counter is activated and the accelerometer is not, only steps should
590 * trigger interrupts (not accelerometer data).
591 *
592 * The whole point of this sensor type is to save power by keeping the
593 * SoC in suspend mode when the device is at rest.
594 */
595
596#define SENSOR_TYPE_STEP_COUNTER (19)
597
598
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800599/**
600 * Values returned by the accelerometer in various locations in the universe.
601 * all values are in SI units (m/s^2)
602 */
603#define GRAVITY_SUN (275.0f)
604#define GRAVITY_EARTH (9.80665f)
605
606/** Maximum magnetic field on Earth's surface */
607#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
608
609/** Minimum magnetic field on Earth's surface */
610#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
611
612
613/**
614 * status of orientation sensor
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800615 */
Kevin Powellb01a0432010-07-19 19:12:15 -0700616
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800617#define SENSOR_STATUS_UNRELIABLE 0
618#define SENSOR_STATUS_ACCURACY_LOW 1
619#define SENSOR_STATUS_ACCURACY_MEDIUM 2
620#define SENSOR_STATUS_ACCURACY_HIGH 3
621
622
623/**
624 * sensor event data
625 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800626typedef struct {
627 union {
628 float v[3];
629 struct {
630 float x;
631 float y;
632 float z;
633 };
634 struct {
635 float azimuth;
636 float pitch;
637 float roll;
638 };
639 };
640 int8_t status;
641 uint8_t reserved[3];
642} sensors_vec_t;
643
644/**
645 * Union of the various types of sensor data
646 * that can be returned.
647 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700648typedef struct sensors_event_t {
649 /* must be sizeof(struct sensors_event_t) */
650 int32_t version;
651
652 /* sensor identifier */
653 int32_t sensor;
654
655 /* sensor type */
656 int32_t type;
657
658 /* reserved */
659 int32_t reserved0;
660
661 /* time is in nanosecond */
662 int64_t timestamp;
663
664 union {
665 float data[16];
666
667 /* acceleration values are in meter per second per second (m/s^2) */
668 sensors_vec_t acceleration;
669
670 /* magnetic vector values are in micro-Tesla (uT) */
671 sensors_vec_t magnetic;
672
673 /* orientation values are in degrees */
674 sensors_vec_t orientation;
675
Mathias Agopianc04e5f62010-09-14 10:53:55 -0700676 /* gyroscope values are in rad/s */
677 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -0700678
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700679 /* temperature is in degrees centigrade (Celsius) */
680 float temperature;
681
682 /* distance in centimeters */
683 float distance;
684
685 /* light in SI lux units */
686 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -0700687
688 /* pressure in hectopascal (hPa) */
689 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100690
691 /* relative humidity in percent */
692 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -0800693
694 /* step-counter */
695 uint64_t step_counter;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700696 };
697 uint32_t reserved1[4];
698} sensors_event_t;
699
700
701
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800702struct sensor_t;
703
704/**
705 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
706 * and the fields of this data structure must begin with hw_module_t
707 * followed by module specific information.
708 */
709struct sensors_module_t {
710 struct hw_module_t common;
711
712 /**
713 * Enumerate all available sensors. The list is returned in "list".
714 * @return number of sensors in the list
715 */
716 int (*get_sensors_list)(struct sensors_module_t* module,
717 struct sensor_t const** list);
718};
719
720struct sensor_t {
Mathias Agopiana4557722012-11-28 17:21:55 -0800721 /* name of this sensor */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800722 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -0800723
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800724 /* vendor of the hardware part */
725 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -0800726
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800727 /* version of the hardware part + driver. The value of this field
728 * must increase when the driver is updated in a way that changes the
729 * output of this sensor. This is important for fused sensors when the
730 * fusion algorithm is updated.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800731 */
732 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -0800733
734 /* handle that identifies this sensors. This handle is used to reference
735 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800736 */
737 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -0800738
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800739 /* this sensor's type. */
740 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -0800741
742 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800743 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -0800744
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800745 /* smallest difference between two values reported by this sensor */
746 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -0800747
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800748 /* rough estimate of this sensor's power consumption in mA */
749 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -0800750
751 /* this value depends on the trigger mode:
752 *
753 * continuous: minimum sample period allowed in microseconds
754 * on-change : 0
755 * one-shot :-1
756 * special : 0, unless otherwise noted
757 */
Mathias Agopian1511e202010-07-29 15:33:22 -0700758 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -0800759
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800760 /* reserved fields, must be zero */
Mathias Agopian1511e202010-07-29 15:33:22 -0700761 void* reserved[8];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800762};
763
764
Mathias Agopiana4557722012-11-28 17:21:55 -0800765/*
766 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
767 * and is present for backward binary and source compatibility.
768 * (see documentation of the hooks in struct sensors_poll_device_1 below)
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800769 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700770struct sensors_poll_device_t {
771 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700772 int (*activate)(struct sensors_poll_device_t *dev,
773 int handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700774 int (*setDelay)(struct sensors_poll_device_t *dev,
775 int handle, int64_t ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700776 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700777 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700778};
779
Mathias Agopiana4557722012-11-28 17:21:55 -0800780/*
781 * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0
782 */
783typedef struct sensors_poll_device_1 {
784 union {
785 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
786 * and can be down-cast to it
787 */
788 sensors_poll_device_t v0;
789
790 struct {
791 struct hw_device_t common;
792
793 /* Activate/de-activate one sensor.
794 *
795 * handle is the handle of the sensor to change.
796 * enabled set to 1 to enable, or 0 to disable the sensor.
797 *
798 * unless otherwise noted in the sensor types definitions, an
799 * activated sensor never prevents the SoC to go into suspend
800 * mode; that is, the HAL shall not hold a partial wake-lock on
801 * behalf of applications.
802 *
803 * one-shot sensors de-activate themselves automatically upon
804 * receiving an event and they must still accept to be deactivated
805 * through a call to activate(..., ..., 0).
806 *
807 * if "enabled" is true and the sensor is already activated, this
808 * function is a no-op and succeeds.
809 *
810 * if "enabled" is false and the sensor is already de-activated,
811 * this function is a no-op and succeeds.
812 *
813 * return 0 on success, negative errno code otherwise
814 */
815 int (*activate)(struct sensors_poll_device_t *dev,
816 int handle, int enabled);
817
818 /**
819 * Set the delay between sensor events in nanoseconds for a given sensor.
820 *
821 * What the delay parameter means depends on the specified
822 * sensor's trigger mode:
823 *
824 * continuous: setDelay() sets the sampling rate.
825 * on-change: setDelay() limits the delivery rate of events
826 * one-shot: setDelay() is ignored. it has no effect.
827 * special: see specific sensor type definitions
828 *
829 * For continuous and on-change sensors, if the requested value is
830 * less than sensor_t::minDelay, then it's silently clamped to
831 * sensor_t::minDelay unless sensor_t::minDelay is 0, in which
832 * case it is clamped to >= 1ms.
833 *
834 * @return 0 if successful, < 0 on error
835 */
836 int (*setDelay)(struct sensors_poll_device_t *dev,
837 int handle, int64_t ns);
838
839 /**
840 * Returns an array of sensor data.
841 * This function must block until events are available.
842 *
843 * return the number of events read on success, or -errno in case
844 * of an error.
845 *
846 * The number of events returned in data must be less or equal
847 * to SENSORS_QUERY_MAX_EVENTS_BATCH_COUNT.
848 *
849 * This function shall never return 0 (no event).
850 */
851 int (*poll)(struct sensors_poll_device_t *dev,
852 sensors_event_t* data, int count);
853 };
854 };
855
856 /*
857 * Used to retrieve information about the sensor HAL
858 *
859 * Returns 0 on success or -errno on error.
860 */
861 int (*query)(struct sensors_poll_device_1* dev, int what, int* value);
862
863
864 /*
865 * Enables batch mode for the given sensor.
866 *
867 * A timeout value of zero disables batch mode for the given sensor.
868 *
869 * While in batch mode sensor events are reported in batches at least
870 * every "timeout" nanosecond; that is all events since the previous batch
871 * are recorded and returned all at once. Batches can be interleaved and
872 * split, and as usual events of the same sensor type are time-ordered.
873 *
874 * setDelay() is not affected and it behaves as usual.
875 *
876 * Each event has a timestamp associated with it, the timestamp
877 * must be accurate and correspond to the time at which the event
878 * physically happened.
879 *
880 * If internal h/w FIFOs fill-up before the timeout, then events are
881 * reported at that point. No event shall be dropped or lost,
882 *
883 * By default batch mode doesn't significantly change the interaction with
884 * suspend mode, that is, sensors must continue to allow the SoC to
885 * go into suspend mode and sensors must stay active to fill their
886 * internal FIFO, in this mode, when the FIFO fills-up, it shall wrap
887 * around (basically behave like a circular buffer, overwriting events).
888 * As soon as the SoC comes out of suspend mode, a batch is produced with
889 * as much as the recent history as possible, and batch operation
890 * resumes as usual.
891 *
892 * The behavior described above allows applications to record the recent
893 * history of a set of sensor while keeping the SoC into suspend. It
894 * also allows the hardware to not have to rely on a wake-up interrupt line.
895 *
896 * There are cases however where an application cannot afford to lose
897 * any events, even when the device goes into suspend mode. The behavior
898 * specified above can be altered by setting the
899 * SENSORS_BATCH_WAKE_UPON_FIFO_FULL flag. If this flag is set, the SoC
900 * must be woken up from suspend and a batch must be returned before
901 * the FIFO fills-up. Enough head room must be allocated in the FIFO to allow
902 * the device to entirely come out of suspend (which might take a while and
903 * is device dependent) such that no event are lost.
904 *
905 * If the hardware cannot support this mode, or, if the physical
906 * FIFO is so small that the device would never be allowed to go into
907 * suspend for long enough (typically 4 to 10 seconds), then this
908 * function MUST fail when the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL
909 * is set.
910 *
911 *
912 * If the flag SENSORS_BATCH_DRY_RUN is set, this function returns
913 * without modifying the batch mode and has no side effects, but returns
914 * errors as usual (as it would if this flag was not set). This flag
915 * is used to check if batch mode is available for a given configuration.
916 *
917 * Return values:
918 *
919 * If successful, 0 is returned.
920 * If the specified sensor doesn't support batch mode, -EINVAL is returned.
921 * If the specified sensor's trigger-mode is one-shot, -EINVAL is returned.
922 * If any of the constraint above cannot be satisfied, -EINVAL is returned.
923 *
924 * If timeout is set to 0, this function must succeed.
925 *
926 *
927 * IMPLEMENTATION NOTES:
928 *
929 * batch mode, if supported, should happen at the hardware level,
930 * typically using hardware FIFOs. In particular, it SHALL NOT be
931 * implemented in the HAL, as this would be counter productive.
932 * The goal here is to save significant amounts of power.
933 *
934 * In SENSORS_BATCH_WAKE_UPON_FIFO_FULL, if the hardware has a
935 * limited FIFO size that wouldn't permit significant savings
936 * (typical on some gyroscopes), because it wouldn't allow the SoC to go
937 * into suspend mode for enough time, then it is imperative to NOT SUPPORT
938 * batch mode for that sensor.
939 *
940 * batch mode can be enabled or disabled at any time, in particular
941 * while the specified sensor is already enabled and this shall not
942 * result in the loss of events.
943 *
944 */
945 int (*batch)(struct sensors_poll_device_1* dev,
946 int handle, int flags, int64_t timeout);
947
948 void (*reserved_procs[8])(void);
949
950} sensors_poll_device_1_t;
951
952
953
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800954/** convenience API for opening and closing a device */
955
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700956static inline int sensors_open(const struct hw_module_t* module,
957 struct sensors_poll_device_t** device) {
958 return module->methods->open(module,
959 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
960}
961
962static inline int sensors_close(struct sensors_poll_device_t* device) {
963 return device->common.close(&device->common);
964}
965
Mathias Agopiana4557722012-11-28 17:21:55 -0800966static inline int sensors_open_1(const struct hw_module_t* module,
967 sensors_poll_device_1** device) {
968 return module->methods->open(module,
969 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
970}
971
972static inline int sensors_close_1(sensors_poll_device_1* device) {
973 return device->common.close(&device->common);
974}
975
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800976__END_DECLS
977
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800978#endif // ANDROID_SENSORS_INTERFACE_H