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>
This commit is contained in:
Mark Charlebois 2015-03-17 13:57:33 -07:00
parent df53defca6
commit 13d84ef17b
2 changed files with 12 additions and 2 deletions

View File

@ -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) {

View File

@ -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;
}