aio: move aio setup from core into module
authorThomas Ingleby <thomas.c.ingleby@intel.com>
Mon, 3 Nov 2014 15:16:33 +0000 (15:16 +0000)
committerThomas Ingleby <thomas.c.ingleby@intel.com>
Mon, 17 Nov 2014 17:40:48 +0000 (17:40 +0000)
Added additional syslog messages for debugging

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
include/mraa_internal.h
src/aio/aio.c
src/mraa.c

index e0df290..1b460ff 100644 (file)
@@ -46,13 +46,6 @@ extern mraa_board_t* plat;
 mraa_result_t mraa_setup_mux_mapped(mraa_pin_t meta);
 
 /**
- * Will check input is valid for aio and will also setup required multiplexers.
- * @param pin the pin as read from the board surface. i.e A3 would be 3/
- * @return the pin as found in the pinmap
- */
-unsigned int mraa_setup_aio(int pin);
-
-/**
  * Setup i2c interface, sets up multiplexer on device.
  *
  * @return unsigned int if using /dev/i2c-2 returned would be 2
index dd131ff..30ccbfb 100644 (file)
@@ -47,7 +47,7 @@ aio_get_valid_fp(mraa_aio_context dev)
 
     dev->adc_in_fp = open(file_path, O_RDONLY);
     if (dev->adc_in_fp == -1) {
-       syslog(LOG_ERR, "aio: Failed to open input raw file %s for reading!",
+        syslog(LOG_ERR, "aio: Failed to open input raw file %s for reading!",
                 file_path);
         return MRAA_ERROR_INVALID_RESOURCE;
     }
@@ -56,30 +56,33 @@ aio_get_valid_fp(mraa_aio_context dev)
 }
 
 mraa_aio_context
-mraa_aio_init(unsigned int aio_channel)
+mraa_aio_init(unsigned int aio)
 {
+    if (plat == NULL) {
+        syslog(LOG_ERR, "aio: Platform not initialised");
+        return NULL;
+    }
     if (advance_func->aio_init_pre != NULL) {
-        mraa_result_t pre_ret = (advance_func->aio_init_pre(aio_channel));
+        mraa_result_t pre_ret = (advance_func->aio_init_pre(aio));
         if (pre_ret != MRAA_SUCCESS)
             return NULL;
     }
+    if (aio < 0 || aio > plat->aio_count) {
+        syslog(LOG_ERR, "aio: requested channel out of range");
+        return NULL;
+    }
+
+    int pin = aio + plat->gpio_count;
 
-    int checked_pin = mraa_setup_aio(aio_channel);
-    if (checked_pin < 0) {
-        switch (checked_pin) {
-            case MRAA_NO_SUCH_IO:
-                syslog(LOG_ERR, "aio: Invalid input channel %d specified",
-                        aio_channel);
-                return NULL;
-            case MRAA_IO_SETUP_FAILURE:
-                syslog(LOG_ERR, "aio: Failed to set-up input channel %d "
-                        "multiplexer", aio_channel);
-                return NULL;
-            case MRAA_PLATFORM_NO_INIT:
-                syslog(LOG_ERR, "aio: Platform not initialised");
-                return NULL;
-            default:
-                return NULL;
+    if (plat->pins[pin].capabilites.aio != 1) {
+        syslog(LOG_ERR, "aio: pin uncapable of aio");
+        return NULL;
+    }
+
+    if (plat->pins[pin].aio.mux_total > 0) {
+        if (mraa_setup_mux_mapped(plat->pins[pin].aio) != MRAA_SUCCESS) {
+            syslog(LOG_ERR, "aio: unable to setup multiplexers for pin");
+            return NULL;
         }
     }
 
@@ -87,10 +90,10 @@ mraa_aio_init(unsigned int aio_channel)
     mraa_aio_context dev = malloc(sizeof(struct _aio));
     if (dev == NULL) {
         syslog(LOG_ERR, "aio: Insufficient memory for specified input channel "
-                "%d\n", aio_channel);
+                "%d\n", aio);
         return NULL;
     }
-    dev->channel = checked_pin;
+    dev->channel = plat->pins[pin].aio.pinmap;
     dev->value_bit = DEFAULT_BITS;
 
     //Open valid  analog input file and get the pointer.
index 377cc19..97267f2 100644 (file)
@@ -166,26 +166,6 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
 }
 
 unsigned int
-mraa_setup_aio(int aio)
-{
-    if (plat == NULL)
-        return MRAA_PLATFORM_NO_INIT;
-
-    if (aio < 0 || aio > plat->aio_count)
-        return MRAA_NO_SUCH_IO;
-
-    int pin = aio + plat->gpio_count;
-
-    if (plat->pins[pin].capabilites.aio != 1)
-      return MRAA_NO_SUCH_IO;
-
-    if (plat->pins[pin].aio.mux_total > 0)
-       if (mraa_setup_mux_mapped(plat->pins[pin].aio) != MRAA_SUCCESS)
-            return MRAA_NO_SUCH_IO;
-    return plat->pins[pin].aio.pinmap;
-}
-
-unsigned int
 mraa_setup_i2c(int* bus)
 {
     if (plat == NULL)