mraa_result_t mraa_setup_mux_mapped(mraa_pin_t meta);
/**
- * Will check input is valid for aio and will also setup required multiplexers.
- * @param pin the pin as read from the board surface. i.e A3 would be 3/
- * @return the pin as found in the pinmap
- */
-unsigned int mraa_setup_aio(int pin);
-
-/**
* Setup i2c interface, sets up multiplexer on device.
*
* @return unsigned int if using /dev/i2c-2 returned would be 2
dev->adc_in_fp = open(file_path, O_RDONLY);
if (dev->adc_in_fp == -1) {
- syslog(LOG_ERR, "aio: Failed to open input raw file %s for reading!",
+ syslog(LOG_ERR, "aio: Failed to open input raw file %s for reading!",
file_path);
return MRAA_ERROR_INVALID_RESOURCE;
}
}
mraa_aio_context
-mraa_aio_init(unsigned int aio_channel)
+mraa_aio_init(unsigned int aio)
{
+ if (plat == NULL) {
+ syslog(LOG_ERR, "aio: Platform not initialised");
+ return NULL;
+ }
if (advance_func->aio_init_pre != NULL) {
- mraa_result_t pre_ret = (advance_func->aio_init_pre(aio_channel));
+ mraa_result_t pre_ret = (advance_func->aio_init_pre(aio));
if (pre_ret != MRAA_SUCCESS)
return NULL;
}
+ if (aio < 0 || aio > plat->aio_count) {
+ syslog(LOG_ERR, "aio: requested channel out of range");
+ return NULL;
+ }
+
+ int pin = aio + plat->gpio_count;
- int checked_pin = mraa_setup_aio(aio_channel);
- if (checked_pin < 0) {
- switch (checked_pin) {
- case MRAA_NO_SUCH_IO:
- syslog(LOG_ERR, "aio: Invalid input channel %d specified",
- aio_channel);
- return NULL;
- case MRAA_IO_SETUP_FAILURE:
- syslog(LOG_ERR, "aio: Failed to set-up input channel %d "
- "multiplexer", aio_channel);
- return NULL;
- case MRAA_PLATFORM_NO_INIT:
- syslog(LOG_ERR, "aio: Platform not initialised");
- return NULL;
- default:
- return NULL;
+ if (plat->pins[pin].capabilites.aio != 1) {
+ syslog(LOG_ERR, "aio: pin uncapable of aio");
+ return NULL;
+ }
+
+ if (plat->pins[pin].aio.mux_total > 0) {
+ if (mraa_setup_mux_mapped(plat->pins[pin].aio) != MRAA_SUCCESS) {
+ syslog(LOG_ERR, "aio: unable to setup multiplexers for pin");
+ return NULL;
}
}
mraa_aio_context dev = malloc(sizeof(struct _aio));
if (dev == NULL) {
syslog(LOG_ERR, "aio: Insufficient memory for specified input channel "
- "%d\n", aio_channel);
+ "%d\n", aio);
return NULL;
}
- dev->channel = checked_pin;
+ dev->channel = plat->pins[pin].aio.pinmap;
dev->value_bit = DEFAULT_BITS;
//Open valid analog input file and get the pointer.
}
unsigned int
-mraa_setup_aio(int aio)
-{
- if (plat == NULL)
- return MRAA_PLATFORM_NO_INIT;
-
- if (aio < 0 || aio > plat->aio_count)
- return MRAA_NO_SUCH_IO;
-
- int pin = aio + plat->gpio_count;
-
- if (plat->pins[pin].capabilites.aio != 1)
- return MRAA_NO_SUCH_IO;
-
- if (plat->pins[pin].aio.mux_total > 0)
- if (mraa_setup_mux_mapped(plat->pins[pin].aio) != MRAA_SUCCESS)
- return MRAA_NO_SUCH_IO;
- return plat->pins[pin].aio.pinmap;
-}
-
-unsigned int
mraa_setup_i2c(int* bus)
{
if (plat == NULL)