aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2015-01-03 17:45:25 +0100
committerLorenz Meier <lm@inf.ethz.ch>2015-01-03 17:54:48 +0100
commit268cf7efc59057119d261838157e17d6c2d318f6 (patch)
tree3e0011f2691134643721b1dd0c82c81351b58a47 /src
parentf3e3565d1ba827f20c8cc724a56c8e429b0cc7cc (diff)
downloadpx4-firmware-268cf7efc59057119d261838157e17d6c2d318f6.tar.gz
px4-firmware-268cf7efc59057119d261838157e17d6c2d318f6.tar.bz2
px4-firmware-268cf7efc59057119d261838157e17d6c2d318f6.zip
HMC5883: Fix I2C operation
Diffstat (limited to 'src')
-rw-r--r--src/drivers/hmc5883/hmc5883.cpp30
-rw-r--r--src/drivers/hmc5883/hmc5883_i2c.cpp2
2 files changed, 23 insertions, 9 deletions
diff --git a/src/drivers/hmc5883/hmc5883.cpp b/src/drivers/hmc5883/hmc5883.cpp
index 5989703dd..80b2c5f13 100644
--- a/src/drivers/hmc5883/hmc5883.cpp
+++ b/src/drivers/hmc5883/hmc5883.cpp
@@ -1330,16 +1330,28 @@ start(int external_bus, enum Rotation rotation)
/* create the driver, only attempt I2C for the external bus */
if (interface == nullptr && (HMC5883_I2C_interface != nullptr)) {
interface = HMC5883_I2C_interface(PX4_I2C_BUS_EXPANSION);
+
+ if (interface->init() != OK) {
+ delete interface;
+ interface = nullptr;
+ warnx("no device on I2C bus #%u", PX4_I2C_BUS_EXPANSION);
+ }
}
- if (interface == nullptr) {
- warnx("failed to allocate an interface");
+#ifdef PX4_I2C_BUS_ONBOARD
+ if (interface == nullptr && (HMC5883_I2C_interface != nullptr)) {
+ interface = HMC5883_I2C_interface(PX4_I2C_BUS_ONBOARD);
+
+ if (interface->init() != OK) {
+ delete interface;
+ interface = nullptr;
+ warnx("no device on I2C bus #%u", PX4_I2C_BUS_ONBOARD);
+ }
}
+#endif
- if (interface->init() != OK) {
- delete interface;
- warnx("interface init failed");
- } else {
+ /* interface will be null if init failed */
+ if (interface != nullptr) {
g_dev_ext = new HMC5883(interface, HMC5883L_DEVICE_PATH_EXT, rotation);
if (g_dev_ext != nullptr && OK != g_dev_ext->init()) {
@@ -1367,17 +1379,19 @@ start(int external_bus, enum Rotation rotation)
#endif
#ifdef PX4_I2C_BUS_ONBOARD
+ /* this device is already connected as external if present above */
if (interface == nullptr && (HMC5883_I2C_interface != nullptr)) {
interface = HMC5883_I2C_interface(PX4_I2C_BUS_ONBOARD);
}
#endif
if (interface == nullptr) {
- warnx("failed to allocate an interface");
+ warnx("no internal bus scanned");
+ goto fail;
}
if (interface->init() != OK) {
delete interface;
- warnx("interface init failed");
+ warnx("no device on internal bus");
} else {
g_dev_int = new HMC5883(interface, HMC5883L_DEVICE_PATH_INT, rotation);
diff --git a/src/drivers/hmc5883/hmc5883_i2c.cpp b/src/drivers/hmc5883/hmc5883_i2c.cpp
index 2d3e8fa08..782ea62fe 100644
--- a/src/drivers/hmc5883/hmc5883_i2c.cpp
+++ b/src/drivers/hmc5883/hmc5883_i2c.cpp
@@ -88,7 +88,7 @@ HMC5883_I2C_interface(int bus)
}
HMC5883_I2C::HMC5883_I2C(int bus) :
- I2C("HMC5883_I2C", nullptr, bus, 0, 400000)
+ I2C("HMC5883_I2C", nullptr, bus, HMC5883L_ADDRESS, 400000)
{
}