altb_pmic / AHRS

Dependencies:   Eigen

Dependents:   IndNav_QK3_T265

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BMI088.h Source File

BMI088.h

00001 #ifndef BMI088_H
00002 #define BMI088_H
00003 
00004 #include <stdint.h>
00005 #include "mbed.h"
00006 
00007 #define BMI088_ACC_ADDRESS              0x18
00008 
00009 #define BMI088_ACC_CHIP_ID              0x00 // Default value 0x1E
00010 #define BMI088_ACC_ERR_REG              0x02
00011 #define BMI088_ACC_STATUS               0x03
00012 
00013 #define BMI088_ACC_X_LSB                0x12
00014 #define BMI088_ACC_X_MSB                0x13
00015 #define BMI088_ACC_Y_LSB                0x14
00016 #define BMI088_ACC_Y_MSB                0x15
00017 #define BMI088_ACC_Z_LSB                0x16
00018 #define BMI088_ACC_Z_MSB                0x17
00019 
00020 #define BMI088_ACC_SENSOR_TIME_0        0x18
00021 #define BMI088_ACC_SENSOR_TIME_1        0x19
00022 #define BMI088_ACC_SENSOR_TIME_2        0x1A
00023 
00024 
00025 #define BMI088_ACC_INT_STAT_1           0x1D
00026 
00027 #define BMI088_ACC_TEMP_MSB             0x22
00028 #define BMI088_ACC_TEMP_LSB             0x23
00029 
00030 #define BMI088_ACC_CONF                 0x40
00031 #define BMI088_ACC_RANGE                0x41
00032 
00033 #define BMI088_ACC_INT1_IO_CTRL         0x53
00034 #define BMI088_ACC_INT2_IO_CTRL         0x54
00035 #define BMI088_ACC_INT_MAP_DATA         0x58
00036 
00037 #define BMI088_ACC_SELF_TEST            0x6D
00038 
00039 #define BMI088_ACC_PWR_CONF             0x7C
00040 #define BMI088_ACC_PWR_CTRl             0x7D
00041 
00042 #define BMI088_ACC_SOFT_RESET           0x7E
00043 
00044 #define BMI088_GYRO_ADDRESS             0x68
00045 
00046 #define BMI088_GYRO_CHIP_ID             0x00 // Default value 0x0F
00047 
00048 #define BMI088_GYRO_RATE_X_LSB          0x02
00049 #define BMI088_GYRO_RATE_X_MSB          0x03
00050 #define BMI088_GYRO_RATE_Y_LSB          0x04
00051 #define BMI088_GYRO_RATE_Y_MSB          0x05
00052 #define BMI088_GYRO_RATE_Z_LSB          0x06
00053 #define BMI088_GYRO_RATE_Z_MSB          0x07
00054 
00055 #define BMI088_GYRO_INT_STAT_1          0x0A
00056 
00057 #define BMI088_GYRO_RANGE               0x0F
00058 #define BMI088_GYRO_BAND_WIDTH          0x10
00059 
00060 #define BMI088_GYRO_LPM_1               0x11
00061 
00062 #define BMI088_GYRO_SOFT_RESET          0x14
00063 
00064 #define BMI088_GYRO_INT_CTRL            0x15
00065 #define BMI088_GYRO_INT3_INT4_IO_CONF   0x16
00066 #define BMI088_GYRO_INT3_INT4_IO_MAP    0x18
00067 
00068 #define BMI088_GYRO_SELF_TEST           0x3C
00069 
00070 
00071 enum device_type_t { // device type
00072     ACC = 0x00, //
00073     GYRO = 0x01, //
00074 };
00075 
00076 enum acc_scale_type_t { // measurement rage
00077     RANGE_3G = 0x00, //
00078     RANGE_6G = 0x01, //
00079     RANGE_12G = 0x02, //
00080     RANGE_24G = 0x03, //
00081 };
00082 
00083 enum acc_odr_type_t { // Normal fg(Hz) | OSR2 fg(Hz) | OSR4 fg(Hz) <- output data rate
00084     ODR_12 = 0x05,    //          5             2             1
00085     ODR_25 = 0x06,    //         10             5             3
00086     ODR_50 = 0x07,    //         20             9             5
00087     ODR_100 = 0x08,   //         40            19            10
00088     ODR_200 = 0x09,   //         80            38            20
00089     ODR_400 = 0x0A,   //        145            75            40
00090     ODR_800 = 0x0B,   // 230xy/200z           140            80
00091     ODR_1600 = 0x0C,  // 280xy/245z    234xy/215z           145
00092 };
00093 
00094 enum acc_power_type_t { // power mode
00095     ACC_ACTIVE = 0x00, //
00096     ACC_SUSPEND = 0x03, //
00097 };
00098 
00099 enum gyro_scale_type_t { // measurement rage
00100     RANGE_2000 = 0x00, //
00101     RANGE_1000 = 0x01, //
00102     RANGE_500 = 0x02, //
00103     RANGE_250 = 0x03, //
00104     RANGE_125 = 0x04, //
00105 };
00106 
00107 enum gyro_odr_type_t { // output data rate
00108     ODR_2000_BW_532 = 0x00, //
00109     ODR_2000_BW_230 = 0x01, //
00110     ODR_1000_BW_116 = 0x02, //
00111     ODR_400_BW_47 = 0x03, //
00112     ODR_200_BW_23 = 0x04, //
00113     ODR_100_BW_12 = 0x05, //
00114     ODR_200_BW_64 = 0x06, //
00115     ODR_100_BW_32 = 0x07, //
00116 };
00117 
00118 enum gyro_power_type_t { // power mode
00119     GYRO_NORMAL = 0x00, //
00120     GYRO_SUSPEND = 0x80, //
00121     GYRO_DEEP_SUSPEND = 0x20, //
00122 };
00123 
00124 class BMI088
00125 {
00126 public:
00127 
00128     // Constructor
00129     BMI088(I2C& i2c);
00130 
00131     // Deconstructor
00132     //virtual ~BMI088();
00133 
00134     // Methods
00135     bool isConnection(void);
00136 
00137     void initialize(void);
00138 
00139 
00140     void setAccPowerMode(acc_power_type_t mode);
00141     void setGyroPowerMode(gyro_power_type_t mode);
00142 
00143     void setAccScaleRange(acc_scale_type_t range);
00144     void setAccOutputDataRate(acc_odr_type_t odr);
00145     void setAccOutputDataRateOSR2(acc_odr_type_t odr);
00146     void setAccOutputDataRateOSR4(acc_odr_type_t odr);
00147 
00148     void setGyroScaleRange(gyro_scale_type_t range);
00149     void setGyroOutputDataRate(gyro_odr_type_t odr);
00150 
00151     void getAcceleration(float* x, float* y, float* z);
00152     float getAccelerationX(void);
00153     float getAccelerationY(void);
00154     float getAccelerationZ(void);
00155 
00156     void getGyroscope(float* x, float* y, float* z);
00157     float getGyroscopeX(void);
00158     float getGyroscopeY(void);
00159     float getGyroscopeZ(void);
00160 
00161     int16_t getTemperature(void);
00162 
00163     uint8_t getAccID(void);
00164     uint8_t getGyroID(void);
00165 
00166     void resetAcc(void);
00167     void resetGyro(void);
00168     
00169     void readAccel(void);
00170     void readGyro(void);
00171     float gyroX, gyroY, gyroZ; // x, y, and z axis readings of the gyroscope (float value)
00172     float accX, accY, accZ; // x, y, and z axis readings of the accelerometer (float value)
00173 
00174 private:
00175 
00176     // Methods
00177     void write8(device_type_t dev, uint8_t reg, uint8_t val);
00178     uint8_t read8(device_type_t dev, uint8_t reg);
00179     uint16_t read16(device_type_t dev, uint8_t reg);
00180     uint16_t read16Be(device_type_t dev, uint8_t reg);
00181     uint32_t read24(device_type_t dev, uint8_t reg);
00182     void read(device_type_t dev, uint8_t reg, uint8_t *buf, uint16_t len);
00183 
00184     // Class Variables
00185     I2C *i2c;
00186     uint16_t begin();
00187 
00188     float accRange;
00189     float gyroRange;
00190     uint8_t devAddrAcc;
00191     uint8_t devAddrGyro;
00192 };
00193 
00194 //extern BMI088 bmi088;
00195 
00196 #endif