My implementation of Bosh BMI160 Only I2C is tested so far.

Dependents:   test_BMI160 TFT_test_MAX32630FTHR

BMI160.h

Committer:
Rhyme
Date:
2017-09-12
Revision:
3:9d3079170b35
Parent:
2:4cc456503e9f
Child:
4:93f16677f730

File content as of revision 3:9d3079170b35:

#ifndef _BMI160_H_
#define _BMI160_H_
/**
 * @brief BMI160 Bosch Small, low power inertial measurement unit
 *
 */
class BMI160 {
public:
 /**
  * BMI160 I2C Interface
  *
  * @param sda SDA pin
  * @param scl SCL pin
  * @param addr address of the I2C peripheral
  */
  BMI160(PinName sda, PinName scl, int addr) ;

 /**
  * BMI160 SPI Interface
  *
  * @param sck  SPI SCKL pin
  * @param miso SPI Master In Slave Out pin
  * @param mosi SPI Master Out Slave In pin
  * @param cs   SPI Chip Select pin
  */
  BMI160(PinName sck, PinName miso, PinName mosi, PinName cs) ;

/**
 * BMI160 destructor
 */
  ~BMI160() ;

/**
 * setCMD set value to the CMD register (0x7E)
 *
 * @param cmd uint8_t value to write
 * @returns none
 */
  void setCMD(uint8_t cmd) ;
  
/**
 * getStatus get value of the STATUS register (0x1B)
 * @param none
 * @returns the value of the STATUS register
 */
  uint8_t getStatus(void) ;
  
/**
 * getChipID get value of the CHIP_ID register (0x10)
 * @param none
 * @returns the chip ID (supposed to be 0xD1)
 */
  uint8_t getChipID(void) ;
  uint8_t getAccRange(void) ;
  int16_t getGyrRange(void) ;
  
  int16_t getAccRawX(void) ;
  int16_t getAccRawY(void) ;
  int16_t getAccRawZ(void) ;
  int16_t getGyrRawX(void) ;
  int16_t getGyrRawY(void) ;
  int16_t getGyrRawZ(void) ;
  void getAccRaw(int16_t *value) ;
  void getGyrRaw(int16_t *value) ;
  
  float getAccX(void) ;
  float getAccY(void) ;
  float getAccZ(void) ;
  float getGyrX(void) ;
  float getGyrY(void) ;
  float getGyrZ(void) ;
  void getAcc(float *value) ;
  void getGyr(float *value) ;
  
private:
  SPI *m_spi ;
  I2C *m_i2c ;
  DigitalOut *m_cs ;
  int m_addr ;
  int acc_range ;
  int gyr_range ;
  
  void init(void) ;
  void i2c_readRegs(int addr, uint8_t *data, int len) ;
  void i2c_writeRegs(uint8_t *data, int len) ;
  void spi_readRegs(int addr, uint8_t *data, int len) ;
  void spi_writeRegs(uint8_t *data, int len) ;
  void readRegs(int addr, uint8_t *data, int len) ;
  void writeRegs(uint8_t *data, int len) ;
} ;

#define ACC_PMU_SUSPEND  0x00
#define ACC_PMU_NORMAL   0x01
#define ACC_PMU_LOWPOWER 0x02
#define GYR_PMU_SUSPEND  0x00
#define GYR_PMU_NORMAL   0x01
#define GYR_PMU_FASTSU   0x03
#define MAG_PMU_SUSPEND  0x00
#define MAG_PMU_NORMAL   0x01
#define MAG_PMU_LOWPOWER 0x02
#endif /* _BMI160_H_ */