+ // Now detect IIO devices, linux only
+ // find how many i2c buses we have if we haven't already
+ if (num_iio_devices == 0) {
+ if (nftw("/sys/bus/iio/devices", &mraa_count_iio_devices, 20, FTW_PHYS) == -1) {
+ return MRAA_ERROR_UNSPECIFIED;
+ }
+ }
+ 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));
+ struct _iio* device;
+ for (i=0; i < num_iio_devices; i++) {
+ device = &plat->iio_devices[i];
+ device->num = i;
+ snprintf(filepath, 64, "/sys/bus/iio/devices/iio:device%d", i);
+ fd = open(filepath, O_RDONLY);
+ if (fd != -1) {
+ len = read(fd, &name, 64);
+ device->name = malloc((sizeof(char) * len) + sizeof(char));
+ strncpy(device->name, name, len);
+ }
+ }
+