Home | History | Annotate | Download | only in bosch_bmi160
      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 #ifndef BOSCH_BMM150_H_
     18 
     19 #define BOSCH_BMM150_H_
     20 
     21 #include <stdio.h>
     22 #include <stdint.h>
     23 
     24 #ifdef __cplusplus
     25 extern "C" {
     26 #endif
     27 
     28 #define kScale_mag 0.0625f         // 1.0f / 16.0f;
     29 
     30 #define BMM150_REG_DATA           0x42
     31 #define BMM150_REG_CTRL_1         0x4b
     32 #define BMM150_REG_CTRL_2         0x4c
     33 #define BMM150_REG_REPXY          0x51
     34 #define BMM150_REG_REPZ           0x52
     35 #define BMM150_REG_DIG_X1         0x5d
     36 #define BMM150_REG_DIG_Y1         0x5e
     37 #define BMM150_REG_DIG_Z4_LSB     0x62
     38 #define BMM150_REG_DIG_Z4_MSB     0x63
     39 #define BMM150_REG_DIG_X2         0x64
     40 #define BMM150_REG_DIG_Y2         0x65
     41 #define BMM150_REG_DIG_Z2_LSB     0x68
     42 #define BMM150_REG_DIG_Z2_MSB     0x69
     43 #define BMM150_REG_DIG_Z1_LSB     0x6a
     44 #define BMM150_REG_DIG_Z1_MSB     0x6b
     45 #define BMM150_REG_DIG_XYZ1_LSB   0x6c
     46 #define BMM150_REG_DIG_XYZ1_MSB   0x6d
     47 #define BMM150_REG_DIG_Z3_LSB     0x6e
     48 #define BMM150_REG_DIG_Z3_MSB     0x6f
     49 #define BMM150_REG_DIG_XY2        0x70
     50 #define BMM150_REG_DIG_XY1        0x71
     51 
     52 #define BMM150_MAG_FLIP_OVERFLOW_ADCVAL     ((int16_t)-4096)
     53 #define BMM150_MAG_HALL_OVERFLOW_ADCVAL     ((int16_t)-16384)
     54 #define BMM150_MAG_OVERFLOW_OUTPUT          ((int16_t)-32768)
     55 #define BMM150_CALIB_HEX_LACKS              0x100000
     56 #define BMM150_MAG_OVERFLOW_OUTPUT_S32      ((int32_t)(-2147483647-1))
     57 
     58 struct MagTask {
     59     uint16_t dig_z1;
     60     int16_t dig_z2, dig_z3, dig_z4;
     61     uint16_t dig_xyz1;
     62     uint8_t raw_dig_data[24];
     63     int8_t dig_x1, dig_y1, dig_x2, dig_y2;
     64     uint8_t dig_xy1;
     65     int8_t dig_xy2;
     66 };
     67 
     68 #define MAG_I2C_ADDR 0x10
     69 #define MAG_REG_DATA BMM150_REG_DATA
     70 
     71 void bmm150SaveDigData(struct MagTask *magTask, uint8_t *data, size_t offset);
     72 void parseMagData(struct MagTask *magTask, uint8_t *buf, float *x, float *y, float *z);
     73 
     74 #ifdef __cplusplus
     75 }
     76 #endif
     77 
     78 #endif  // BOSCH_BMM150_H_
     79