blob: 589aba02674f4df8996c46a53546b17cf6ec9987 [file] [log] [blame]
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08001/*
Mathias Agopiana4557722012-11-28 17:21:55 -08002 * Copyright (C) 2012 The Android Open Source Project
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_SENSORS_INTERFACE_H
18#define ANDROID_SENSORS_INTERFACE_H
19
20#include <stdint.h>
21#include <sys/cdefs.h>
22#include <sys/types.h>
23
24#include <hardware/hardware.h>
Mike Lockwood21b652f2009-05-22 10:05:48 -040025#include <cutils/native_handle.h>
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080026
Andreas Huber92190172016-10-10 13:18:52 -070027#include "sensors-base.h"
28
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080029__BEGIN_DECLS
30
Mathias Agopian56f66cc2012-11-08 15:57:38 -080031/*****************************************************************************/
32
33#define SENSORS_HEADER_VERSION 1
34#define SENSORS_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
35#define SENSORS_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, SENSORS_HEADER_VERSION)
Mathias Agopiana4557722012-11-28 17:21:55 -080036#define SENSORS_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION_2(1, 0, SENSORS_HEADER_VERSION)
Mathias Agopian16671c52013-07-24 21:07:40 -070037#define SENSORS_DEVICE_API_VERSION_1_1 HARDWARE_DEVICE_API_VERSION_2(1, 1, SENSORS_HEADER_VERSION)
Aravind Akella477fbd52014-04-07 22:46:01 +000038#define SENSORS_DEVICE_API_VERSION_1_2 HARDWARE_DEVICE_API_VERSION_2(1, 2, SENSORS_HEADER_VERSION)
Aravind Akella6242f322014-02-28 18:46:19 -080039#define SENSORS_DEVICE_API_VERSION_1_3 HARDWARE_DEVICE_API_VERSION_2(1, 3, SENSORS_HEADER_VERSION)
Ashutosh Joshi6507f502015-04-03 16:22:32 -070040#define SENSORS_DEVICE_API_VERSION_1_4 HARDWARE_DEVICE_API_VERSION_2(1, 4, SENSORS_HEADER_VERSION)
Mathias Agopian56f66cc2012-11-08 15:57:38 -080041
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080042/**
Clay Murphy8db1fb42013-12-19 09:58:28 -080043 * Please see the Sensors section of source.android.com for an
44 * introduction to and detailed descriptions of Android sensor types:
45 * http://source.android.com/devices/sensors/index.html
46 */
47
48/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080049 * The id of this module
50 */
51#define SENSORS_HARDWARE_MODULE_ID "sensors"
52
53/**
54 * Name of the sensors device to open
55 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -070056#define SENSORS_HARDWARE_POLL "poll"
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080057
58/**
Peng Xuf1444352017-01-17 14:53:16 -080059 * Sensor handle is greater than 0 and less than INT32_MAX.
60 *
61 * **** Deprecated ****
62 * Defined values below are kept for code compatibility. Note sensor handle can be as large as
63 * INT32_MAX.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080064 */
65#define SENSORS_HANDLE_BASE 0
Peng Xuf1444352017-01-17 14:53:16 -080066#define SENSORS_HANDLE_BITS 31
Peng Xu95f79b12017-01-11 14:16:15 -080067#define SENSORS_HANDLE_COUNT (1ull<<SENSORS_HANDLE_BITS)
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -080068
69
Mathias Agopiana4557722012-11-28 17:21:55 -080070/*
Aravind Akella6242f322014-02-28 18:46:19 -080071 * **** Deprecated *****
Mathias Agopiana4557722012-11-28 17:21:55 -080072 * flags for (*batch)()
73 * Availability: SENSORS_DEVICE_API_VERSION_1_0
Aravind Akella6242f322014-02-28 18:46:19 -080074 * see (*batch)() documentation for details.
75 * Deprecated as of SENSORS_DEVICE_API_VERSION_1_3.
76 * WAKE_UP_* sensors replace WAKE_UPON_FIFO_FULL concept.
Mathias Agopiana4557722012-11-28 17:21:55 -080077 */
78enum {
79 SENSORS_BATCH_DRY_RUN = 0x00000001,
80 SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002
81};
82
Mathias Agopian16671c52013-07-24 21:07:40 -070083/*
84 * what field for meta_data_event_t
85 */
86enum {
87 /* a previous flush operation has completed */
Andreas Huber92190172016-10-10 13:18:52 -070088 // META_DATA_FLUSH_COMPLETE = 1,
Mathias Agopianaf32a8d2013-08-06 20:33:38 -070089 META_DATA_VERSION /* always last, leave auto-assigned */
Mathias Agopian16671c52013-07-24 21:07:40 -070090};
91
Mathias Agopiana4557722012-11-28 17:21:55 -080092/*
Aravind Akella477fbd52014-04-07 22:46:01 +000093 * The permission to use for body sensors (like heart rate monitors).
94 * See sensor types for more details on what sensors should require this
95 * permission.
96 */
97#define SENSOR_PERMISSION_BODY_SENSORS "android.permission.BODY_SENSORS"
98
99/*
Peng Xu95f79b12017-01-11 14:16:15 -0800100 * sensor flags legacy names
101 *
102 * please use SENSOR_FLAG_* directly for new implementation.
103 * @see sensor_t
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700104 */
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700105
Peng Xud1562992016-03-29 18:14:05 -0700106#define SENSOR_FLAG_MASK(nbit, shift) (((1<<(nbit))-1)<<(shift))
107#define SENSOR_FLAG_MASK_1(shift) SENSOR_FLAG_MASK(1, shift)
108
109/*
110 * Mask and shift for reporting mode sensor flags defined above.
111 */
Peng Xu95f79b12017-01-11 14:16:15 -0800112#define REPORTING_MODE_SHIFT SENSOR_FLAG_SHIFT_REPORTING_MODE
Peng Xud1562992016-03-29 18:14:05 -0700113#define REPORTING_MODE_NBIT (3)
Peng Xu95f79b12017-01-11 14:16:15 -0800114#define REPORTING_MODE_MASK SENSOR_FLAG_MASK_REPORTING_MODE
Peng Xud1562992016-03-29 18:14:05 -0700115
116/*
117 * Mask and shift for data_injection mode sensor flags defined above.
118 */
Peng Xu95f79b12017-01-11 14:16:15 -0800119#define DATA_INJECTION_SHIFT SENSOR_FLAG_SHIFT_DATA_INJECTION
120#define DATA_INJECTION_MASK SENSOR_FLAG_DATA_INJECTION
Peng Xud1562992016-03-29 18:14:05 -0700121
122/*
123 * Mask and shift for dynamic sensor flag.
124 */
Peng Xu95f79b12017-01-11 14:16:15 -0800125#define DYNAMIC_SENSOR_SHIFT SENSOR_FLAG_SHIFT_DYNAMIC_SENSOR
126#define DYNAMIC_SENSOR_MASK SENSOR_FLAG_DYNAMIC_SENSOR
Peng Xud1562992016-03-29 18:14:05 -0700127
128/*
129 * Mask and shift for sensor additional information support.
130 */
Peng Xu95f79b12017-01-11 14:16:15 -0800131#define ADDITIONAL_INFO_SHIFT SENSOR_FLAG_SHIFT_ADDITIONAL_INFO
132#define ADDITIONAL_INFO_MASK SENSOR_FLAG_ADDITIONAL_INFO
Peng Xud1562992016-03-29 18:14:05 -0700133
Peng Xu08a4dd92016-11-03 11:56:27 -0700134/*
Peng Xu95f79b12017-01-11 14:16:15 -0800135 * Legacy alias of SENSOR_TYPE_MAGNETIC_FIELD.
136 *
137 * Previously, the type of a sensor measuring local magnetic field is named
138 * SENSOR_TYPE_GEOMAGNETIC_FIELD and SENSOR_TYPE_MAGNETIC_FIELD is its alias.
139 * SENSOR_TYPE_MAGNETIC_FIELD is redefined as primary name to avoid confusion.
140 * SENSOR_TYPE_GEOMAGNETIC_FIELD is the alias and is deprecating. New implementation must not use
141 * SENSOR_TYPE_GEOMAGNETIC_FIELD.
Peng Xu08a4dd92016-11-03 11:56:27 -0700142 */
Peng Xu95f79b12017-01-11 14:16:15 -0800143#define SENSOR_TYPE_GEOMAGNETIC_FIELD SENSOR_TYPE_MAGNETIC_FIELD
Peng Xu08a4dd92016-11-03 11:56:27 -0700144
Peng Xu95f79b12017-01-11 14:16:15 -0800145/*
146 * Sensor string types for Android defined sensor types.
147 *
148 * For Android defined sensor types, string type will be override in sensor service and thus no
149 * longer needed to be added to sensor_t data structure.
150 *
151 * These definitions are going to be removed soon.
152 */
153#define SENSOR_STRING_TYPE_ACCELEROMETER "android.sensor.accelerometer"
154#define SENSOR_STRING_TYPE_MAGNETIC_FIELD "android.sensor.magnetic_field"
155#define SENSOR_STRING_TYPE_ORIENTATION "android.sensor.orientation"
156#define SENSOR_STRING_TYPE_GYROSCOPE "android.sensor.gyroscope"
157#define SENSOR_STRING_TYPE_LIGHT "android.sensor.light"
158#define SENSOR_STRING_TYPE_PRESSURE "android.sensor.pressure"
159#define SENSOR_STRING_TYPE_TEMPERATURE "android.sensor.temperature"
160#define SENSOR_STRING_TYPE_PROXIMITY "android.sensor.proximity"
161#define SENSOR_STRING_TYPE_GRAVITY "android.sensor.gravity"
162#define SENSOR_STRING_TYPE_LINEAR_ACCELERATION "android.sensor.linear_acceleration"
163#define SENSOR_STRING_TYPE_ROTATION_VECTOR "android.sensor.rotation_vector"
164#define SENSOR_STRING_TYPE_RELATIVE_HUMIDITY "android.sensor.relative_humidity"
165#define SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE "android.sensor.ambient_temperature"
166#define SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.magnetic_field_uncalibrated"
167#define SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR "android.sensor.game_rotation_vector"
168#define SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED "android.sensor.gyroscope_uncalibrated"
169#define SENSOR_STRING_TYPE_SIGNIFICANT_MOTION "android.sensor.significant_motion"
170#define SENSOR_STRING_TYPE_STEP_DETECTOR "android.sensor.step_detector"
171#define SENSOR_STRING_TYPE_STEP_COUNTER "android.sensor.step_counter"
172#define SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.geomagnetic_rotation_vector"
173#define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate"
174#define SENSOR_STRING_TYPE_TILT_DETECTOR "android.sensor.tilt_detector"
175#define SENSOR_STRING_TYPE_WAKE_GESTURE "android.sensor.wake_gesture"
176#define SENSOR_STRING_TYPE_GLANCE_GESTURE "android.sensor.glance_gesture"
177#define SENSOR_STRING_TYPE_PICK_UP_GESTURE "android.sensor.pick_up_gesture"
178#define SENSOR_STRING_TYPE_WRIST_TILT_GESTURE "android.sensor.wrist_tilt_gesture"
179#define SENSOR_STRING_TYPE_DEVICE_ORIENTATION "android.sensor.device_orientation"
180#define SENSOR_STRING_TYPE_POSE_6DOF "android.sensor.pose_6dof"
Ashutosh Joshicb963312016-01-25 18:48:57 -0800181#define SENSOR_STRING_TYPE_STATIONARY_DETECT "android.sensor.stationary_detect"
Ashutosh Joshicb963312016-01-25 18:48:57 -0800182#define SENSOR_STRING_TYPE_MOTION_DETECT "android.sensor.motion_detect"
Ashutosh Joshicb963312016-01-25 18:48:57 -0800183#define SENSOR_STRING_TYPE_HEART_BEAT "android.sensor.heart_beat"
Peng Xu95f79b12017-01-11 14:16:15 -0800184#define SENSOR_STRING_TYPE_DYNAMIC_SENSOR_META "android.sensor.dynamic_sensor_meta"
185#define SENSOR_STRING_TYPE_ADDITIONAL_INFO "android.sensor.additional_info"
Ashutosh Joshid14335b2017-04-14 08:22:38 -0700186#define SENSOR_STRING_TYPE_LOW_LATENCY_OFFBODY_DETECT "android.sensor.low_latency_offbody_detect"
Peng Xu95f79b12017-01-11 14:16:15 -0800187#define SENSOR_STRING_TYPE_ACCELEROMETER_UNCALIBRATED "android.sensor.accelerometer_uncalibrated"
Anthony Stangee2a118a2020-01-16 15:34:20 -0500188#define SENSOR_STRING_TYPE_HINGE_ANGLE "android.sensor.hinge_angle"
Brian Duddied3e67d52021-12-20 18:03:27 -0800189#define SENSOR_STRING_TYPE_HEAD_TRACKER "android.sensor.head_tracker"
Eva Chen2588d752021-04-09 15:42:31 -0700190#define SENSOR_STRING_TYPE_ACCELEROMETER_LIMITED_AXES "android.sensor.accelerometer_limited_axes"
191#define SENSOR_STRING_TYPE_GYROSCOPE_LIMITED_AXES "android.sensor.gyroscope_limited_axes"
192#define SENSOR_STRING_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED "android.sensor.accelerometer_limited_axes_uncalibrated"
193#define SENSOR_STRING_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED "android.sensor.gyroscope_limited_axes_uncalibrated"
Peng Xu0743a5c2016-01-21 17:30:02 -0800194
195/**
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800196 * Values returned by the accelerometer in various locations in the universe.
197 * all values are in SI units (m/s^2)
198 */
199#define GRAVITY_SUN (275.0f)
200#define GRAVITY_EARTH (9.80665f)
201
202/** Maximum magnetic field on Earth's surface */
203#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
204
205/** Minimum magnetic field on Earth's surface */
206#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
207
Peng Xue641ba92016-01-20 00:27:21 -0800208struct sensor_t;
209
Mathias Agopian56f66cc2012-11-08 15:57:38 -0800210/**
211 * sensor event data
212 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800213typedef struct {
214 union {
215 float v[3];
216 struct {
217 float x;
218 float y;
219 float z;
220 };
221 struct {
222 float azimuth;
223 float pitch;
224 float roll;
225 };
226 };
227 int8_t status;
228 uint8_t reserved[3];
229} sensors_vec_t;
230
231/**
Ashutosh Joshid1e25622017-01-10 18:33:53 -0800232 * uncalibrated accelerometer, gyroscope and magnetometer event data
Etienne Le Grandca858142013-02-26 19:17:20 -0800233 */
234typedef struct {
Etienne Le Grand28f04112013-03-27 18:59:10 -0700235 union {
236 float uncalib[3];
237 struct {
238 float x_uncalib;
239 float y_uncalib;
240 float z_uncalib;
241 };
242 };
243 union {
244 float bias[3];
245 struct {
246 float x_bias;
247 float y_bias;
248 float z_bias;
249 };
250 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800251} uncalibrated_event_t;
252
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700253/**
254 * Meta data event data
255 */
Mathias Agopian16671c52013-07-24 21:07:40 -0700256typedef struct meta_data_event {
257 int32_t what;
258 int32_t sensor;
259} meta_data_event_t;
260
Etienne Le Grandca858142013-02-26 19:17:20 -0800261/**
Peng Xue641ba92016-01-20 00:27:21 -0800262 * Dynamic sensor meta event. See the description of SENSOR_TYPE_DYNAMIC_SENSOR_META type for
263 * details.
264 */
265typedef struct dynamic_sensor_meta_event {
Peng Xue20707a2016-01-27 18:26:10 -0800266 int32_t connected;
267 int32_t handle;
Peng Xue641ba92016-01-20 00:27:21 -0800268 const struct sensor_t * sensor; // should be NULL if connected == false
Peng Xu69b5dba2016-04-22 22:34:51 -0700269 uint8_t uuid[16]; // UUID of a dynamic sensor (using RFC 4122 byte order)
270 // For UUID 12345678-90AB-CDEF-1122-334455667788 the uuid field
271 // should be initialized as:
272 // {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x11, ...}
Peng Xue641ba92016-01-20 00:27:21 -0800273} dynamic_sensor_meta_event_t;
274
275/**
Etienne Le Grand7b361582014-05-16 11:08:28 -0700276 * Heart rate event data
277 */
278typedef struct {
279 // Heart rate in beats per minute.
280 // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT
281 float bpm;
282 // Status of the sensor for this reading. Set to one SENSOR_STATUS_...
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700283 // Note that this value should only be set for sensors that explicitly define
284 // the meaning of this field. This field is not piped through the framework
285 // for other sensors.
Etienne Le Grand7b361582014-05-16 11:08:28 -0700286 int8_t status;
287} heart_rate_event_t;
288
Peng Xu0743a5c2016-01-21 17:30:02 -0800289typedef struct {
290 int32_t type; // type of payload data, see additional_info_type_t
291 int32_t serial; // sequence number of this frame for this type
292 union {
293 // for each frame, a single data type, either int32_t or float, should be used.
294 int32_t data_int32[14];
295 float data_float[14];
296 };
297} additional_info_event_t;
298
Brian Duddie373a1b92022-01-19 16:06:13 -0800299typedef struct {
300 float rx;
301 float ry;
302 float rz;
303 float vx;
304 float vy;
305 float vz;
306 int32_t discontinuity_count;
307} head_tracker_event_t;
308
Etienne Le Grand7b361582014-05-16 11:08:28 -0700309/**
Tyler Trephan65151452022-01-20 23:52:29 +0000310 * limited axes imu event data
311 */
312typedef struct {
313 union {
314 float calib[3];
315 struct {
316 float x;
317 float y;
318 float z;
319 };
320 };
321 union {
322 float supported[3];
323 struct {
324 float x_supported;
325 float y_supported;
326 float z_supported;
327 };
328 };
329} limited_axes_imu_event_t;
330
331/**
332 * limited axes uncalibrated imu event data
333 */
334typedef struct {
335 union {
336 float uncalib[3];
337 struct {
338 float x_uncalib;
339 float y_uncalib;
340 float z_uncalib;
341 };
342 };
343 union {
344 float bias[3];
345 struct {
346 float x_bias;
347 float y_bias;
348 float z_bias;
349 };
350 };
351 union {
352 float supported[3];
353 struct {
354 float x_supported;
355 float y_supported;
356 float z_supported;
357 };
358 };
359} limited_axes_imu_uncalibrated_event_t;
360
361/**
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800362 * Union of the various types of sensor data
363 * that can be returned.
364 */
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700365typedef struct sensors_event_t {
366 /* must be sizeof(struct sensors_event_t) */
367 int32_t version;
368
369 /* sensor identifier */
370 int32_t sensor;
371
372 /* sensor type */
373 int32_t type;
374
375 /* reserved */
376 int32_t reserved0;
377
378 /* time is in nanosecond */
379 int64_t timestamp;
380
381 union {
Mathias Agopian27e16682013-07-08 14:00:54 -0700382 union {
383 float data[16];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700384
Mathias Agopian27e16682013-07-08 14:00:54 -0700385 /* acceleration values are in meter per second per second (m/s^2) */
386 sensors_vec_t acceleration;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700387
Mathias Agopian27e16682013-07-08 14:00:54 -0700388 /* magnetic vector values are in micro-Tesla (uT) */
389 sensors_vec_t magnetic;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700390
Mathias Agopian27e16682013-07-08 14:00:54 -0700391 /* orientation values are in degrees */
392 sensors_vec_t orientation;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700393
Mathias Agopian27e16682013-07-08 14:00:54 -0700394 /* gyroscope values are in rad/s */
395 sensors_vec_t gyro;
Makarand Karvekar3120b582010-08-11 15:10:10 -0700396
Mathias Agopian27e16682013-07-08 14:00:54 -0700397 /* temperature is in degrees centigrade (Celsius) */
398 float temperature;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700399
Mathias Agopian27e16682013-07-08 14:00:54 -0700400 /* distance in centimeters */
401 float distance;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700402
Mathias Agopian27e16682013-07-08 14:00:54 -0700403 /* light in SI lux units */
404 float light;
Mathias Agopian1832f552010-07-29 15:22:30 -0700405
Mathias Agopian27e16682013-07-08 14:00:54 -0700406 /* pressure in hectopascal (hPa) */
407 float pressure;
Urs Fleischd2ed15a2010-12-29 17:00:33 +0100408
Mathias Agopian27e16682013-07-08 14:00:54 -0700409 /* relative humidity in percent */
410 float relative_humidity;
Mathias Agopiana4557722012-11-28 17:21:55 -0800411
Mathias Agopian27e16682013-07-08 14:00:54 -0700412 /* uncalibrated gyroscope values are in rad/s */
413 uncalibrated_event_t uncalibrated_gyro;
Etienne Le Grandca858142013-02-26 19:17:20 -0800414
Mathias Agopian27e16682013-07-08 14:00:54 -0700415 /* uncalibrated magnetometer values are in micro-Teslas */
416 uncalibrated_event_t uncalibrated_magnetic;
Mathias Agopian16671c52013-07-24 21:07:40 -0700417
Ashutosh Joshid1e25622017-01-10 18:33:53 -0800418 /* uncalibrated accelerometer values are in meter per second per second (m/s^2) */
419 uncalibrated_event_t uncalibrated_accelerometer;
420
Etienne Le Grand7b361582014-05-16 11:08:28 -0700421 /* heart rate data containing value in bpm and status */
422 heart_rate_event_t heart_rate;
Aravind Akella477fbd52014-04-07 22:46:01 +0000423
Mathias Agopian16671c52013-07-24 21:07:40 -0700424 /* this is a special event. see SENSOR_TYPE_META_DATA above.
425 * sensors_meta_data_event_t events are all reported with a type of
426 * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
427 */
428 meta_data_event_t meta_data;
Peng Xue641ba92016-01-20 00:27:21 -0800429
430 /* dynamic sensor meta event. See SENSOR_TYPE_DYNAMIC_SENSOR_META type for details */
431 dynamic_sensor_meta_event_t dynamic_sensor_meta;
Peng Xu0743a5c2016-01-21 17:30:02 -0800432
433 /*
434 * special additional sensor information frame, see
435 * SENSOR_TYPE_ADDITIONAL_INFO for details.
436 */
437 additional_info_event_t additional_info;
Brian Duddie373a1b92022-01-19 16:06:13 -0800438
439 /* vector describing head orientation (added for legacy code support only) */
440 head_tracker_event_t head_tracker;
Tyler Trephan65151452022-01-20 23:52:29 +0000441
442 /*
443 * limited axes imu event, See
444 * SENSOR_TYPE_GYROSCOPE_LIMITED_AXES and
445 * SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES for details.
446 */
447 limited_axes_imu_event_t limited_axes_imu;
448
449 /*
450 * limited axes imu uncalibrated event, See
451 * SENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED and
452 * SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED for details.
453 */
454 limited_axes_imu_uncalibrated_event_t limited_axes_imu_uncalibrated;
Mathias Agopian27e16682013-07-08 14:00:54 -0700455 };
Etienne Le Grandca858142013-02-26 19:17:20 -0800456
Mathias Agopian27e16682013-07-08 14:00:54 -0700457 union {
458 uint64_t data[8];
459
460 /* step-counter */
461 uint64_t step_counter;
462 } u64;
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700463 };
Aravind Akella6242f322014-02-28 18:46:19 -0800464
465 /* Reserved flags for internal use. Set to zero. */
466 uint32_t flags;
467
468 uint32_t reserved1[3];
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700469} sensors_event_t;
470
471
Mathias Agopian16671c52013-07-24 21:07:40 -0700472/* see SENSOR_TYPE_META_DATA */
473typedef sensors_event_t sensors_meta_data_event_t;
474
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700475
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800476/**
477 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
478 * and the fields of this data structure must begin with hw_module_t
479 * followed by module specific information.
480 */
481struct sensors_module_t {
482 struct hw_module_t common;
483
484 /**
485 * Enumerate all available sensors. The list is returned in "list".
Colin Cross867e1e32016-10-06 16:44:46 -0700486 * return number of sensors in the list
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800487 */
488 int (*get_sensors_list)(struct sensors_module_t* module,
489 struct sensor_t const** list);
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700490
491 /**
492 * Place the module in a specific mode. The following modes are defined
493 *
Ashutosh Joshi050f2e42015-04-15 13:56:53 -0700494 * 0 - Normal operation. Default state of the module.
Peng Xu0743a5c2016-01-21 17:30:02 -0800495 * 1 - Loopback mode. Data is injected for the supported
Ashutosh Joshi050f2e42015-04-15 13:56:53 -0700496 * sensors by the sensor service in this mode.
Colin Cross867e1e32016-10-06 16:44:46 -0700497 * return 0 on success
Ashutosh Joshi050f2e42015-04-15 13:56:53 -0700498 * -EINVAL if requested mode is not supported
Aravind Akellac7f54132015-06-22 18:26:54 -0700499 * -EPERM if operation is not allowed
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700500 */
501 int (*set_operation_mode)(unsigned int mode);
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800502};
503
504struct sensor_t {
Mathias Agopian1144bea2013-01-29 15:52:10 -0800505
506 /* Name of this sensor.
507 * All sensors of the same "type" must have a different "name".
508 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800509 const char* name;
Mathias Agopiana4557722012-11-28 17:21:55 -0800510
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800511 /* vendor of the hardware part */
512 const char* vendor;
Mathias Agopiana4557722012-11-28 17:21:55 -0800513
Mathias Agopiane9eaf372011-11-07 21:32:34 -0800514 /* version of the hardware part + driver. The value of this field
515 * must increase when the driver is updated in a way that changes the
516 * output of this sensor. This is important for fused sensors when the
517 * fusion algorithm is updated.
Aravind Akella6242f322014-02-28 18:46:19 -0800518 */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800519 int version;
Mathias Agopiana4557722012-11-28 17:21:55 -0800520
521 /* handle that identifies this sensors. This handle is used to reference
522 * this sensor throughout the HAL API.
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800523 */
524 int handle;
Mathias Agopiana4557722012-11-28 17:21:55 -0800525
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800526 /* this sensor's type. */
527 int type;
Mathias Agopiana4557722012-11-28 17:21:55 -0800528
529 /* maximum range of this sensor's value in SI units */
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800530 float maxRange;
Mathias Agopiana4557722012-11-28 17:21:55 -0800531
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800532 /* smallest difference between two values reported by this sensor */
533 float resolution;
Mathias Agopiana4557722012-11-28 17:21:55 -0800534
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800535 /* rough estimate of this sensor's power consumption in mA */
536 float power;
Mathias Agopiana4557722012-11-28 17:21:55 -0800537
Aravind Akellac841efd2014-06-03 19:21:35 -0700538 /* this value depends on the reporting mode:
Mathias Agopiana4557722012-11-28 17:21:55 -0800539 *
540 * continuous: minimum sample period allowed in microseconds
541 * on-change : 0
542 * one-shot :-1
543 * special : 0, unless otherwise noted
544 */
Mathias Agopian1511e202010-07-29 15:33:22 -0700545 int32_t minDelay;
Mathias Agopiana4557722012-11-28 17:21:55 -0800546
Mathias Agopian16671c52013-07-24 21:07:40 -0700547 /* number of events reserved for this sensor in the batch mode FIFO.
548 * If there is a dedicated FIFO for this sensor, then this is the
549 * size of this FIFO. If the FIFO is shared with other sensors,
550 * this is the size reserved for that sensor and it can be zero.
551 */
552 uint32_t fifoReservedEventCount;
553
554 /* maximum number of events of this sensor that could be batched.
555 * This is especially relevant when the FIFO is shared between
556 * several sensors; this value is then set to the size of that FIFO.
557 */
558 uint32_t fifoMaxEventCount;
559
Peng Xu95f79b12017-01-11 14:16:15 -0800560 /* type of this sensor as a string.
561 *
562 * If type is OEM specific or sensor manufacturer specific type
563 * (>=SENSOR_TYPE_DEVICE_PRIVATE_BASE), this string must be defined with reserved domain of
564 * vendor/OEM as a prefix, e.g. com.google.glass.onheaddetector
565 *
566 * For sensors of Android defined types, Android framework will override this value. It is ok to
567 * leave it pointing to an empty string.
Aravind Akella477fbd52014-04-07 22:46:01 +0000568 */
569 const char* stringType;
570
571 /* permission required to see this sensor, register to it and receive data.
572 * Set to "" if no permission is required. Some sensor types like the
573 * heart rate monitor have a mandatory require_permission.
574 * For sensors that always require a specific permission, like the heart
575 * rate monitor, the android framework might overwrite this string
576 * automatically.
577 */
578 const char* requiredPermission;
579
Aravind Akella110d2f22014-09-04 15:36:31 -0700580 /* This value is defined only for continuous mode and on-change sensors. It is the delay between
581 * two sensor events corresponding to the lowest frequency that this sensor supports. When lower
582 * frequencies are requested through batch()/setDelay() the events will be generated at this
583 * frequency instead. It can be used by the framework or applications to estimate when the batch
584 * FIFO may be full.
Aravind Akellac841efd2014-06-03 19:21:35 -0700585 *
586 * NOTE: 1) period_ns is in nanoseconds where as maxDelay/minDelay are in microseconds.
Aravind Akella110d2f22014-09-04 15:36:31 -0700587 * continuous, on-change: maximum sampling period allowed in microseconds.
588 * one-shot, special : 0
Aravind Akellac841efd2014-06-03 19:21:35 -0700589 * 2) maxDelay should always fit within a 32 bit signed integer. It is declared as 64 bit
590 * on 64 bit architectures only for binary compatibility reasons.
Aravind Akella6242f322014-02-28 18:46:19 -0800591 * Availability: SENSORS_DEVICE_API_VERSION_1_3
592 */
593 #ifdef __LP64__
594 int64_t maxDelay;
595 #else
596 int32_t maxDelay;
597 #endif
598
Aravind Akellac841efd2014-06-03 19:21:35 -0700599 /* Flags for sensor. See SENSOR_FLAG_* above. Only the least significant 32 bits are used here.
600 * It is declared as 64 bit on 64 bit architectures only for binary compatibility reasons.
601 * Availability: SENSORS_DEVICE_API_VERSION_1_3
602 */
Aravind Akella6242f322014-02-28 18:46:19 -0800603 #ifdef __LP64__
604 uint64_t flags;
605 #else
606 uint32_t flags;
607 #endif
608
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800609 /* reserved fields, must be zero */
Aravind Akella6242f322014-02-28 18:46:19 -0800610 void* reserved[2];
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800611};
612
Peng Xu08a4dd92016-11-03 11:56:27 -0700613/**
614 * Shared memory information for a direct channel
615 */
616struct sensors_direct_mem_t {
617 int type; // enum SENSOR_DIRECT_MEM_...
618 int format; // enum SENSOR_DIRECT_FMT_...
619 size_t size; // size of the memory region, in bytes
620 const struct native_handle *handle; // shared memory handle, which is interpreted differently
621 // depending on type
622};
623
624/**
625 * Direct channel report configuration
626 */
627struct sensors_direct_cfg_t {
628 int rate_level; // enum SENSOR_DIRECT_RATE_...
629};
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800630
Mathias Agopiana4557722012-11-28 17:21:55 -0800631/*
632 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
633 * and is present for backward binary and source compatibility.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800634 * See the Sensors HAL interface section for complete descriptions of the
635 * following functions:
636 * http://source.android.com/devices/sensors/index.html#hal
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800637 */
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700638struct sensors_poll_device_t {
639 struct hw_device_t common;
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700640 int (*activate)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700641 int sensor_handle, int enabled);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700642 int (*setDelay)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700643 int sensor_handle, int64_t sampling_period_ns);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700644 int (*poll)(struct sensors_poll_device_t *dev,
Mathias Agopiancdefccd2010-07-15 18:29:03 -0700645 sensors_event_t* data, int count);
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700646};
647
Mathias Agopiana4557722012-11-28 17:21:55 -0800648/*
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700649 * struct sensors_poll_device_1 is used in HAL versions >= SENSORS_DEVICE_API_VERSION_1_0
Mathias Agopiana4557722012-11-28 17:21:55 -0800650 */
651typedef struct sensors_poll_device_1 {
652 union {
653 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
654 * and can be down-cast to it
655 */
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800656 struct sensors_poll_device_t v0;
Mathias Agopiana4557722012-11-28 17:21:55 -0800657
658 struct {
659 struct hw_device_t common;
660
Peng Xuaaeeaa42016-10-05 14:56:54 -0700661 /* Activate/de-activate one sensor.
Mathias Agopiana4557722012-11-28 17:21:55 -0800662 *
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700663 * sensor_handle is the handle of the sensor to change.
Mathias Agopiana4557722012-11-28 17:21:55 -0800664 * enabled set to 1 to enable, or 0 to disable the sensor.
665 *
Aniroop Mathur443a4ac2017-07-10 22:35:47 +0530666 * Before sensor activation, existing sensor events that have not
667 * been picked up by poll() should be abandoned so that application
668 * upon new activation request will not get stale events.
669 * (events that are generated during latter activation or during
670 * data injection mode after sensor deactivation)
Peng Xuaaeeaa42016-10-05 14:56:54 -0700671 *
Clay Murphy8db1fb42013-12-19 09:58:28 -0800672 * Return 0 on success, negative errno code otherwise.
Mathias Agopiana4557722012-11-28 17:21:55 -0800673 */
674 int (*activate)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700675 int sensor_handle, int enabled);
Mathias Agopiana4557722012-11-28 17:21:55 -0800676
677 /**
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700678 * Set the events's period in nanoseconds for a given sensor.
679 * If sampling_period_ns > max_delay it will be truncated to
680 * max_delay and if sampling_period_ns < min_delay it will be
681 * replaced by min_delay.
Mathias Agopiana4557722012-11-28 17:21:55 -0800682 */
683 int (*setDelay)(struct sensors_poll_device_t *dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700684 int sensor_handle, int64_t sampling_period_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -0800685
686 /**
Peng Xu355e3f62016-07-19 15:11:53 -0700687 * Write an array of sensor_event_t to data. The size of the
688 * available buffer is specified by count. Returns number of
689 * valid sensor_event_t.
690 *
691 * This function should block if there is no sensor event
692 * available when being called. Thus, return value should always be
693 * positive.
Mathias Agopiana4557722012-11-28 17:21:55 -0800694 */
695 int (*poll)(struct sensors_poll_device_t *dev,
696 sensors_event_t* data, int count);
697 };
698 };
699
Mathias Agopiana4557722012-11-28 17:21:55 -0800700
701 /*
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700702 * Sets a sensor’s parameters, including sampling frequency and maximum
703 * report latency. This function can be called while the sensor is
704 * activated, in which case it must not cause any sensor measurements to
705 * be lost: transitioning from one sampling rate to the other cannot cause
706 * lost events, nor can transitioning from a high maximum report latency to
707 * a low maximum report latency.
Clay Murphy8db1fb42013-12-19 09:58:28 -0800708 * See the Batching sensor results page for details:
709 * http://source.android.com/devices/sensors/batching.html
Mathias Agopiana4557722012-11-28 17:21:55 -0800710 */
711 int (*batch)(struct sensors_poll_device_1* dev,
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700712 int sensor_handle, int flags, int64_t sampling_period_ns,
713 int64_t max_report_latency_ns);
Mathias Agopiana4557722012-11-28 17:21:55 -0800714
Mathias Agopian16671c52013-07-24 21:07:40 -0700715 /*
716 * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
717 * to the end of the "batch mode" FIFO for the specified sensor and flushes
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700718 * the FIFO.
719 * If the FIFO is empty or if the sensor doesn't support batching (FIFO size zero),
Aravind Akellac841efd2014-06-03 19:21:35 -0700720 * it should return SUCCESS along with a trivial META_DATA_FLUSH_COMPLETE event added to the
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700721 * event stream. This applies to all sensors other than one-shot sensors.
722 * If the sensor is a one-shot sensor, flush must return -EINVAL and not generate
723 * any flush complete metadata.
Aravind Akellaa7f2cda2014-08-21 16:31:14 -0700724 * If the sensor is not active at the time flush() is called, flush() should return
725 * -EINVAL.
Mathias Agopian16671c52013-07-24 21:07:40 -0700726 */
Etienne Le Grand772d85a2014-08-19 14:30:19 -0700727 int (*flush)(struct sensors_poll_device_1* dev, int sensor_handle);
Mathias Agopian16671c52013-07-24 21:07:40 -0700728
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700729 /*
Ashutosh Joshi050f2e42015-04-15 13:56:53 -0700730 * Inject a single sensor sample to be to this device.
731 * data points to the sensor event to be injected
Colin Cross867e1e32016-10-06 16:44:46 -0700732 * return 0 on success
Aravind Akellac7f54132015-06-22 18:26:54 -0700733 * -EPERM if operation is not allowed
Ashutosh Joshi050f2e42015-04-15 13:56:53 -0700734 * -EINVAL if sensor event cannot be injected
Ashutosh Joshi6507f502015-04-03 16:22:32 -0700735 */
736 int (*inject_sensor_data)(struct sensors_poll_device_1 *dev, const sensors_event_t *data);
737
Peng Xu08a4dd92016-11-03 11:56:27 -0700738 /*
739 * Register/unregister direct report channel.
740 *
741 * A HAL declares support for direct report by setting non-NULL values for both
742 * register_direct_channel and config_direct_report.
743 *
744 * This function has two operation modes:
745 *
746 * Register: mem != NULL, register a channel using supplied shared memory information. By the
747 * time this function returns, sensors must finish initializing shared memory content
748 * (format dependent, see SENSOR_DIRECT_FMT_*).
749 * Parameters:
750 * mem points to a valid struct sensors_direct_mem_t.
751 * channel_handle is ignored.
752 * Return value:
Peng Xuf1444352017-01-17 14:53:16 -0800753 * A handle of channel (>0, <INT32_MAX) when success, which later can be referred in
754 * unregister or config_direct_report call, or error code (<0) when failed
Peng Xu08a4dd92016-11-03 11:56:27 -0700755 * Unregister: mem == NULL, unregister a previously registered channel.
756 * Parameters:
757 * mem set to NULL
758 * channel_handle contains handle of channel to be unregistered
759 * Return value:
760 * 0, even if the channel_handle is invalid, in which case it will be a no-op.
761 */
762 int (*register_direct_channel)(struct sensors_poll_device_1 *dev,
763 const struct sensors_direct_mem_t* mem, int channel_handle);
764
765 /*
766 * Configure direct sensor event report in direct channel.
767 *
768 * Start, modify rate or stop direct report of a sensor in a certain direct channel. A special
769 * case is setting sensor handle -1 to stop means to stop all active sensor report on the
770 * channel specified.
771 *
772 * A HAL declares support for direct report by setting non-NULL values for both
773 * register_direct_channel and config_direct_report.
774 *
775 * Parameters:
776 * sensor_handle sensor to be configured. The sensor has to support direct report
777 * mode by setting flags of sensor_t. Also, direct report mode is only
778 * defined for continuous reporting mode sensors.
779 * channel_handle channel handle to be configured.
780 * config direct report parameters, see sensor_direct_cfg_t.
781 * Return value:
782 * - when sensor is started or sensor rate level is changed: return positive identifier of
783 * sensor in specified channel if successful, otherwise return negative error code.
784 * - when sensor is stopped: return 0 for success or negative error code for failure.
785 */
786 int (*config_direct_report)(struct sensors_poll_device_1 *dev,
787 int sensor_handle, int channel_handle, const struct sensors_direct_cfg_t *config);
788
789 /*
Peng Xubed42d42017-04-06 17:52:29 -0700790 * Reserved for future use, must be zero.
Peng Xu08a4dd92016-11-03 11:56:27 -0700791 */
792 void (*reserved_procs[5])(void);
Mathias Agopiana4557722012-11-28 17:21:55 -0800793
794} sensors_poll_device_1_t;
795
796
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800797/** convenience API for opening and closing a device */
798
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700799static inline int sensors_open(const struct hw_module_t* module,
800 struct sensors_poll_device_t** device) {
801 return module->methods->open(module,
Colin Crosscc8d9f92016-10-06 16:44:23 -0700802 SENSORS_HARDWARE_POLL, TO_HW_DEVICE_T_OPEN(device));
Mathias Agopianb1e212e2010-07-08 16:44:54 -0700803}
804
805static inline int sensors_close(struct sensors_poll_device_t* device) {
806 return device->common.close(&device->common);
807}
808
Mathias Agopiana4557722012-11-28 17:21:55 -0800809static inline int sensors_open_1(const struct hw_module_t* module,
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800810 sensors_poll_device_1_t** device) {
Mathias Agopiana4557722012-11-28 17:21:55 -0800811 return module->methods->open(module,
Colin Crosscc8d9f92016-10-06 16:44:23 -0700812 SENSORS_HARDWARE_POLL, TO_HW_DEVICE_T_OPEN(device));
Mathias Agopiana4557722012-11-28 17:21:55 -0800813}
814
Andrew Hsieh1082c0b2012-12-11 20:51:41 -0800815static inline int sensors_close_1(sensors_poll_device_1_t* device) {
Mathias Agopiana4557722012-11-28 17:21:55 -0800816 return device->common.close(&device->common);
817}
818
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800819__END_DECLS
820
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800821#endif // ANDROID_SENSORS_INTERFACE_H