Home | History | Annotate | Download | only in inc
      1 /*
      2  * Copyright (C) 2017 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 #ifndef __HALINTF_H
     18 #define __HALINTF_H
     19 #include <stdint.h>
     20 #include "toolchain.h"
     21 #include "sensType.h"
     22 
     23 /*
     24  * This files contains data structure for HAL and driver / algo to exchange information.
     25  */
     26 
     27 #define APP_TO_SENSOR_HAL_SIZE_MAX      HOSTINTF_SENSOR_DATA_MAX
     28 #define APP_TO_SENSOR_HAL_PAYLOAD_MAX \
     29         (APP_TO_SENSOR_HAL_DATA_MAX - sizeof(struct AppToSensorHalDataBuffer))
     30 #define APP_TO_SENSOR_HAL_TYPE(sensor, subtype) (((sensor) && 0xFF) | (((subtype) & 0x7F) << 8))
     31 #define APP_TO_SENSOR_HAL_TYPE_MASK     0x7FFF
     32 
     33 enum {
     34     // gyro sensor calibration:  GyroCalBias
     35     HALINTF_TYPE_GYRO_CAL_BIAS = APP_TO_SENSOR_HAL_TYPE(SENS_TYPE_GYRO, 1),
     36 
     37     // gyro sensor over temperature calibration: GyroOtcData
     38     HALINTF_TYPE_GYRO_OTC_DATA = APP_TO_SENSOR_HAL_TYPE(SENS_TYPE_GYRO, 2),
     39 
     40     // mag sensor calibration: MagCalBias
     41     HALINTF_TYPE_MAG_CAL_BIAS = APP_TO_SENSOR_HAL_TYPE(SENS_TYPE_MAG, 1),
     42 
     43     // mag local field information: MagLocalField
     44     HALINTF_TYPE_MAG_LOCAL_FIELD = APP_TO_SENSOR_HAL_TYPE(SENS_TYPE_MAG, 2),
     45 
     46     // mag sensor spherical calibration: MagSphericalData
     47     HALINTF_TYPE_MAG_SPERICAL_DATA = APP_TO_SENSOR_HAL_TYPE(SENS_TYPE_MAG, 3),
     48 };
     49 
     50 SET_PACKED_STRUCT_MODE_ON
     51 struct GyroCalBias {
     52     int32_t hardwareBias[3];   // unit depending on hardware implementation
     53     float softwareBias[3];          // rad/s
     54 } ATTRIBUTE_PACKED;
     55 SET_PACKED_STRUCT_MODE_OFF
     56 
     57 SET_PACKED_STRUCT_MODE_ON
     58 struct GyroOtcData {
     59     float lastOffset[3];    // rad/s
     60     float lastTemperature;  // Celsius
     61     float sensitivity[3];   // rad/s/K
     62     float intercept[3];     // rad/s
     63 } ATTRIBUTE_PACKED;
     64 SET_PACKED_STRUCT_MODE_OFF
     65 
     66 SET_PACKED_STRUCT_MODE_ON
     67 struct MagCalBias {
     68     float bias[3];     // in uT
     69 } ATTRIBUTE_PACKED;
     70 SET_PACKED_STRUCT_MODE_OFF
     71 
     72 SET_PACKED_STRUCT_MODE_ON
     73 struct MagLocalField {
     74     float strength;    // in uT
     75     float declination; // in rad
     76     float inclination; // in rad
     77 } ATTRIBUTE_PACKED;
     78 SET_PACKED_STRUCT_MODE_OFF
     79 
     80 SET_PACKED_STRUCT_MODE_ON
     81 struct MagSphericalData {
     82     float bias[3];
     83     float scale[3];
     84     float skew[3];
     85 } ATTRIBUTE_PACKED;
     86 SET_PACKED_STRUCT_MODE_OFF
     87 
     88 // data structure for upload bulk data to sensor hal
     89 SET_PACKED_STRUCT_MODE_ON
     90 struct AppToSensorHalDataPayload {
     91     uint8_t size;       // number of bytes in payload data
     92     uint8_t reserved;
     93     uint16_t type;      // use EVENT_TYPE_BIT_DISCARDABLE to mark discardable update
     94     union
     95     {
     96         uint32_t u[0];
     97         int32_t i[0];
     98         float f[0];
     99         struct GyroCalBias gyroCalBias[0];
    100         struct GyroOtcData gyroOtcData[0];
    101         struct MagCalBias  magCalBias[0];
    102         struct MagLocalField magLocalField[0];
    103         struct MagSphericalData magSphericalData[0];
    104     };
    105 } ATTRIBUTE_PACKED;
    106 SET_PACKED_STRUCT_MODE_OFF
    107 
    108 // buffer data structure with header, header compatible with HostIntfDataBuffer
    109 SET_PACKED_STRUCT_MODE_ON
    110 struct AppToSensorHalDataBuffer {
    111     uint32_t eventType; // placeholder for HostIntfDataBuffer event type field
    112     struct AppToSensorHalDataPayload payload;
    113 };
    114 SET_PACKED_STRUCT_MODE_OFF
    115 
    116 #endif //__HALINTF_H
    117 
    118