From bdb76d013eb97c681aa2206e250adbb33c5ee9cb Mon Sep 17 00:00:00 2001 From: Michael Schaeuble Date: Fri, 9 Dec 2016 11:55:16 +0100 Subject: [PATCH] Fix incorrect MPU9250 device ID We propagate the bus parameters from the bus interface to the sensor devices. Thus, the device ID of the sensor driver is set to the correct bus id and address. Otherwise it would be zero, which is an issue if several MPU9250s are running at the same time. --- src/drivers/device/device_nuttx.h | 14 ++++++++++++++ src/drivers/mpu9250/mpu9250.cpp | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/src/drivers/device/device_nuttx.h b/src/drivers/device/device_nuttx.h index 6ea64d228c..706f5bd134 100644 --- a/src/drivers/device/device_nuttx.h +++ b/src/drivers/device/device_nuttx.h @@ -130,6 +130,20 @@ public: */ virtual int ioctl(unsigned operation, unsigned &arg); + /** + * Return the bus ID the device is connected to. + * + * @return The bus ID + */ + virtual uint8_t get_device_bus() {return _device_id.devid_s.bus;}; + + /** + * Return the bus address of the device. + * + * @return The bus address + */ + virtual uint8_t get_device_address() {return _device_id.devid_s.address;}; + /* device bus types for DEVID */ diff --git a/src/drivers/mpu9250/mpu9250.cpp b/src/drivers/mpu9250/mpu9250.cpp index b78fb35a00..8a33fbb3ce 100644 --- a/src/drivers/mpu9250/mpu9250.cpp +++ b/src/drivers/mpu9250/mpu9250.cpp @@ -166,11 +166,17 @@ MPU9250::MPU9250(device::Device *interface, device::Device *mag_interface, const // disable debug() calls _debug_enabled = false; + /* Set device parameters and make sure parameters of the bus device are adopted */ _device_id.devid_s.devtype = DRV_ACC_DEVTYPE_MPU9250; + _device_id.devid_s.bus = _interface->get_device_bus();; + _device_id.devid_s.address = _interface->get_device_address();; /* Prime _gyro with parents devid. */ + /* Set device parameters and make sure parameters of the bus device are adopted */ _gyro->_device_id.devid = _device_id.devid; _gyro->_device_id.devid_s.devtype = DRV_GYR_DEVTYPE_MPU9250; + _gyro->_device_id.devid_s.bus = _interface->get_device_bus(); + _gyro->_device_id.devid_s.address = _interface->get_device_address(); /* Prime _mag with parents devid. */ _mag->_device_id.devid = _device_id.devid;