aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJianxun Zhang <jianxun.zhang@intel.com>2015-10-19 00:41:34 -0700
committerMihai Tudor Panu <mihai.tudor.panu@intel.com>2015-11-30 14:54:06 -0800
commitac21c9336bfac7017f2e511edfbfa997b5781baa (patch)
tree173499dd1be0ae2a6d3db3ef09132c1734150f4b
parentfd509c7d790991c6ce65c4613d3ab92de71e5113 (diff)
mpu9150: option to disable I2C bypass setting
The existing hardcoded logic enables i2c bypass mode for AK8975. This can cause the accelerometer to disappear on I2C bus. We add a new member as a switch that can be used to disable bypass. Change-Id: I2c61f4910d46ffb5940bb3c14b58bc65984fd12e Signed-off-by: Jianxun Zhang <jianxun.zhang@intel.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
-rw-r--r--src/mpu9150/mpu9150.cxx41
-rw-r--r--src/mpu9150/mpu9150.h5
2 files changed, 27 insertions, 19 deletions
diff --git a/src/mpu9150/mpu9150.cxx b/src/mpu9150/mpu9150.cxx
index a4463a9..a253e84 100644
--- a/src/mpu9150/mpu9150.cxx
+++ b/src/mpu9150/mpu9150.cxx
@@ -31,11 +31,12 @@
using namespace upm;
using namespace std;
-MPU9150::MPU9150 (int bus, int address, int magAddress) :
+MPU9150::MPU9150 (int bus, int address, int magAddress, bool enableAk8975) :
m_mag(0), MPU60X0(bus, address)
{
m_magAddress = magAddress;
m_i2cBus = bus;
+ m_enableAk8975 = enableAk8975;
}
MPU9150::~MPU9150()
@@ -54,26 +55,30 @@ bool MPU9150::init()
return false;
}
- // Now, we need to enable I2C bypass on the MPU60X0 component. This
- // will allow us to access the AK8975 Magnetometer on I2C addr 0x0c.
- if (!enableI2CBypass(true))
+ // Enabling I2C bypass will allow us to access the
+ // AK8975 Magnetometer on I2C addr 0x0c.
+ if (m_enableAk8975 == true)
{
- throw std::runtime_error(std::string(__FUNCTION__) +
- ": Unable to enable I2C bypass");
- return false;
- }
+ if (!enableI2CBypass(true))
+ {
+ throw std::runtime_error(std::string(__FUNCTION__) +
+ ": Unable to enable I2C bypass");
+ return false;
+ }
- // Now that we've done that, create an AK8975 instance and
- // initialize it.
- m_mag = new AK8975(m_i2cBus, m_magAddress);
+ // Now that we've done that, create an AK8975 instance and
+ // initialize it.
- if (!m_mag->init())
- {
- throw std::runtime_error(std::string(__FUNCTION__) +
- ": Unable to init magnetometer");
- delete m_mag;
- m_mag = 0;
- return false;
+ m_mag = new AK8975(m_i2cBus, m_magAddress);
+
+ if (!m_mag->init())
+ {
+ throw std::runtime_error(std::string(__FUNCTION__) +
+ ": Unable to init magnetometer");
+ delete m_mag;
+ m_mag = 0;
+ return false;
+ }
}
return true;
diff --git a/src/mpu9150/mpu9150.h b/src/mpu9150/mpu9150.h
index 32a6944..6567962 100644
--- a/src/mpu9150/mpu9150.h
+++ b/src/mpu9150/mpu9150.h
@@ -66,9 +66,11 @@ namespace upm {
* @param bus I2C bus to use
* @param address The address for this device
* @param magAddress The address of the connected magnetometer
+ * @param enableAk8975 Enables i2c bypass mode for magnetometer, default
+ * is true
*/
MPU9150 (int bus=MPU9150_I2C_BUS, int address=MPU9150_DEFAULT_I2C_ADDR,
- int magAddress=AK8975_DEFAULT_I2C_ADDR);
+ int magAddress=AK8975_DEFAULT_I2C_ADDR, bool enableAk8975=true);
/**
* MPU9150 destructor
@@ -126,6 +128,7 @@ namespace upm {
private:
int m_i2cBus;
uint8_t m_magAddress;
+ bool m_enableAk8975;
};
}