Private
Public Access
2
0

aio: move aio setup from core into module

Added additional syslog messages for debugging

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
This commit is contained in:
Thomas Ingleby
2014-11-03 15:16:33 +00:00
parent 401f0cfe65
commit 66c5011cfb
3 changed files with 24 additions and 48 deletions

View File

@@ -45,13 +45,6 @@ extern mraa_board_t* plat;
*/
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.
*

View File

@@ -47,7 +47,7 @@ aio_get_valid_fp(mraa_aio_context dev)
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;
}
@@ -56,30 +56,33 @@ aio_get_valid_fp(mraa_aio_context dev)
}
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 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;
int pin = aio + plat->gpio_count;
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;
}
}
@@ -87,10 +90,10 @@ mraa_aio_init(unsigned int aio_channel)
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.

View File

@@ -165,26 +165,6 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
return MRAA_SUCCESS;
}
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)
{