Skip to content

Commit

Permalink
Peripheralman: Remove IIO from ioinit for android
Browse files Browse the repository at this point in the history
Since peripheral manager does not build in the IIO source, ifdef's were
added around the initio functionality for IIO.

IMO this is an ugly fix, but I don't see a better way since the
PERIPHERALMAN architecture is qualified throughout the CMake and source
with ifdef's.

Signed-off-by: Noel Eck <[email protected]>
  • Loading branch information
noel-eck committed Jul 24, 2018
1 parent 4487c98 commit 6fe510a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions api/mraa/initio.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ extern "C" {
#include "aio.h"
#include "gpio.h"
#include "i2c.h"

#if !defined(PERIPHERALMAN)
#include "iio.h"
#endif

#include "pwm.h"
#include "spi.h"
#include "uart.h"
Expand All @@ -53,8 +57,10 @@ typedef struct _mraa_io_descriptor {
mraa_gpio_context* gpios;
int n_i2c;
mraa_i2c_context* i2cs;
#if !defined(PERIPHERALMAN)
int n_iio;
mraa_iio_context* iios;
#endif
int n_pwm;
mraa_pwm_context* pwms;
int n_spi;
Expand Down
10 changes: 10 additions & 0 deletions api/mraa/initio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
#include "aio.hpp"
#include "gpio.hpp"
#include "i2c.hpp"

#if !defined(PERIPHERALMAN)
#include "iio.hpp"
#endif

#include "pwm.hpp"
#include "spi.hpp"
#include "uart.hpp"
Expand Down Expand Up @@ -67,10 +71,12 @@ class MraaIo
i2cs.emplace_back(descs->i2cs[i]);
}

#if !defined(PERIPHERALMAN)
iios.reserve(descs->n_iio);
for (int i = 0; i < descs->n_iio; ++i) {
iios.emplace_back(descs->iios[i]);
}
#endif

pwms.reserve(descs->n_pwm);
for (int i = 0; i < descs->n_pwm; ++i) {
Expand Down Expand Up @@ -116,9 +122,11 @@ class MraaIo
if (descs->n_i2c) {
free(descs->i2cs);
}
#if !defined(PERIPHERALMAN)
if (descs->n_iio) {
free(descs->iios);
}
#endif
if (descs->n_pwm) {
free(descs->pwms);
}
Expand All @@ -140,7 +148,9 @@ class MraaIo
std::vector<Aio> aios;
std::vector<Gpio> gpios;
std::vector<I2c> i2cs;
#if !defined(PERIPHERALMAN)
std::vector<Iio> iios;
#endif
std::vector<Pwm> pwms;
std::vector<Spi> spis;
std::vector<Uart> uarts;
Expand Down
12 changes: 10 additions & 2 deletions src/initio/initio.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ parse_pwm(char** proto, size_t n)
return dev;
}

#if !defined(PERIPHERALMAN)
static mraa_iio_context
parse_iio(char** proto, size_t n)
{
Expand All @@ -313,6 +314,7 @@ parse_iio(char** proto, size_t n)

return dev;
}
#endif

static mraa_i2c_context
parse_i2c(char** proto, size_t n)
Expand Down Expand Up @@ -633,7 +635,9 @@ mraa_io_init(const char* strdesc, mraa_io_descriptor** desc)
new_desc->gpios[new_desc->n_gpio++] = dev;
}
}
} else if (strncmp(str_tokens[0], IIO_KEY, strlen(IIO_KEY)) == 0 &&
}
#if !defined(PERIPHERALMAN)
else if (strncmp(str_tokens[0], IIO_KEY, strlen(IIO_KEY)) == 0 &&
strlen(str_tokens[0]) == strlen(IIO_KEY)) {
mraa_iio_context dev = parse_iio(str_tokens, num_desc_tokens);
if (!dev) {
Expand All @@ -650,7 +654,9 @@ mraa_io_init(const char* strdesc, mraa_io_descriptor** desc)
new_desc->iios[new_desc->n_iio++] = dev;
}
}
} else if (strncmp(str_tokens[0], I2C_KEY, strlen(I2C_KEY)) == 0 &&
}
#endif
else if (strncmp(str_tokens[0], I2C_KEY, strlen(I2C_KEY)) == 0 &&
strlen(str_tokens[0]) == strlen(I2C_KEY)) {
mraa_i2c_context dev = parse_i2c(str_tokens, num_desc_tokens);
if (!dev) {
Expand Down Expand Up @@ -807,12 +813,14 @@ mraa_io_close(mraa_io_descriptor* desc)
free(desc->i2cs);
}

#if !defined(PERIPHERALMAN)
for (int i = 0; i < desc->n_iio; ++i) {
mraa_iio_close(desc->iios[i]);
}
if (desc->n_iio) {
free(desc->iios);
}
#endif

for (int i = 0; i < desc->n_pwm; ++i) {
mraa_pwm_close(desc->pwms[i]);
Expand Down

0 comments on commit 6fe510a

Please sign in to comment.