From bf11362daec06a4802e68626c47928b8652d8a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Wed, 7 Jun 2017 10:09:44 +0200 Subject: [PATCH] i2c_posix: fix use of wrong device path previously, get_devname() was used as the I2C device path, but on NuttX, get_devname() is the device file which the driver creates. This patch changes it, so the sematics are the same as on NuttX: both now use _bus to decide to which I2C bus device to talk to. I did not see any other use-cases than the led on ocpoc. --- posix-configs/ocpoc/px4.config | 2 +- src/drivers/boards/ocpoc/board_config.h | 1 - src/drivers/device/i2c_posix.cpp | 18 +++++++----------- src/drivers/drv_led.h | 4 ---- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/posix-configs/ocpoc/px4.config b/posix-configs/ocpoc/px4.config index aa386b2055..0e6f47351d 100644 --- a/posix-configs/ocpoc/px4.config +++ b/posix-configs/ocpoc/px4.config @@ -11,7 +11,7 @@ param set SYS_MC_EST_GROUP 2 df_mpu9250_wrapper start_without_mag -R 10 df_hmc5883_wrapper start df_ms5611_wrapper start -rgbled start -b /dev/i2c-1 +rgbled start -b 1 ocpoc_adc start gps start -d /dev/ttyS5 -s sensors start diff --git a/src/drivers/boards/ocpoc/board_config.h b/src/drivers/boards/ocpoc/board_config.h index 3ec75be68a..c22b6191c7 100644 --- a/src/drivers/boards/ocpoc/board_config.h +++ b/src/drivers/boards/ocpoc/board_config.h @@ -56,4 +56,3 @@ #include "../common/board_common.h" #define BOARD_MAX_LEDS 1 // Number external of LED's this board has -#define BOARD_RGBLED0_PATH "/dev/i2c-1" diff --git a/src/drivers/device/i2c_posix.cpp b/src/drivers/device/i2c_posix.cpp index 48bb3529e0..5a9fb923e9 100644 --- a/src/drivers/device/i2c_posix.cpp +++ b/src/drivers/device/i2c_posix.cpp @@ -50,7 +50,7 @@ #include #define PX4_SIMULATE_I2C 0 -static int simulate = PX4_SIMULATE_I2C; +static constexpr const int simulate = PX4_SIMULATE_I2C; namespace device { @@ -104,13 +104,6 @@ I2C::init() return ret; } - _fd = px4_open(get_devname(), PX4_F_RDONLY | PX4_F_WRONLY); - - if (_fd < 0) { - DEVICE_DEBUG("px4_open failed of device %s", get_devname()); - return PX4_ERROR; - } - #ifdef __PX4_QURT simulate = true; #endif @@ -120,11 +113,14 @@ I2C::init() } else { #ifndef __PX4_QURT - // Open the actual I2C device and map to the virtual dev name - _fd = ::open(get_devname(), O_RDWR); + + // Open the actual I2C device + char dev_path[16]; + snprintf(dev_path, sizeof(dev_path), "/dev/i2c-%i", _bus); + _fd = ::open(dev_path, O_RDWR); if (_fd < 0) { - warnx("could not open %s", get_devname()); + PX4_ERR("could not open %s", dev_path); px4_errno = errno; return PX4_ERROR; } diff --git a/src/drivers/drv_led.h b/src/drivers/drv_led.h index 9f8d73ca2c..48a7c1d747 100644 --- a/src/drivers/drv_led.h +++ b/src/drivers/drv_led.h @@ -57,8 +57,4 @@ // set the queue size to the number of LED's, so that each led can be controlled individually static const int LED_UORB_QUEUE_LENGTH = BOARD_MAX_LEDS; -#if defined(BOARD_RGBLED0_PATH) -#define RGBLED0_DEVICE_PATH BOARD_RGBLED0_PATH -#else #define RGBLED0_DEVICE_PATH "/dev/rgbled0" -#endif