1 /* 2 * Copyright (C) 2014 Invensense, Inc. 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_H 18 #define ANDROID_SENSORS_H 19 20 #include <stdint.h> 21 #include <errno.h> 22 #include <sys/cdefs.h> 23 #include <sys/types.h> 24 25 #include <linux/input.h> 26 27 #include <hardware/hardware.h> 28 #include <hardware/sensors.h> 29 30 __BEGIN_DECLS 31 32 /*****************************************************************************/ 33 34 #ifndef ARRAY_SIZE 35 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 36 #endif 37 38 #undef ENABLE_PRESSURE 39 40 enum { 41 ID_GY = 0, 42 ID_RG, 43 ID_A, 44 ID_M, 45 ID_RM, 46 #ifdef ENABLE_PRESSURE 47 ID_PS, 48 #endif 49 ID_O, 50 ID_RV, 51 ID_GRV, 52 ID_LA, 53 ID_GR, 54 ID_SM, 55 ID_P, 56 ID_SC, 57 ID_GMRV, 58 ID_SO 59 }; 60 61 enum { 62 Gyro = 0, 63 RawGyro, 64 Accelerometer, 65 MagneticField, 66 RawMagneticField, 67 #ifdef ENABLE_PRESSURE 68 Pressure, 69 #endif 70 Orientation, 71 RotationVector, 72 GameRotationVector, 73 LinearAccel, 74 Gravity, 75 SignificantMotion, 76 StepDetector, 77 StepCounter, 78 GeomagneticRotationVector, 79 NumSensors 80 }; 81 82 #ifdef ENABLE_PRESSURE 83 #define LAST_HW_SENSOR Pressure 84 #else 85 #define LAST_HW_SENSOR RawMagneticField 86 #endif 87 88 /* Physical parameters of the sensors supported by Invensense MPL */ 89 #define SENSORS_GYROSCOPE_HANDLE (ID_GY) 90 #define SENSORS_RAW_GYROSCOPE_HANDLE (ID_RG) 91 #define SENSORS_ACCELERATION_HANDLE (ID_A) 92 #define SENSORS_MAGNETIC_FIELD_HANDLE (ID_M) 93 #define SENSORS_RAW_MAGNETIC_FIELD_HANDLE (ID_RM) 94 #define SENSORS_PRESSURE_HANDLE (ID_PS) 95 #define SENSORS_ORIENTATION_HANDLE (ID_O) 96 #define SENSORS_ROTATION_VECTOR_HANDLE (ID_RV) 97 #define SENSORS_GAME_ROTATION_VECTOR_HANDLE (ID_GRV) 98 #define SENSORS_LINEAR_ACCEL_HANDLE (ID_LA) 99 #define SENSORS_GRAVITY_HANDLE (ID_GR) 100 #define SENSORS_SIGNIFICANT_MOTION_HANDLE (ID_SM) 101 #define SENSORS_PEDOMETER_HANDLE (ID_P) 102 #define SENSORS_STEP_COUNTER_HANDLE (ID_SC) 103 #define SENSORS_GEOMAGNETIC_ROTATION_VECTOR_HANDLE (ID_GMRV) 104 #define SENSORS_SCREEN_ORIENTATION_HANDLE (ID_SO) 105 106 /*****************************************************************************/ 107 108 /* 109 Android KitKat 110 Populate sensor_t structure according to hardware sensors.h 111 { name, vendor, version, handle, type, maxRange, resolution, power, minDelay, 112 fifoReservedEventCount, fifoMaxEventCount, reserved[] } 113 */ 114 #if defined ANDROID_KITKAT 115 static struct sensor_t sBaseSensorList[] = 116 { 117 {"MPL Gyroscope", "Invensense", 1, SENSORS_GYROSCOPE_HANDLE, 118 SENSOR_TYPE_GYROSCOPE, 2000.0f, 1.0f, 0.5f, 10000, 0, 124, 119 SENSOR_STRING_TYPE_GYROSCOPE, 0, 0, SENSOR_FLAG_CONTINUOUS_MODE, {}}, 120 {"MPL Raw Gyroscope", "Invensense", 1, SENSORS_RAW_GYROSCOPE_HANDLE, 121 SENSOR_TYPE_GYROSCOPE_UNCALIBRATED, 2000.0f, 1.0f, 0.5f, 10000, 0, 124, 122 SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED, 0, 0, SENSOR_FLAG_CONTINUOUS_MODE, {}}, 123 {"MPL Accelerometer", "Invensense", 1, SENSORS_ACCELERATION_HANDLE, 124 SENSOR_TYPE_ACCELEROMETER, 10240.0f, 1.0f, 0.5f, 10000, 0, 124, 125 SENSOR_STRING_TYPE_ACCELEROMETER, 0, 0, SENSOR_FLAG_CONTINUOUS_MODE, {}}, 126 {"MPL Magnetic Field", "Invensense", 1, SENSORS_MAGNETIC_FIELD_HANDLE, 127 SENSOR_TYPE_MAGNETIC_FIELD, 10240.0f, 1.0f, 0.5f, 10000, 0, 124, 128 SENSOR_STRING_TYPE_MAGNETIC_FIELD, 0, 0, SENSOR_FLAG_CONTINUOUS_MODE, {}}, 129 {"MPL Raw Magnetic Field", "Invensense", 1, SENSORS_RAW_MAGNETIC_FIELD_HANDLE, 130 SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED, 10240.0f, 1.0f, 0.5f, 10000, 0, 124, 131 SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED, 0, 0, SENSOR_FLAG_CONTINUOUS_MODE, {}}, 132 #ifdef ENABLE_PRESSURE 133 {"MPL Pressure", "Invensense", 1, SENSORS_PRESSURE_HANDLE, 134 SENSOR_TYPE_PRESSURE, 10240.0f, 1.0f, 0.5f, 10000, 0, 165, 135 SENSOR_STRING_TYPE_PRESSURE, 0, 0, SENSOR_FLAG_CONTINUOUS_MODE, {}}, 136 #endif 137 {"MPL Orientation", "Invensense", 1, SENSORS_ORIENTATION_HANDLE, 138 SENSOR_TYPE_ORIENTATION, 360.0f, 1.0f, 9.7f, 10000, 0, 0, 139 SENSOR_STRING_TYPE_ORIENTATION, 0, 0, SENSOR_FLAG_CONTINUOUS_MODE, {}}, 140 {"MPL Rotation Vector", "Invensense", 1, SENSORS_ROTATION_VECTOR_HANDLE, 141 SENSOR_TYPE_ROTATION_VECTOR, 10240.0f, 1.0f, 0.5f, 10000, 0, 0, 142 SENSOR_STRING_TYPE_ROTATION_VECTOR, 0, 0, SENSOR_FLAG_CONTINUOUS_MODE, {}}, 143 {"MPL Game Rotation Vector", "Invensense", 1, SENSORS_GAME_ROTATION_VECTOR_HANDLE, 144 SENSOR_TYPE_GAME_ROTATION_VECTOR, 10240.0f, 1.0f, 0.5f, 10000, 0, 62, 145 SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR, 0, 0, SENSOR_FLAG_CONTINUOUS_MODE, {}}, 146 {"MPL Linear Acceleration", "Invensense", 1, SENSORS_LINEAR_ACCEL_HANDLE, 147 SENSOR_TYPE_LINEAR_ACCELERATION, 10240.0f, 1.0f, 0.5f, 10000, 0, 0, 148 SENSOR_STRING_TYPE_LINEAR_ACCELERATION, 0, 0, SENSOR_FLAG_CONTINUOUS_MODE, {}}, 149 {"MPL Gravity", "Invensense", 1, SENSORS_GRAVITY_HANDLE, 150 SENSOR_TYPE_GRAVITY, 10240.0f, 1.0f, 0.5f, 10000, 0, 0, 151 SENSOR_STRING_TYPE_GRAVITY, 0, 0, SENSOR_FLAG_CONTINUOUS_MODE, {}}, 152 {"MPL Significant Motion", "Invensense", 1, SENSORS_SIGNIFICANT_MOTION_HANDLE, 153 SENSOR_TYPE_SIGNIFICANT_MOTION, 100.0f, 1.0f, 1.1f, 0, 0, 0, 154 SENSOR_STRING_TYPE_SIGNIFICANT_MOTION, 0, 0, 155 SENSOR_FLAG_ONE_SHOT_MODE | SENSOR_FLAG_WAKE_UP, {}}, 156 {"MPL Step Detector", "Invensense", 1, SENSORS_PEDOMETER_HANDLE, 157 SENSOR_TYPE_STEP_DETECTOR, 100.0f, 1.0f, 1.1f, 0, 0, 124, 158 SENSOR_STRING_TYPE_STEP_DETECTOR, 0, 0, SENSOR_FLAG_SPECIAL_REPORTING_MODE, {}}, 159 {"MPL Step Counter", "Invensense", 1, SENSORS_STEP_COUNTER_HANDLE, 160 SENSOR_TYPE_STEP_COUNTER, 100.0f, 1.0f, 1.1f, 0, 0, 0, 161 SENSOR_STRING_TYPE_STEP_COUNTER, 0, 0, SENSOR_FLAG_ON_CHANGE_MODE, {}}, 162 {"MPL Geomagnetic Rotation Vector", "Invensense", 1, 163 SENSORS_GEOMAGNETIC_ROTATION_VECTOR_HANDLE, 164 SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR, 10240.0f, 1.0f, 0.5f, 5000, 0, 0, 165 SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR, 0, 0, SENSOR_FLAG_CONTINUOUS_MODE, {}}, 166 #ifdef ENABLE_DMP_SCREEN_AUTO_ROTATION 167 {"MPL Screen Orientation", "Invensense ", 1, SENSORS_SCREEN_ORIENTATION_HANDLE, 168 SENSOR_TYPE_SCREEN_ORIENTATION, 100.0f, 1.0f, 1.1f, 0, 0, 0, 169 SENSOR_STRING_TYPE_SCREEN_ORIENTATION, 0, 0, SENSOR_FLAG_ON_CHANGE_MODE, {}}, 170 #endif 171 }; 172 #else //ANDROID_KITKAT END 173 static struct sensor_t sBaseSensorList[] = 174 { 175 {"MPL Gyroscope", "Invensense", 1, 176 SENSORS_GYROSCOPE_HANDLE, 177 SENSOR_TYPE_GYROSCOPE, 2000.0f, 1.0f, 0.5f, 10000, {}}, 178 {"MPL Raw Gyroscope", "Invensense", 1, 179 SENSORS_RAW_GYROSCOPE_HANDLE, 180 SENSOR_TYPE_GYROSCOPE_UNCALIBRATED, 2000.0f, 1.0f, 0.5f, 10000, {}}, 181 {"MPL Accelerometer", "Invensense", 1, 182 SENSORS_ACCELERATION_HANDLE, 183 SENSOR_TYPE_ACCELEROMETER, 10240.0f, 1.0f, 0.5f, 10000, {}}, 184 {"MPL Magnetic Field", "Invensense", 1, 185 SENSORS_MAGNETIC_FIELD_HANDLE, 186 SENSOR_TYPE_MAGNETIC_FIELD, 10240.0f, 1.0f, 0.5f, 10000, {}}, 187 {"MPL Raw Magnetic Field", "Invensense", 1, 188 SENSORS_RAW_MAGNETIC_FIELD_HANDLE, 189 SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED, 10240.0f, 1.0f, 0.5f, 10000, {}}, 190 #ifdef ENABLE_PRESSURE 191 {"MPL Pressure", "Invensense", 1, 192 SENSORS_PRESSURE_HANDLE, 193 SENSOR_TYPE_PRESSURE, 10240.0f, 1.0f, 0.5f, 10000, {}}, 194 #endif 195 {"MPL Orientation", "Invensense", 1, 196 SENSORS_ORIENTATION_HANDLE, 197 SENSOR_TYPE_ORIENTATION, 360.0f, 1.0f, 9.7f, 10000, {}}, 198 {"MPL Rotation Vector", "Invensense", 1, 199 SENSORS_ROTATION_VECTOR_HANDLE, 200 SENSOR_TYPE_ROTATION_VECTOR, 10240.0f, 1.0f, 0.5f, 10000, {}}, 201 {"MPL Game Rotation Vector", "Invensense", 1, 202 SENSORS_GAME_ROTATION_VECTOR_HANDLE, 203 SENSOR_TYPE_GAME_ROTATION_VECTOR, 10240.0f, 1.0f, 0.5f, 10000, {}}, 204 {"MPL Linear Acceleration", "Invensense", 1, 205 SENSORS_LINEAR_ACCEL_HANDLE, 206 SENSOR_TYPE_LINEAR_ACCELERATION, 10240.0f, 1.0f, 0.5f, 10000, {}}, 207 {"MPL Gravity", "Invensense", 1, 208 SENSORS_GRAVITY_HANDLE, 209 SENSOR_TYPE_GRAVITY, 10240.0f, 1.0f, 0.5f, 10000, {}}, 210 {"MPL Significant Motion", "Invensense", 1, 211 SENSORS_SIGNIFICANT_MOTION_HANDLE, 212 SENSOR_TYPE_SIGNIFICANT_MOTION, 100.0f, 1.0f, 1.1f, 0, {}}, 213 {"MPL Step Detector", "Invensense", 1, 214 SENSORS_PEDOMETER_HANDLE, 215 SENSOR_TYPE_STEP_DETECTOR, 100.0f, 1.0f, 1.1f, 0, {}}, 216 {"MPL Step Counter", "Invensense", 1, 217 SENSORS_STEP_COUNTER_HANDLE, 218 SENSOR_TYPE_STEP_COUNTER, 100.0f, 1.0f, 1.1f, 0, {}}, 219 {"MPL Geomagnetic Rotation Vector", "Invensense", 1, 220 SENSORS_GEOMAGNETIC_ROTATION_VECTOR_HANDLE, 221 SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR, 10240.0f, 1.0f, 0.5f, 10000, {}}, 222 #ifdef ENABLE_DMP_SCREEN_AUTO_ROTATION 223 {"MPL Screen Orientation", "Invensense ", 1, 224 SENSORS_SCREEN_ORIENTATION_HANDLE, 225 SENSOR_TYPE_SCREEN_ORIENTATION, 100.0f, 1.0f, 1.1f, 0, {}}, 226 #endif 227 }; 228 #endif //ANDROID_JELLYBEAN END 229 230 /*****************************************************************************/ 231 232 /* 233 * The SENSORS Module 234 */ 235 236 /* ITG3500 */ 237 #define EVENT_TYPE_GYRO_X REL_X 238 #define EVENT_TYPE_GYRO_Y REL_Y 239 #define EVENT_TYPE_GYRO_Z REL_Z 240 /* MPU6050 MPU9150 */ 241 #define EVENT_TYPE_IACCEL_X REL_RX 242 #define EVENT_TYPE_IACCEL_Y REL_RY 243 #define EVENT_TYPE_IACCEL_Z REL_RZ 244 /* MPU6050 MPU9150 */ 245 #define EVENT_TYPE_ICOMPASS_X REL_X 246 #define EVENT_TYPE_ICOMPASS_Y REL_Y 247 #define EVENT_TYPE_ICOMPASS_Z REL_Z 248 /* MPUxxxx */ 249 #define EVENT_TYPE_TIMESTAMP_HI REL_MISC 250 #define EVENT_TYPE_TIMESTAMP_LO REL_WHEEL 251 252 /* Accel BMA250 */ 253 #define EVENT_TYPE_ACCEL_X ABS_X 254 #define EVENT_TYPE_ACCEL_Y ABS_Y 255 #define EVENT_TYPE_ACCEL_Z ABS_Z 256 #define LSG (1000.0f) 257 258 // conversion of acceleration data to SI units (m/s^2) 259 #define RANGE_A (4*GRAVITY_EARTH) 260 #define RESOLUTION_A (GRAVITY_EARTH / LSG) 261 #define CONVERT_A (GRAVITY_EARTH / LSG) 262 #define CONVERT_A_X (CONVERT_A) 263 #define CONVERT_A_Y (CONVERT_A) 264 #define CONVERT_A_Z (CONVERT_A) 265 266 /* AKM compasses */ 267 #define EVENT_TYPE_MAGV_X ABS_RX 268 #define EVENT_TYPE_MAGV_Y ABS_RY 269 #define EVENT_TYPE_MAGV_Z ABS_RZ 270 #define EVENT_TYPE_MAGV_STATUS ABS_RUDDER 271 272 /* conversion of magnetic data to uT units */ 273 #define CONVERT_M (0.06f) 274 275 /* conversion of sensor rates */ 276 #define hertz_request = 200; 277 #define DEFAULT_MPL_GYRO_RATE (20000L) //us 278 #define DEFAULT_MPL_COMPASS_RATE (20000L) //us 279 280 #define DEFAULT_HW_GYRO_RATE (100) //Hz 281 #define DEFAULT_HW_ACCEL_RATE (20) //ms 282 #define DEFAULT_HW_COMPASS_RATE (20000000L) //ns 283 #define DEFAULT_HW_AKMD_COMPASS_RATE (200000000L) //ns 284 285 /* convert ns to hardware units */ 286 #define HW_GYRO_RATE_NS (1000000000LL / rate_request) // to Hz 287 #define HW_ACCEL_RATE_NS (rate_request / (1000000L)) // to ms 288 #define HW_COMPASS_RATE_NS (rate_request) // to ns 289 290 /* convert Hz to hardware units */ 291 #define HW_GYRO_RATE_HZ (hertz_request) 292 #define HW_ACCEL_RATE_HZ (1000 / hertz_request) 293 #define HW_COMPASS_RATE_HZ (1000000000LL / hertz_request) 294 295 #define RATE_200HZ 5000000LL 296 #define RATE_15HZ 66667000LL 297 #define RATE_5HZ 200000000LL 298 __END_DECLS 299 300 #endif // ANDROID_SENSORS_H 301