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