i2c: move i2c setup from core into module
authorThomas Ingleby <thomas.c.ingleby@intel.com>
Mon, 3 Nov 2014 15:44:40 +0000 (15:44 +0000)
committerThomas Ingleby <thomas.c.ingleby@intel.com>
Mon, 17 Nov 2014 17:40:48 +0000 (17:40 +0000)
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
include/mraa_internal.h
src/i2c/i2c.c
src/mraa.c

index 1b460ff..964f34a 100644 (file)
@@ -45,13 +45,6 @@ extern mraa_board_t* plat;
  */
 mraa_result_t mraa_setup_mux_mapped(mraa_pin_t meta);
 
-/**
- * Setup i2c interface, sets up multiplexer on device.
- *
- * @return unsigned int if using /dev/i2c-2 returned would be 2
- */
-unsigned int mraa_setup_i2c(int* bus);
-
 /** Setup spi interface, sets up multiplexer on device.
  *
  * @return spi bus type
index e05fd91..637e411 100644 (file)
 mraa_i2c_context
 mraa_i2c_init(int bus)
 {
-    int checked_pin = mraa_setup_i2c(&bus);
-    if (checked_pin < 0) {
-        switch(checked_pin) {
-            case MRAA_NO_SUCH_IO:
-                syslog(LOG_ERR, "i2c: No i2c on board");
-                return NULL;
-            case MRAA_IO_SETUP_FAILURE:
-                syslog(LOG_ERR, "i2c: Failed to set-up i2c multiplexer");
-                return NULL;
-            case MRAA_PLATFORM_NO_INIT:
-                syslog(LOG_ERR, "i2c: Platform Not Initialised");
-                return NULL;
-            default: return NULL;
-        }
+    if (plat == NULL) {
+        syslog(LOG_ERR, "i2c: Platform Not Initialised");
+        return NULL;
+    }
+    if (plat->i2c_bus_count == 0) {
+        syslog(LOG_ERR, "No i2c buses defined in platform");
+        return NULL;
+    }
+    if (bus >= plat->i2c_bus_count) {
+        syslog(LOG_ERR, "Above i2c bus count");
+        return NULL;
+    }
+
+    if (plat->i2c_bus[bus].bus_id == -1) {
+        syslog(LOG_ERR, "Invalid i2c bus, moving to default i2c bus");
+        bus = plat->def_i2c_bus;
     }
-    return mraa_i2c_init_raw((unsigned int) checked_pin);
+
+    int pos = plat->i2c_bus[bus].sda;
+    if (plat->pins[pos].i2c.mux_total > 0)
+        if (mraa_setup_mux_mapped(plat->pins[pos].i2c) != MRAA_SUCCESS) {
+            syslog(LOG_ERR, "i2c: Failed to set-up i2c sda multiplexer");
+            return NULL;
+        }
+
+    pos = plat->i2c_bus[bus].scl;
+    if (plat->pins[pos].i2c.mux_total > 0)
+        if (mraa_setup_mux_mapped(plat->pins[pos].i2c) != MRAA_SUCCESS) {
+            syslog(LOG_ERR, "i2c: Failed to set-up i2c scl multiplexer");
+            return NULL;
+        }
+
+    return mraa_i2c_init_raw((unsigned int) plat->i2c_bus[bus].bus_id);
 }
 
 mraa_i2c_context
index 97267f2..2457d0c 100644 (file)
@@ -165,39 +165,6 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
     return MRAA_SUCCESS;
 }
 
-unsigned int
-mraa_setup_i2c(int* bus)
-{
-    if (plat == NULL)
-        return MRAA_PLATFORM_NO_INIT;
-
-    if (plat->i2c_bus_count == 0) {
-        syslog(LOG_ERR, "No i2c buses defined in platform");
-        return MRAA_NO_SUCH_IO;
-    }
-    if (*bus >= plat->i2c_bus_count) {
-        syslog(LOG_ERR, "Above i2c bus count");
-        return MRAA_NO_SUCH_IO;
-    }
-
-    if (plat->i2c_bus[*bus].bus_id == -1) {
-        syslog(LOG_ERR, "Invalid i2c bus, moving to default i2c bus");
-        *bus = plat->def_i2c_bus;
-    }
-
-    int pos = plat->i2c_bus[*bus].sda;
-    if (plat->pins[pos].i2c.mux_total > 0)
-        if (mraa_setup_mux_mapped(plat->pins[pos].i2c) != MRAA_SUCCESS)
-             return MRAA_IO_SETUP_FAILURE;
-
-    pos = plat->i2c_bus[*bus].scl;
-    if (plat->pins[pos].i2c.mux_total > 0)
-        if (mraa_setup_mux_mapped(plat->pins[pos].i2c) != MRAA_SUCCESS)
-             return MRAA_IO_SETUP_FAILURE;
-
-    return plat->i2c_bus[*bus].bus_id;
-}
-
 mraa_spi_bus_t*
 mraa_setup_spi(int bus)
 {