iio: fixed IIO device counting
[contrib/mraa.git] / src / mraa.c
1 /*
2  * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3  * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
4  * Copyright (c) 2014 Intel Corporation.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25
26 #define _GNU_SOURCE
27 #if !defined(_XOPEN_SOURCE) || _XOPEN_SOURCE < 600
28 #define _XOPEN_SOURCE 600 /* Get nftw() and S_IFSOCK declarations */
29 #endif
30
31 #include <stddef.h>
32 #include <stdlib.h>
33 #include <sched.h>
34 #include <string.h>
35 #include <pwd.h>
36 #include <glob.h>
37 #include <ftw.h>
38 #include <dirent.h>
39 #include <sys/stat.h>
40 #include <fcntl.h>
41 #include <string.h>
42 #include <stdio.h>
43
44 #include "mraa_internal.h"
45 #include "gpio.h"
46 #include "version.h"
47
48 #define MAX_PLATFORM_NAME_LENGTH 128
49 #define IIO_DEVICE_WILDCARD "iio:device*"
50 mraa_board_t* plat = NULL;
51 mraa_iio_info_t* plat_iio = NULL;
52
53 static char platform_name[MAX_PLATFORM_NAME_LENGTH];
54
55 static int num_i2c_devices = 0;
56 static int num_iio_devices = 0;
57
58 const char*
59 mraa_get_version()
60 {
61     return gVERSION;
62 }
63
64 mraa_result_t
65 mraa_set_log_level(int level)
66 {
67     if (level <= 7 && level >= 0) {
68         setlogmask(LOG_UPTO(level));
69         syslog(LOG_DEBUG, "Loglevel %d is set", level);
70         return MRAA_SUCCESS;
71     }
72     syslog(LOG_NOTICE, "Invalid loglevel %d requested", level);
73     return MRAA_ERROR_INVALID_PARAMETER;
74 }
75
76 static int
77 mraa_count_iio_devices(const char* path, const struct stat* sb, int flag, struct FTW* ftwb)
78 {
79     // we are only interested in files with specific names
80     if (fnmatch(IIO_DEVICE_WILDCARD, basename(path), 0) == 0) {
81         num_iio_devices++;
82     }
83     return 0;
84 }
85
86 #if (defined SWIGPYTHON) || (defined SWIG)
87 mraa_result_t
88 #else
89 mraa_result_t __attribute__((constructor))
90 #endif
91 mraa_init()
92 {
93     if (plat != NULL) {
94         return MRAA_ERROR_PLATFORM_ALREADY_INITIALISED;
95     }
96
97     uid_t proc_euid = geteuid();
98     struct passwd* proc_user = getpwuid(proc_euid);
99
100 #ifdef DEBUG
101     setlogmask(LOG_UPTO(LOG_DEBUG));
102 #else
103     setlogmask(LOG_UPTO(LOG_NOTICE));
104 #endif
105
106     openlog("libmraa", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
107     syslog(LOG_NOTICE, "libmraa version %s initialised by user '%s' with EUID %d",
108            mraa_get_version(), (proc_user != NULL) ? proc_user->pw_name : "<unknown>", proc_euid);
109
110 #ifdef SWIGPYTHON
111     // Initialise python threads, this allows use to grab the GIL when we are
112     // required to do so
113     Py_InitializeEx(0);
114     PyEval_InitThreads();
115 #endif
116
117     mraa_platform_t platform_type;
118 #if defined(X86PLAT)
119     // Use runtime x86 platform detection
120     platform_type = mraa_x86_platform();
121 #elif defined(ARMPLAT)
122     // Use runtime ARM platform detection
123     platform_type = mraa_arm_platform();
124 #else
125 #error mraa_ARCH NOTHING
126 #endif
127
128     if (plat != NULL)
129         plat->platform_type = platform_type;
130
131 #if defined(USBPLAT)
132     // This is a platform extender so create null base platform if one doesn't already exist
133     if (plat == NULL) {
134         plat = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
135         if (plat != NULL) {
136             plat->platform_type = MRAA_NULL_PLATFORM;
137             plat->platform_name = "Unknown platform";
138         }
139     }
140     // Now detect sub platform
141     if (plat != NULL) {
142         mraa_platform_t usb_platform_type = mraa_usb_platform_extender(plat);
143         if (plat->platform_type == MRAA_UNKNOWN_PLATFORM && usb_platform_type != MRAA_UNKNOWN_PLATFORM) {
144             plat->platform_type = usb_platform_type;
145         } else {
146             return MRAA_ERROR_PLATFORM_NOT_INITIALISED;
147         }
148     }
149     if (plat == NULL) {
150         printf("mraa: FATAL error, failed to initialise platform\n");
151         return MRAA_ERROR_PLATFORM_NOT_INITIALISED;
152     }
153 #endif
154
155     plat_iio = (mraa_iio_info_t*) calloc(1, sizeof(mraa_iio_info_t));
156     // Now detect IIO devices, linux only
157     // find how many iio devices we have if we haven't already
158     if (num_iio_devices == 0) {
159         if (nftw("/sys/bus/iio/devices", &mraa_count_iio_devices, 20, FTW_PHYS) == -1) {
160             return MRAA_ERROR_UNSPECIFIED;
161         }
162     }
163     char name[64], filepath[64];
164     int fd, len, i;
165     plat_iio->iio_device_count = num_iio_devices;
166     plat_iio->iio_devices = calloc(num_iio_devices, sizeof(struct _iio));
167     struct _iio* device;
168     for (i=0; i < num_iio_devices; i++) {
169         device = &plat_iio->iio_devices[i];
170         device->num = i;
171         snprintf(filepath, 64, "/sys/bus/iio/devices/iio:device%d/name", i);
172         fd = open(filepath, O_RDONLY);
173         if (fd > 0) {
174             len = read(fd, &name, 64);
175             if (len > 1) {
176                 // use strndup
177                 device->name = malloc((sizeof(char) * len) + sizeof(char));
178                 strncpy(device->name, name, len);
179             }
180             close(fd);
181         }
182     }
183
184     syslog(LOG_NOTICE, "libmraa initialised for platform '%s' of type %d", mraa_get_platform_name(), mraa_get_platform_type());
185     return MRAA_SUCCESS;
186 }
187
188 void
189 mraa_deinit()
190 {
191     if (plat != NULL) {
192         if (plat->pins != NULL) {
193             free(plat->pins);
194         }
195         mraa_board_t* sub_plat = plat->sub_platform;
196         if (sub_plat != NULL) {
197             if (sub_plat->pins != NULL) {
198                 free(sub_plat->pins);
199             }
200             free(sub_plat);
201         }
202         free(plat);
203
204     }
205     if (plat_iio != NULL) {
206         free(plat_iio);
207     }
208     closelog();
209 }
210
211 int
212 mraa_set_priority(const unsigned int priority)
213 {
214     struct sched_param sched_s;
215
216     memset(&sched_s, 0, sizeof(struct sched_param));
217     if (priority > sched_get_priority_max(SCHED_RR)) {
218         sched_s.sched_priority = sched_get_priority_max(SCHED_RR);
219     } else {
220         sched_s.sched_priority = priority;
221     }
222
223     return sched_setscheduler(0, SCHED_RR, &sched_s);
224 }
225
226 mraa_result_t
227 mraa_setup_mux_mapped(mraa_pin_t meta)
228 {
229     int mi;
230
231     for (mi = 0; mi < meta.mux_total; mi++) {
232         mraa_gpio_context mux_i;
233         mux_i = mraa_gpio_init_raw(meta.mux[mi].pin);
234         if (mux_i == NULL) {
235             return MRAA_ERROR_INVALID_HANDLE;
236         }
237         // this function will sometimes fail, however this is not critical as
238         // long as the write succeeds - Test case galileo gen2 pin2
239         mraa_gpio_dir(mux_i, MRAA_GPIO_OUT);
240         mraa_gpio_owner(mux_i, 0);
241
242         if (mraa_gpio_write(mux_i, meta.mux[mi].value) != MRAA_SUCCESS) {
243             mraa_gpio_close(mux_i);
244             return MRAA_ERROR_INVALID_RESOURCE;
245         }
246         mraa_gpio_close(mux_i);
247     }
248
249     return MRAA_SUCCESS;
250 }
251
252 void
253 mraa_result_print(mraa_result_t result)
254 {
255     switch (result) {
256         case MRAA_SUCCESS:
257             fprintf(stdout, "MRAA: SUCCESS\n");
258             break;
259         case MRAA_ERROR_FEATURE_NOT_IMPLEMENTED:
260             fprintf(stdout, "MRAA: Feature not implemented.\n");
261             break;
262         case MRAA_ERROR_FEATURE_NOT_SUPPORTED:
263             fprintf(stdout, "MRAA: Feature not supported by Hardware.\n");
264             break;
265         case MRAA_ERROR_INVALID_VERBOSITY_LEVEL:
266             fprintf(stdout, "MRAA: Invalid verbosity level.\n");
267             break;
268         case MRAA_ERROR_INVALID_PARAMETER:
269             fprintf(stdout, "MRAA: Invalid parameter.\n");
270             break;
271         case MRAA_ERROR_INVALID_HANDLE:
272             fprintf(stdout, "MRAA: Invalid Handle.\n");
273             break;
274         case MRAA_ERROR_NO_RESOURCES:
275             fprintf(stdout, "MRAA: No resources.\n");
276             break;
277         case MRAA_ERROR_INVALID_RESOURCE:
278             fprintf(stdout, "MRAA: Invalid resource.\n");
279             break;
280         case MRAA_ERROR_INVALID_QUEUE_TYPE:
281             fprintf(stdout, "MRAA: Invalid Queue Type.\n");
282             break;
283         case MRAA_ERROR_NO_DATA_AVAILABLE:
284             fprintf(stdout, "MRAA: No Data available.\n");
285             break;
286         case MRAA_ERROR_INVALID_PLATFORM:
287             fprintf(stdout, "MRAA: Platform not recognised.\n");
288             break;
289         case MRAA_ERROR_PLATFORM_NOT_INITIALISED:
290             fprintf(stdout, "MRAA: Platform not initialised.\n");
291             break;
292         case MRAA_ERROR_PLATFORM_ALREADY_INITIALISED:
293             fprintf(stdout, "MRAA: Platform already initialised.\n");
294             break;
295         case MRAA_ERROR_UNSPECIFIED:
296             fprintf(stdout, "MRAA: Unspecified Error.\n");
297             break;
298         default:
299             fprintf(stdout, "MRAA: Unrecognised error.\n");
300             break;
301     }
302 }
303
304
305 mraa_boolean_t
306 mraa_has_sub_platform()
307 {
308     return (plat != NULL) && (plat->sub_platform != NULL);
309 }
310
311 mraa_boolean_t
312 mraa_pin_mode_test(int pin, mraa_pinmodes_t mode)
313 {
314     if (plat == NULL)
315         return 0;
316
317     mraa_board_t* current_plat = plat;
318     if (mraa_is_sub_platform_id(pin)) {
319         current_plat = plat->sub_platform;
320         if (current_plat == NULL) {
321             syslog(LOG_ERR, "mraa_pin_mode_test: Sub platform Not Initialised");
322             return 0;
323         }
324         pin = mraa_get_sub_platform_index(pin);
325     }
326
327     if (current_plat == NULL || current_plat->platform_type == MRAA_UNKNOWN_PLATFORM) {
328         return 0;
329     }
330     if (pin > (current_plat->phy_pin_count - 1) || pin < 0)
331         return 0;
332
333     switch (mode) {
334         case MRAA_PIN_VALID:
335             if (current_plat->pins[pin].capabilites.valid == 1)
336                 return 1;
337             break;
338         case MRAA_PIN_GPIO:
339             if (current_plat->pins[pin].capabilites.gpio == 1)
340                 return 1;
341             break;
342         case MRAA_PIN_PWM:
343             if (current_plat->pins[pin].capabilites.pwm == 1)
344                 return 1;
345             break;
346         case MRAA_PIN_FAST_GPIO:
347             if (current_plat->pins[pin].capabilites.fast_gpio == 1)
348                 return 1;
349             break;
350         case MRAA_PIN_SPI:
351             if (current_plat->pins[pin].capabilites.spi == 1)
352                 return 1;
353             break;
354         case MRAA_PIN_I2C:
355             if (current_plat->pins[pin].capabilites.i2c == 1)
356                 return 1;
357             break;
358         case MRAA_PIN_AIO:
359             if (current_plat->pins[pin].capabilites.aio == 1)
360                 return 1;
361             break;
362         case MRAA_PIN_UART:
363             if (current_plat->pins[pin].capabilites.uart == 1)
364                 return 1;
365             break;
366         default:
367             syslog(LOG_NOTICE, "requested pinmode invalid");
368             break;
369     }
370     return 0;
371 }
372
373 mraa_platform_t
374 mraa_get_platform_type()
375 {
376     if (plat == NULL)
377         return MRAA_UNKNOWN_PLATFORM;
378     return plat->platform_type;
379 }
380
381 int
382 mraa_get_platform_combined_type()
383 {
384     int type = mraa_get_platform_type();
385     int sub_type = mraa_has_sub_platform() ? plat->sub_platform->platform_type : MRAA_UNKNOWN_PLATFORM;
386     return type | (sub_type << 8);
387 }
388
389 unsigned int
390 mraa_adc_raw_bits()
391 {
392     if (plat == NULL)
393         return 0;
394
395     if (plat->aio_count == 0)
396         return 0;
397
398     return plat->adc_raw;
399 }
400
401 unsigned int
402 mraa_get_platform_adc_raw_bits(uint8_t platform_offset)
403 {
404     if (platform_offset == MRAA_MAIN_PLATFORM_OFFSET)
405         return mraa_adc_raw_bits();
406     else {
407         if (!mraa_has_sub_platform())
408             return 0;
409
410         if (plat->sub_platform->aio_count == 0)
411             return 0;
412
413         return plat->sub_platform->adc_raw;
414     }
415 }
416
417
418 unsigned int
419 mraa_adc_supported_bits()
420 {
421     if (plat == NULL)
422         return 0;
423
424     if (plat->aio_count == 0)
425         return 0;
426
427     return plat->adc_supported;
428 }
429
430 unsigned int
431 mraa_get_platform_adc_supported_bits(int platform_offset)
432 {
433     if (platform_offset == MRAA_MAIN_PLATFORM_OFFSET)
434         return mraa_adc_supported_bits();
435     else {
436         if (!mraa_has_sub_platform())
437             return 0;
438
439         if (plat->sub_platform->aio_count == 0)
440             return 0;
441
442         return plat->sub_platform->adc_supported;
443     }
444 }
445
446
447 char*
448 mraa_get_platform_name()
449 {
450     if (plat == NULL) {
451         return NULL;
452     }
453     if (mraa_has_sub_platform()) {
454         snprintf(platform_name, MAX_PLATFORM_NAME_LENGTH, "%s + %s", plat->platform_name, plat->sub_platform->platform_name);
455     } else {
456         strncpy(platform_name, plat->platform_name, MAX_PLATFORM_NAME_LENGTH-1);
457     }
458
459     return platform_name;
460 }
461
462 int
463 mraa_get_i2c_bus_count()
464 {
465     if (plat == NULL) {
466         return -1;
467     }
468     return plat->i2c_bus_count;
469 }
470
471 int
472 mraa_get_i2c_bus_id(unsigned i2c_bus)
473 {
474     if (plat == NULL) {
475         return -1;
476     }
477
478     if (i2c_bus >= plat->i2c_bus_count) {
479         return -1;
480     }
481
482     return plat->i2c_bus[i2c_bus].bus_id;
483 }
484
485 unsigned int
486 mraa_get_pin_count()
487 {
488     if (plat == NULL) {
489         return 0;
490     }
491     return plat->phy_pin_count;
492 }
493
494 unsigned int
495 mraa_get_platform_pin_count(uint8_t platform_offset)
496 {
497     if (platform_offset == MRAA_MAIN_PLATFORM_OFFSET)
498         return mraa_get_pin_count();
499     else {
500         if (mraa_has_sub_platform())
501            return plat->sub_platform->phy_pin_count;
502         else
503            return 0;
504     }
505 }
506
507
508 char*
509 mraa_get_pin_name(int pin)
510 {
511     if (plat == NULL)
512         return 0;
513
514     mraa_board_t* current_plat = plat;
515     if (mraa_is_sub_platform_id(pin)) {
516         current_plat = plat->sub_platform;
517         if (current_plat == NULL) {
518             syslog(LOG_ERR, "mraa_get_pin_name: Sub platform Not Initialised");
519             return 0;
520         }
521         pin = mraa_get_sub_platform_index(pin);
522     }
523
524     if (pin > (current_plat->phy_pin_count - 1) || pin < 0)
525         return NULL;
526     return (char*) current_plat->pins[pin].name;
527 }
528
529 int
530 mraa_get_default_i2c_bus(uint8_t platform_offset)
531 {
532     if (plat == NULL)
533         return -1;
534     if (platform_offset == MRAA_MAIN_PLATFORM_OFFSET) {
535         return plat->def_i2c_bus;
536     } else {
537         if (mraa_has_sub_platform())
538            return plat->sub_platform->def_i2c_bus;
539         else
540            return -1;
541     }
542 }
543
544
545 mraa_boolean_t
546 mraa_file_exist(const char* filename)
547 {
548     glob_t results;
549     results.gl_pathc = 0;
550     glob(filename, 0, NULL, &results);
551     int file_found = results.gl_pathc == 1;
552     globfree(&results);
553     return file_found;
554 }
555
556 mraa_boolean_t
557 mraa_file_contains(const char* filename, const char* content)
558 {
559     mraa_boolean_t found = 0;
560     if ((filename == NULL) || (content == NULL)) {
561         return 0;
562     }
563
564     char* file = mraa_file_unglob(filename);
565     if (file != NULL) {
566         size_t len = 1024;
567         char* line = malloc(len);
568         if (line == NULL) {
569             free(file);
570             return 0;
571         }
572         FILE* fh = fopen(file, "r");
573         if (fh == NULL) {
574             free(file);
575             free(line);
576             return 0;
577         }
578         while ((getline(&line, &len, fh) != -1) && (found == 0)) {
579             if (strstr(line, content)) {
580                 found = 1;
581                 break;
582             }
583         }
584         fclose(fh);
585         free(file);
586         free(line);
587     }
588     return found;
589 }
590
591 mraa_boolean_t
592 mraa_file_contains_both(const char* filename, const char* content, const char* content2)
593 {
594     mraa_boolean_t found = 0;
595     if ((filename == NULL) || (content == NULL)) {
596         return 0;
597     }
598
599     char* file = mraa_file_unglob(filename);
600     if (file != NULL) {
601         size_t len = 1024;
602         char* line = malloc(len);
603         if (line == NULL) {
604             free(file);
605             return 0;
606         }
607         FILE* fh = fopen(file, "r");
608         if (fh == NULL) {
609             free(file);
610             free(line);
611             return 0;
612         }
613         while ((getline(&line, &len, fh) != -1) && (found == 0)) {
614             if (strstr(line, content) && strstr(line, content2)) {
615                 found = 1;
616                 break;
617             }
618         }
619         fclose(fh);
620         free(file);
621         free(line);
622     }
623     return found;
624 }
625
626 char*
627 mraa_file_unglob(const char* filename)
628 {
629     glob_t results;
630     char* res = NULL;
631     results.gl_pathc = 0;
632     glob(filename, 0, NULL, &results);
633     if (results.gl_pathc == 1)
634         res = strdup(results.gl_pathv[0]);
635     globfree(&results);
636     return res;
637 }
638
639 mraa_boolean_t
640 mraa_link_targets(const char* filename, const char* targetname)
641 {
642     int size = 100;
643     int nchars = 0;
644     char* buffer = NULL;
645     while (nchars == 0) {
646         buffer = (char*) realloc(buffer, size);
647         if (buffer == NULL)
648             return 0;
649         nchars = readlink(filename, buffer, size);
650         if (nchars < 0) {
651             free(buffer);
652             return 0;
653         } else {
654             buffer[nchars] = '\0';
655         }
656         if (nchars >= size) {
657             size *= 2;
658             nchars = 0;
659         }
660     }
661     if (strstr(buffer, targetname)) {
662         free(buffer);
663         return 1;
664     } else {
665         free(buffer);
666         return 0;
667     }
668 }
669
670 static int
671 mraa_count_i2c_files(const char* path, const struct stat* sb, int flag, struct FTW* ftwb)
672 {
673     switch (sb->st_mode & S_IFMT) {
674         case S_IFLNK:
675             num_i2c_devices++;
676             break;
677     }
678     return 0;
679 }
680
681 int
682 mraa_find_i2c_bus(const char* devname, int startfrom)
683 {
684     char path[64];
685     int fd;
686     int i = startfrom;
687     int ret = -1;
688
689     // because feeding mraa_find_i2c_bus result back into the function is
690     // useful treat -1 as 0
691     if (startfrom < 0) {
692         startfrom = 0;
693     }
694
695     // find how many i2c buses we have if we haven't already
696     if (num_i2c_devices == 0) {
697         if (nftw("/sys/class/i2c-dev/", &mraa_count_i2c_files, 20, FTW_PHYS) == -1) {
698             return -1;
699         }
700     }
701
702     // i2c devices are numbered numerically so 0 must exist otherwise there is
703     // no i2c-dev loaded
704     if (mraa_file_exist("/sys/class/i2c-dev/i2c-0")) {
705         for (i; i < num_i2c_devices; i++) {
706             off_t size, err;
707             snprintf(path, 64, "/sys/class/i2c-dev/i2c-%u/name", i);
708             fd = open(path, O_RDONLY);
709             if (fd < 0) {
710                 break;
711             }
712             size = lseek(fd, 0, SEEK_END);
713             if (size < 0) {
714                 syslog(LOG_WARNING, "mraa: failed to seek i2c filename file");
715                 close(fd);
716                 break;
717             }
718             err = lseek(fd, 0, SEEK_SET);
719             if (err < 0) {
720                 syslog(LOG_WARNING, "mraa: failed to seek i2c filename file");
721                 close(fd);
722                 break;
723             }
724             char* value = malloc(size);
725             if (value == NULL) {
726                 syslog(LOG_ERR, "mraa: failed to allocate memory for i2c file");
727                 close(fd);
728                 break;
729             }
730             ssize_t r = read(fd, value, size);
731             if (r > 0) {
732                 if (strcasestr(value, devname) != NULL) {
733                     free(value);
734                     close(fd);
735                     return i;
736                 }
737             } else {
738                 syslog(LOG_ERR, "mraa: sysfs i2cdev failed");
739             }
740             free(value);
741             close(fd);
742         }
743     } else {
744         syslog(LOG_WARNING, "mraa: no i2c-dev detected, load i2c-dev");
745     }
746
747     return ret;
748 }
749
750 mraa_boolean_t
751 mraa_is_sub_platform_id(int pin_or_bus)
752 {
753     return (pin_or_bus & MRAA_SUB_PLATFORM_MASK) != 0;
754 }
755
756 int
757 mraa_get_sub_platform_id(int pin_or_bus)
758 {
759     return pin_or_bus | MRAA_SUB_PLATFORM_MASK;
760 }
761
762 int
763 mraa_get_sub_platform_index(int pin_or_bus)
764 {
765     return pin_or_bus & (~MRAA_SUB_PLATFORM_MASK);
766 }
767
768 int
769 mraa_get_iio_device_count()
770 {
771     return plat_iio->iio_device_count;
772 }
773
774 int
775 mraa_find_iio_device(const char* devicename)
776 {
777     int i = 0;
778     for (i; i < plat_iio->iio_device_count; i++) {
779 #if 0
780         // compare with devices array
781         if (!strcmp() {
782         }
783 #endif
784     }
785     return 0;
786 }