1 /* 2 * Copyright (C) 2016 The Android Open Source Project 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 #include "sensorlist.h" 18 19 #include <math.h> 20 21 #include "hubdefs.h" 22 23 using namespace android; 24 25 const int kVersion = 1; 26 27 const float kMinSampleRateHzAccel = 6.250f; 28 const float kMaxSampleRateHzAccel = 400.0f; 29 const float kAccelRangeG = 8.0f; 30 extern const float kScaleAccel = (kAccelRangeG * 9.81f / 32768.0f); 31 32 const float kMinSampleRateHzGyro = 6.250f; 33 const float kMaxSampleRateHzGyro = 400.0f; 34 35 const float kMinSampleRateHzMag = 3.125f; 36 const float kMaxSampleRateHzMag = 50.0f; 37 extern const float kScaleMag = 0.15f; 38 39 const float kMinSampleRateHzPolling = 0.1f; 40 const float kMaxSampleRateHzPolling = 25.0f; 41 42 const float kMinSampleRateHzPressure = 0.1f; 43 const float kMaxSampleRateHzPressure = 10.0f; 44 45 const float kMinSampleRateHzTemperature = kMinSampleRateHzPolling; 46 const float kMaxSampleRateHzTemperature = kMaxSampleRateHzPolling; 47 48 const float kMinSampleRateHzHumidity = kMinSampleRateHzPolling; 49 const float kMaxSampleRateHzHumidity = kMaxSampleRateHzPolling; 50 51 const float kMinSampleRateHzProximity = kMinSampleRateHzPolling; 52 const float kMaxSampleRateHzProximity = 5.0; 53 54 const float kMinSampleRateHzLight = kMinSampleRateHzPolling; 55 const float kMaxSampleRateHzLight = 5.0; 56 57 const float kMinSampleRateHzOrientation = 12.5f; 58 const float kMaxSampleRateHzOrientation = 200.0f; 59 60 #define MINDELAY(x) ((int32_t)ceil(1.0E6f/(x))) 61 62 #ifdef DIRECT_REPORT_ENABLED 63 constexpr uint32_t kDirectReportFlagAccel = ( 64 // support up to rate level fast (nominal 200Hz); 65 (SENSOR_DIRECT_RATE_FAST << SENSOR_FLAG_SHIFT_DIRECT_REPORT) 66 // support ashmem and gralloc direct channel 67 | SENSOR_FLAG_DIRECT_CHANNEL_ASHMEM 68 | SENSOR_FLAG_DIRECT_CHANNEL_GRALLOC); 69 constexpr uint32_t kDirectReportFlagGyro = ( 70 // support up to rate level fast (nominal 200Hz); 71 (SENSOR_DIRECT_RATE_FAST << SENSOR_FLAG_SHIFT_DIRECT_REPORT) 72 // support ashmem and gralloc direct channel 73 | SENSOR_FLAG_DIRECT_CHANNEL_ASHMEM 74 | SENSOR_FLAG_DIRECT_CHANNEL_GRALLOC); 75 constexpr uint32_t kDirectReportFlagMag = ( 76 // support up to rate level normal (nominal 50Hz); 77 (SENSOR_DIRECT_RATE_NORMAL << SENSOR_FLAG_SHIFT_DIRECT_REPORT) 78 // support ashmem and gralloc direct channel 79 | SENSOR_FLAG_DIRECT_CHANNEL_ASHMEM 80 | SENSOR_FLAG_DIRECT_CHANNEL_GRALLOC); 81 #else 82 constexpr uint32_t kDirectReportFlagAccel = 0; 83 constexpr uint32_t kDirectReportFlagGyro = 0; 84 constexpr uint32_t kDirectReportFlagMag = 0; 85 #endif 86 87 /* 88 * The following max count is determined by the total number of blocks 89 * avaliable in the shared nanohub buffer and number of samples each type of 90 * event can hold within a buffer block. 91 * For neonkey's case, there are 227 blocks in the shared sensor buffer and 92 * each block can hold 30 OneAxis Samples, 15 ThreeAxis Samples or 24 93 * RawThreeAxis Samples. 94 */ 95 const int kMaxOneAxisEventCount = 227*30; 96 const int kMaxThreeAxisEventCount = 227*15; 97 const int kMaxRawThreeAxisEventCount = 227*24; 98 99 const int kMinFifoReservedEventCount = 20; 100 101 const char SENSOR_STRING_TYPE_INTERNAL_TEMPERATURE[] = 102 "com.google.sensor.internal_temperature"; 103 const char SENSOR_STRING_TYPE_DOUBLE_TAP[] = 104 "com.google.sensor.double_tap"; 105 106 extern const sensor_t kSensorList[] = { 107 { 108 "RPR0521 Proximity Sensor", 109 "Rohm", 110 kVersion, 111 COMMS_SENSOR_PROXIMITY, 112 SENSOR_TYPE_PROXIMITY, 113 5.0f, // maxRange (cm) 114 1.0f, // resolution (cm) 115 0.0f, // XXX power 116 MINDELAY(kMaxSampleRateHzProximity), // minDelay 117 300, // XXX fifoReservedEventCount 118 kMaxOneAxisEventCount, // XXX fifoMaxEventCount 119 SENSOR_STRING_TYPE_PROXIMITY, 120 "", // requiredPermission 121 (long)(1.0E6f / kMinSampleRateHzProximity), // maxDelay 122 SENSOR_FLAG_WAKE_UP | SENSOR_FLAG_ON_CHANGE_MODE, 123 { NULL, NULL } 124 }, 125 { 126 "RPR0521 Light Sensor", 127 "Rohm", 128 kVersion, 129 COMMS_SENSOR_LIGHT, 130 SENSOR_TYPE_LIGHT, 131 43000.0f, // maxRange (lx) 132 10.0f, // XXX resolution (lx) 133 0.0f, // XXX power 134 MINDELAY(kMaxSampleRateHzLight), // minDelay 135 kMinFifoReservedEventCount, // XXX fifoReservedEventCount 136 kMaxOneAxisEventCount, // XXX fifoMaxEventCount 137 SENSOR_STRING_TYPE_LIGHT, 138 "", // requiredPermission 139 (long)(1.0E6f / kMinSampleRateHzLight), // maxDelay 140 SENSOR_FLAG_ON_CHANGE_MODE, 141 { NULL, NULL } 142 }, 143 { 144 "BMI160 accelerometer", 145 "Bosch", 146 kVersion, 147 COMMS_SENSOR_ACCEL, 148 SENSOR_TYPE_ACCELEROMETER, 149 GRAVITY_EARTH * kAccelRangeG, // maxRange 150 kScaleAccel, // resolution 151 0.0f, // XXX power 152 MINDELAY(kMaxSampleRateHzAccel), // minDelay 153 3000, // XXX fifoReservedEventCount 154 kMaxRawThreeAxisEventCount, // XXX fifoMaxEventCount 155 SENSOR_STRING_TYPE_ACCELEROMETER, 156 "", // requiredPermission 157 (long)(1.0E6f / kMinSampleRateHzAccel), // maxDelay 158 SENSOR_FLAG_CONTINUOUS_MODE | kDirectReportFlagAccel, 159 { NULL, NULL } 160 }, 161 { 162 "BMI160 accelerometer (uncalibrated)", 163 "Bosch", 164 kVersion, 165 COMMS_SENSOR_ACCEL_UNCALIBRATED, 166 SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED, 167 GRAVITY_EARTH * kAccelRangeG, // maxRange 168 kScaleAccel, // resolution 169 0.0f, // XXX power 170 MINDELAY(kMaxSampleRateHzAccel), // minDelay 171 3000, // XXX fifoReservedEventCount 172 kMaxRawThreeAxisEventCount, // XXX fifoMaxEventCount 173 SENSOR_STRING_TYPE_ACCELEROMETER_UNCALIBRATED, 174 "", // requiredPermission 175 (long)(1.0E6f / kMinSampleRateHzAccel), // maxDelay 176 SENSOR_FLAG_CONTINUOUS_MODE | kDirectReportFlagAccel, 177 { NULL, NULL } 178 }, 179 { 180 "BMI160 gyroscope", 181 "Bosch", 182 kVersion, 183 COMMS_SENSOR_GYRO, 184 SENSOR_TYPE_GYROSCOPE, 185 1000.0f * M_PI / 180.0f, // maxRange 186 1000.0f * M_PI / (180.0f * 32768.0f), // resolution 187 0.0f, // XXX power 188 MINDELAY(kMaxSampleRateHzGyro), // minDelay 189 kMinFifoReservedEventCount, // XXX fifoReservedEventCount 190 kMaxThreeAxisEventCount, // XXX fifoMaxEventCount 191 SENSOR_STRING_TYPE_GYROSCOPE, 192 "", // requiredPermission 193 (long)(1.0E6f / kMinSampleRateHzGyro), // maxDelay 194 SENSOR_FLAG_CONTINUOUS_MODE | kDirectReportFlagGyro, 195 { NULL, NULL } 196 }, 197 { 198 "BMI160 gyroscope (uncalibrated)", 199 "Bosch", 200 kVersion, 201 COMMS_SENSOR_GYRO_UNCALIBRATED, 202 SENSOR_TYPE_GYROSCOPE_UNCALIBRATED, 203 1000.0f * M_PI / 180.0f, // maxRange 204 1000.0f * M_PI / (180.0f * 32768.0f), // resolution 205 0.0f, // XXX power 206 MINDELAY(kMaxSampleRateHzGyro), // minDelay 207 kMinFifoReservedEventCount, // XXX fifoReservedEventCount 208 kMaxThreeAxisEventCount, // XXX fifoMaxEventCount 209 SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED, 210 "", // requiredPermission 211 (long)(1.0E6f / kMinSampleRateHzGyro), // maxDelay 212 SENSOR_FLAG_CONTINUOUS_MODE | kDirectReportFlagGyro, 213 { NULL, NULL } 214 }, 215 { 216 "BMM150 magnetometer", 217 "Bosch", 218 kVersion, 219 COMMS_SENSOR_MAG, 220 SENSOR_TYPE_MAGNETIC_FIELD, 221 1300.0f, // XXX maxRange 222 kScaleMag, // XXX resolution 223 0.0f, // XXX power 224 MINDELAY(kMaxSampleRateHzMag), // minDelay 225 600, // XXX fifoReservedEventCount 226 kMaxThreeAxisEventCount, // XXX fifoMaxEventCount 227 SENSOR_STRING_TYPE_MAGNETIC_FIELD, 228 "", // requiredPermission 229 (long)(1.0E6f / kMinSampleRateHzMag), // maxDelay 230 SENSOR_FLAG_CONTINUOUS_MODE | kDirectReportFlagMag, 231 { NULL, NULL } 232 }, 233 { 234 "BMM150 magnetometer (uncalibrated)", 235 "Bosch", 236 kVersion, 237 COMMS_SENSOR_MAG_UNCALIBRATED, 238 SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED, 239 1300.0f, // XXX maxRange 240 kScaleMag, // XXX resolution 241 0.0f, // XXX power 242 MINDELAY(kMaxSampleRateHzMag), // minDelay 243 600, // XXX fifoReservedEventCount 244 kMaxThreeAxisEventCount, // XXX fifoMaxEventCount 245 SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED, 246 "", // requiredPermission 247 (long)(1.0E6f / kMinSampleRateHzMag), // maxDelay 248 SENSOR_FLAG_CONTINUOUS_MODE | kDirectReportFlagMag, 249 { NULL, NULL } 250 }, 251 { 252 "BMP280 pressure", 253 "Bosch", 254 kVersion, 255 COMMS_SENSOR_PRESSURE, 256 SENSOR_TYPE_PRESSURE, 257 1100.0f, // maxRange (hPa) 258 0.005f, // resolution (hPa) 259 0.0f, // XXX power 260 MINDELAY(kMaxSampleRateHzPressure), // minDelay 261 300, // XXX fifoReservedEventCount 262 kMaxOneAxisEventCount, // XXX fifoMaxEventCount 263 SENSOR_STRING_TYPE_PRESSURE, 264 "", // requiredPermission 265 (long)(1.0E6f / kMinSampleRateHzPressure), // maxDelay 266 SENSOR_FLAG_CONTINUOUS_MODE, 267 { NULL, NULL } 268 }, 269 { 270 "BMP280 temperature", 271 "Bosch", 272 kVersion, 273 COMMS_SENSOR_TEMPERATURE, 274 SENSOR_TYPE_INTERNAL_TEMPERATURE, 275 85.0f, // maxRange (degC) 276 0.01, // resolution (degC) 277 0.0f, // XXX power 278 MINDELAY(kMaxSampleRateHzTemperature), // minDelay 279 kMinFifoReservedEventCount, // XXX fifoReservedEventCount 280 kMaxOneAxisEventCount, // XXX fifoMaxEventCount 281 SENSOR_STRING_TYPE_INTERNAL_TEMPERATURE, 282 "", // requiredPermission 283 (long)(1.0E6f / kMinSampleRateHzTemperature), // maxDelay 284 SENSOR_FLAG_CONTINUOUS_MODE, 285 { NULL, NULL } 286 }, 287 { 288 "SI7034-A10 humidity", 289 "Silicon Labs", 290 kVersion, 291 COMMS_SENSOR_HUMIDITY, 292 SENSOR_TYPE_RELATIVE_HUMIDITY, 293 100.0f, // maxRange (%) 294 0.001f, // resolution (%) 295 0.0f, // XXX power 296 MINDELAY(kMaxSampleRateHzHumidity), // minDelay 297 300, // XXX fifoReservedEventCount 298 kMaxOneAxisEventCount, // XXX fifoMaxEventCount 299 SENSOR_STRING_TYPE_RELATIVE_HUMIDITY, 300 "", // requiredPermission 301 (long)(1.0E6f / kMinSampleRateHzHumidity), // maxDelay 302 SENSOR_FLAG_CONTINUOUS_MODE, 303 { NULL, NULL } 304 }, 305 { 306 "SI7034-A10 ambient temperature", 307 "Silicon Labs", 308 kVersion, 309 COMMS_SENSOR_AMBIENT_TEMPERATURE, 310 SENSOR_TYPE_AMBIENT_TEMPERATURE, 311 125.0f, // maxRange (degC) 312 0.001f, // resolution (degC) 313 0.0f, // XXX power 314 MINDELAY(kMaxSampleRateHzTemperature), // minDelay 315 kMinFifoReservedEventCount, // XXX fifoReservedEventCount 316 kMaxOneAxisEventCount, // XXX fifoMaxEventCount 317 SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE, 318 "", // requiredPermission 319 (long)(1.0E6f / kMinSampleRateHzTemperature), // maxDelay 320 SENSOR_FLAG_CONTINUOUS_MODE, 321 { NULL, NULL } 322 }, 323 { 324 "Orientation", 325 "Google", 326 kVersion, 327 COMMS_SENSOR_ORIENTATION, 328 SENSOR_TYPE_ORIENTATION, 329 360.0f, // maxRange (deg) 330 1.0f, // XXX resolution (deg) 331 0.0f, // XXX power 332 MINDELAY(kMaxSampleRateHzOrientation), // minDelay 333 kMinFifoReservedEventCount, // XXX fifoReservedEventCount 334 kMaxThreeAxisEventCount, // XXX fifoMaxEventCount 335 SENSOR_STRING_TYPE_ORIENTATION, 336 "", // requiredPermission 337 (long)(1.0E6f / kMinSampleRateHzOrientation), // maxDelay 338 SENSOR_FLAG_CONTINUOUS_MODE, 339 { NULL, NULL } 340 }, 341 { 342 "BMI160 Step detector", 343 "Bosch", 344 kVersion, 345 COMMS_SENSOR_STEP_DETECTOR, 346 SENSOR_TYPE_STEP_DETECTOR, 347 1.0f, // maxRange 348 1.0f, // XXX resolution 349 0.0f, // XXX power 350 0, // minDelay 351 100, // XXX fifoReservedEventCount 352 kMaxOneAxisEventCount, // XXX fifoMaxEventCount 353 SENSOR_STRING_TYPE_STEP_DETECTOR, 354 "", // requiredPermission 355 0, // maxDelay 356 SENSOR_FLAG_SPECIAL_REPORTING_MODE, 357 { NULL, NULL } 358 }, 359 { 360 "BMI160 Step counter", 361 "Bosch", 362 kVersion, 363 COMMS_SENSOR_STEP_COUNTER, 364 SENSOR_TYPE_STEP_COUNTER, 365 1.0f, // XXX maxRange 366 1.0f, // resolution 367 0.0f, // XXX power 368 0, // minDelay 369 kMinFifoReservedEventCount, // XXX fifoReservedEventCount 370 kMaxOneAxisEventCount, // XXX fifoMaxEventCount 371 SENSOR_STRING_TYPE_STEP_COUNTER, 372 "", // requiredPermission 373 0, // maxDelay 374 SENSOR_FLAG_ON_CHANGE_MODE, 375 { NULL, NULL } 376 }, 377 { 378 "Gravity", 379 "Google", 380 kVersion, 381 COMMS_SENSOR_GRAVITY, 382 SENSOR_TYPE_GRAVITY, 383 1000.0f, // maxRange 384 1.0f, // XXX resolution 385 0.0f, // XXX power 386 MINDELAY(kMaxSampleRateHzOrientation), // minDelay 387 kMinFifoReservedEventCount, // XXX fifoReservedEventCount 388 kMaxThreeAxisEventCount, // XXX fifoMaxEventCount 389 SENSOR_STRING_TYPE_GRAVITY, 390 "", // requiredPermission 391 (long)(1.0E6f / kMinSampleRateHzOrientation), // maxDelay 392 SENSOR_FLAG_CONTINUOUS_MODE, 393 { NULL, NULL } 394 }, 395 { 396 "Linear Acceleration", 397 "Google", 398 kVersion, 399 COMMS_SENSOR_LINEAR_ACCEL, 400 SENSOR_TYPE_LINEAR_ACCELERATION, 401 1000.0f, // maxRange 402 1.0f, // XXX resolution 403 0.0f, // XXX power 404 MINDELAY(kMaxSampleRateHzOrientation), // minDelay 405 kMinFifoReservedEventCount, // XXX fifoReservedEventCount 406 kMaxThreeAxisEventCount, // XXX fifoMaxEventCount 407 SENSOR_STRING_TYPE_LINEAR_ACCELERATION, 408 "", // requiredPermission 409 (long)(1.0E6f / kMinSampleRateHzOrientation), // maxDelay 410 SENSOR_FLAG_CONTINUOUS_MODE, 411 { NULL, NULL } 412 }, 413 { 414 "Rotation Vector", 415 "Google", 416 kVersion, 417 COMMS_SENSOR_ROTATION_VECTOR, 418 SENSOR_TYPE_ROTATION_VECTOR, 419 1.0f, // maxRange 420 0.001f, // XXX resolution 421 0.0f, // XXX power 422 MINDELAY(kMaxSampleRateHzOrientation), // minDelay 423 kMinFifoReservedEventCount, // XXX fifoReservedEventCount 424 kMaxThreeAxisEventCount, // XXX fifoMaxEventCount 425 SENSOR_STRING_TYPE_ROTATION_VECTOR, 426 "", // requiredPermission 427 (long)(1.0E6f / kMinSampleRateHzOrientation), // maxDelay 428 SENSOR_FLAG_CONTINUOUS_MODE, 429 { NULL, NULL } 430 }, 431 { 432 "Geomagnetic Rotation Vector", 433 "Google", 434 kVersion, 435 COMMS_SENSOR_GEO_MAG, 436 SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR, 437 1.0f, // maxRange 438 0.001, // XXX resolution 439 0.0f, // XXX power 440 MINDELAY(kMaxSampleRateHzOrientation), // minDelay 441 kMinFifoReservedEventCount, // XXX fifoReservedEventCount 442 kMaxThreeAxisEventCount, // XXX fifoMaxEventCount 443 SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR, 444 "", // requiredPermission 445 (long)(1.0E6f / kMinSampleRateHzOrientation), // maxDelay 446 SENSOR_FLAG_CONTINUOUS_MODE, 447 { NULL, NULL } 448 }, 449 { 450 "Game Rotation Vector", 451 "Google", 452 kVersion, 453 COMMS_SENSOR_GAME_ROTATION_VECTOR, 454 SENSOR_TYPE_GAME_ROTATION_VECTOR, 455 1.0f, // maxRange 456 0.001f, // XXX resolution 457 0.0f, // XXX power 458 MINDELAY(kMaxSampleRateHzOrientation), // minDelay 459 300, // XXX fifoReservedEventCount 460 kMaxThreeAxisEventCount, // XXX fifoMaxEventCount 461 SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR, 462 "", // requiredPermission 463 (long)(1.0E6f / kMinSampleRateHzOrientation), // maxDelay 464 SENSOR_FLAG_CONTINUOUS_MODE, 465 { NULL, NULL } 466 }, 467 { 468 "Tilt Detector", 469 "Google", 470 kVersion, 471 COMMS_SENSOR_TILT, 472 SENSOR_TYPE_TILT_DETECTOR, 473 1.0f, // maxRange 474 1.0f, // XXX resolution 475 0.0f, // XXX power 476 0, // minDelay 477 kMinFifoReservedEventCount, // XXX fifoReservedEventCount 478 kMaxOneAxisEventCount, // XXX fifoMaxEventCount 479 SENSOR_STRING_TYPE_TILT_DETECTOR, 480 "", // requiredPermission 481 0, // maxDelay 482 SENSOR_FLAG_WAKE_UP | SENSOR_FLAG_SPECIAL_REPORTING_MODE, 483 { NULL, NULL } 484 }, 485 { 486 "Double Tap", 487 "Google", 488 kVersion, 489 COMMS_SENSOR_DOUBLE_TAP, 490 SENSOR_TYPE_DOUBLE_TAP, 491 1.0f, // maxRange 492 1.0f, // XXX resolution 493 0.1f, // XXX power 494 0, // minDelay 495 kMinFifoReservedEventCount, // XXX fifoReservedEventCount 496 kMaxOneAxisEventCount, // XXX fifoMaxEventCount 497 SENSOR_STRING_TYPE_DOUBLE_TAP, 498 "", // requiredPermission 499 0, // maxDelay 500 SENSOR_FLAG_SPECIAL_REPORTING_MODE, 501 { NULL, NULL } 502 }, 503 { 504 "Device Orientation", 505 "Google", 506 kVersion, 507 COMMS_SENSOR_WINDOW_ORIENTATION, 508 SENSOR_TYPE_DEVICE_ORIENTATION, 509 3.0f, // maxRange 510 1.0f, // XXX resolution 511 0.1f, // XXX power 512 0, // minDelay 513 kMinFifoReservedEventCount, // XXX fifoReservedEventCount 514 kMaxOneAxisEventCount, // XXX fifoMaxEventCount 515 SENSOR_STRING_TYPE_DEVICE_ORIENTATION, 516 "", // requiredPermission 517 0, // maxDelay 518 SENSOR_FLAG_ON_CHANGE_MODE, 519 { NULL, NULL } 520 }, 521 }; 522 523 extern const size_t kSensorCount = sizeof(kSensorList) / sizeof(sensor_t); 524