iio: Remove iio structures from mraa_platform_t
authorBrendan Le Foll <brendan.le.foll@intel.com>
Tue, 6 Oct 2015 10:51:56 +0000 (11:51 +0100)
committerBrendan Le Foll <brendan.le.foll@intel.com>
Tue, 15 Dec 2015 10:42:06 +0000 (10:42 +0000)
This means that a valid platform is no longer required for iio operations and
therefore this is now only a req for using USBPLAT

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
include/mraa_internal.h
include/mraa_internal_types.h
src/iio/iio.c
src/mraa.c

index 93babe7..7b5968d 100644 (file)
@@ -35,6 +35,7 @@ extern "C" {
 #include "mraa_adv_func.h"
 
 extern mraa_board_t* plat;
+extern mraa_iio_info_t* plat_iio;
 
 /**
  * Takes in pin information and sets up the multiplexors.
index 640fb38..3eb54f8 100644 (file)
@@ -284,9 +284,10 @@ typedef struct _board_t {
     mraa_pininfo_t* pins;     /**< Pointer to pin array */
     mraa_adv_func_t* adv_func;    /**< Pointer to advanced function disptach table */
     struct _board_t* sub_platform;     /**< Pointer to sub platform */
-    struct _iio* iio_devices; /**< Pointer to IIO devices */
-    uint8_t iio_device_count; /**< IIO device count */
     /*@}*/
 } mraa_board_t;
 
-
+typedef struct {
+    struct _iio* iio_devices; /**< Pointer to IIO devices */
+    uint8_t iio_device_count; /**< IIO device count */
+} mraa_iio_info_t;
index dcf80d4..8093b89 100644 (file)
 mraa_iio_context
 mraa_iio_init(int device)
 {
-    if (device > plat->iio_device_count) {
+    if (device > plat_iio->iio_device_count) {
         return NULL;
     }
 
-    mraa_iio_get_channel_data(&plat->iio_devices[device]);
-    return &plat->iio_devices[device];
+    mraa_iio_get_channel_data(&plat_iio->iio_devices[device]);
+    return &plat_iio->iio_devices[device];
 }
 
 int
index f54eaab..9dbffd3 100644 (file)
@@ -47,7 +47,7 @@
 
 #define MAX_PLATFORM_NAME_LENGTH 128
 mraa_board_t* plat = NULL;
-// static mraa_board_t* current_plat = NULL;
+mraa_iio_info_t* plat_iio = NULL;
 
 static char platform_name[MAX_PLATFORM_NAME_LENGTH];
 
@@ -128,15 +128,15 @@ mraa_init()
     if (plat != NULL)
         plat->platform_type = platform_type;
 
+#if defined(USBPLAT)
     // This is a platform extender so create null base platform if one doesn't already exist
     if (plat == NULL) {
         plat = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
         if (plat != NULL) {
             plat->platform_type = MRAA_NULL_PLATFORM;
-            plat->platform_name = "Null platform";
+            plat->platform_name = "Unknown platform";
         }
     }
-#if defined(USBPLAT)
     // Now detect sub platform
     if (plat != NULL) {
         mraa_platform_t usb_platform_type = mraa_usb_platform_extender(plat);
@@ -152,6 +152,7 @@ mraa_init()
     }
 #endif
 
+    plat_iio = (mraa_iio_info_t*) calloc(1, sizeof(mraa_iio_info_t));
     // Now detect IIO devices, linux only
     // find how many i2c buses we have if we haven't already
     if (num_iio_devices == 0) {
@@ -161,11 +162,11 @@ mraa_init()
     }
     char name[64], filepath[64];
     int fd, len, i;
-    plat->iio_device_count = num_iio_devices;
-    plat->iio_devices = calloc(num_iio_devices, sizeof(struct _iio));
+    plat_iio->iio_device_count = num_iio_devices;
+    plat_iio->iio_devices = calloc(num_iio_devices, sizeof(struct _iio));
     struct _iio* device;
     for (i=0; i < num_iio_devices; i++) {
-        device = &plat->iio_devices[i];
+        device = &plat_iio->iio_devices[i];
         device->num = i;
         snprintf(filepath, 64, "/sys/bus/iio/devices/iio:device%d/name", i);
         fd = open(filepath, O_RDONLY);
@@ -201,6 +202,9 @@ mraa_deinit()
         free(plat);
 
     }
+    if (plat_iio != NULL) {
+        free(plat_iio);
+    }
     closelog();
 }
 
@@ -764,14 +768,14 @@ mraa_get_sub_platform_index(int pin_or_bus)
 int
 mraa_get_iio_device_count()
 {
-    return plat->iio_device_count;
+    return plat_iio->iio_device_count;
 }
 
 int
 mraa_find_iio_device(const char* devicename)
 {
     int i = 0;
-    for (i; i < plat->iio_device_count; i++) {
+    for (i; i < plat_iio->iio_device_count; i++) {
 #if 0
         // compare with devices array
         if (!strcmp() {