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 | /* attributes queriable with query() */ |
| 58 | enum { |
| 59 | /* |
| 60 | * Availability: SENSORS_DEVICE_API_VERSION_1_0 |
| 61 | * return the maximum number of events that can be returned |
| 62 | * in a single call to (*poll)(). This value is used by the |
| 63 | * framework to adequately dimension the buffer passed to |
| 64 | * (*poll)(), note that (*poll)() still needs to pay attention to |
| 65 | * the count parameter passed to it, it cannot blindly expect that |
| 66 | * this value will be used for all calls to (*poll)(). |
| 67 | * |
| 68 | * Generally this value should be set to match the sum of the internal |
| 69 | * FIFOs of all available sensors. |
| 70 | */ |
| 71 | SENSORS_QUERY_MAX_EVENTS_BATCH_COUNT = 0 |
| 72 | }; |
| 73 | |
| 74 | /* |
| 75 | * flags for (*batch)() |
| 76 | * Availability: SENSORS_DEVICE_API_VERSION_1_0 |
| 77 | * see (*batch)() documentation for details |
| 78 | */ |
| 79 | enum { |
| 80 | SENSORS_BATCH_DRY_RUN = 0x00000001, |
| 81 | SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002 |
| 82 | }; |
| 83 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 84 | /** |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 85 | * 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] | 86 | * |
| 87 | * This API is relative to the screen of the device in its default orientation, |
| 88 | * that is, if the device can be used in portrait or landscape, this API |
| 89 | * is only relative to the NATURAL orientation of the screen. In other words, |
| 90 | * the axis are not swapped when the device's screen orientation changes. |
| 91 | * Higher level services /may/ perform this transformation. |
| 92 | * |
| 93 | * x<0 x>0 |
| 94 | * ^ |
| 95 | * | |
| 96 | * +-----------+--> y>0 |
| 97 | * | | |
| 98 | * | | |
| 99 | * | | |
| 100 | * | | / z<0 |
| 101 | * | | / |
| 102 | * | | / |
| 103 | * O-----------+/ |
| 104 | * |[] [ ] []/ |
| 105 | * +----------/+ y<0 |
| 106 | * / |
| 107 | * / |
| 108 | * |/ z>0 (toward the sky) |
| 109 | * |
| 110 | * O: Origin (x=0,y=0,z=0) |
| 111 | * |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 112 | */ |
| 113 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 114 | /* |
| 115 | * Interaction with suspend mode |
| 116 | * |
| 117 | * Unless otherwise noted, an enabled sensor shall not prevent the |
| 118 | * SoC to go into suspend mode. It is the responsibility of applications |
| 119 | * to keep a partial wake-lock should they wish to receive sensor |
| 120 | * events while the screen is off. While in suspend mode, and unless |
| 121 | * otherwise noted, enabled sensors' events are lost. |
| 122 | * |
| 123 | * Note that conceptually, the sensor itself is not de-activated while in |
| 124 | * suspend mode -- it's just that the data it returns are lost. As soon as |
| 125 | * the SoC gets out of suspend mode, operations resume as usual. Of course, |
| 126 | * in practice sensors shall be disabled while in suspend mode to |
| 127 | * save power, unless batch mode is active, in which case they must |
| 128 | * continue fill their internal FIFO (see the documentation of batch() to |
| 129 | * learn how suspend interacts with batch mode). |
| 130 | * |
| 131 | * In batch mode and only when the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is |
| 132 | * set and supported, the specified sensor must be able to wake-up the SoC. |
| 133 | * |
| 134 | * There are notable exceptions to this behavior, which are sensor-dependent |
| 135 | * (see sensor types definitions below) |
| 136 | * |
| 137 | * |
| 138 | * The sensor type documentation below specifies the wake-up behavior of |
| 139 | * each sensor: |
| 140 | * wake-up: yes this sensor must wake-up the SoC to deliver events |
| 141 | * wake-up: no this sensor shall not wake-up the SoC, events are dropped |
| 142 | * |
| 143 | */ |
| 144 | |
| 145 | /* |
| 146 | * Sensor type |
| 147 | * |
| 148 | * Each sensor has a type which defines what this sensor measures and how |
| 149 | * measures are reported. All types are defined below. |
| 150 | */ |
| 151 | |
| 152 | /* |
| 153 | * Sensor fusion and virtual sensors |
| 154 | * |
| 155 | * Many sensor types are or can be implemented as virtual sensors from |
| 156 | * physical sensors on the device. For instance the rotation vector sensor, |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame^] | 157 | * orientation sensor, step-detector, step-counter, etc... |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 158 | * |
| 159 | * From the point of view of this API these virtual sensors MUST appear as |
| 160 | * real, individual sensors. It is the responsibility of the driver and HAL |
| 161 | * to make sure this is the case. |
| 162 | * |
| 163 | * In particular, all sensors must be able to function concurrently. |
| 164 | * For example, if defining both an accelerometer and a step counter, |
| 165 | * then both must be able to work concurrently. |
| 166 | */ |
| 167 | |
| 168 | /* |
| 169 | * Trigger modes |
| 170 | * |
| 171 | * Sensors can report events in different ways called trigger modes, |
| 172 | * each sensor type has one and only one trigger mode associated to it. |
| 173 | * Currently there are four trigger modes defined: |
| 174 | * |
| 175 | * continuous: events are reported at a constant rate defined by setDelay(). |
| 176 | * eg: accelerometers, gyroscopes. |
| 177 | * on-change: events are reported only if the sensor's value has changed. |
| 178 | * setDelay() is used to set a lower limit to the reporting |
| 179 | * period (minimum time between two events). |
| 180 | * The HAL must return an event immediately when an on-change |
| 181 | * sensor is activated. |
| 182 | * eg: proximity, light sensors |
| 183 | * one-shot: a single event is reported and the sensor returns to the |
| 184 | * disabled state, no further events are reported. setDelay() is |
| 185 | * ignored. |
| 186 | * eg: significant motion sensor |
| 187 | * special: see details in the sensor type specification below |
| 188 | * |
| 189 | */ |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 190 | |
| 191 | /* |
| 192 | * SENSOR_TYPE_ACCELEROMETER |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 193 | * trigger-mode: continuous |
| 194 | * wake-up sensor: no |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 195 | * |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 196 | * All values are in SI units (m/s^2) and measure the acceleration of the |
| 197 | * device minus the force of gravity. |
| 198 | * |
| 199 | * Acceleration sensors return sensor events for all 3 axes at a constant |
| 200 | * rate defined by setDelay(). |
| 201 | * |
| 202 | * x: Acceleration on the x-axis |
| 203 | * y: Acceleration on the y-axis |
| 204 | * z: Acceleration on the z-axis |
| 205 | * |
| 206 | * Note that the readings from the accelerometer include the acceleration |
| 207 | * due to gravity (which is opposite to the direction of the gravity vector). |
| 208 | * |
| 209 | * Examples: |
| 210 | * The norm of <x, y, z> should be close to 0 when in free fall. |
| 211 | * |
| 212 | * When the device lies flat on a table and is pushed on its left side |
| 213 | * toward the right, the x acceleration value is positive. |
| 214 | * |
| 215 | * When the device lies flat on a table, the acceleration value is +9.81, |
| 216 | * which correspond to the acceleration of the device (0 m/s^2) minus the |
| 217 | * force of gravity (-9.81 m/s^2). |
| 218 | * |
| 219 | * When the device lies flat on a table and is pushed toward the sky, the |
| 220 | * acceleration value is greater than +9.81, which correspond to the |
| 221 | * acceleration of the device (+A m/s^2) minus the force of |
| 222 | * gravity (-9.81 m/s^2). |
| 223 | */ |
| 224 | #define SENSOR_TYPE_ACCELEROMETER (1) |
| 225 | |
| 226 | /* |
| 227 | * SENSOR_TYPE_GEOMAGNETIC_FIELD |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 228 | * trigger-mode: continuous |
| 229 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 230 | * |
| 231 | * All values are in micro-Tesla (uT) and measure the geomagnetic |
| 232 | * field in the X, Y and Z axis. |
| 233 | * |
| 234 | * Returned values include calibration mechanisms such that the vector is |
| 235 | * aligned with the magnetic declination and heading of the earth's |
| 236 | * geomagnetic field. |
| 237 | * |
| 238 | * Magnetic Field sensors return sensor events for all 3 axes at a constant |
| 239 | * rate defined by setDelay(). |
| 240 | */ |
| 241 | #define SENSOR_TYPE_GEOMAGNETIC_FIELD (2) |
| 242 | #define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD |
| 243 | |
| 244 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 245 | * SENSOR_TYPE_ORIENTATION |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 246 | * trigger-mode: continuous |
| 247 | * wake-up sensor: no |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 248 | * |
| 249 | * All values are angles in degrees. |
| 250 | * |
Mathias Agopian | 66a4095 | 2010-07-22 17:11:50 -0700 | [diff] [blame] | 251 | * Orientation sensors return sensor events for all 3 axes at a constant |
| 252 | * rate defined by setDelay(). |
| 253 | * |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 254 | * azimuth: angle between the magnetic north direction and the Y axis, around |
| 255 | * the Z axis (0<=azimuth<360). |
| 256 | * 0=North, 90=East, 180=South, 270=West |
| 257 | * |
| 258 | * pitch: Rotation around X axis (-180<=pitch<=180), with positive values when |
| 259 | * the z-axis moves toward the y-axis. |
| 260 | * |
| 261 | * roll: Rotation around Y axis (-90<=roll<=90), with positive values when |
Mathias Agopian | 19ea59f | 2010-02-26 13:15:18 -0800 | [diff] [blame] | 262 | * the x-axis moves towards the z-axis. |
| 263 | * |
| 264 | * Note: For historical reasons the roll angle is positive in the clockwise |
| 265 | * direction (mathematically speaking, it should be positive in the |
| 266 | * counter-clockwise direction): |
| 267 | * |
| 268 | * Z |
| 269 | * ^ |
| 270 | * (+roll) .--> | |
| 271 | * / | |
| 272 | * | | roll: rotation around Y axis |
| 273 | * X <-------(.) |
| 274 | * Y |
| 275 | * note that +Y == -roll |
| 276 | * |
| 277 | * |
| 278 | * |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 279 | * Note: This definition is different from yaw, pitch and roll used in aviation |
| 280 | * where the X axis is along the long side of the plane (tail to nose). |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 281 | */ |
| 282 | #define SENSOR_TYPE_ORIENTATION (3) |
| 283 | |
| 284 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 285 | * SENSOR_TYPE_GYROSCOPE |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 286 | * trigger-mode: continuous |
| 287 | * wake-up sensor: no |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 288 | * |
Kevin Powell | b01a043 | 2010-07-19 19:12:15 -0700 | [diff] [blame] | 289 | * All values are in radians/second and measure the rate of rotation |
| 290 | * around the X, Y and Z axis. The coordinate system is the same as is |
Mathias Agopian | c04e5f6 | 2010-09-14 10:53:55 -0700 | [diff] [blame] | 291 | * used for the acceleration sensor. Rotation is positive in the |
| 292 | * counter-clockwise direction (right-hand rule). That is, an observer |
| 293 | * looking from some positive location on the x, y or z axis at a device |
| 294 | * positioned on the origin would report positive rotation if the device |
| 295 | * appeared to be rotating counter clockwise. Note that this is the |
| 296 | * standard mathematical definition of positive rotation and does not agree |
| 297 | * with the definition of roll given earlier. |
| 298 | * The range should at least be 17.45 rad/s (ie: ~1000 deg/s). |
Kevin Powell | b01a043 | 2010-07-19 19:12:15 -0700 | [diff] [blame] | 299 | * |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 300 | * automatic gyro-drift compensation is allowed but not required. |
| 301 | */ |
| 302 | #define SENSOR_TYPE_GYROSCOPE (4) |
| 303 | |
| 304 | /* |
| 305 | * SENSOR_TYPE_LIGHT |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 306 | * trigger-mode: on-change |
| 307 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 308 | * |
| 309 | * The light sensor value is returned in SI lux units. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 310 | */ |
| 311 | #define SENSOR_TYPE_LIGHT (5) |
| 312 | |
| 313 | /* |
| 314 | * SENSOR_TYPE_PRESSURE |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 315 | * trigger-mode: continuous |
| 316 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 317 | * |
| 318 | * The pressure sensor return the athmospheric pressure in hectopascal (hPa) |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 319 | */ |
| 320 | #define SENSOR_TYPE_PRESSURE (6) |
| 321 | |
| 322 | /* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */ |
| 323 | #define SENSOR_TYPE_TEMPERATURE (7) |
| 324 | |
| 325 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 326 | * SENSOR_TYPE_PROXIMITY |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 327 | * trigger-mode: on-change |
| 328 | * wake-up sensor: yes |
Mike Lockwood | a241431 | 2009-11-03 10:29:50 -0500 | [diff] [blame] | 329 | * |
| 330 | * The distance value is measured in centimeters. Note that some proximity |
| 331 | * sensors only support a binary "close" or "far" measurement. In this case, |
| 332 | * the sensor should report its maxRange value in the "far" state and a value |
| 333 | * less than maxRange in the "near" state. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 334 | */ |
| 335 | #define SENSOR_TYPE_PROXIMITY (8) |
| 336 | |
| 337 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 338 | * SENSOR_TYPE_GRAVITY |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 339 | * trigger-mode: continuous |
| 340 | * wake-up sensor: no |
Mathias Agopian | 42b743c | 2010-11-22 15:55:32 -0800 | [diff] [blame] | 341 | * |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 342 | * A gravity output indicates the direction of and magnitude of gravity in |
| 343 | * the devices's coordinates. On Earth, the magnitude is 9.8 m/s^2. |
| 344 | * Units are m/s^2. The coordinate system is the same as is used for the |
| 345 | * acceleration sensor. When the device is at rest, the output of the |
| 346 | * gravity sensor should be identical to that of the accelerometer. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 347 | */ |
| 348 | #define SENSOR_TYPE_GRAVITY (9) |
| 349 | |
| 350 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 351 | * SENSOR_TYPE_LINEAR_ACCELERATION |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 352 | * trigger-mode: continuous |
| 353 | * wake-up sensor: no |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 354 | * |
| 355 | * Indicates the linear acceleration of the device in device coordinates, |
| 356 | * not including gravity. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 357 | * |
| 358 | * The output is conceptually: |
| 359 | * output of TYPE_ACCELERATION - output of TYPE_GRAVITY |
| 360 | * |
| 361 | * Readings on all axes should be close to 0 when device lies on a table. |
| 362 | * Units are m/s^2. |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 363 | * 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] | 364 | */ |
| 365 | #define SENSOR_TYPE_LINEAR_ACCELERATION (10) |
| 366 | |
| 367 | |
| 368 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 369 | * SENSOR_TYPE_ROTATION_VECTOR |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 370 | * trigger-mode: continuous |
| 371 | * wake-up sensor: no |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 372 | * |
Kevin Powell | b01a043 | 2010-07-19 19:12:15 -0700 | [diff] [blame] | 373 | * A rotation vector represents the orientation of the device as a combination |
| 374 | * of an angle and an axis, in which the device has rotated through an angle |
| 375 | * theta around an axis <x, y, z>. The three elements of the rotation vector |
| 376 | * are <x*sin(theta/2), y*sin(theta/2), z*sin(theta/2)>, such that the magnitude |
| 377 | * of the rotation vector is equal to sin(theta/2), and the direction of the |
| 378 | * rotation vector is equal to the direction of the axis of rotation. The three |
| 379 | * elements of the rotation vector are equal to the last three components of a |
| 380 | * unit quaternion <cos(theta/2), x*sin(theta/2), y*sin(theta/2), z*sin(theta/2)>. |
| 381 | * Elements of the rotation vector are unitless. The x, y, and z axis are defined |
| 382 | * in the same was as for the acceleration sensor. |
Mathias Agopian | 42b743c | 2010-11-22 15:55:32 -0800 | [diff] [blame] | 383 | * |
Mathias Agopian | d93ff97 | 2011-05-02 19:10:31 -0700 | [diff] [blame] | 384 | * The reference coordinate system is defined as a direct orthonormal basis, |
| 385 | * where: |
| 386 | * |
| 387 | * - X is defined as the vector product Y.Z (It is tangential to |
| 388 | * the ground at the device's current location and roughly points East). |
| 389 | * |
| 390 | * - Y is tangential to the ground at the device's current location and |
| 391 | * points towards the magnetic North Pole. |
| 392 | * |
| 393 | * - Z points towards the sky and is perpendicular to the ground. |
| 394 | * |
| 395 | * |
Mathias Agopian | 42b743c | 2010-11-22 15:55:32 -0800 | [diff] [blame] | 396 | * The rotation-vector is stored as: |
| 397 | * |
| 398 | * sensors_event_t.data[0] = x*sin(theta/2) |
| 399 | * sensors_event_t.data[1] = y*sin(theta/2) |
| 400 | * sensors_event_t.data[2] = z*sin(theta/2) |
| 401 | * sensors_event_t.data[3] = cos(theta/2) |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 402 | */ |
| 403 | #define SENSOR_TYPE_ROTATION_VECTOR (11) |
| 404 | |
| 405 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 406 | * SENSOR_TYPE_RELATIVE_HUMIDITY |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 407 | * trigger-mode: on-change |
| 408 | * wake-up sensor: no |
Urs Fleisch | d2ed15a | 2010-12-29 17:00:33 +0100 | [diff] [blame] | 409 | * |
| 410 | * A relative humidity sensor measures relative ambient air humidity and |
| 411 | * returns a value in percent. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 412 | */ |
| 413 | #define SENSOR_TYPE_RELATIVE_HUMIDITY (12) |
| 414 | |
| 415 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 416 | * SENSOR_TYPE_AMBIENT_TEMPERATURE |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 417 | * trigger-mode: on-change |
| 418 | * wake-up sensor: no |
Mathias Agopian | 54f9dd0 | 2011-03-22 18:42:03 -0700 | [diff] [blame] | 419 | * |
| 420 | * The ambient (room) temperature in degree Celsius. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 421 | */ |
| 422 | #define SENSOR_TYPE_AMBIENT_TEMPERATURE (13) |
| 423 | |
| 424 | /* |
| 425 | * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 426 | * trigger-mode: continuous |
| 427 | * wake-up sensor: no |
Mathias Agopian | 54f9dd0 | 2011-03-22 18:42:03 -0700 | [diff] [blame] | 428 | * |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 429 | * All values are in micro-Tesla (uT) and measure the ambient magnetic |
| 430 | * field in the X, Y and Z axis. |
| 431 | * |
| 432 | * No periodic calibration is performed (ie: there are no discontinuities |
| 433 | * in the data stream while using this sensor). Assumptions that the the |
| 434 | * magnetic field is due to the Earth's poles should be avoided. |
| 435 | * |
| 436 | * Factory calibration and temperature compensation should still be applied. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 437 | */ |
| 438 | #define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14) |
| 439 | |
| 440 | /* |
| 441 | * SENSOR_TYPE_GAME_ROTATION_VECTOR |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 442 | * trigger-mode: continuous |
| 443 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 444 | * |
| 445 | * SENSOR_TYPE_GAME_ROTATION_VECTOR is identical to SENSOR_TYPE_ROTATION_VECTOR, |
| 446 | * except that it doesn't use the geomagnetic field. Therefore the Y axis doesn't |
| 447 | * point north, but instead to some other reference, that reference is allowed |
| 448 | * to drift by the same order of magnitude than the gyroscope drift around |
| 449 | * the Z axis. |
| 450 | * |
| 451 | * In the ideal case, a phone rotated and returning to the same real-world |
| 452 | * orientation should report the same game rotation vector |
| 453 | * (without using the earth's geomagnetic field). |
| 454 | * |
| 455 | * see SENSOR_TYPE_ROTATION_VECTOR for more details |
| 456 | */ |
| 457 | #define SENSOR_TYPE_GAME_ROTATION_VECTOR (15) |
| 458 | |
| 459 | /* |
| 460 | * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 461 | * trigger-mode: continuous |
| 462 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 463 | * |
| 464 | * All values are in radians/second and measure the rate of rotation |
| 465 | * around the X, Y and Z axis. The coordinate system is the same as is |
| 466 | * used for the acceleration sensor. Rotation is positive in the |
| 467 | * counter-clockwise direction (right-hand rule). That is, an observer |
| 468 | * looking from some positive location on the x, y or z axis at a device |
| 469 | * positioned on the origin would report positive rotation if the device |
| 470 | * appeared to be rotating counter clockwise. Note that this is the |
| 471 | * standard mathematical definition of positive rotation and does not agree |
| 472 | * with the definition of roll given earlier. |
| 473 | * The range should at least be 17.45 rad/s (ie: ~1000 deg/s). |
| 474 | * |
| 475 | * No gyro-drift compensation shall be performed. |
| 476 | * Factory calibration and temperature compensation should still be applied. |
| 477 | */ |
| 478 | #define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16) |
| 479 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 480 | |
| 481 | /* |
| 482 | * SENSOR_TYPE_SIGNIFICANT_MOTION |
| 483 | * trigger-mode: one-shot |
| 484 | * wake-up sensor: yes |
| 485 | * |
| 486 | * A sensor of this type triggers an event each time significant motion |
| 487 | * is detected and automatically disables itself. |
| 488 | * The only allowed value to return is 1.0. |
| 489 | * |
| 490 | * |
| 491 | * TODO: give more details about what constitute significant motion |
| 492 | * and/or what algorithm is to be used |
| 493 | * |
| 494 | * |
| 495 | * IMPORTANT NOTE: this sensor type is very different from other types |
| 496 | * in that it must work when the screen is off without the need of |
| 497 | * holding a partial wake-lock and MUST allow the SoC to go into suspend. |
| 498 | * When significant motion is detected, the sensor must awaken the SoC and |
| 499 | * the event be reported. |
| 500 | * |
| 501 | * If a particular hardware cannot support this mode of operation then this |
| 502 | * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable |
| 503 | * to "emulate" this sensor in the HAL. |
| 504 | * |
| 505 | * The whole point of this sensor type is to save power by keeping the |
| 506 | * SoC in suspend mode when the device is at rest. |
| 507 | * |
| 508 | * When the sensor is not activated, it must also be deactivated in the |
| 509 | * hardware: it must not wake up the SoC anymore, even in case of |
| 510 | * significant motion. |
| 511 | * |
| 512 | * setDelay() has no effect and is ignored. |
| 513 | * Once a "significant motion" event is returned, a sensor of this type |
| 514 | * must disables itself automatically, as if activate(..., 0) had been called. |
| 515 | */ |
| 516 | |
| 517 | #define SENSOR_TYPE_SIGNIFICANT_MOTION (17) |
| 518 | |
| 519 | |
| 520 | /* |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame^] | 521 | * SENSOR_TYPE_STEP_DETECTOR |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 522 | * trigger-mode: special |
| 523 | * wake-up sensor: no |
| 524 | * |
| 525 | * A sensor of this type triggers an event each time a step is taken |
| 526 | * by the user. The only allowed value to return is 1.0 and an event is |
| 527 | * generated for each step. Like with any other event, the timestamp |
| 528 | * indicates when the event (here the step) occurred, this corresponds to when |
| 529 | * the foot hit the ground, generating a high variation in acceleration. |
| 530 | * |
| 531 | * While this sensor operates, it shall not disrupt any other sensors, in |
| 532 | * particular, but not limited to, the accelerometer; which might very well |
| 533 | * be in use as well. |
| 534 | * |
| 535 | * This sensor must be low power. That is, if the step detection cannot be |
| 536 | * done in hardware, this sensor should not be defined. Also, when the |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame^] | 537 | * step detector is activated and the accelerometer is not, only steps should |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 538 | * trigger interrupts (not accelerometer data). |
| 539 | * |
| 540 | * setDelay() has no impact on this sensor type |
| 541 | */ |
| 542 | |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame^] | 543 | #define SENSOR_TYPE_STEP_DETECTOR (18) |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 544 | |
| 545 | |
| 546 | /* |
| 547 | * SENSOR_TYPE_STEP_COUNTER |
| 548 | * trigger-mode: on-change |
| 549 | * wake-up sensor: no |
| 550 | * |
| 551 | * A sensor of this type returns the number of steps taken by the user since |
| 552 | * the last reboot. The value is returned as a uint64_t and is reset to |
| 553 | * zero only on a system reboot. |
| 554 | * |
| 555 | * The timestamp of the event is set to the time when the first step |
| 556 | * for that event was taken. |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame^] | 557 | * 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] | 558 | * |
| 559 | * The minimum size of the hardware's internal counter shall be 16 bits |
| 560 | * (this restriction is here to avoid too frequent wake-ups when the |
| 561 | * delay is very large). |
| 562 | * |
| 563 | * IMPORTANT NOTE: this sensor type is different from other types |
| 564 | * in that it must work when the screen is off without the need of |
| 565 | * holding a partial wake-lock and MUST allow the SoC to go into suspend. |
| 566 | * Unlike other sensors, while in suspend mode this sensor must stay active, |
| 567 | * no events are reported during that time but, steps continue to be |
| 568 | * accounted for; an event will be reported as soon as the SoC resumes if |
| 569 | * the timeout has expired. |
| 570 | * |
| 571 | * In other words, when the screen is off and the device allowed to |
| 572 | * go into suspend mode, we don't want to be woken up, regardless of the |
| 573 | * setDelay() value, but the steps shall continue to be counted. |
| 574 | * |
| 575 | * The driver must however ensure that the internal step count never |
| 576 | * overflows. It is allowed in this situation to wake the SoC up so the |
| 577 | * driver can do the counter maintenance. |
| 578 | * |
| 579 | * While this sensor operates, it shall not disrupt any other sensors, in |
| 580 | * particular, but not limited to, the accelerometer; which might very well |
| 581 | * be in use as well. |
| 582 | * |
| 583 | * If a particular hardware cannot support these modes of operation then this |
| 584 | * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable |
| 585 | * to "emulate" this sensor in the HAL. |
| 586 | * |
| 587 | * This sensor must be low power. That is, if the step detection cannot be |
| 588 | * done in hardware, this sensor should not be defined. Also, when the |
| 589 | * step counter is activated and the accelerometer is not, only steps should |
| 590 | * trigger interrupts (not accelerometer data). |
| 591 | * |
| 592 | * The whole point of this sensor type is to save power by keeping the |
| 593 | * SoC in suspend mode when the device is at rest. |
| 594 | */ |
| 595 | |
| 596 | #define SENSOR_TYPE_STEP_COUNTER (19) |
| 597 | |
| 598 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 599 | /** |
| 600 | * Values returned by the accelerometer in various locations in the universe. |
| 601 | * all values are in SI units (m/s^2) |
| 602 | */ |
| 603 | #define GRAVITY_SUN (275.0f) |
| 604 | #define GRAVITY_EARTH (9.80665f) |
| 605 | |
| 606 | /** Maximum magnetic field on Earth's surface */ |
| 607 | #define MAGNETIC_FIELD_EARTH_MAX (60.0f) |
| 608 | |
| 609 | /** Minimum magnetic field on Earth's surface */ |
| 610 | #define MAGNETIC_FIELD_EARTH_MIN (30.0f) |
| 611 | |
| 612 | |
| 613 | /** |
| 614 | * status of orientation sensor |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 615 | */ |
Kevin Powell | b01a043 | 2010-07-19 19:12:15 -0700 | [diff] [blame] | 616 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 617 | #define SENSOR_STATUS_UNRELIABLE 0 |
| 618 | #define SENSOR_STATUS_ACCURACY_LOW 1 |
| 619 | #define SENSOR_STATUS_ACCURACY_MEDIUM 2 |
| 620 | #define SENSOR_STATUS_ACCURACY_HIGH 3 |
| 621 | |
| 622 | |
| 623 | /** |
| 624 | * sensor event data |
| 625 | */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 626 | typedef struct { |
| 627 | union { |
| 628 | float v[3]; |
| 629 | struct { |
| 630 | float x; |
| 631 | float y; |
| 632 | float z; |
| 633 | }; |
| 634 | struct { |
| 635 | float azimuth; |
| 636 | float pitch; |
| 637 | float roll; |
| 638 | }; |
| 639 | }; |
| 640 | int8_t status; |
| 641 | uint8_t reserved[3]; |
| 642 | } sensors_vec_t; |
| 643 | |
| 644 | /** |
| 645 | * Union of the various types of sensor data |
| 646 | * that can be returned. |
| 647 | */ |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 648 | typedef struct sensors_event_t { |
| 649 | /* must be sizeof(struct sensors_event_t) */ |
| 650 | int32_t version; |
| 651 | |
| 652 | /* sensor identifier */ |
| 653 | int32_t sensor; |
| 654 | |
| 655 | /* sensor type */ |
| 656 | int32_t type; |
| 657 | |
| 658 | /* reserved */ |
| 659 | int32_t reserved0; |
| 660 | |
| 661 | /* time is in nanosecond */ |
| 662 | int64_t timestamp; |
| 663 | |
| 664 | union { |
| 665 | float data[16]; |
| 666 | |
| 667 | /* acceleration values are in meter per second per second (m/s^2) */ |
| 668 | sensors_vec_t acceleration; |
| 669 | |
| 670 | /* magnetic vector values are in micro-Tesla (uT) */ |
| 671 | sensors_vec_t magnetic; |
| 672 | |
| 673 | /* orientation values are in degrees */ |
| 674 | sensors_vec_t orientation; |
| 675 | |
Mathias Agopian | c04e5f6 | 2010-09-14 10:53:55 -0700 | [diff] [blame] | 676 | /* gyroscope values are in rad/s */ |
| 677 | sensors_vec_t gyro; |
Makarand Karvekar | 3120b58 | 2010-08-11 15:10:10 -0700 | [diff] [blame] | 678 | |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 679 | /* temperature is in degrees centigrade (Celsius) */ |
| 680 | float temperature; |
| 681 | |
| 682 | /* distance in centimeters */ |
| 683 | float distance; |
| 684 | |
| 685 | /* light in SI lux units */ |
| 686 | float light; |
Mathias Agopian | 1832f55 | 2010-07-29 15:22:30 -0700 | [diff] [blame] | 687 | |
| 688 | /* pressure in hectopascal (hPa) */ |
| 689 | float pressure; |
Urs Fleisch | d2ed15a | 2010-12-29 17:00:33 +0100 | [diff] [blame] | 690 | |
| 691 | /* relative humidity in percent */ |
| 692 | float relative_humidity; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 693 | |
| 694 | /* step-counter */ |
| 695 | uint64_t step_counter; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 696 | }; |
| 697 | uint32_t reserved1[4]; |
| 698 | } sensors_event_t; |
| 699 | |
| 700 | |
| 701 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 702 | struct sensor_t; |
| 703 | |
| 704 | /** |
| 705 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
| 706 | * and the fields of this data structure must begin with hw_module_t |
| 707 | * followed by module specific information. |
| 708 | */ |
| 709 | struct sensors_module_t { |
| 710 | struct hw_module_t common; |
| 711 | |
| 712 | /** |
| 713 | * Enumerate all available sensors. The list is returned in "list". |
| 714 | * @return number of sensors in the list |
| 715 | */ |
| 716 | int (*get_sensors_list)(struct sensors_module_t* module, |
| 717 | struct sensor_t const** list); |
| 718 | }; |
| 719 | |
| 720 | struct sensor_t { |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 721 | /* name of this sensor */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 722 | const char* name; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 723 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 724 | /* vendor of the hardware part */ |
| 725 | const char* vendor; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 726 | |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 727 | /* version of the hardware part + driver. The value of this field |
| 728 | * must increase when the driver is updated in a way that changes the |
| 729 | * output of this sensor. This is important for fused sensors when the |
| 730 | * fusion algorithm is updated. |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 731 | */ |
| 732 | int version; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 733 | |
| 734 | /* handle that identifies this sensors. This handle is used to reference |
| 735 | * this sensor throughout the HAL API. |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 736 | */ |
| 737 | int handle; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 738 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 739 | /* this sensor's type. */ |
| 740 | int type; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 741 | |
| 742 | /* 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] | 743 | float maxRange; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 744 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 745 | /* smallest difference between two values reported by this sensor */ |
| 746 | float resolution; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 747 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 748 | /* rough estimate of this sensor's power consumption in mA */ |
| 749 | float power; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 750 | |
| 751 | /* this value depends on the trigger mode: |
| 752 | * |
| 753 | * continuous: minimum sample period allowed in microseconds |
| 754 | * on-change : 0 |
| 755 | * one-shot :-1 |
| 756 | * special : 0, unless otherwise noted |
| 757 | */ |
Mathias Agopian | 1511e20 | 2010-07-29 15:33:22 -0700 | [diff] [blame] | 758 | int32_t minDelay; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 759 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 760 | /* reserved fields, must be zero */ |
Mathias Agopian | 1511e20 | 2010-07-29 15:33:22 -0700 | [diff] [blame] | 761 | void* reserved[8]; |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 762 | }; |
| 763 | |
| 764 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 765 | /* |
| 766 | * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1 |
| 767 | * and is present for backward binary and source compatibility. |
| 768 | * (see documentation of the hooks in struct sensors_poll_device_1 below) |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 769 | */ |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 770 | struct sensors_poll_device_t { |
| 771 | struct hw_device_t common; |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 772 | int (*activate)(struct sensors_poll_device_t *dev, |
| 773 | int handle, int enabled); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 774 | int (*setDelay)(struct sensors_poll_device_t *dev, |
| 775 | int handle, int64_t ns); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 776 | int (*poll)(struct sensors_poll_device_t *dev, |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 777 | sensors_event_t* data, int count); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 778 | }; |
| 779 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 780 | /* |
| 781 | * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0 |
| 782 | */ |
| 783 | typedef struct sensors_poll_device_1 { |
| 784 | union { |
| 785 | /* sensors_poll_device_1 is compatible with sensors_poll_device_t, |
| 786 | * and can be down-cast to it |
| 787 | */ |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 788 | struct sensors_poll_device_t v0; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 789 | |
| 790 | struct { |
| 791 | struct hw_device_t common; |
| 792 | |
| 793 | /* Activate/de-activate one sensor. |
| 794 | * |
| 795 | * handle is the handle of the sensor to change. |
| 796 | * enabled set to 1 to enable, or 0 to disable the sensor. |
| 797 | * |
| 798 | * unless otherwise noted in the sensor types definitions, an |
| 799 | * activated sensor never prevents the SoC to go into suspend |
| 800 | * mode; that is, the HAL shall not hold a partial wake-lock on |
| 801 | * behalf of applications. |
| 802 | * |
| 803 | * one-shot sensors de-activate themselves automatically upon |
| 804 | * receiving an event and they must still accept to be deactivated |
| 805 | * through a call to activate(..., ..., 0). |
| 806 | * |
| 807 | * if "enabled" is true and the sensor is already activated, this |
| 808 | * function is a no-op and succeeds. |
| 809 | * |
| 810 | * if "enabled" is false and the sensor is already de-activated, |
| 811 | * this function is a no-op and succeeds. |
| 812 | * |
| 813 | * return 0 on success, negative errno code otherwise |
| 814 | */ |
| 815 | int (*activate)(struct sensors_poll_device_t *dev, |
| 816 | int handle, int enabled); |
| 817 | |
| 818 | /** |
| 819 | * Set the delay between sensor events in nanoseconds for a given sensor. |
| 820 | * |
| 821 | * What the delay parameter means depends on the specified |
| 822 | * sensor's trigger mode: |
| 823 | * |
| 824 | * continuous: setDelay() sets the sampling rate. |
| 825 | * on-change: setDelay() limits the delivery rate of events |
| 826 | * one-shot: setDelay() is ignored. it has no effect. |
| 827 | * special: see specific sensor type definitions |
| 828 | * |
| 829 | * For continuous and on-change sensors, if the requested value is |
| 830 | * less than sensor_t::minDelay, then it's silently clamped to |
| 831 | * sensor_t::minDelay unless sensor_t::minDelay is 0, in which |
| 832 | * case it is clamped to >= 1ms. |
| 833 | * |
| 834 | * @return 0 if successful, < 0 on error |
| 835 | */ |
| 836 | int (*setDelay)(struct sensors_poll_device_t *dev, |
| 837 | int handle, int64_t ns); |
| 838 | |
| 839 | /** |
| 840 | * Returns an array of sensor data. |
| 841 | * This function must block until events are available. |
| 842 | * |
| 843 | * return the number of events read on success, or -errno in case |
| 844 | * of an error. |
| 845 | * |
| 846 | * The number of events returned in data must be less or equal |
| 847 | * to SENSORS_QUERY_MAX_EVENTS_BATCH_COUNT. |
| 848 | * |
| 849 | * This function shall never return 0 (no event). |
| 850 | */ |
| 851 | int (*poll)(struct sensors_poll_device_t *dev, |
| 852 | sensors_event_t* data, int count); |
| 853 | }; |
| 854 | }; |
| 855 | |
| 856 | /* |
| 857 | * Used to retrieve information about the sensor HAL |
| 858 | * |
| 859 | * Returns 0 on success or -errno on error. |
| 860 | */ |
| 861 | int (*query)(struct sensors_poll_device_1* dev, int what, int* value); |
| 862 | |
| 863 | |
| 864 | /* |
| 865 | * Enables batch mode for the given sensor. |
| 866 | * |
| 867 | * A timeout value of zero disables batch mode for the given sensor. |
| 868 | * |
| 869 | * While in batch mode sensor events are reported in batches at least |
| 870 | * every "timeout" nanosecond; that is all events since the previous batch |
| 871 | * are recorded and returned all at once. Batches can be interleaved and |
| 872 | * split, and as usual events of the same sensor type are time-ordered. |
| 873 | * |
| 874 | * setDelay() is not affected and it behaves as usual. |
| 875 | * |
| 876 | * Each event has a timestamp associated with it, the timestamp |
| 877 | * must be accurate and correspond to the time at which the event |
| 878 | * physically happened. |
| 879 | * |
| 880 | * If internal h/w FIFOs fill-up before the timeout, then events are |
| 881 | * reported at that point. No event shall be dropped or lost, |
| 882 | * |
| 883 | * By default batch mode doesn't significantly change the interaction with |
| 884 | * suspend mode, that is, sensors must continue to allow the SoC to |
| 885 | * go into suspend mode and sensors must stay active to fill their |
| 886 | * internal FIFO, in this mode, when the FIFO fills-up, it shall wrap |
| 887 | * around (basically behave like a circular buffer, overwriting events). |
| 888 | * As soon as the SoC comes out of suspend mode, a batch is produced with |
| 889 | * as much as the recent history as possible, and batch operation |
| 890 | * resumes as usual. |
| 891 | * |
| 892 | * The behavior described above allows applications to record the recent |
| 893 | * history of a set of sensor while keeping the SoC into suspend. It |
| 894 | * also allows the hardware to not have to rely on a wake-up interrupt line. |
| 895 | * |
| 896 | * There are cases however where an application cannot afford to lose |
| 897 | * any events, even when the device goes into suspend mode. The behavior |
| 898 | * specified above can be altered by setting the |
| 899 | * SENSORS_BATCH_WAKE_UPON_FIFO_FULL flag. If this flag is set, the SoC |
| 900 | * must be woken up from suspend and a batch must be returned before |
| 901 | * the FIFO fills-up. Enough head room must be allocated in the FIFO to allow |
| 902 | * the device to entirely come out of suspend (which might take a while and |
| 903 | * is device dependent) such that no event are lost. |
| 904 | * |
| 905 | * If the hardware cannot support this mode, or, if the physical |
| 906 | * FIFO is so small that the device would never be allowed to go into |
| 907 | * suspend for long enough (typically 4 to 10 seconds), then this |
| 908 | * function MUST fail when the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL |
| 909 | * is set. |
| 910 | * |
| 911 | * |
| 912 | * If the flag SENSORS_BATCH_DRY_RUN is set, this function returns |
| 913 | * without modifying the batch mode and has no side effects, but returns |
| 914 | * errors as usual (as it would if this flag was not set). This flag |
| 915 | * is used to check if batch mode is available for a given configuration. |
| 916 | * |
| 917 | * Return values: |
| 918 | * |
| 919 | * If successful, 0 is returned. |
| 920 | * If the specified sensor doesn't support batch mode, -EINVAL is returned. |
| 921 | * If the specified sensor's trigger-mode is one-shot, -EINVAL is returned. |
| 922 | * If any of the constraint above cannot be satisfied, -EINVAL is returned. |
| 923 | * |
| 924 | * If timeout is set to 0, this function must succeed. |
| 925 | * |
| 926 | * |
| 927 | * IMPLEMENTATION NOTES: |
| 928 | * |
| 929 | * batch mode, if supported, should happen at the hardware level, |
| 930 | * typically using hardware FIFOs. In particular, it SHALL NOT be |
| 931 | * implemented in the HAL, as this would be counter productive. |
| 932 | * The goal here is to save significant amounts of power. |
| 933 | * |
| 934 | * In SENSORS_BATCH_WAKE_UPON_FIFO_FULL, if the hardware has a |
| 935 | * limited FIFO size that wouldn't permit significant savings |
| 936 | * (typical on some gyroscopes), because it wouldn't allow the SoC to go |
| 937 | * into suspend mode for enough time, then it is imperative to NOT SUPPORT |
| 938 | * batch mode for that sensor. |
| 939 | * |
| 940 | * batch mode can be enabled or disabled at any time, in particular |
| 941 | * while the specified sensor is already enabled and this shall not |
| 942 | * result in the loss of events. |
| 943 | * |
| 944 | */ |
| 945 | int (*batch)(struct sensors_poll_device_1* dev, |
| 946 | int handle, int flags, int64_t timeout); |
| 947 | |
| 948 | void (*reserved_procs[8])(void); |
| 949 | |
| 950 | } sensors_poll_device_1_t; |
| 951 | |
| 952 | |
| 953 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 954 | /** convenience API for opening and closing a device */ |
| 955 | |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 956 | static inline int sensors_open(const struct hw_module_t* module, |
| 957 | struct sensors_poll_device_t** device) { |
| 958 | return module->methods->open(module, |
| 959 | SENSORS_HARDWARE_POLL, (struct hw_device_t**)device); |
| 960 | } |
| 961 | |
| 962 | static inline int sensors_close(struct sensors_poll_device_t* device) { |
| 963 | return device->common.close(&device->common); |
| 964 | } |
| 965 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 966 | static inline int sensors_open_1(const struct hw_module_t* module, |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 967 | sensors_poll_device_1_t** device) { |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 968 | return module->methods->open(module, |
| 969 | SENSORS_HARDWARE_POLL, (struct hw_device_t**)device); |
| 970 | } |
| 971 | |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 972 | static inline int sensors_close_1(sensors_poll_device_1_t* device) { |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 973 | return device->common.close(&device->common); |
| 974 | } |
| 975 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 976 | __END_DECLS |
| 977 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 978 | #endif // ANDROID_SENSORS_INTERFACE_H |