Private
Public Access
2
0

i2c: Work started on using pinmap with i2c

* Update examples and swig interface.

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
This commit is contained in:
Thomas Ingleby
2014-05-02 16:07:18 +01:00
parent 1005df1652
commit 64d3c78ca9
7 changed files with 80 additions and 9 deletions

View File

@@ -26,16 +26,41 @@
#include "smbus.h"
maa_i2c_context*
maa_i2c_init()
maa_i2c_init(int bus)
{
unsigned int checked_pin = maa_check_i2c(bus);
if (checked_pin < 0) {
switch(checked_pin) {
case -1:
fprintf(stderr, "No i2c on board\n");
return NULL;
case -2:
fprintf(stderr, "Failed to set-up i2c multiplexer!\n");
return NULL;
case -3:
fprintf(stderr, "Platform Not Initialised");
return NULL;
default: return NULL;
}
}
return maa_i2c_init_raw(checked_pin);
}
maa_i2c_context*
maa_i2c_init_raw(unsigned int bus)
{
if (bus < 0) {
fprintf(stderr, "Bus -%u- bellow zero\n", bus);
return NULL;
}
maa_i2c_context* dev = (maa_i2c_context*) malloc(sizeof(maa_i2c_context));
if (dev == NULL)
return NULL;
// Galileo only has one I2C master which should be /dev/i2c-0
// reliability is a fickle friend!
if ((dev->fh = open("/dev/i2c-0", O_RDWR)) < 1) {
fprintf(stderr, "Failed to open requested i2c port");
char filepath[32];
snprintf(filepath, 32, "/dev/i2c-%u", bus);
if ((dev->fh = open(filepath, O_RDWR)) < 1) {
fprintf(stderr, "Failed to open requested i2c port %s", filepath);
}
return dev;
}