upm  0.8.0
Sensor/Actuator repository for libmraa (v1.1.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
BMG160 Class Reference

API for the BMG160 16 bit Trixial Gyroscope. More...

Detailed Description

The BMG160 is a 3-axis angular rate sensor that is made of a surface micro machined sensing element and an evaluation ASIC. Both parts are packed into one single LGA 3.0mm x 3.0mm x 0.95mm housing. The BMG160 is designed to meet requirements for consumer applications such as image stabilization (DSC and camera-phone), gaming and pointing devices. It is capable to measure angular rates in three perpendicular room dimensions, the x-, y- and z-axis, and to provide the corresponding output signals. The BMG160 is fitted with digital bi-directional SPI and I2C interfaces for optimum system integration.

Not all functionality of this chip has been implemented in this driver, however all the pieces are present to add any desired functionality. This driver supports both I2C (default) and SPI operation.

This device requires 3.3v operation.

// Instantiate an BMG160 using default I2C parameters
upm::BMG160 *sensor = new upm::BMG160();
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
// for CS: BMG160(0, -1, 10);
// now output data every 250 milliseconds
while (shouldRun)
{
float x, y, z;
sensor->update();
sensor->getGyroscope(&x, &y, &z);
cout << "Gyroscope x: " << x
<< " y: " << y
<< " z: " << z
<< " degrees/s"
<< endl;
// we show both C and F for temperature
cout << "Compensation Temperature: " << sensor->getTemperature()
<< " C / " << sensor->getTemperature(true) << " F"
<< endl;
cout << endl;
usleep(250000);
}

Public Types

enum  BMG160_REGS_T : uint8_t {
  REG_CHIP_ID = 0x00, REG_RATE_X_LSB = 0x02, REG_RATE_X_MSB = 0x03, REG_RATE_Y_LSB = 0x04,
  REG_RATE_Y_MSB = 0x05, REG_RATE_Z_LSB = 0x06, REG_RATE_Z_MSB = 0x07, REG_TEMP = 0x08,
  REG_INT_STATUS_0 = 0x09, REG_INT_STATUS_1 = 0x0a, REG_INT_STATUS_2 = 0x0b, REG_INT_STATUS_3 = 0x0c,
  REG_FIFO_STATUS = 0x0e, REG_GYR_RANGE = 0x0f, REG_GYR_BW = 0x10, REG_LPM1 = 0x11,
  REG_LPM2 = 0x12, REG_RATE_HBW = 0x13, REG_SOFTRESET = 0x14, REG_INT_EN_0 = 0x15,
  REG_INT_EN_1 = 0x16, REG_INT_MAP_0 = 0x17, REG_INT_MAP_1 = 0x18, REG_INT_MAP_2 = 0x19,
  REG_INT_1A = 0x1a, REG_INT_1B = 0x1b, REG_INT_1C = 0x1c, REG_INT_1E = 0x1e,
  REG_INT_RST_LATCH = 0x21, REG_HIGH_TH_X = 0x22, REG_HIGH_DUR_X = 0x23, REG_HIGH_TH_Y = 0x24,
  REG_HIGH_DUR_Y = 0x25, REG_HIGH_TH_Z = 0x26, REG_HIGH_DUR_Z = 0x27, REG_SOC = 0x31,
  REG_A_FOC = 0x32, REG_TRIM_NVM_CTRL = 0x33, REG_SPI3_WDT = 0x34, REG_OFC1 = 0x36,
  REG_OFC2 = 0x37, REG_OFC3 = 0x38, REG_OFC4 = 0x39, REG_TRIM_GP0 = 0x3a,
  REG_TRIM_GP1 = 0x3b, REG_BIST = 0x3c, REG_FIFO_CONFIG_0 = 0x3d, REG_FIFO_CONFIG_1 = 0x3e,
  REG_FIFO_DATA = 0x3f
}
 
enum  INT_STATUS_0_BITS_T { _INT_STATUS_0_RESERVED_BITS = 0xf0 | 0x08 | 0x01, INT_STATUS_0_HIGH_INT = 0x02, INT_STATUS_0_ANY_INT = 0x04 }
 
enum  INT_STATUS_1_BITS_T {
  _INT_STATUS_1_RESERVED_BITS = 0x0f, INT_STATUS_1_FIFO_INT = 0x10, INT_STATUS_1_FAST_OFFSET_INT = 0x20, INT_STATUS_1_AUTO_OFFSET_INT = 0x40,
  INT_STATUS_1_DATA_INT = 0x80
}
 
enum  INT_STATUS_2_BITS_T {
  _INT_STATUS_2_RESERVED_BITS = 0xf0, INT_STATUS_2_ANY_FIRST_X = 0x01, INT_STATUS_2_ANY_FIRST_Y = 0x02, INT_STATUS_2_ANY_FIRST_Z = 0x04,
  INT_STATUS_2_ANY_SIGN = 0x08
}
 
enum  INT_STATUS_3_BITS_T {
  _INT_STATUS_3_RESERVED_BITS = 0xf0, INT_STATUS_3_HIGH_FIRST_X = 0x01, INT_STATUS_3_HIGH_FIRST_Y = 0x02, INT_STATUS_3_HIGH_FIRST_Z = 0x04,
  INT_STATUS_3_HIGH_SIGN = 0x08
}
 
enum  FIFO_STATUS_BITS_T {
  FIFO_STATUS_FRAME_COUNTER0 = 0x01, FIFO_STATUS_FRAME_COUNTER1 = 0x02, FIFO_STATUS_FRAME_COUNTER2 = 0x04, FIFO_STATUS_FRAME_COUNTER3 = 0x08,
  FIFO_STATUS_FRAME_COUNTER4 = 0x10, FIFO_STATUS_FRAME_COUNTER5 = 0x20, FIFO_STATUS_FRAME_COUNTER6 = 0x40, _FIFO_STATUS_FRAME_COUNTER_MASK = 127,
  _FIFO_STATUS_FRAME_COUNTER_SHIFT = 0, FIFO_STATUS_FIFO_OVERRUN = 0x80
}
 
enum  GYR_RANGE_BITS_T {
  _GYR_RANGE_RESERVED_BITS = 0x20 | 0x10 | 0x08, GYR_RANGE0 = 0x01, GYR_RANGE1 = 0x02, GYR_RANGE2 = 0x04,
  _GYR_RANGE_MASK = 7, _GYR_RANGE_SHIFT = 0, GYR_RANGE_FIXED0 = 0x40, GYR_RANGE_FIXED1 = 0x80,
  _GYR_RANGE_FIXED_MASK = 3, _GYR_RANGE_FIXED_SHIFT = 6, _GYR_RANGE_FIXED_VALUE = 2
}
 
enum  RANGE_T {
  RANGE_2000 = 0, RANGE_1000 = 1, RANGE_500 = 2, RANGE_250 = 3,
  RANGE_125 = 4
}
 
enum  GYR_BW_BITS_T {
  _GYR_BW_RESERVED_BITS = 0xf0, GYR_BW0 = 0x01, GYR_BW1 = 0x02, GYR_BW2 = 0x04,
  GYR_BW3 = 0x08, _GYR_BW_MASK = 15, _GYR_BW_SHIFT = 0
}
 
enum  BW_T {
  BW_2000_UNFILTERED = 0, BW_2000_230 = 1, BW_1000_116 = 2, BW_400_47 = 3,
  BW_200_23 = 4, BW_100_12 = 5, BW_200_64 = 6, BW_100_32 = 7
}
 
enum  LPM1_BITS_T {
  _LPM1_RESERVED_MASK = 0x40 | 0x10 | 0x01, LPM1_SLEEP_DUR0 = 0x02, LPM1_SLEEP_DUR1 = 0x04, LPM1_SLEEP_DUR2 = 0x08,
  _LPM1_SLEEP_MASK = 7, _LPM1_SLEEP_SHIFT = 1, LPM1_POWER_MODE0 = 0x20, LPM1_POWER_MODE1 = 0x40,
  LPM1_POWER_MODE2 = 0x80, _LPM1_POWER_MODE_MASK = 7, _LPM1_POWER_MODE_SHIFT = 5
}
 
enum  SLEEP_DUR_T {
  SLEEP_DUR_2 = 0, SLEEP_DUR_4 = 1, SLEEP_DUR_5 = 2, SLEEP_DUR_8 = 3,
  SLEEP_DUR_10 = 4, SLEEP_DUR_15 = 5, SLEEP_DUR_18 = 6, SLEEP_DUR_20 = 7
}
 
enum  POWER_MODE_T { POWER_MODE_NORMAL = 0, POWER_MODE_DEEP_SUSPEND = 1, POWER_MODE_SUSPEND = 4 }
 
enum  LPM2_BITS_T {
  _LPM2_RESERVED_BITS = 0x08, LPM2_AUTOSLEEP_DUR0 = 0x01, LPM2_AUTOSLEEP_DUR1 = 0x02, LPM2_AUTOSLEEP_DUR2 = 0x04,
  _LPM2_AUTOSLEEP_DUR_MASK = 7, _LPM2_AUTOSLEEP_DUR_SHIFT = 0, LPM2_EXT_TRIG_SEL0 = 0x10, LPM2_EXT_TRIG_SEL1 = 0x20,
  _LPM2_EXT_TRIG_SEL_MASK = 3, _LPM2_EXT_TRIG_SEL_SHIFT = 4, LPM2_POWER_SAVE_MODE = 0x40, LPM2_FAST_POWERUP = 0x80
}
 
enum  AUTOSLEEP_DUR_T {
  AUTOSLEEP_DUR_NONE = 0, AUTOSLEEP_DUR_4MS = 1, AUTOSLEEP_DUR_5MS = 2, AUTOSLEEP_DUR_8MS = 3,
  AUTOSLEEP_DUR_10MS = 4, AUTOSLEEP_DUR_15MS = 5, AUTOSLEEP_DUR_20MS = 6, AUTOSLEEP_DUR_40MS = 7
}
 
enum  EXT_TRIG_SEL_T { EXT_TRIG_SEL_NONE = 0, EXT_TRIG_SEL_INT1 = 1, EXT_TRIG_SEL_INT2 = 2, EXT_TRIG_SEL_SDO = 3 }
 
enum  RATE_HBW_BITS_T { _RATE_HBW_RESERVED_BITS = 0x0f | 0x10 | 0x20, RATE_HBW_SHADOW_DIS = 0x40, RATE_HBW_DATA_HIGH_BW = 0x80 }
 
enum  INT_EN_0_BITS_T { _INT_EN_0_RESERVED_BITS = 0x20 | 0x10 | 0x08 | 0x02 | 0x01, INT_EN_0_AUTO_OFFSET_EN = 0x04, INT_EN_0_FIFO_EN = 0x40, INT_EN_0_DATA_EN = 0x80 }
 
enum  INT_EN_1_BITS_T {
  _INT_EN_1_INT1_RESERVED_BITS = 0xf0, INT_EN_1_INT1_LVL = 0x01, INT_EN_1_INT1_OD = 0x02, INT_EN_1_INT2_LVL = 0x04,
  INT_EN_1_INT2_OD = 0x08
}
 
enum  INT_MAP_0_BITS_T { _INT_MAP_0_RESERVED_BITS = 0xf0 | 0x04 | 0x01, INT_MAP_0_INT1_ANY = 0x02, INT_MAP_0_INT1_HIGH = 0x08 }
 
enum  INT_MAP_1_BITS_T {
  INT_MAP_1_INT1_DATA = 0x01, INT_MAP_1_INT1_FAST_OFFSET = 0x02, INT_MAP_1_INT1_FIFO = 0x04, INT_MAP_1_INT1_AUTO_OFFSET = 0x08,
  INT_MAP_1_INT2_AUTO_OFFSET = 0x10, INT_MAP_1_INT2_FIFO = 0x20, INT_MAP_1_INT2_FAST_OFFSET = 0x40, INT_MAP_1_INT2_DATA = 0x80
}
 
enum  INT_1A_BITS_T { _INT_1A_RESERVED_BITS = 0xd5, INT_1A_ANY_UNFILT_DATA = 0x02, INT_1A_HIGH_UNFILT_DATA = 0x08, INT_1A_SLOW_OFFSET_UNFILT = 0x20 }
 
enum  INT_1B_BITS_T {
  INT_1B_ANY_TH0 = 0x01, INT_1B_ANY_TH1 = 0x02, INT_1B_ANY_TH2 = 0x04, INT_1B_ANY_TH3 = 0x08,
  INT_1B_ANY_TH4 = 0x10, INT_1B_ANY_TH5 = 0x20, INT_1B_ANY_TH6 = 0x40, _INT_1B_ANY_TH_MASK = 127,
  _INT_1B_ANY_TH_SHIFT = 0, INT_1B_FAST_OFFSET_UNFILT = 0x80
}
 
enum  INT_1C_BITS_T {
  _INT_1C_RESERVED_BITS = 0x08, INT_1C_ANY_EN_X = 0x01, INT_1C_ANY_EN_Y = 0x02, INT_1C_ANY_EN_Z = 0x04,
  INT_1C_ANY_DUR_SAMPLE0 = 0x10, INT_1C_ANY_DUR_SAMPLE1 = 0x20, INT_1C_ANY_DUR_SAMPLE_MASK = 3, INT_1C_ANY_DUR_SAMPLE_SHIFT = 4,
  INT_1C_AWAKE_DUR0 = 0x40, INT_1C_AWAKE_DUR1 = 0x80, INT_1C_AWAKE_DUR_MASK = 3, INT_1C_AWAKE_DUR_SHIFT = 6
}
 
enum  ANY_DUR_SAMPLE_T { ANY_DUR_SAMPLE_4 = 0, ANY_DUR_SAMPLE_8 = 1, ANY_DUR_SAMPLE_12 = 2, ANY_DUR_SAMPLE_16 = 3 }
 
enum  AWAKE_DUR_SAMPLE_T { AWAKE_DUR_SAMPLE_8 = 0, AWAKE_DUR_SAMPLE_16 = 1, AWAKE_DUR_SAMPLE_32 = 2, AWAKE_DUR_SAMPLE_64 = 3 }
 
enum  INT_1E_BITS_T { _INT_1E_RESERVED_BITS = 0x7f, INT_1E_FIFO_WM_EN = 0x80 }
 
enum  INT_RST_LATCH_BITS_T {
  _INT_RST_LATCH_RESERVED_BITS = 0x20, INT_RST_LATCH0 = 0x01, INT_RST_LATCH1 = 0x02, INT_RST_LATCH2 = 0x04,
  INT_RST_LATCH3 = 0x08, _INT_RST_LATCH_MASK = 15, _INT_RST_LATCH_SHIFT = 0, INT_RST_LATCH_STATUS_BIT = 0x10,
  INT_RST_LATCH_OFFSET_RESET = 0x40, INT_RST_LATCH_RESET_INT = 0x80
}
 
enum  RST_LATCH_T {
  RST_LATCH_NON_LATCHED = 0, RST_LATCH_TEMPORARY_250MS = 1, RST_LATCH_TEMPORARY_500MS = 2, RST_LATCH_TEMPORARY_1S = 3,
  RST_LATCH_TEMPORARY_2S = 4, RST_LATCH_TEMPORARY_4S = 5, RST_LATCH_TEMPORARY_8S = 6, RST_LATCH_LATCHED = 7,
  RST_LATCH_TEMPORARY_250US = 9, RST_LATCH_TEMPORARY_500US = 10, RST_LATCH_TEMPORARY_1MS = 11, RST_LATCH_TEMPORARY_12_5MS = 12,
  RST_LATCH_TEMPORARY_25MS = 13, RST_LATCH_TEMPORARY_50MS = 14
}
 
enum  HIGH_TH_BITS_T {
  HIGH_TH_EN = 0x01, HIGH_TH_TH0 = 0x02, HIGH_TH_TH1 = 0x04, HIGH_TH_TH2 = 0x08,
  HIGH_TH_TH3 = 0x10, HIGH_TH_TH4 = 0x20, _HIGH_TH_TH_MASK = 31, _HIGH_TH_TH_SHIFT = 1,
  HIGH_TH_HY0 = 0x40, HIGH_TH_HY1 = 0x80, _HIGH_TH_HY_MASK = 3, _HIGH_TH_HY_SHIFT = 6
}
 
enum  SOC_BITS_T {
  SOC_SLOW_OFFSET_EN_X = 0x01, SOC_SLOW_OFFSET_EN_Y = 0x02, SOC_SLOW_OFFSET_EN_Z = 0x04, SOC_SLOW_OFFSET_DUR0 = 0x08,
  SOC_SLOW_OFFSET_DUR1 = 0x10, SOC_SLOW_OFFSET_DUR2 = 0x20, _SOC_SLOW_OFFSET_DUR_MASK = 7, _SOC_SLOW_OFFSET_DUR_SHIFT = 3,
  SOC_SLOW_OFFSET_TH0 = 0x40, SOC_SLOW_OFFSET_TH1 = 0x80, _SOC_SLOW_OFFSET_TH_MASK = 3, _SOC_SLOW_OFFSET_TH_SHIFT = 6
}
 
enum  SLOW_OFFSET_DUR_T {
  SLOW_OFFSET_DUR_40MS = 0, SLOW_OFFSET_DUR_80MS = 1, SLOW_OFFSET_DUR_160MS = 2, SLOW_OFFSET_DUR_320MS = 3,
  SLOW_OFFSET_DUR_640MS = 4, SLOW_OFFSET_DUR_1280MS = 5
}
 
enum  SLOW_OFFSET_TH_T { SLOW_OFFSET_TH_0_1 = 0, SLOW_OFFSET_TH_0_2 = 1, SLOW_OFFSET_TH_0_5 = 2, SLOW_OFFSET_TH_1 = 3 }
 
enum  A_FOC_BITS_T {
  A_FOC_FAST_OFFSET_EN_X = 0x01, A_FOC_FAST_OFFSET_EN_Y = 0x02, A_FOC_FAST_OFFSET_EN_Z = 0x04, A_FOC_FAST_OFFSET_EN = 0x08,
  A_FOC_FAST_OFFSET_WORDLENGTH0 = 0x10, A_FOC_FAST_OFFSET_WORDLENGTH1 = 0x20, _A_FOC_FAST_OFFSET_WORDLENGTH_MASK = 3, _A_FOC_FAST_OFFSET_WORDLENGTH_SHIFT = 4,
  A_FOC_AUTO_OFFSET_WORDLENGTH0 = 0x40, A_FOC_AUTO_OFFSET_WORDLENGTH1 = 0x80, _A_FOC_AUTO_OFFSET_WORDLENGTH_MASK = 3, _A_FOC_AUTO_OFFSET_WORDLENGTH_SHIFT = 6
}
 
enum  FAST_OFFSET_WORDLENGTH_T { FAST_OFFSET_WORDLENGTH_32 = 0, FAST_OFFSET_WORDLENGTH_64 = 1, FAST_OFFSET_WORDLENGTH_128 = 2, FAST_OFFSET_WORDLENGTH_256 = 3 }
 
enum  AUTO_OFFSET_WORDLENGTH_T { AUTO_OFFSET_WORDLENGTH_32 = 0, AUTO_OFFSET_WORDLENGTH_64 = 1, AUTO_OFFSET_WORDLENGTH_128 = 2, AUTO_OFFSET_WORDLENGTH_256 = 3 }
 
enum  TRIM_NVM_CTRL_BITS_T {
  TRIM_NVM_CTRL_NVM_PROG_MODE = 0x01, TRIM_NVM_CTRL_NVM_PROG_TRIG = 0x02, TRIM_NVM_CTRL_NVM_PROG_RDY = 0x04, TRIM_NVM_CTRL_NVM_PROG_LOAD = 0x08,
  TRIM_NVM_CTRL_NVM_REMAIN0 = 0x10, TRIM_NVM_CTRL_NVM_REMAIN1 = 0x20, TRIM_NVM_CTRL_NVM_REMAIN2 = 0x40, TRIM_NVM_CTRL_NVM_REMAIN3 = 0x80,
  _TRIM_NVM_CTRL_NVM_REMAIN_MASK = 15, _TRIM_NVM_CTRL_NVM_REMAIN_SHIFT = 4
}
 
enum  SPI3_WDT_BITS_T { _SPI3_WDT_RESERVED_BITS = 0xf0 | 0x08, SPI3_WDT_SPI3 = 0x01, SPI3_WDT_I2C_WDT_SEL = 0x02, SPI3_WDT_I2C_WDT_EN = 0x04 }
 
enum  OFC1_OFFSET_BITS_T {
  OFC1_OFFSET_Z0 = 0x01, OFC1_OFFSET_Z1 = 0x02, OFC1_OFFSET_Z2 = 0x04, _OFC1_OFFSET_Z_MASK = 7,
  _OFC1_OFFSET_Z_SHIFT = 0, OFC1_OFFSET_Y0 = 0x08, OFC1_OFFSET_Y1 = 0x10, OFC1_OFFSET_Y2 = 0x20,
  _OFC1_OFFSET_Y_MASK = 7, _OFC1_OFFSET_Y_SHIFT = 3, OFC1_OFFSET_X0 = 0x08, OFC1_OFFSET_X1 = 0x10,
  _OFC1_OFFSET_X_MASK = 3, _OFC1_OFFSET_X_SHIFT = 6
}
 
enum  GP0_BITS_T {
  GP0_OFFSET_Z = 0x01, GP0_OFFSET_Y = 0x02, GP0_OFFSET_X0 = 0x04, GP0_OFFSET_X1 = 0x08,
  _GP0_OFFSET_X_MASK = 3, _GP0_OFFSET_X_SHIFT = 2, GP0_GP00 = 0x10, GP0_GP01 = 0x20,
  GP0_GP02 = 0x40, GP0_GP03 = 0x80, _GP0_GP0_MASK = 15, _GP0_GP0_SHIFT = 4
}
 
enum  BIST_BITS_T {
  _BIST_RESERVED_BITS = 0x80 | 0x40 | 0x20 | 0x08, BIST_TRIG_BIST = 0x01, BIST_BIST_RDY = 0x02, BIST_BIST_FAIL = 0x04,
  BIST_RATE_OK = 0x10
}
 
enum  FIFO_CONFIG_0_BITS_T {
  FIFO_CONFIG_0_WATER_MARK0 = 0x01, FIFO_CONFIG_0_WATER_MARK1 = 0x02, FIFO_CONFIG_0_WATER_MARK2 = 0x04, FIFO_CONFIG_0_WATER_MARK3 = 0x08,
  FIFO_CONFIG_0_WATER_MARK4 = 0x10, FIFO_CONFIG_0_WATER_MARK5 = 0x20, FIFO_CONFIG_0_WATER_MARK6 = 0x40, _FIFO_CONFIG_0_WATER_MARK_MASK = 127,
  _FIFO_CONFIG_0_WATER_MARK_SHIFT = 0, FIFO_CONFIG_0_TAG = 0x80
}
 
enum  FIFO_CONFIG_1_BITS_T {
  _FIFO_CONFIG_1_RESERVED_BITS = 0x20 | 0x10 |0x08 | 0x04, FIFO_CONFIG_1_FIFO_DATA_SEL0 = 0x01, FIFO_CONFIG_1_FIFO_DATA_SEL1 = 0x02, _FIFO_CONFIG_1_FIFO_DATA_SEL = 3,
  _FIFO_CONFIG_1_FIFO_DATA_SHIFT = 0, FIFO_CONFIG_1_FIFO_MODE0 = 0x40, FIFO_CONFIG_1_FIFO_MODE1 = 0x80, _FIFO_CONFIG_1_FIFO_MODE_MASK = 3,
  _FIFO_CONFIG_1_FIFO_MODE_SHIFT = 6
}
 
enum  FIFO_DATA_SEL_T { FIFO_DATA_SEL_XYZ = 0, FIFO_DATA_SEL_X = 1, FIFO_DATA_SEL_Y = 2, FIFO_DATA_SEL_Z = 3 }
 
enum  FIFO_MODE_T { FIFO_MODE_BYPASS = 0, FIFO_MODE_FIFO = 1, FIFO_MODE_STREAM = 2 }
 
enum  INTERRUPT_PINS_T { INTERRUPT_INT1, INTERRUPT_INT2 }
 

Public Member Functions

 BMG160 (int bus=BMG160_I2C_BUS, int addr=BMG160_DEFAULT_ADDR, int cs=-1)
 
 ~BMG160 ()
 
void update ()
 
uint8_t getChipID ()
 
void getGyroscope (float *x, float *y, float *z)
 
float * getGyroscope ()
 
float getTemperature (bool fahrenheit=false)
 
void init (POWER_MODE_T pwr=POWER_MODE_NORMAL, RANGE_T range=RANGE_250, BW_T bw=BW_400_47)
 
void reset ()
 
void setRange (RANGE_T range)
 
void setBandwidth (BW_T bw)
 
void setPowerMode (POWER_MODE_T power)
 
void enableFIFO (bool useFIFO)
 
void fifoSetWatermark (int wm)
 
void fifoConfig (FIFO_MODE_T mode, FIFO_DATA_SEL_T axes)
 
uint8_t getInterruptEnable0 ()
 
void setInterruptEnable0 (uint8_t bits)
 
uint8_t getInterruptMap0 ()
 
void setInterruptMap0 (uint8_t bits)
 
uint8_t getInterruptMap1 ()
 
void setInterruptMap1 (uint8_t bits)
 
uint8_t getInterruptSrc ()
 
void setInterruptSrc (uint8_t bits)
 
uint8_t getInterruptOutputControl ()
 
void setInterruptOutputControl (uint8_t bits)
 
void clearInterruptLatches ()
 
RST_LATCH_T getInterruptLatchBehavior ()
 
void setInterruptLatchBehavior (RST_LATCH_T latch)
 
uint8_t getInterruptStatus0 ()
 
uint8_t getInterruptStatus1 ()
 
uint8_t getInterruptStatus2 ()
 
uint8_t getInterruptStatus3 ()
 
void enableRegisterShadowing (bool shadow)
 
void enableOutputFiltering (bool filter)
 
void installISR (INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void(*isr)(void *), void *arg)
 
void uninstallISR (INTERRUPT_PINS_T intr)
 
uint8_t readReg (uint8_t reg)
 
int readRegs (uint8_t reg, uint8_t *buffer, int len)
 
void writeReg (uint8_t reg, uint8_t val)
 

Static Public Attributes

static const uint8_t BMG160_RESET_BYTE = 0xb6
 

Protected Member Functions

void csOn ()
 
void csOff ()
 

Protected Attributes

mraa::I2c * m_i2c
 
mraa::Spi * m_spi
 
mraa::Gpio * m_gpioCS
 
mraa::Gpio * m_gpioIntr1
 
mraa::Gpio * m_gpioIntr2
 
uint8_t m_addr
 
float m_gyrX
 
float m_gyrY
 
float m_gyrZ
 
float m_gyrScale
 
float m_temperature
 

Member Enumeration Documentation

enum BMG160_REGS_T : uint8_t

BMG160 registers

REG_INT_STATUS_0 bits

REG_INT_STATUS_1 bits

REG_INT_STATUS_2 bits

REG_INT_STATUS_3 bits

REG_FIFO_STATUS bits

REG_GYR_RANGE bits

enum RANGE_T

GYR_RANGE (gyroscope deg/s range) values

REG_GYR_BW bits

enum BW_T

GYR_BW (gyroscope filter bandwidth) values

REG_LPM1 bits

SLEEP_DUR values

POWER_MODE values

REG_LPM2 bits

LPM2_AUTOSLEEP_DUR values

LPM2_EXT_TRIG_SEL values

REG_RATE_HBW bits

REG_INT_EN_0 bits

REG_INT_EN_1 bits

REG_INT_MAP_0 bits

REG_INT_MAP_1 bits

REG_INT_1A bits

REG_INT_1B bits

REG_INT_1C bits

INT_1C_ANY_DUR_SAMPLE values

INT_1C_AWAKE_DUR values

REG_INT_1E bits

REG_INT_RST_LATCH bits

RST_LATCH values

REG_HIGH_TH_* (X, Y, and Z) register bits

enum SOC_BITS_T

REG_SOC bits

SOC_SLOW_OFFSET_DUR values

SOC_SLOW_OFFSET_TH values

REG_A_FOC bits

FAST_OFFSET_WORDLENGTH values

AUTO_OFFSET_WORDLENGTH values

REG_TRIM_NVM_CTRL bits

REG_SPI3_WDT bits

REG_OFC1 bits, the missing x, y, and z llsb bits are in GP0

enum GP0_BITS_T

REG_GP0 bits

REG_BIST bits

REG_FIFO_CONFIG_0 bits

REG_FIFO_CONFIG_1 bits

FIFO_DATA_SEL values

FIFO_MODE values

Constructor & Destructor Documentation

BMG160 ( int  bus = BMG160_I2C_BUS,
int  addr = BMG160_DEFAULT_ADDR,
int  cs = -1 
)

BMG160 constructor.

This device can support both I2C and SPI. For SPI, set the addr to -1, and specify a positive integer representing the Chip Select (CS) pin for the cs argument. If you are using a hardware CS pin (like edison with arduino breakout), then you can connect the proper pin to the hardware CS pin on your MCU and supply -1 for cs. The default operating mode is I2C.

Parameters
busI2C or SPI bus to use.
addrThe address for this device. -1 for SPI.
csThe gpio pin to use for the SPI Chip Select. -1 for I2C or for SPI with a hardware controlled pin.
theChipIDThe chip ID to use for validation

Here is the call graph for this function:

~BMG160 ( )

BMG160 Destructor.

Here is the call graph for this function:

Member Function Documentation

void update ( void  )

Update the internal stored values from sensor data.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t getChipID ( )

Return the chip ID.

Returns
The chip ID (BMG160_CHIPID).

Here is the call graph for this function:

Here is the caller graph for this function:

void getGyroscope ( float *  x,
float *  y,
float *  z 
)

Return gyroscope data in degrees per second. update() must have been called prior to calling this method.

Parameters
xPointer to a floating point value that will have the current x component placed into it.
yPointer to a floating point value that will have the current y component placed into it.
zPointer to a floating point value that will have the current z component placed into it.

Here is the caller graph for this function:

float * getGyroscope ( )

Return gyroscope data in degrees per second in the form of a floating point array. The pointer returned by this function is statically allocated and will be rewritten on each call. update() must have been called prior to calling this method.

Returns
A floating point array containing x, y, and z in that order.
float getTemperature ( bool  fahrenheit = false)

Return the current measured temperature. Note, this is not ambient temperature. update() must have been called prior to calling this method.

Parameters
fahrenheittrue to return data in Fahrenheit, false for Celicus. Celsius is the default.
Returns
The temperature in degrees Celsius or Fahrenheit.
void init ( POWER_MODE_T  pwr = POWER_MODE_NORMAL,
RANGE_T  range = RANGE_250,
BW_T  bw = BW_400_47 
)

Initialize the device and start operation. This function is called from the constructor so will not typically need to be called by a user unless the device is reset.

Parameters
pwrOne of the POWER_MODE_T values. The default is POWER_MODE_NORMAL.
rangeOne of the RANGE_T values. The default is RANGE_250.
bwOne of the filtering BW_T values. The default is BW_400_47.

Here is the call graph for this function:

Here is the caller graph for this function:

void reset ( )

Reset the device as if during a power on reset. All configured values are lost when this happens. You should call init() afterwards, or at least perform the same initialization init() does before continuing.

Here is the call graph for this function:

void setRange ( RANGE_T  range)

Set the gyroscope detection scaling range. This device supports 125, 250, 500, 100, and 2000 degree/s ranges.

Parameters
rangeOne of the RANGE_T values.

Here is the call graph for this function:

Here is the caller graph for this function:

void setBandwidth ( BW_T  bw)

Set the output filtering bandwidth of the device.

Parameters
bwOne of the BW_T values.

Here is the call graph for this function:

Here is the caller graph for this function:

void setPowerMode ( POWER_MODE_T  power)

Set the power mode of the device. Care must be taken when setting a low power or suspend mode. See the datasheet for details. I ncertain power modes, register write must be drastically slowed down. which we cannot support.

Parameters
powerOne of the POWER_MODE_T values.

Here is the call graph for this function:

Here is the caller graph for this function:

void enableFIFO ( bool  useFIFO)

Enable update() to read from the FIFO rather than the gyroscope axis registers directly. init() enables this mode by default. An advantage to this mode that all axis data is sampled from the same timeslice. When reading directly from the gyroscope output registers, it's possible for one axis to be updated while another is being read, causing a temporal inconsistancy..

Using the FIFO removes this problem.

Parameters
useFIFOtrue to enable update() to read from the FIFO. When false, update will read from the gyroscope output registers directly.

Here is the caller graph for this function:

void fifoSetWatermark ( int  wm)

Set the FIFO watermark. When the watermark is reached an interrupt (if enabled) will be generated.

Parameters
wmThe FIFO watermark to use. The maximum value is 63.

Here is the call graph for this function:

void fifoConfig ( FIFO_MODE_T  mode,
FIFO_DATA_SEL_T  axes 
)

Set the FIFO configuration. init() uses the FIFO_MODE_BYPASS mode with axes set to FIFO_DATA_SEL_XYZ by default.

Parameters
modeOne of the FIFO_MODE_T values.
axesOne of the FIFO_DATA_SEL_T values.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t getInterruptEnable0 ( )

Return the Interrupt Enables 0 register. These resgisters allow you to enable various interrupt conditions. See the datasheet for details.

Returns
A bitmask of INT_EN_0_BITS_T bits.

Here is the call graph for this function:

void setInterruptEnable0 ( uint8_t  bits)

Set the Interrupt Enables 0 register. See the datasheet for details.

Parameters
bitsA bitmask of INT_EN_0_BITS_T bits.

Here is the call graph for this function:

uint8_t getInterruptMap0 ( )

Return the Interrupt Map 0 register. These registers allow you to map specific interrupts to the interrupt 1 or interrupt 2 pin. See the datasheet for details.

Returns
A bitmask of INT_MAP_0_BITS_T bits.

Here is the call graph for this function:

void setInterruptMap0 ( uint8_t  bits)

Set the Interrupt Map 0 register. These registers allow you to map specific interrupts to the interrupt 1 or interrupt 2 pin. See the datasheet for details.

Parameters
Abitmask of INT_MAP_0_BITS_T bits.

Here is the call graph for this function:

uint8_t getInterruptMap1 ( )

Return the Interrupt Map 1 register. See the datasheet for details.

Returns
A bitmask of INT_MAP_1_BITS_T bits.

Here is the call graph for this function:

void setInterruptMap1 ( uint8_t  bits)

Set the Interrupt Map 1 register. See the datasheet for details.

Parameters
Abitmask of INT_MAP_1_BITS_T bits.

Here is the call graph for this function:

uint8_t getInterruptSrc ( )

Return the Interrupt source register. This register allows determining where data comes from (filtered/unfiltered) for those interrupt sources where this is selectable. See the datasheet for details.

Returns
A bitmask of INT_1A_BITS_T bits.

Here is the call graph for this function:

void setInterruptSrc ( uint8_t  bits)

Set the Interrupt source register. This register allows determining where data comes from (filtered/unfiltered) for those interrupt sources where this is selectable. See the datasheet for details.

Parameters
bitsA bitmask of INT_1A_BITS_T bits.

Here is the call graph for this function:

uint8_t getInterruptOutputControl ( )

Return the Interrupt output control register. This register allows determining the electrical characteristics of the 2 interrupt pins (open-drain/push-pull and level/edge triggering). See the datasheet for details.

Returns
A bitmask of INT_EN_1_BITS_T bits.

Here is the call graph for this function:

void setInterruptOutputControl ( uint8_t  bits)

Set the Interrupt output control register. This register allows determining the electrical characteristics of the 2 interrupt pins (open-drain/push-pull and level/edge triggering). See the datasheet for details.

Parameters
bitsA bitmask of INT_EN_1_BITS_T bits.

Here is the call graph for this function:

void clearInterruptLatches ( )

Clear all latched interrupts. See the datasheet for details.

Here is the call graph for this function:

BMG160::RST_LATCH_T getInterruptLatchBehavior ( )

Return the current interrupt latching behavior. See the datasheet for details.

Returns
One of the RST_LATCH_T values.

Here is the call graph for this function:

void setInterruptLatchBehavior ( RST_LATCH_T  latch)

Set the current interrupt latching behavior. See the datasheet for details.

Parameters
latchOne of the RST_LATCH_T values.

Here is the call graph for this function:

uint8_t getInterruptStatus0 ( )

Return the interrupt status 0 register. These registers indicate which interrupts have been triggered. See the datasheet for details.

Returns
a bitmask of INT_STATUS_0_BITS_T bits.

Here is the call graph for this function:

uint8_t getInterruptStatus1 ( )

Return the interrupt status 1 register. See the datasheet for details.

Returns
a bitmask of INT_STATUS_1_BITS_T bits.

Here is the call graph for this function:

uint8_t getInterruptStatus2 ( )

Return the interrupt status 2 register. See the datasheet for details.

Returns
a bitmask of INT_STATUS_2_BITS_T bits.

Here is the call graph for this function:

uint8_t getInterruptStatus3 ( )

Return the interrupt status 3 register. See the datasheet for details.

Returns
a bitmask of INT_STATUS_3_BITS_T bits.

Here is the call graph for this function:

void enableRegisterShadowing ( bool  shadow)

Enable shadowing of the gyroscope output registers. When enabled, a read of an axis LSB register automatically locks the MSB register of that axis until it has been read. This is usually a good thing to have enabled. init() enables this by default. If disabled, then it becomes possible for part of an axis value to change while another part is being read, causing inconsistent data.

Parameters
shadowtrue to enable axis register shadowing, false otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

void enableOutputFiltering ( bool  filter)

Enable filtering of the gyroscope axis data. init() enables this by default. If disabled, then gyroscope data that is read will be raw and unfiltered (rated R). See the datasheet for details.

Parameters
filtertrue to enable filtering, false to disable.

Here is the call graph for this function:

Here is the caller graph for this function:

void installISR ( INTERRUPT_PINS_T  intr,
int  gpio,
mraa::Edge  level,
void(*)(void *)  isr,
void *  arg 
)

install an interrupt handler.

Parameters
introne of the INTERRUPT_PINS_T values specifying which interrupt pin you are installing.
gpiogpio pin to use as interrupt pin
levelthe interrupt trigger level (one of mraa::Edge values). Make sure that you have configured the interrupt pin properly for whatever level you choose.
isrthe interrupt handler, accepting a void * argument
argthe argument to pass the the interrupt handler

Here is the call graph for this function:

void uninstallISR ( INTERRUPT_PINS_T  intr)

uninstall a previously installed interrupt handler

Parameters
introne of the INTERRUPT_PINS_T values specifying which interrupt pin you are removing.

Here is the caller graph for this function:

uint8_t readReg ( uint8_t  reg)

Read a register.

Parameters
regThe register to read.
Returns
The value of the register.

Here is the caller graph for this function:

int readRegs ( uint8_t  reg,
uint8_t *  buffer,
int  len 
)

Read contiguous registers into a buffer.

Parameters
bufferThe buffer to store the results.
lenThe number of registers to read.
Returns
The number of bytes read.

Here is the caller graph for this function:

void writeReg ( uint8_t  reg,
uint8_t  val 
)

Write to a register

Parameters
regThe register to write to.
valThe value to write.

Here is the caller graph for this function:


The documentation for this class was generated from the following files: