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:
@@ -45,13 +45,6 @@ extern mraa_board_t* plat;
|
|||||||
*/
|
*/
|
||||||
mraa_result_t mraa_setup_mux_mapped(mraa_pin_t meta);
|
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.
|
* Setup i2c interface, sets up multiplexer on device.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ aio_get_valid_fp(mraa_aio_context dev)
|
|||||||
|
|
||||||
dev->adc_in_fp = open(file_path, O_RDONLY);
|
dev->adc_in_fp = open(file_path, O_RDONLY);
|
||||||
if (dev->adc_in_fp == -1) {
|
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);
|
file_path);
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
@@ -56,30 +56,33 @@ aio_get_valid_fp(mraa_aio_context dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mraa_aio_context
|
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) {
|
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)
|
if (pre_ret != MRAA_SUCCESS)
|
||||||
return NULL;
|
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);
|
int pin = aio + plat->gpio_count;
|
||||||
if (checked_pin < 0) {
|
|
||||||
switch (checked_pin) {
|
if (plat->pins[pin].capabilites.aio != 1) {
|
||||||
case MRAA_NO_SUCH_IO:
|
syslog(LOG_ERR, "aio: pin uncapable of aio");
|
||||||
syslog(LOG_ERR, "aio: Invalid input channel %d specified",
|
return NULL;
|
||||||
aio_channel);
|
}
|
||||||
return NULL;
|
|
||||||
case MRAA_IO_SETUP_FAILURE:
|
if (plat->pins[pin].aio.mux_total > 0) {
|
||||||
syslog(LOG_ERR, "aio: Failed to set-up input channel %d "
|
if (mraa_setup_mux_mapped(plat->pins[pin].aio) != MRAA_SUCCESS) {
|
||||||
"multiplexer", aio_channel);
|
syslog(LOG_ERR, "aio: unable to setup multiplexers for pin");
|
||||||
return NULL;
|
return NULL;
|
||||||
case MRAA_PLATFORM_NO_INIT:
|
|
||||||
syslog(LOG_ERR, "aio: Platform not initialised");
|
|
||||||
return NULL;
|
|
||||||
default:
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,10 +90,10 @@ mraa_aio_init(unsigned int aio_channel)
|
|||||||
mraa_aio_context dev = malloc(sizeof(struct _aio));
|
mraa_aio_context dev = malloc(sizeof(struct _aio));
|
||||||
if (dev == NULL) {
|
if (dev == NULL) {
|
||||||
syslog(LOG_ERR, "aio: Insufficient memory for specified input channel "
|
syslog(LOG_ERR, "aio: Insufficient memory for specified input channel "
|
||||||
"%d\n", aio_channel);
|
"%d\n", aio);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
dev->channel = checked_pin;
|
dev->channel = plat->pins[pin].aio.pinmap;
|
||||||
dev->value_bit = DEFAULT_BITS;
|
dev->value_bit = DEFAULT_BITS;
|
||||||
|
|
||||||
//Open valid analog input file and get the pointer.
|
//Open valid analog input file and get the pointer.
|
||||||
|
|||||||
20
src/mraa.c
20
src/mraa.c
@@ -165,26 +165,6 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
|
|||||||
return MRAA_SUCCESS;
|
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
|
unsigned int
|
||||||
mraa_setup_i2c(int* bus)
|
mraa_setup_i2c(int* bus)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user