The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1 | /* |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 2 | * Copyright (C) 2012 The Android Open Source Project |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_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 Lockwood | 21b652f | 2009-05-22 10:05:48 -0400 | [diff] [blame] | 25 | #include <cutils/native_handle.h> |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 26 | |
| 27 | __BEGIN_DECLS |
| 28 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 29 | /*****************************************************************************/ |
| 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 Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 34 | #define SENSORS_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION_2(1, 0, SENSORS_HEADER_VERSION) |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 35 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 36 | /** |
| 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 Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 44 | #define SENSORS_HARDWARE_POLL "poll" |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 45 | |
| 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 Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 57 | /* |
| 58 | * flags for (*batch)() |
| 59 | * Availability: SENSORS_DEVICE_API_VERSION_1_0 |
| 60 | * see (*batch)() documentation for details |
| 61 | */ |
| 62 | enum { |
| 63 | SENSORS_BATCH_DRY_RUN = 0x00000001, |
| 64 | SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002 |
| 65 | }; |
| 66 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 67 | /** |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 68 | * Definition of the axis used by the sensor HAL API |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 69 | * |
| 70 | * This API is relative to the screen of the device in its default orientation, |
| 71 | * that is, if the device can be used in portrait or landscape, this API |
| 72 | * is only relative to the NATURAL orientation of the screen. In other words, |
| 73 | * the axis are not swapped when the device's screen orientation changes. |
| 74 | * Higher level services /may/ perform this transformation. |
| 75 | * |
| 76 | * x<0 x>0 |
| 77 | * ^ |
| 78 | * | |
| 79 | * +-----------+--> y>0 |
| 80 | * | | |
| 81 | * | | |
| 82 | * | | |
| 83 | * | | / z<0 |
| 84 | * | | / |
| 85 | * | | / |
| 86 | * O-----------+/ |
| 87 | * |[] [ ] []/ |
| 88 | * +----------/+ y<0 |
| 89 | * / |
| 90 | * / |
| 91 | * |/ z>0 (toward the sky) |
| 92 | * |
| 93 | * O: Origin (x=0,y=0,z=0) |
| 94 | * |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 95 | */ |
| 96 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 97 | /* |
| 98 | * Interaction with suspend mode |
| 99 | * |
| 100 | * Unless otherwise noted, an enabled sensor shall not prevent the |
| 101 | * SoC to go into suspend mode. It is the responsibility of applications |
| 102 | * to keep a partial wake-lock should they wish to receive sensor |
| 103 | * events while the screen is off. While in suspend mode, and unless |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 104 | * otherwise noted (batch mode, sensor particularities, ...), enabled sensors' |
| 105 | * events are lost. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 106 | * |
| 107 | * Note that conceptually, the sensor itself is not de-activated while in |
| 108 | * suspend mode -- it's just that the data it returns are lost. As soon as |
| 109 | * the SoC gets out of suspend mode, operations resume as usual. Of course, |
| 110 | * in practice sensors shall be disabled while in suspend mode to |
| 111 | * save power, unless batch mode is active, in which case they must |
| 112 | * continue fill their internal FIFO (see the documentation of batch() to |
| 113 | * learn how suspend interacts with batch mode). |
| 114 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 115 | * In batch mode, and only when the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 116 | * set and supported, the specified sensor must be able to wake-up the SoC and |
| 117 | * be able to buffer at least 10 seconds worth of the requested sensor events. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 118 | * |
| 119 | * There are notable exceptions to this behavior, which are sensor-dependent |
| 120 | * (see sensor types definitions below) |
| 121 | * |
| 122 | * |
| 123 | * The sensor type documentation below specifies the wake-up behavior of |
| 124 | * each sensor: |
| 125 | * wake-up: yes this sensor must wake-up the SoC to deliver events |
| 126 | * wake-up: no this sensor shall not wake-up the SoC, events are dropped |
| 127 | * |
| 128 | */ |
| 129 | |
| 130 | /* |
| 131 | * Sensor type |
| 132 | * |
| 133 | * Each sensor has a type which defines what this sensor measures and how |
| 134 | * measures are reported. All types are defined below. |
| 135 | */ |
| 136 | |
| 137 | /* |
| 138 | * Sensor fusion and virtual sensors |
| 139 | * |
| 140 | * Many sensor types are or can be implemented as virtual sensors from |
| 141 | * physical sensors on the device. For instance the rotation vector sensor, |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame] | 142 | * orientation sensor, step-detector, step-counter, etc... |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 143 | * |
| 144 | * From the point of view of this API these virtual sensors MUST appear as |
| 145 | * real, individual sensors. It is the responsibility of the driver and HAL |
| 146 | * to make sure this is the case. |
| 147 | * |
| 148 | * In particular, all sensors must be able to function concurrently. |
| 149 | * For example, if defining both an accelerometer and a step counter, |
| 150 | * then both must be able to work concurrently. |
| 151 | */ |
| 152 | |
| 153 | /* |
| 154 | * Trigger modes |
| 155 | * |
| 156 | * Sensors can report events in different ways called trigger modes, |
| 157 | * each sensor type has one and only one trigger mode associated to it. |
| 158 | * Currently there are four trigger modes defined: |
| 159 | * |
| 160 | * continuous: events are reported at a constant rate defined by setDelay(). |
| 161 | * eg: accelerometers, gyroscopes. |
| 162 | * on-change: events are reported only if the sensor's value has changed. |
| 163 | * setDelay() is used to set a lower limit to the reporting |
| 164 | * period (minimum time between two events). |
| 165 | * The HAL must return an event immediately when an on-change |
| 166 | * sensor is activated. |
| 167 | * eg: proximity, light sensors |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 168 | * one-shot: upon detection of an event, the sensor deactivates itself and |
| 169 | * then sends a single event. Order matters to avoid race |
| 170 | * conditions. No other event is sent until the sensor get |
| 171 | * reactivated. setDelay() is ignored. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 172 | * eg: significant motion sensor |
| 173 | * special: see details in the sensor type specification below |
| 174 | * |
| 175 | */ |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 176 | |
| 177 | /* |
| 178 | * SENSOR_TYPE_ACCELEROMETER |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 179 | * trigger-mode: continuous |
| 180 | * wake-up sensor: no |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 181 | * |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 182 | * All values are in SI units (m/s^2) and measure the acceleration of the |
| 183 | * device minus the force of gravity. |
| 184 | * |
| 185 | * Acceleration sensors return sensor events for all 3 axes at a constant |
| 186 | * rate defined by setDelay(). |
| 187 | * |
| 188 | * x: Acceleration on the x-axis |
| 189 | * y: Acceleration on the y-axis |
| 190 | * z: Acceleration on the z-axis |
| 191 | * |
| 192 | * Note that the readings from the accelerometer include the acceleration |
| 193 | * due to gravity (which is opposite to the direction of the gravity vector). |
| 194 | * |
| 195 | * Examples: |
| 196 | * The norm of <x, y, z> should be close to 0 when in free fall. |
| 197 | * |
| 198 | * When the device lies flat on a table and is pushed on its left side |
| 199 | * toward the right, the x acceleration value is positive. |
| 200 | * |
| 201 | * When the device lies flat on a table, the acceleration value is +9.81, |
| 202 | * which correspond to the acceleration of the device (0 m/s^2) minus the |
| 203 | * force of gravity (-9.81 m/s^2). |
| 204 | * |
| 205 | * When the device lies flat on a table and is pushed toward the sky, the |
| 206 | * acceleration value is greater than +9.81, which correspond to the |
| 207 | * acceleration of the device (+A m/s^2) minus the force of |
| 208 | * gravity (-9.81 m/s^2). |
| 209 | */ |
| 210 | #define SENSOR_TYPE_ACCELEROMETER (1) |
| 211 | |
| 212 | /* |
| 213 | * SENSOR_TYPE_GEOMAGNETIC_FIELD |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 214 | * trigger-mode: continuous |
| 215 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 216 | * |
| 217 | * All values are in micro-Tesla (uT) and measure the geomagnetic |
| 218 | * field in the X, Y and Z axis. |
| 219 | * |
| 220 | * Returned values include calibration mechanisms such that the vector is |
| 221 | * aligned with the magnetic declination and heading of the earth's |
| 222 | * geomagnetic field. |
| 223 | * |
| 224 | * Magnetic Field sensors return sensor events for all 3 axes at a constant |
| 225 | * rate defined by setDelay(). |
| 226 | */ |
| 227 | #define SENSOR_TYPE_GEOMAGNETIC_FIELD (2) |
| 228 | #define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD |
| 229 | |
| 230 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 231 | * SENSOR_TYPE_ORIENTATION |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 232 | * trigger-mode: continuous |
| 233 | * wake-up sensor: no |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 234 | * |
| 235 | * All values are angles in degrees. |
| 236 | * |
Mathias Agopian | 66a4095 | 2010-07-22 17:11:50 -0700 | [diff] [blame] | 237 | * Orientation sensors return sensor events for all 3 axes at a constant |
| 238 | * rate defined by setDelay(). |
| 239 | * |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 240 | * azimuth: angle between the magnetic north direction and the Y axis, around |
| 241 | * the Z axis (0<=azimuth<360). |
| 242 | * 0=North, 90=East, 180=South, 270=West |
| 243 | * |
| 244 | * pitch: Rotation around X axis (-180<=pitch<=180), with positive values when |
| 245 | * the z-axis moves toward the y-axis. |
| 246 | * |
| 247 | * roll: Rotation around Y axis (-90<=roll<=90), with positive values when |
Mathias Agopian | 19ea59f | 2010-02-26 13:15:18 -0800 | [diff] [blame] | 248 | * the x-axis moves towards the z-axis. |
| 249 | * |
| 250 | * Note: For historical reasons the roll angle is positive in the clockwise |
| 251 | * direction (mathematically speaking, it should be positive in the |
| 252 | * counter-clockwise direction): |
| 253 | * |
| 254 | * Z |
| 255 | * ^ |
| 256 | * (+roll) .--> | |
| 257 | * / | |
| 258 | * | | roll: rotation around Y axis |
| 259 | * X <-------(.) |
| 260 | * Y |
| 261 | * note that +Y == -roll |
| 262 | * |
| 263 | * |
| 264 | * |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 265 | * Note: This definition is different from yaw, pitch and roll used in aviation |
| 266 | * where the X axis is along the long side of the plane (tail to nose). |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 267 | */ |
| 268 | #define SENSOR_TYPE_ORIENTATION (3) |
| 269 | |
| 270 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 271 | * SENSOR_TYPE_GYROSCOPE |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 272 | * trigger-mode: continuous |
| 273 | * wake-up sensor: no |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 274 | * |
Kevin Powell | b01a043 | 2010-07-19 19:12:15 -0700 | [diff] [blame] | 275 | * All values are in radians/second and measure the rate of rotation |
| 276 | * around the X, Y and Z axis. The coordinate system is the same as is |
Mathias Agopian | c04e5f6 | 2010-09-14 10:53:55 -0700 | [diff] [blame] | 277 | * used for the acceleration sensor. Rotation is positive in the |
| 278 | * counter-clockwise direction (right-hand rule). That is, an observer |
| 279 | * looking from some positive location on the x, y or z axis at a device |
| 280 | * positioned on the origin would report positive rotation if the device |
| 281 | * appeared to be rotating counter clockwise. Note that this is the |
| 282 | * standard mathematical definition of positive rotation and does not agree |
| 283 | * with the definition of roll given earlier. |
| 284 | * The range should at least be 17.45 rad/s (ie: ~1000 deg/s). |
Kevin Powell | b01a043 | 2010-07-19 19:12:15 -0700 | [diff] [blame] | 285 | * |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 286 | * automatic gyro-drift compensation is allowed but not required. |
| 287 | */ |
| 288 | #define SENSOR_TYPE_GYROSCOPE (4) |
| 289 | |
| 290 | /* |
| 291 | * SENSOR_TYPE_LIGHT |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 292 | * trigger-mode: on-change |
| 293 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 294 | * |
| 295 | * The light sensor value is returned in SI lux units. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 296 | */ |
| 297 | #define SENSOR_TYPE_LIGHT (5) |
| 298 | |
| 299 | /* |
| 300 | * SENSOR_TYPE_PRESSURE |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 301 | * trigger-mode: continuous |
| 302 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 303 | * |
| 304 | * The pressure sensor return the athmospheric pressure in hectopascal (hPa) |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 305 | */ |
| 306 | #define SENSOR_TYPE_PRESSURE (6) |
| 307 | |
| 308 | /* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */ |
| 309 | #define SENSOR_TYPE_TEMPERATURE (7) |
| 310 | |
| 311 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 312 | * SENSOR_TYPE_PROXIMITY |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 313 | * trigger-mode: on-change |
| 314 | * wake-up sensor: yes |
Mike Lockwood | a241431 | 2009-11-03 10:29:50 -0500 | [diff] [blame] | 315 | * |
| 316 | * The distance value is measured in centimeters. Note that some proximity |
| 317 | * sensors only support a binary "close" or "far" measurement. In this case, |
| 318 | * the sensor should report its maxRange value in the "far" state and a value |
| 319 | * less than maxRange in the "near" state. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 320 | */ |
| 321 | #define SENSOR_TYPE_PROXIMITY (8) |
| 322 | |
| 323 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 324 | * SENSOR_TYPE_GRAVITY |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 325 | * trigger-mode: continuous |
| 326 | * wake-up sensor: no |
Mathias Agopian | 42b743c | 2010-11-22 15:55:32 -0800 | [diff] [blame] | 327 | * |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 328 | * A gravity output indicates the direction of and magnitude of gravity in |
| 329 | * the devices's coordinates. On Earth, the magnitude is 9.8 m/s^2. |
| 330 | * Units are m/s^2. The coordinate system is the same as is used for the |
| 331 | * acceleration sensor. When the device is at rest, the output of the |
| 332 | * gravity sensor should be identical to that of the accelerometer. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 333 | */ |
| 334 | #define SENSOR_TYPE_GRAVITY (9) |
| 335 | |
| 336 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 337 | * SENSOR_TYPE_LINEAR_ACCELERATION |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 338 | * trigger-mode: continuous |
| 339 | * wake-up sensor: no |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 340 | * |
| 341 | * Indicates the linear acceleration of the device in device coordinates, |
| 342 | * not including gravity. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 343 | * |
| 344 | * The output is conceptually: |
| 345 | * output of TYPE_ACCELERATION - output of TYPE_GRAVITY |
| 346 | * |
| 347 | * Readings on all axes should be close to 0 when device lies on a table. |
| 348 | * Units are m/s^2. |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 349 | * The coordinate system is the same as is used for the acceleration sensor. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 350 | */ |
| 351 | #define SENSOR_TYPE_LINEAR_ACCELERATION (10) |
| 352 | |
| 353 | |
| 354 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 355 | * SENSOR_TYPE_ROTATION_VECTOR |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 356 | * trigger-mode: continuous |
| 357 | * wake-up sensor: no |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 358 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 359 | * The rotation vector symbolizes the orientation of the device relative to the |
| 360 | * East-North-Up coordinates frame. It is usually obtained by integration of |
| 361 | * accelerometer, gyroscope and magnetometer readings. |
Mathias Agopian | 42b743c | 2010-11-22 15:55:32 -0800 | [diff] [blame] | 362 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 363 | * The East-North-Up coordinate system is defined as a direct orthonormal basis |
Mathias Agopian | d93ff97 | 2011-05-02 19:10:31 -0700 | [diff] [blame] | 364 | * where: |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 365 | * - X points east and is tangential to the ground. |
| 366 | * - Y points north and is tangential to the ground. |
Mathias Agopian | d93ff97 | 2011-05-02 19:10:31 -0700 | [diff] [blame] | 367 | * - Z points towards the sky and is perpendicular to the ground. |
| 368 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 369 | * The orientation of the phone is represented by the rotation necessary to |
| 370 | * align the East-North-Up coordinates with the phone's coordinates. That is, |
| 371 | * applying the rotation to the world frame (X,Y,Z) would align them with the |
| 372 | * phone coordinates (x,y,z). |
Mathias Agopian | d93ff97 | 2011-05-02 19:10:31 -0700 | [diff] [blame] | 373 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 374 | * The rotation can be seen as rotating the phone by an angle theta around |
| 375 | * an axis rot_axis to go from the reference (East-North-Up aligned) device |
| 376 | * orientation to the current device orientation. |
Mathias Agopian | 42b743c | 2010-11-22 15:55:32 -0800 | [diff] [blame] | 377 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 378 | * The rotation is encoded as the 4 (reordered) components of a unit quaternion: |
| 379 | * sensors_event_t.data[0] = rot_axis.x*sin(theta/2) |
| 380 | * sensors_event_t.data[1] = rot_axis.y*sin(theta/2) |
| 381 | * sensors_event_t.data[2] = rot_axis.z*sin(theta/2) |
| 382 | * sensors_event_t.data[3] = cos(theta/2) |
| 383 | * where |
| 384 | * - rot_axis.x,y,z are the North-East-Up coordinates of a unit length vector |
| 385 | * representing the rotation axis |
| 386 | * - theta is the rotation angle |
| 387 | * |
| 388 | * The quaternion must be of norm 1 (it is a unit quaternion). Failure to ensure |
| 389 | * this will cause erratic client behaviour. |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 390 | * |
| 391 | * In addition, this sensor reports an estimated heading accuracy. |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 392 | * sensors_event_t.data[4] = estimated_accuracy (in radians) |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 393 | * The heading error must be less than estimated_accuracy 95% of the time |
| 394 | * |
| 395 | * This sensor must use a gyroscope and an accelerometer as main orientation |
| 396 | * change input. |
| 397 | * |
| 398 | * This sensor can also include magnetometer input to make up for gyro drift, |
| 399 | * but it cannot be implemented using only a magnetometer. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 400 | */ |
| 401 | #define SENSOR_TYPE_ROTATION_VECTOR (11) |
| 402 | |
| 403 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 404 | * SENSOR_TYPE_RELATIVE_HUMIDITY |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 405 | * trigger-mode: on-change |
| 406 | * wake-up sensor: no |
Urs Fleisch | d2ed15a | 2010-12-29 17:00:33 +0100 | [diff] [blame] | 407 | * |
| 408 | * A relative humidity sensor measures relative ambient air humidity and |
| 409 | * returns a value in percent. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 410 | */ |
| 411 | #define SENSOR_TYPE_RELATIVE_HUMIDITY (12) |
| 412 | |
| 413 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 414 | * SENSOR_TYPE_AMBIENT_TEMPERATURE |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 415 | * trigger-mode: on-change |
| 416 | * wake-up sensor: no |
Mathias Agopian | 54f9dd0 | 2011-03-22 18:42:03 -0700 | [diff] [blame] | 417 | * |
| 418 | * The ambient (room) temperature in degree Celsius. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 419 | */ |
| 420 | #define SENSOR_TYPE_AMBIENT_TEMPERATURE (13) |
| 421 | |
| 422 | /* |
| 423 | * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 424 | * trigger-mode: continuous |
| 425 | * wake-up sensor: no |
Mathias Agopian | 54f9dd0 | 2011-03-22 18:42:03 -0700 | [diff] [blame] | 426 | * |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 427 | * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is |
| 428 | * reported separately instead of being included in the measurement. |
| 429 | * Factory calibration and temperature compensation should still be applied to |
| 430 | * the "uncalibrated" measurement. |
| 431 | * Separating away the hard iron calibration estimation allows the system to |
| 432 | * better recover from bad hard iron estimation. |
| 433 | * |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 434 | * All values are in micro-Tesla (uT) and measure the ambient magnetic |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 435 | * field in the X, Y and Z axis. Assumptions that the the magnetic field |
| 436 | * is due to the Earth's poles should be avoided. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 437 | * |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 438 | * The uncalibrated_magnetic event contains |
| 439 | * - 3 fields for uncalibrated measurement: x_uncalib, y_uncalib, z_uncalib. |
| 440 | * Each is a component of the measured magnetic field, with soft iron |
| 441 | * and temperature compensation applied, but not hard iron calibration. |
| 442 | * These values should be continuous (no re-calibration should cause a jump). |
| 443 | * - 3 fields for hard iron bias estimates: x_bias, y_bias, z_bias. |
| 444 | * Each field is a component of the estimated hard iron calibration. |
Etienne Le Grand | 7a813e8 | 2013-04-23 14:22:23 -0700 | [diff] [blame] | 445 | * They represent the offsets to apply to the calibrated readings to obtain |
| 446 | * uncalibrated readings (x_uncalib ~= x_calibrated + x_bias) |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 447 | * These values are expected to jump as soon as the estimate of the hard iron |
Etienne Le Grand | 7a813e8 | 2013-04-23 14:22:23 -0700 | [diff] [blame] | 448 | * changes, and they should be stable the rest of the time. |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 449 | * |
| 450 | * If this sensor is present, then the corresponding |
| 451 | * SENSOR_TYPE_MAGNETIC_FIELD must be present and both must return the |
| 452 | * same sensor_t::name and sensor_t::vendor. |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 453 | * |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame^] | 454 | * Minimum filtering should be applied to this sensor. In particular, low pass |
| 455 | * filters should be avoided. |
| 456 | * |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 457 | * See SENSOR_TYPE_MAGNETIC_FIELD for more information |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 458 | */ |
| 459 | #define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14) |
| 460 | |
| 461 | /* |
| 462 | * SENSOR_TYPE_GAME_ROTATION_VECTOR |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 463 | * trigger-mode: continuous |
| 464 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 465 | * |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 466 | * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic |
| 467 | * field. Therefore the Y axis doesn't point north, but instead to some other |
| 468 | * reference. That reference is allowed to drift by the same order of |
| 469 | * magnitude than the gyroscope drift around the Z axis. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 470 | * |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 471 | * This sensor does not report an estimated heading accuracy: |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 472 | * sensors_event_t.data[4] is reserved and should be set to 0 |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 473 | * |
| 474 | * In the ideal case, a phone rotated and returning to the same real-world |
| 475 | * orientation should report the same game rotation vector |
| 476 | * (without using the earth's geomagnetic field). |
| 477 | * |
| 478 | * This sensor must be based on a gyroscope. It cannot be implemented using |
| 479 | * a magnetometer. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 480 | * |
| 481 | * see SENSOR_TYPE_ROTATION_VECTOR for more details |
| 482 | */ |
| 483 | #define SENSOR_TYPE_GAME_ROTATION_VECTOR (15) |
| 484 | |
| 485 | /* |
| 486 | * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 487 | * trigger-mode: continuous |
| 488 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 489 | * |
| 490 | * All values are in radians/second and measure the rate of rotation |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 491 | * around the X, Y and Z axis. An estimation of the drift on each axis is |
| 492 | * reported as well. |
| 493 | * |
| 494 | * No gyro-drift compensation shall be performed. |
| 495 | * Factory calibration and temperature compensation should still be applied |
| 496 | * to the rate of rotation (angular speeds). |
| 497 | * |
| 498 | * The coordinate system is the same as is |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 499 | * used for the acceleration sensor. Rotation is positive in the |
| 500 | * counter-clockwise direction (right-hand rule). That is, an observer |
| 501 | * looking from some positive location on the x, y or z axis at a device |
| 502 | * positioned on the origin would report positive rotation if the device |
| 503 | * appeared to be rotating counter clockwise. Note that this is the |
| 504 | * standard mathematical definition of positive rotation and does not agree |
| 505 | * with the definition of roll given earlier. |
| 506 | * The range should at least be 17.45 rad/s (ie: ~1000 deg/s). |
| 507 | * |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 508 | * Content of an uncalibrated_gyro event: (units are rad/sec) |
| 509 | * x_uncalib : angular speed (w/o drift compensation) around the X axis |
| 510 | * y_uncalib : angular speed (w/o drift compensation) around the Y axis |
| 511 | * z_uncalib : angular speed (w/o drift compensation) around the Z axis |
| 512 | * x_bias : estimated drift around X axis in rad/s |
| 513 | * y_bias : estimated drift around Y axis in rad/s |
| 514 | * z_bias : estimated drift around Z axis in rad/s |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 515 | * |
| 516 | * IMPLEMENTATION NOTES: |
| 517 | * |
| 518 | * If the implementation is not able to estimate the drift, then this |
| 519 | * sensor MUST NOT be reported by this HAL. Instead, the regular |
| 520 | * SENSOR_TYPE_GYROSCOPE is used without drift compensation. |
| 521 | * |
| 522 | * If this sensor is present, then the corresponding |
| 523 | * SENSOR_TYPE_GYROSCOPE must be present and both must return the |
| 524 | * same sensor_t::name and sensor_t::vendor. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 525 | */ |
| 526 | #define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16) |
| 527 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 528 | |
| 529 | /* |
| 530 | * SENSOR_TYPE_SIGNIFICANT_MOTION |
| 531 | * trigger-mode: one-shot |
| 532 | * wake-up sensor: yes |
| 533 | * |
| 534 | * A sensor of this type triggers an event each time significant motion |
| 535 | * is detected and automatically disables itself. |
| 536 | * The only allowed value to return is 1.0. |
| 537 | * |
Etienne Le Grand | 1461f28 | 2013-03-05 22:00:33 -0800 | [diff] [blame] | 538 | * A significant motion is a motion that might lead to a change in the user |
| 539 | * location. |
| 540 | * Examples of such motions are: |
| 541 | * walking, biking, sitting in a moving car, coach or train. |
| 542 | * Examples of situations that should not trigger significant motion: |
| 543 | * - phone in pocket and person is not moving |
| 544 | * - phone is on a table, even if the table shakes a bit due to nearby traffic |
| 545 | * or washing machine |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 546 | * |
Etienne Le Grand | 1461f28 | 2013-03-05 22:00:33 -0800 | [diff] [blame] | 547 | * A note on false positive / false negative / power consumption tradeoff |
| 548 | * - The goal of this sensor is to save power. |
| 549 | * - Triggering an event when the user is not moving (false positive) is costly |
| 550 | * in terms of power, so it should be avoided. |
| 551 | * - Not triggering an event when the user is moving (false negative) is |
Etienne Le Grand | 2e7d3cd | 2013-03-07 12:22:32 -0800 | [diff] [blame] | 552 | * acceptable as long as it is not done repeatedly. If the user has been |
Etienne Le Grand | 1461f28 | 2013-03-05 22:00:33 -0800 | [diff] [blame] | 553 | * walking for 10 seconds, not triggering an event within those 10 seconds |
| 554 | * is not acceptable. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 555 | * |
| 556 | * IMPORTANT NOTE: this sensor type is very different from other types |
| 557 | * in that it must work when the screen is off without the need of |
| 558 | * holding a partial wake-lock and MUST allow the SoC to go into suspend. |
| 559 | * When significant motion is detected, the sensor must awaken the SoC and |
| 560 | * the event be reported. |
| 561 | * |
| 562 | * If a particular hardware cannot support this mode of operation then this |
| 563 | * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable |
| 564 | * to "emulate" this sensor in the HAL. |
| 565 | * |
| 566 | * The whole point of this sensor type is to save power by keeping the |
| 567 | * SoC in suspend mode when the device is at rest. |
| 568 | * |
| 569 | * When the sensor is not activated, it must also be deactivated in the |
| 570 | * hardware: it must not wake up the SoC anymore, even in case of |
| 571 | * significant motion. |
| 572 | * |
| 573 | * setDelay() has no effect and is ignored. |
| 574 | * Once a "significant motion" event is returned, a sensor of this type |
| 575 | * must disables itself automatically, as if activate(..., 0) had been called. |
| 576 | */ |
| 577 | |
| 578 | #define SENSOR_TYPE_SIGNIFICANT_MOTION (17) |
| 579 | |
| 580 | |
| 581 | /* |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame] | 582 | * SENSOR_TYPE_STEP_DETECTOR |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 583 | * trigger-mode: special |
| 584 | * wake-up sensor: no |
| 585 | * |
| 586 | * A sensor of this type triggers an event each time a step is taken |
| 587 | * by the user. The only allowed value to return is 1.0 and an event is |
| 588 | * generated for each step. Like with any other event, the timestamp |
| 589 | * indicates when the event (here the step) occurred, this corresponds to when |
| 590 | * the foot hit the ground, generating a high variation in acceleration. |
| 591 | * |
| 592 | * While this sensor operates, it shall not disrupt any other sensors, in |
| 593 | * particular, but not limited to, the accelerometer; which might very well |
| 594 | * be in use as well. |
| 595 | * |
| 596 | * This sensor must be low power. That is, if the step detection cannot be |
| 597 | * done in hardware, this sensor should not be defined. Also, when the |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame] | 598 | * step detector is activated and the accelerometer is not, only steps should |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 599 | * trigger interrupts (not accelerometer data). |
| 600 | * |
| 601 | * setDelay() has no impact on this sensor type |
| 602 | */ |
| 603 | |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame] | 604 | #define SENSOR_TYPE_STEP_DETECTOR (18) |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 605 | |
| 606 | |
| 607 | /* |
| 608 | * SENSOR_TYPE_STEP_COUNTER |
| 609 | * trigger-mode: on-change |
| 610 | * wake-up sensor: no |
| 611 | * |
| 612 | * A sensor of this type returns the number of steps taken by the user since |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 613 | * the last reboot while activated. The value is returned as a uint64_t and is |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame^] | 614 | * reset to zero only on a system / android reboot. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 615 | * |
| 616 | * The timestamp of the event is set to the time when the first step |
| 617 | * for that event was taken. |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame] | 618 | * See SENSOR_TYPE_STEP_DETECTOR for the signification of the time of a step. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 619 | * |
| 620 | * The minimum size of the hardware's internal counter shall be 16 bits |
| 621 | * (this restriction is here to avoid too frequent wake-ups when the |
| 622 | * delay is very large). |
| 623 | * |
| 624 | * IMPORTANT NOTE: this sensor type is different from other types |
| 625 | * in that it must work when the screen is off without the need of |
| 626 | * holding a partial wake-lock and MUST allow the SoC to go into suspend. |
| 627 | * Unlike other sensors, while in suspend mode this sensor must stay active, |
| 628 | * no events are reported during that time but, steps continue to be |
| 629 | * accounted for; an event will be reported as soon as the SoC resumes if |
| 630 | * the timeout has expired. |
| 631 | * |
| 632 | * In other words, when the screen is off and the device allowed to |
| 633 | * go into suspend mode, we don't want to be woken up, regardless of the |
| 634 | * setDelay() value, but the steps shall continue to be counted. |
| 635 | * |
| 636 | * The driver must however ensure that the internal step count never |
| 637 | * overflows. It is allowed in this situation to wake the SoC up so the |
| 638 | * driver can do the counter maintenance. |
| 639 | * |
| 640 | * While this sensor operates, it shall not disrupt any other sensors, in |
| 641 | * particular, but not limited to, the accelerometer; which might very well |
| 642 | * be in use as well. |
| 643 | * |
| 644 | * If a particular hardware cannot support these modes of operation then this |
| 645 | * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable |
| 646 | * to "emulate" this sensor in the HAL. |
| 647 | * |
| 648 | * This sensor must be low power. That is, if the step detection cannot be |
| 649 | * done in hardware, this sensor should not be defined. Also, when the |
| 650 | * step counter is activated and the accelerometer is not, only steps should |
| 651 | * trigger interrupts (not accelerometer data). |
| 652 | * |
| 653 | * The whole point of this sensor type is to save power by keeping the |
| 654 | * SoC in suspend mode when the device is at rest. |
| 655 | */ |
| 656 | |
| 657 | #define SENSOR_TYPE_STEP_COUNTER (19) |
| 658 | |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 659 | /* |
| 660 | * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR |
| 661 | * trigger-mode: continuous |
| 662 | * wake-up sensor: no |
| 663 | * |
| 664 | * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead |
| 665 | * of using a gyroscope. |
| 666 | * |
| 667 | * This sensor must be based on a magnetometer. It cannot be implemented using |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame^] | 668 | * a gyroscope, and gyroscope input cannot be used by this sensor, as the |
| 669 | * goal of this sensor is to be low power. |
| 670 | * The accelerometer can be (and usually is) used. |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 671 | * |
| 672 | * Just like SENSOR_TYPE_ROTATION_VECTOR, this sensor reports an estimated |
| 673 | * heading accuracy: |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 674 | * sensors_event_t.data[4] = estimated_accuracy (in radians) |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 675 | * The heading error must be less than estimated_accuracy 95% of the time |
| 676 | * |
| 677 | * see SENSOR_TYPE_ROTATION_VECTOR for more details |
| 678 | */ |
| 679 | #define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20) |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 680 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 681 | /** |
| 682 | * Values returned by the accelerometer in various locations in the universe. |
| 683 | * all values are in SI units (m/s^2) |
| 684 | */ |
| 685 | #define GRAVITY_SUN (275.0f) |
| 686 | #define GRAVITY_EARTH (9.80665f) |
| 687 | |
| 688 | /** Maximum magnetic field on Earth's surface */ |
| 689 | #define MAGNETIC_FIELD_EARTH_MAX (60.0f) |
| 690 | |
| 691 | /** Minimum magnetic field on Earth's surface */ |
| 692 | #define MAGNETIC_FIELD_EARTH_MIN (30.0f) |
| 693 | |
| 694 | |
| 695 | /** |
| 696 | * status of orientation sensor |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 697 | */ |
Kevin Powell | b01a043 | 2010-07-19 19:12:15 -0700 | [diff] [blame] | 698 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 699 | #define SENSOR_STATUS_UNRELIABLE 0 |
| 700 | #define SENSOR_STATUS_ACCURACY_LOW 1 |
| 701 | #define SENSOR_STATUS_ACCURACY_MEDIUM 2 |
| 702 | #define SENSOR_STATUS_ACCURACY_HIGH 3 |
| 703 | |
| 704 | |
| 705 | /** |
| 706 | * sensor event data |
| 707 | */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 708 | typedef struct { |
| 709 | union { |
| 710 | float v[3]; |
| 711 | struct { |
| 712 | float x; |
| 713 | float y; |
| 714 | float z; |
| 715 | }; |
| 716 | struct { |
| 717 | float azimuth; |
| 718 | float pitch; |
| 719 | float roll; |
| 720 | }; |
| 721 | }; |
| 722 | int8_t status; |
| 723 | uint8_t reserved[3]; |
| 724 | } sensors_vec_t; |
| 725 | |
| 726 | /** |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 727 | * uncalibrated gyroscope and magnetometer event data |
| 728 | */ |
| 729 | typedef struct { |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 730 | union { |
| 731 | float uncalib[3]; |
| 732 | struct { |
| 733 | float x_uncalib; |
| 734 | float y_uncalib; |
| 735 | float z_uncalib; |
| 736 | }; |
| 737 | }; |
| 738 | union { |
| 739 | float bias[3]; |
| 740 | struct { |
| 741 | float x_bias; |
| 742 | float y_bias; |
| 743 | float z_bias; |
| 744 | }; |
| 745 | }; |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 746 | } uncalibrated_event_t; |
| 747 | |
| 748 | /** |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 749 | * Union of the various types of sensor data |
| 750 | * that can be returned. |
| 751 | */ |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 752 | typedef struct sensors_event_t { |
| 753 | /* must be sizeof(struct sensors_event_t) */ |
| 754 | int32_t version; |
| 755 | |
| 756 | /* sensor identifier */ |
| 757 | int32_t sensor; |
| 758 | |
| 759 | /* sensor type */ |
| 760 | int32_t type; |
| 761 | |
| 762 | /* reserved */ |
| 763 | int32_t reserved0; |
| 764 | |
| 765 | /* time is in nanosecond */ |
| 766 | int64_t timestamp; |
| 767 | |
| 768 | union { |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 769 | union { |
| 770 | float data[16]; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 771 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 772 | /* acceleration values are in meter per second per second (m/s^2) */ |
| 773 | sensors_vec_t acceleration; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 774 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 775 | /* magnetic vector values are in micro-Tesla (uT) */ |
| 776 | sensors_vec_t magnetic; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 777 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 778 | /* orientation values are in degrees */ |
| 779 | sensors_vec_t orientation; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 780 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 781 | /* gyroscope values are in rad/s */ |
| 782 | sensors_vec_t gyro; |
Makarand Karvekar | 3120b58 | 2010-08-11 15:10:10 -0700 | [diff] [blame] | 783 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 784 | /* temperature is in degrees centigrade (Celsius) */ |
| 785 | float temperature; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 786 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 787 | /* distance in centimeters */ |
| 788 | float distance; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 789 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 790 | /* light in SI lux units */ |
| 791 | float light; |
Mathias Agopian | 1832f55 | 2010-07-29 15:22:30 -0700 | [diff] [blame] | 792 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 793 | /* pressure in hectopascal (hPa) */ |
| 794 | float pressure; |
Urs Fleisch | d2ed15a | 2010-12-29 17:00:33 +0100 | [diff] [blame] | 795 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 796 | /* relative humidity in percent */ |
| 797 | float relative_humidity; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 798 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 799 | /* uncalibrated gyroscope values are in rad/s */ |
| 800 | uncalibrated_event_t uncalibrated_gyro; |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 801 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 802 | /* uncalibrated magnetometer values are in micro-Teslas */ |
| 803 | uncalibrated_event_t uncalibrated_magnetic; |
| 804 | }; |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 805 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 806 | union { |
| 807 | uint64_t data[8]; |
| 808 | |
| 809 | /* step-counter */ |
| 810 | uint64_t step_counter; |
| 811 | } u64; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 812 | }; |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 813 | uint32_t reserved1[4]; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 814 | } sensors_event_t; |
| 815 | |
| 816 | |
| 817 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 818 | struct sensor_t; |
| 819 | |
| 820 | /** |
| 821 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
| 822 | * and the fields of this data structure must begin with hw_module_t |
| 823 | * followed by module specific information. |
| 824 | */ |
| 825 | struct sensors_module_t { |
| 826 | struct hw_module_t common; |
| 827 | |
| 828 | /** |
| 829 | * Enumerate all available sensors. The list is returned in "list". |
| 830 | * @return number of sensors in the list |
| 831 | */ |
| 832 | int (*get_sensors_list)(struct sensors_module_t* module, |
| 833 | struct sensor_t const** list); |
| 834 | }; |
| 835 | |
| 836 | struct sensor_t { |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 837 | |
| 838 | /* Name of this sensor. |
| 839 | * All sensors of the same "type" must have a different "name". |
| 840 | */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 841 | const char* name; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 842 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 843 | /* vendor of the hardware part */ |
| 844 | const char* vendor; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 845 | |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 846 | /* version of the hardware part + driver. The value of this field |
| 847 | * must increase when the driver is updated in a way that changes the |
| 848 | * output of this sensor. This is important for fused sensors when the |
| 849 | * fusion algorithm is updated. |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 850 | */ |
| 851 | int version; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 852 | |
| 853 | /* handle that identifies this sensors. This handle is used to reference |
| 854 | * this sensor throughout the HAL API. |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 855 | */ |
| 856 | int handle; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 857 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 858 | /* this sensor's type. */ |
| 859 | int type; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 860 | |
| 861 | /* maximum range of this sensor's value in SI units */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 862 | float maxRange; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 863 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 864 | /* smallest difference between two values reported by this sensor */ |
| 865 | float resolution; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 866 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 867 | /* rough estimate of this sensor's power consumption in mA */ |
| 868 | float power; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 869 | |
| 870 | /* this value depends on the trigger mode: |
| 871 | * |
| 872 | * continuous: minimum sample period allowed in microseconds |
| 873 | * on-change : 0 |
| 874 | * one-shot :-1 |
| 875 | * special : 0, unless otherwise noted |
| 876 | */ |
Mathias Agopian | 1511e20 | 2010-07-29 15:33:22 -0700 | [diff] [blame] | 877 | int32_t minDelay; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 878 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 879 | /* reserved fields, must be zero */ |
Mathias Agopian | 1511e20 | 2010-07-29 15:33:22 -0700 | [diff] [blame] | 880 | void* reserved[8]; |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 881 | }; |
| 882 | |
| 883 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 884 | /* |
| 885 | * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1 |
| 886 | * and is present for backward binary and source compatibility. |
| 887 | * (see documentation of the hooks in struct sensors_poll_device_1 below) |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 888 | */ |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 889 | struct sensors_poll_device_t { |
| 890 | struct hw_device_t common; |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 891 | int (*activate)(struct sensors_poll_device_t *dev, |
| 892 | int handle, int enabled); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 893 | int (*setDelay)(struct sensors_poll_device_t *dev, |
| 894 | int handle, int64_t ns); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 895 | int (*poll)(struct sensors_poll_device_t *dev, |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 896 | sensors_event_t* data, int count); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 897 | }; |
| 898 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 899 | /* |
| 900 | * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0 |
| 901 | */ |
| 902 | typedef struct sensors_poll_device_1 { |
| 903 | union { |
| 904 | /* sensors_poll_device_1 is compatible with sensors_poll_device_t, |
| 905 | * and can be down-cast to it |
| 906 | */ |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 907 | struct sensors_poll_device_t v0; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 908 | |
| 909 | struct { |
| 910 | struct hw_device_t common; |
| 911 | |
| 912 | /* Activate/de-activate one sensor. |
| 913 | * |
| 914 | * handle is the handle of the sensor to change. |
| 915 | * enabled set to 1 to enable, or 0 to disable the sensor. |
| 916 | * |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame^] | 917 | * if enabled is set to 1, the sensor is activated even if |
| 918 | * setDelay() wasn't called before. In this case, a default rate |
| 919 | * should be used. |
| 920 | * |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 921 | * unless otherwise noted in the sensor types definitions, an |
| 922 | * activated sensor never prevents the SoC to go into suspend |
| 923 | * mode; that is, the HAL shall not hold a partial wake-lock on |
| 924 | * behalf of applications. |
| 925 | * |
| 926 | * one-shot sensors de-activate themselves automatically upon |
| 927 | * receiving an event and they must still accept to be deactivated |
| 928 | * through a call to activate(..., ..., 0). |
| 929 | * |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame^] | 930 | * if "enabled" is 1 and the sensor is already activated, this |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 931 | * function is a no-op and succeeds. |
| 932 | * |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame^] | 933 | * if "enabled" is 0 and the sensor is already de-activated, |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 934 | * this function is a no-op and succeeds. |
| 935 | * |
| 936 | * return 0 on success, negative errno code otherwise |
| 937 | */ |
| 938 | int (*activate)(struct sensors_poll_device_t *dev, |
| 939 | int handle, int enabled); |
| 940 | |
| 941 | /** |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 942 | * Set the events's period in nanoseconds for a given sensor. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 943 | * |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 944 | * What the period_ns parameter means depends on the specified |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 945 | * sensor's trigger mode: |
| 946 | * |
| 947 | * continuous: setDelay() sets the sampling rate. |
| 948 | * on-change: setDelay() limits the delivery rate of events |
| 949 | * one-shot: setDelay() is ignored. it has no effect. |
| 950 | * special: see specific sensor type definitions |
| 951 | * |
| 952 | * For continuous and on-change sensors, if the requested value is |
| 953 | * less than sensor_t::minDelay, then it's silently clamped to |
| 954 | * sensor_t::minDelay unless sensor_t::minDelay is 0, in which |
| 955 | * case it is clamped to >= 1ms. |
| 956 | * |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame^] | 957 | * setDelay will not be called when the sensor is in batching mode. |
| 958 | * In this case, batch() will be called with the new period. |
| 959 | * |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 960 | * @return 0 if successful, < 0 on error |
| 961 | */ |
| 962 | int (*setDelay)(struct sensors_poll_device_t *dev, |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 963 | int handle, int64_t period_ns); |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 964 | |
| 965 | /** |
| 966 | * Returns an array of sensor data. |
| 967 | * This function must block until events are available. |
| 968 | * |
| 969 | * return the number of events read on success, or -errno in case |
| 970 | * of an error. |
| 971 | * |
| 972 | * The number of events returned in data must be less or equal |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 973 | * to the "count" argument. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 974 | * |
| 975 | * This function shall never return 0 (no event). |
| 976 | */ |
| 977 | int (*poll)(struct sensors_poll_device_t *dev, |
| 978 | sensors_event_t* data, int count); |
| 979 | }; |
| 980 | }; |
| 981 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 982 | |
| 983 | /* |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 984 | * Enables batch mode for the given sensor and sets the delay between events |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 985 | * |
| 986 | * A timeout value of zero disables batch mode for the given sensor. |
| 987 | * |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 988 | * The period_ns parameter is equivalent to calling setDelay() -- this |
| 989 | * function both enables or disables the batch mode AND sets the events's |
| 990 | * period in nanosecond. See setDelay() above for a detailed explanation of |
| 991 | * the period_ns parameter. |
| 992 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 993 | * BATCH MODE: |
| 994 | * ----------- |
| 995 | * In non-batch mode, all sensor events must be reported as soon as they |
| 996 | * are detected. For example, an accelerometer activated at 50Hz will |
| 997 | * trigger interrupts 50 times per second. |
| 998 | * While in batch mode, sensor events do not need to be reported as soon |
| 999 | * as they are detected. They can be temporarily stored in batches and |
| 1000 | * reported in batches, as long as no event is delayed by more than |
| 1001 | * "timeout" nanoseconds. That is, all events since the previous batch |
| 1002 | * are recorded and returned all at once. This allows to reduce the amount |
| 1003 | * of interrupts sent to the SoC, and allow the SoC to switch to a lower |
| 1004 | * power state (Idle) while the sensor is capturing and batching data. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1005 | * |
| 1006 | * setDelay() is not affected and it behaves as usual. |
| 1007 | * |
| 1008 | * Each event has a timestamp associated with it, the timestamp |
| 1009 | * must be accurate and correspond to the time at which the event |
| 1010 | * physically happened. |
| 1011 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1012 | * Batching does not modify the behavior of poll(): batches from different |
| 1013 | * sensors can be interleaved and split. As usual, all events from the same |
| 1014 | * sensor are time-ordered. |
| 1015 | * |
| 1016 | * BEHAVIOUR OUTSIDE OF SUSPEND MODE: |
| 1017 | * ---------------------------------- |
| 1018 | * |
| 1019 | * When the SoC is awake (not in suspend mode), events must be reported in |
| 1020 | * batches at least every "timeout". No event shall be dropped or lost. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1021 | * If internal h/w FIFOs fill-up before the timeout, then events are |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1022 | * reported at that point to ensure no event is lost. |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1023 | * |
| 1024 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1025 | * NORMAL BEHAVIOR IN SUSPEND MODE: |
| 1026 | * --------------------------------- |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1027 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1028 | * By default, batch mode doesn't significantly change the interaction with |
| 1029 | * suspend mode. That is, sensors must continue to allow the SoC to |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1030 | * go into suspend mode and sensors must stay active to fill their |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1031 | * internal FIFO. In this mode, when the FIFO fills up, it shall wrap |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1032 | * around (basically behave like a circular buffer, overwriting events). |
| 1033 | * As soon as the SoC comes out of suspend mode, a batch is produced with |
| 1034 | * as much as the recent history as possible, and batch operation |
| 1035 | * resumes as usual. |
| 1036 | * |
| 1037 | * The behavior described above allows applications to record the recent |
| 1038 | * history of a set of sensor while keeping the SoC into suspend. It |
| 1039 | * also allows the hardware to not have to rely on a wake-up interrupt line. |
| 1040 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1041 | * WAKE_UPON_FIFO_FULL BEHAVIOR IN SUSPEND MODE: |
| 1042 | * ---------------------------------------------- |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1043 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1044 | * There are cases, however, where an application cannot afford to lose |
| 1045 | * any events, even when the device goes into suspend mode. |
| 1046 | * For a given rate, if a sensor has the capability to store at least 10 |
| 1047 | * seconds worth of events in its FIFO and is able to wake up the Soc, it |
| 1048 | * can implement an optional secondary mode: the WAKE_UPON_FIFO_FULL mode. |
| 1049 | * |
| 1050 | * The caller will set the SENSORS_BATCH_WAKE_UPON_FIFO_FULL flag to |
| 1051 | * activate this mode. If the sensor does not support this mode, batch() |
| 1052 | * will fail when the flag is set. |
| 1053 | * |
| 1054 | * When running with the WAKE_UPON_FIFO_FULL flag set, no events can be |
| 1055 | * lost. When the FIFO is getting full, the sensor must wake up the SoC from |
| 1056 | * suspend and return a batch before the FIFO fills-up. |
| 1057 | * Depending on the device, it might take a few miliseconds for the SoC to |
| 1058 | * entirely come out of suspend and start flushing the FIFO. Enough head |
| 1059 | * room must be allocated in the FIFO to allow the device to entirely come |
| 1060 | * out of suspend without the FIFO overflowing (no events shall be lost). |
| 1061 | * |
| 1062 | * Implementing the WAKE_UPON_FIFO_FULL mode is optional. |
| 1063 | * If the hardware cannot support this mode, or if the physical |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1064 | * FIFO is so small that the device would never be allowed to go into |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1065 | * suspend for at least 10 seconds, then this function MUST fail when |
| 1066 | * the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is set, regardless of |
| 1067 | * the value of the timeout parameter. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1068 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1069 | * |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1070 | * DRY RUN: |
| 1071 | * -------- |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1072 | * |
| 1073 | * If the flag SENSORS_BATCH_DRY_RUN is set, this function returns |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1074 | * without modifying the batch mode or the event period and has no side |
| 1075 | * effects, but returns errors as usual (as it would if this flag was |
| 1076 | * not set). This flag is used to check if batch mode is available for a |
| 1077 | * given configuration -- in particular for a given sensor at a given rate. |
| 1078 | * |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1079 | * |
| 1080 | * Return values: |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1081 | * -------------- |
| 1082 | * |
| 1083 | * Because sensors must be independent, the return value must not depend |
| 1084 | * on the state of the system (whether another sensor is on or not), |
| 1085 | * nor on whether the flag SENSORS_BATCH_DRY_RUN is set (in other words, |
| 1086 | * if a batch call with SENSORS_BATCH_DRY_RUN is successful, |
| 1087 | * the same call without SENSORS_BATCH_DRY_RUN must succeed as well). |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1088 | * |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame^] | 1089 | * When timeout is not 0: |
| 1090 | * If successful, 0 is returned. |
| 1091 | * If the specified sensor doesn't support batch mode, return -EINVAL. |
| 1092 | * If the specified sensor's trigger-mode is one-shot, return -EINVAL. |
| 1093 | * If WAKE_UPON_FIFO_FULL is specified and the specified sensor's internal |
| 1094 | * FIFO is too small to store at least 10 seconds worth of data at the |
| 1095 | * given rate, -EINVAL is returned. Note that as stated above, this has to |
| 1096 | * be determined at compile time, and not based on the state of the |
| 1097 | * system. |
| 1098 | * If some other constraints above cannot be satisfied, return -EINVAL. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1099 | * |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1100 | * Note: the timeout parameter, when > 0, has no impact on whether this |
| 1101 | * function succeeds or fails. |
| 1102 | * |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame^] | 1103 | * When timeout is 0: |
| 1104 | * The caller will never set the wake_upon_fifo_full flag. |
| 1105 | * The function must succeed, and batch mode must be deactivated. |
| 1106 | * |
| 1107 | * Independently of whether DRY_RUN is specified, When the call to batch() |
| 1108 | * fails, no state should be changed. In particular, a failed call to |
| 1109 | * batch() should not change the rate of the sensor. Example: |
| 1110 | * setDelay(..., 10ms) |
| 1111 | * batch(..., 20ms, ...) fails |
| 1112 | * rate should stay 10ms. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1113 | * |
| 1114 | * |
| 1115 | * IMPLEMENTATION NOTES: |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1116 | * --------------------- |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1117 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1118 | * Batch mode, if supported, should happen at the hardware level, |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1119 | * typically using hardware FIFOs. In particular, it SHALL NOT be |
| 1120 | * implemented in the HAL, as this would be counter productive. |
| 1121 | * The goal here is to save significant amounts of power. |
| 1122 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1123 | * In some implementations, events from several sensors can share the |
| 1124 | * same physical FIFO. In that case, all events in the FIFO can be sent and |
| 1125 | * processed by the HAL as soon as one batch must be reported. |
| 1126 | * For example, if the following sensors are activated: |
| 1127 | * - accelerometer batched with timeout = 20s |
| 1128 | * - gyroscope batched with timeout = 5s |
| 1129 | * then the accelerometer batches can be reported at the same time the |
| 1130 | * gyroscope batches are reported (every 5 seconds) |
| 1131 | * |
| 1132 | * Batch mode can be enabled or disabled at any time, in particular |
| 1133 | * while the specified sensor is already enabled, and this shall not |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1134 | * result in the loss of events. |
| 1135 | * |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 1136 | * COMPARATIVE IMPORTANCE OF BATCHING FOR DIFFERENT SENSORS: |
| 1137 | * --------------------------------------------------------- |
| 1138 | * |
| 1139 | * On platforms on which hardware fifo size is limited, the system designers |
| 1140 | * might have to choose how much fifo to reserve for each sensor. To help |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1141 | * with this choice, here is a list of applications made possible when |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 1142 | * batching is implemented on the different sensors. |
| 1143 | * |
| 1144 | * High value: Low power pedestrian dead reckoning |
| 1145 | * Target batching time: 20 seconds to 1 minute |
| 1146 | * Sensors to batch: |
| 1147 | * - Step detector |
| 1148 | * - Rotation vector or game rotation vector at 5Hz |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1149 | * Gives us step and heading while letting the SoC go to Suspend. |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 1150 | * |
| 1151 | * High value: Medium power activity/gesture recognition |
| 1152 | * Target batching time: 3 seconds |
| 1153 | * Sensors to batch: accelerometer between 20Hz and 50Hz |
| 1154 | * Allows recognizing arbitrary activities and gestures without having |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1155 | * to keep the SoC fully awake while the data is collected. |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 1156 | * |
| 1157 | * Medium-high value: Interrupt load reduction |
| 1158 | * Target batching time: < 1 second |
| 1159 | * Sensors to batch: any high frequency sensor. |
| 1160 | * If the gyroscope is set at 800Hz, even batching just 10 gyro events can |
| 1161 | * reduce the number of interrupts from 800/second to 80/second. |
| 1162 | * |
| 1163 | * Medium value: Continuous low frequency data collection |
| 1164 | * Target batching time: > 1 minute |
| 1165 | * Sensors to batch: barometer, humidity sensor, other low frequency |
| 1166 | * sensors. |
| 1167 | * Allows creating monitoring applications at low power. |
| 1168 | * |
| 1169 | * Medium value: Continuous full-sensors collection |
| 1170 | * Target batching time: > 1 minute |
| 1171 | * Sensors to batch: all, at high frequencies |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1172 | * Allows full collection of sensor data while leaving the SoC in |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 1173 | * suspend mode. Only to consider if fifo space is not an issue. |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1174 | * |
| 1175 | * In each of the cases above, if WAKE_UPON_FIFO_FULL is implemented, the |
| 1176 | * applications might decide to let the SoC go to suspend, allowing for even |
| 1177 | * more power savings. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1178 | */ |
| 1179 | int (*batch)(struct sensors_poll_device_1* dev, |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1180 | int handle, int flags, int64_t period_ns, int64_t timeout); |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1181 | |
| 1182 | void (*reserved_procs[8])(void); |
| 1183 | |
| 1184 | } sensors_poll_device_1_t; |
| 1185 | |
| 1186 | |
| 1187 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1188 | /** convenience API for opening and closing a device */ |
| 1189 | |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 1190 | static inline int sensors_open(const struct hw_module_t* module, |
| 1191 | struct sensors_poll_device_t** device) { |
| 1192 | return module->methods->open(module, |
| 1193 | SENSORS_HARDWARE_POLL, (struct hw_device_t**)device); |
| 1194 | } |
| 1195 | |
| 1196 | static inline int sensors_close(struct sensors_poll_device_t* device) { |
| 1197 | return device->common.close(&device->common); |
| 1198 | } |
| 1199 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1200 | static inline int sensors_open_1(const struct hw_module_t* module, |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 1201 | sensors_poll_device_1_t** device) { |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1202 | return module->methods->open(module, |
| 1203 | SENSORS_HARDWARE_POLL, (struct hw_device_t**)device); |
| 1204 | } |
| 1205 | |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 1206 | static inline int sensors_close_1(sensors_poll_device_1_t* device) { |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1207 | return device->common.close(&device->common); |
| 1208 | } |
| 1209 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1210 | __END_DECLS |
| 1211 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1212 | #endif // ANDROID_SENSORS_INTERFACE_H |