Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
BMI088.h
00001 /* 00002 * A library for Grove - 6-Axis Accelerometer&Gyroscope(BMI088) 00003 * 00004 * Copyright (c) 2018 seeed technology co., ltd. 00005 * Author : Wayen Weng 00006 * Create Time : June 2018 00007 * Change Log : 00008 * 00009 * The MIT License (MIT) 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining a copy 00012 * of this software and associated documentation files (the "Software"), to deal 00013 * in the Software without restriction, including without limitation the rights 00014 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00015 * copies of the Software, and to permit persons to whom the Software is 00016 * furnished to do so, subject to the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be included in 00019 * all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00022 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00023 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00024 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00025 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00026 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00027 * THE SOFTWARE. 00028 */ 00029 #include "mbed.h" 00030 00031 #ifndef __BOSCH_BMI088_H__ 00032 #define __BOSCH_BMI088_H__ 00033 00034 #define BMI088_ACC_ADDRESS 0x19<<1 //0x19<<1 00035 00036 #define BMI088_ACC_CHIP_ID 0x00 // Default value 0x1E 00037 #define BMI088_ACC_ERR_REG 0x02 00038 #define BMI088_ACC_STATUS 0x03 00039 00040 #define BMI088_ACC_X_LSB 0x12 00041 #define BMI088_ACC_X_MSB 0x13 00042 #define BMI088_ACC_Y_LSB 0x14 00043 #define BMI088_ACC_Y_MSB 0x15 00044 #define BMI088_ACC_Z_LSB 0x16 00045 #define BMI088_ACC_Z_MSB 0x17 00046 00047 #define BMI088_ACC_SENSOR_TIME_0 0x18 00048 #define BMI088_ACC_SENSOR_TIME_1 0x19 00049 #define BMI088_ACC_SENSOR_TIME_2 0x1A 00050 00051 #define BMI088_ACC_INT_STAT_1 0x1D 00052 00053 #define BMI088_ACC_TEMP_MSB 0x22 00054 #define BMI088_ACC_TEMP_LSB 0x23 00055 00056 #define BMI088_ACC_CONF 0x40 00057 #define BMI088_ACC_RANGE 0x41 00058 00059 #define BMI088_ACC_INT1_IO_CTRL 0x53 00060 #define BMI088_ACC_INT2_IO_CTRL 0x54 00061 #define BMI088_ACC_INT_MAP_DATA 0x58 00062 00063 #define BMI088_ACC_SELF_TEST 0x6D 00064 00065 #define BMI088_ACC_PWR_CONF 0x7C 00066 #define BMI088_ACC_PWR_CTRl 0x7D 00067 00068 #define BMI088_ACC_SOFT_RESET 0x7E 00069 00070 #define BMI088_GYRO_ADDRESS 0x69<<1//0xD2 //0x69<<1 00071 00072 #define BMI088_GYRO_CHIP_ID 0x00 // Default value 0x0F 00073 00074 #define BMI088_GYRO_RATE_X_LSB 0x02 00075 #define BMI088_GYRO_RATE_X_MSB 0x03 00076 #define BMI088_GYRO_RATE_Y_LSB 0x04 00077 #define BMI088_GYRO_RATE_Y_MSB 0x05 00078 #define BMI088_GYRO_RATE_Z_LSB 0x06 00079 #define BMI088_GYRO_RATE_Z_MSB 0x07 00080 00081 #define BMI088_GYRO_INT_STAT_1 0x0A 00082 00083 #define BMI088_GYRO_RANGE 0x0F 00084 #define BMI088_GYRO_BAND_WIDTH 0x10 00085 00086 #define BMI088_GYRO_LPM_1 0x11 00087 00088 #define BMI088_GYRO_SOFT_RESET 0x14 00089 00090 #define BMI088_GYRO_INT_CTRL 0x15 00091 #define BMI088_GYRO_INT3_INT4_IO_CONF 0x16 00092 #define BMI088_GYRO_INT3_INT4_IO_MAP 0x18 00093 00094 #define BMI088_GYRO_SELF_TEST 0x3C 00095 00096 enum device_type_t // device type 00097 { 00098 ACC = 0x00, // 00099 GYRO = 0x01, // 00100 }; 00101 00102 enum acc_scale_type_t // measurement rage 00103 { 00104 RANGE_3G = 0x00, // 00105 RANGE_6G = 0x01, // 00106 RANGE_12G = 0x02, // 00107 RANGE_24G = 0x03, // 00108 }; 00109 00110 enum acc_odr_type_t // output data rate 00111 { 00112 ODR_12 = 0x05, // 00113 ODR_25 = 0x06, // 00114 ODR_50 = 0x07, // 00115 ODR_100 = 0x08, // 00116 ODR_200 = 0x09, // 00117 ODR_400 = 0x0A, // 00118 ODR_800 = 0x0B, // 00119 ODR_1600 = 0x0C, // 00120 }; 00121 00122 enum acc_power_type_t // power mode 00123 { 00124 ACC_ACTIVE = 0x00, // 00125 ACC_SUSPEND = 0x03, // 00126 }; 00127 00128 enum gyro_scale_type_t // measurement rage 00129 { 00130 RANGE_2000 = 0x00, // 00131 RANGE_1000 = 0x01, // 00132 RANGE_500 = 0x02, // 00133 RANGE_250 = 0x03, // 00134 RANGE_125 = 0x04, // 00135 }; 00136 00137 enum gyro_odr_type_t // output data rate 00138 { 00139 ODR_2000_BW_532 = 0x00, // 00140 ODR_2000_BW_230 = 0x01, // 00141 ODR_1000_BW_116 = 0x02, // 00142 ODR_400_BW_47 = 0x03, // 00143 ODR_200_BW_23 = 0x04, // 00144 ODR_100_BW_12 = 0x05, // 00145 ODR_200_BW_64 = 0x06, // 00146 ODR_100_BW_32 = 0x07, // 00147 }; 00148 00149 enum gyro_power_type_t // power mode 00150 { 00151 GYRO_NORMAL = 0x00, // 00152 GYRO_SUSPEND = 0x80, // 00153 GYRO_DEEP_SUSPEND = 0x20, // 00154 }; 00155 00156 class BMI088 00157 { 00158 public: 00159 00160 BMI088(void); 00161 00162 bool isConnection(void); 00163 00164 void initialize(void); 00165 00166 void setAccPoweMode(acc_power_type_t mode); 00167 void setGyroPoweMode(gyro_power_type_t mode); 00168 00169 void setAccScaleRange(acc_scale_type_t range); 00170 void setAccOutputDataRate(acc_odr_type_t odr); 00171 00172 void setGyroScaleRange(gyro_scale_type_t range); 00173 void setGyroOutputDataRate(gyro_odr_type_t odr); 00174 00175 void getAcceleration(float* x, float* y, float* z); 00176 float getAccelerationX(void); 00177 float getAccelerationY(void); 00178 float getAccelerationZ(void); 00179 00180 void getGyroscope(float* x, float* y, float* z); 00181 float getGyroscopeX(void); 00182 float getGyroscopeY(void); 00183 float getGyroscopeZ(void); 00184 00185 uint16_t getTemperature(void); 00186 00187 uint8_t getAccID(void); 00188 uint8_t getGyroID(void); 00189 00190 void resetAcc(void); 00191 void resetGyro(void); 00192 00193 private: 00194 00195 void write8(device_type_t dev, char reg, uint8_t val); 00196 char read8(device_type_t dev, char reg); 00197 uint16_t read16(device_type_t dev, char reg); 00198 uint16_t read16Be(device_type_t dev, char reg); 00199 uint32_t read24(device_type_t dev, char reg); 00200 void read(device_type_t dev, char reg, char *, uint16_t len); 00201 00202 float accRange; 00203 float gyroRange; 00204 uint8_t devAddrAcc; 00205 uint8_t devAddrGyro; 00206 protected: 00207 I2C i2c; 00208 }; 00209 00210 extern BMI088 bmi088; 00211 00212 #endif
Generated on Wed Jul 20 2022 23:32:05 by
1.7.2