Private
Public Access
2
0

iio: Remove iio structures from mraa_platform_t

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>
This commit is contained in:
Brendan Le Foll
2015-10-06 11:51:56 +01:00
parent 529cf8a26e
commit 65614f5f58
4 changed files with 20 additions and 14 deletions

View File

@@ -35,6 +35,7 @@ extern "C" {
#include "mraa_adv_func.h" #include "mraa_adv_func.h"
extern mraa_board_t* plat; extern mraa_board_t* plat;
extern mraa_iio_info_t* plat_iio;
/** /**
* Takes in pin information and sets up the multiplexors. * Takes in pin information and sets up the multiplexors.

View File

@@ -284,9 +284,10 @@ typedef struct _board_t {
mraa_pininfo_t* pins; /**< Pointer to pin array */ mraa_pininfo_t* pins; /**< Pointer to pin array */
mraa_adv_func_t* adv_func; /**< Pointer to advanced function disptach table */ mraa_adv_func_t* adv_func; /**< Pointer to advanced function disptach table */
struct _board_t* sub_platform; /**< Pointer to sub platform */ 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; } 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;

View File

@@ -37,12 +37,12 @@
mraa_iio_context mraa_iio_context
mraa_iio_init(int device) mraa_iio_init(int device)
{ {
if (device > plat->iio_device_count) { if (device > plat_iio->iio_device_count) {
return NULL; return NULL;
} }
mraa_iio_get_channel_data(&plat->iio_devices[device]); mraa_iio_get_channel_data(&plat_iio->iio_devices[device]);
return &plat->iio_devices[device]; return &plat_iio->iio_devices[device];
} }
int int

View File

@@ -47,7 +47,7 @@
#define MAX_PLATFORM_NAME_LENGTH 128 #define MAX_PLATFORM_NAME_LENGTH 128
mraa_board_t* plat = NULL; 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]; static char platform_name[MAX_PLATFORM_NAME_LENGTH];
@@ -128,15 +128,15 @@ mraa_init()
if (plat != NULL) if (plat != NULL)
plat->platform_type = platform_type; plat->platform_type = platform_type;
#if defined(USBPLAT)
// This is a platform extender so create null base platform if one doesn't already exist // This is a platform extender so create null base platform if one doesn't already exist
if (plat == NULL) { if (plat == NULL) {
plat = (mraa_board_t*) calloc(1, sizeof(mraa_board_t)); plat = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
if (plat != NULL) { if (plat != NULL) {
plat->platform_type = MRAA_NULL_PLATFORM; plat->platform_type = MRAA_NULL_PLATFORM;
plat->platform_name = "Null platform"; plat->platform_name = "Unknown platform";
} }
} }
#if defined(USBPLAT)
// Now detect sub platform // Now detect sub platform
if (plat != NULL) { if (plat != NULL) {
mraa_platform_t usb_platform_type = mraa_usb_platform_extender(plat); mraa_platform_t usb_platform_type = mraa_usb_platform_extender(plat);
@@ -152,6 +152,7 @@ mraa_init()
} }
#endif #endif
plat_iio = (mraa_iio_info_t*) calloc(1, sizeof(mraa_iio_info_t));
// Now detect IIO devices, linux only // Now detect IIO devices, linux only
// find how many i2c buses we have if we haven't already // find how many i2c buses we have if we haven't already
if (num_iio_devices == 0) { if (num_iio_devices == 0) {
@@ -161,11 +162,11 @@ mraa_init()
} }
char name[64], filepath[64]; char name[64], filepath[64];
int fd, len, i; int fd, len, i;
plat->iio_device_count = num_iio_devices; plat_iio->iio_device_count = num_iio_devices;
plat->iio_devices = calloc(num_iio_devices, sizeof(struct _iio)); plat_iio->iio_devices = calloc(num_iio_devices, sizeof(struct _iio));
struct _iio* device; struct _iio* device;
for (i=0; i < num_iio_devices; i++) { for (i=0; i < num_iio_devices; i++) {
device = &plat->iio_devices[i]; device = &plat_iio->iio_devices[i];
device->num = i; device->num = i;
snprintf(filepath, 64, "/sys/bus/iio/devices/iio:device%d/name", i); snprintf(filepath, 64, "/sys/bus/iio/devices/iio:device%d/name", i);
fd = open(filepath, O_RDONLY); fd = open(filepath, O_RDONLY);
@@ -201,6 +202,9 @@ mraa_deinit()
free(plat); free(plat);
} }
if (plat_iio != NULL) {
free(plat_iio);
}
closelog(); closelog();
} }
@@ -764,14 +768,14 @@ mraa_get_sub_platform_index(int pin_or_bus)
int int
mraa_get_iio_device_count() mraa_get_iio_device_count()
{ {
return plat->iio_device_count; return plat_iio->iio_device_count;
} }
int int
mraa_find_iio_device(const char* devicename) mraa_find_iio_device(const char* devicename)
{ {
int i = 0; int i = 0;
for (i; i < plat->iio_device_count; i++) { for (i; i < plat_iio->iio_device_count; i++) {
#if 0 #if 0
// compare with devices array // compare with devices array
if (!strcmp() { if (!strcmp() {