My implementation of Bosh BMI160 Only I2C is tested so far.
Dependents: test_BMI160 TFT_test_MAX32630FTHR
BMI160.h
00001 #ifndef _BMI160_H_ 00002 #define _BMI160_H_ 00003 /** 00004 * @brief BMI160 Bosch Small, low power inertial measurement unit 00005 * 00006 */ 00007 class BMI160 { 00008 public: 00009 /** 00010 * BMI160 I2C Interface 00011 * 00012 * @param sda SDA pin 00013 * @param scl SCL pin 00014 * @param addr address of the I2C peripheral 00015 */ 00016 BMI160(PinName sda, PinName scl, int addr) ; 00017 00018 /** 00019 * BMI160 SPI Interface 00020 * 00021 * @param sck SPI SCKL pin 00022 * @param miso SPI Master In Slave Out pin 00023 * @param mosi SPI Master Out Slave In pin 00024 * @param cs SPI Chip Select pin 00025 */ 00026 BMI160(PinName sck, PinName miso, PinName mosi, PinName cs) ; 00027 00028 /** 00029 * BMI160 destructor 00030 */ 00031 ~BMI160() ; 00032 00033 /** 00034 * setCMD set value to the CMD register (0x7E) 00035 * 00036 * @param cmd uint8_t value to write 00037 * @returns none 00038 */ 00039 void setCMD(uint8_t cmd) ; 00040 00041 /** 00042 * getStatus get value of the STATUS register (0x1B) 00043 * @param none 00044 * @returns the value of the STATUS register 00045 */ 00046 uint8_t getStatus(void) ; 00047 00048 /** 00049 * getChipID get value of the CHIP_ID register (0x10) 00050 * @param none 00051 * @returns the chip ID (supposed to be 0xD1) 00052 */ 00053 uint8_t getChipID(void) ; 00054 00055 /** 00056 * get range of Acc (0x41) 00057 * @param none 00058 * @returns accelerometer g-range 00059 * @note the value is 2, 4, or 8 00060 */ 00061 uint8_t getAccRange(void) ; 00062 00063 /** 00064 * get range of Gyr (0x43) 00065 * @param none 00066 * @returns Angular Rate Range and Resolution 00067 * @note the values are 00068 * @note 2000 ( 16.4 LSB/deg/s <-> 61.0 mdeg/s/LSB) 00069 * @note 1000 ( 32.8 LSB/deg/s <-> 30.5 mdeg/s/LSB) 00070 * @note 500 ( 65.6 LSB/deg/s <-> 15.3 mdeg/s/LSB) 00071 * @note 250 (131.2 LSB/deg/s <-> 7.6 mdeg/s/LSB) 00072 * @note 125 (262.4 LSB/deg/s <-> 3.8 mdeg/s/LSB) 00073 */ 00074 int16_t getGyrRange(void) ; 00075 00076 /** 00077 * get Raw acc x value 00078 * @param none 00079 * @returns 16bit signed value 00080 */ 00081 int16_t getAccRawX(void) ; 00082 00083 /** 00084 * get Raw acc y value 00085 * @param none 00086 * @returns 16bit signed value 00087 */ 00088 int16_t getAccRawY(void) ; 00089 00090 /** 00091 * get Raw acc z value 00092 * @param none 00093 * @returns 16bit signed value 00094 */ 00095 int16_t getAccRawZ(void) ; 00096 00097 /** 00098 * get Raw gyr x value 00099 * @param none 00100 * @returns 16bit signed value 00101 */ 00102 int16_t getGyrRawX(void) ; 00103 00104 /** 00105 * get Raw gyr y value 00106 * @param none 00107 * @returns 16bit signed value 00108 */ 00109 int16_t getGyrRawY(void) ; 00110 00111 /** 00112 * get Raw gyr z value 00113 * @param none 00114 * @returns 16bit signed value 00115 */ 00116 int16_t getGyrRawZ(void) ; 00117 00118 /** 00119 * get Raw acc x,y,z values 00120 * @param 16bit array address to receive the data 00121 * @returns none 00122 */ 00123 void getAccRaw(int16_t *value) ; 00124 00125 /** 00126 * get Raw gyr x,y,z values 00127 * @param 16bit array address to receive the data 00128 * @returns none 00129 */ 00130 void getGyrRaw(int16_t *value) ; 00131 00132 /** 00133 * get acc x value 00134 * @param none 00135 * @returns value (-acc_range ~ +acc_range) 00136 */ 00137 float getAccX(void) ; 00138 00139 /** 00140 * get acc y value 00141 * @param none 00142 * @returns value (-acc_range ~ +acc_range) 00143 */ 00144 float getAccY(void) ; 00145 00146 /** 00147 * get acc z value 00148 * @param none 00149 * @returns value (-acc_range ~ +acc_range) 00150 */ 00151 float getAccZ(void) ; 00152 00153 /** 00154 * get gyr x value 00155 * @param none 00156 * @returns value (-gyr_range ~ +gyr_range) 00157 */ 00158 float getGyrX(void) ; 00159 00160 /** 00161 * get gyr y value 00162 * @param none 00163 * @returns value (-gyr_range ~ +gyr_range) 00164 */ 00165 float getGyrY(void) ; 00166 00167 /** 00168 * get gyr z value 00169 * @param none 00170 * @returns value (-gyr_range ~ +gyr_range) 00171 */ 00172 float getGyrZ(void) ; 00173 00174 /** 00175 * get acc x, y, z values 00176 * @param float array address to receive the values 00177 * @returns none 00178 * @note the value range is (-acc_range ~ +acc_range) 00179 */ 00180 void getAcc(float *value) ; 00181 00182 /** 00183 * get gyr x, y, z values 00184 * @param float array address to receive the values 00185 * @returns none 00186 * @note the value range is (-gyr_range ~ +gyr_range) 00187 */ 00188 void getGyr(float *value) ; 00189 00190 private: 00191 SPI *m_spi ; 00192 I2C *m_i2c ; 00193 DigitalOut *m_cs ; 00194 int m_addr ; 00195 int acc_range ; 00196 int gyr_range ; 00197 00198 void init(void) ; 00199 void i2c_readRegs(int addr, uint8_t *data, int len) ; 00200 void i2c_writeRegs(uint8_t *data, int len) ; 00201 void spi_readRegs(int addr, uint8_t *data, int len) ; 00202 void spi_writeRegs(uint8_t *data, int len) ; 00203 void readRegs(int addr, uint8_t *data, int len) ; 00204 void writeRegs(uint8_t *data, int len) ; 00205 } ; 00206 00207 #define ACC_PMU_SUSPEND 0x00 00208 #define ACC_PMU_NORMAL 0x01 00209 #define ACC_PMU_LOWPOWER 0x02 00210 #define GYR_PMU_SUSPEND 0x00 00211 #define GYR_PMU_NORMAL 0x01 00212 #define GYR_PMU_FASTSU 0x03 00213 #define MAG_PMU_SUSPEND 0x00 00214 #define MAG_PMU_NORMAL 0x01 00215 #define MAG_PMU_LOWPOWER 0x02 00216 #endif /* _BMI160_H_ */
Generated on Tue Jul 12 2022 21:42:56 by
1.7.2