From 13d84ef17b3c3793579e5f84bae4fa42154571b0 Mon Sep 17 00:00:00 2001 From: Mark Charlebois Date: Tue, 17 Mar 2015 13:57:33 -0700 Subject: [PATCH] Linux: I2C opens /dev/i2c-x For now it uses the bus number as the id. Not sure how this should actually be mapped. Seems like the I2C devices come up in random order and have random id but that a specific device can be found in the /sys/bus/i2c interface. Signed-off-by: Mark Charlebois --- src/drivers/blinkm/blinkm_linux.cpp | 4 ++++ src/drivers/device/i2c_linux.cpp | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/drivers/blinkm/blinkm_linux.cpp b/src/drivers/blinkm/blinkm_linux.cpp index e38fb408e7..5a139a710a 100644 --- a/src/drivers/blinkm/blinkm_linux.cpp +++ b/src/drivers/blinkm/blinkm_linux.cpp @@ -943,6 +943,10 @@ blinkm_main(int argc, char *argv[]) int x; + if (argc < 2) { + blinkm_usage(); + return 1; + } for (x = 1; x < argc; x++) { if (strcmp(argv[x], "-b") == 0 || strcmp(argv[x], "--bus") == 0) { if (argc > x + 1) { diff --git a/src/drivers/device/i2c_linux.cpp b/src/drivers/device/i2c_linux.cpp index 1a3492c8f2..e62da87979 100644 --- a/src/drivers/device/i2c_linux.cpp +++ b/src/drivers/device/i2c_linux.cpp @@ -97,9 +97,15 @@ I2C::init() return ret; } - _fd = ::open(_dname.c_str(), O_RDWR); + // Open the actual I2C device and map to the virtual dev name + char str[22]; + + // Fixme - not sure bus is the right mapping here + // may have to go through /sys/bus/i2c interface to find the right map + snprintf(str, sizeof(str), "/dev/i2c-%d", _bus); + _fd = ::open(str, O_RDWR); if (_fd < 0) { - warnx("could not open %s", _dname.c_str()); + warnx("could not open %s for virtual device %s", str, _dname.c_str()); return -errno; }