diff options
author | Mark Charlebois <charlebm@gmail.com> | 2015-03-17 13:57:33 -0700 |
---|---|---|
committer | Mark Charlebois <charlebm@gmail.com> | 2015-04-20 11:13:24 -0700 |
commit | 13d84ef17b3c3793579e5f84bae4fa42154571b0 (patch) | |
tree | 215d47b910079cee4293fcd51991af136c715fd6 /src/drivers | |
parent | df53defca6887fc5889a5aa1fe56434b431fece8 (diff) | |
download | px4-firmware-13d84ef17b3c3793579e5f84bae4fa42154571b0.tar.gz px4-firmware-13d84ef17b3c3793579e5f84bae4fa42154571b0.tar.bz2 px4-firmware-13d84ef17b3c3793579e5f84bae4fa42154571b0.zip |
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 <charlebm@gmail.com>
Diffstat (limited to 'src/drivers')
-rw-r--r-- | src/drivers/blinkm/blinkm_linux.cpp | 4 | ||||
-rw-r--r-- | 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 e38fb408e..5a139a710 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 1a3492c8f..e62da8797 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; } |