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