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