pinmap: Added aio support.
* Intel Galileo Rev D: Added analog information * maa_check_aio, similar to maa_check_gpio, will setup multiplexers. * aio: Removed now duplicated functionality. Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
This commit is contained in:
@@ -42,62 +42,6 @@ static maa_result_t aio_get_valid_fp(maa_aio_context* dev)
|
||||
return MAA_SUCCESS;
|
||||
}
|
||||
|
||||
/** Configure multiplexer for Analog Input
|
||||
*
|
||||
* @param aio_channel = Analog input channel to read
|
||||
*
|
||||
* @return maa_result_t - result type.
|
||||
*
|
||||
*/
|
||||
static maa_result_t maa_aio_set_mux(unsigned int aio_channel)
|
||||
{
|
||||
maa_result_t result;
|
||||
maa_gpio_context* aio_gate;
|
||||
|
||||
//Initialise VINx multiplexer gate pins
|
||||
aio_gate = maa_gpio_init(adc_gate_pins[aio_channel]);
|
||||
|
||||
if (NULL == aio_gate) {
|
||||
fprintf(stderr, "Failed to initialise first gate pin %d for ADC "
|
||||
"channel %d !\n", adc_gate_pins[aio_channel], aio_channel);
|
||||
return MAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
//Set direction to output for the ADC input gate
|
||||
result = maa_gpio_dir(aio_gate, MAA_GPIO_OUT);
|
||||
|
||||
if (MAA_SUCCESS == result) {
|
||||
// Write gate configuration output value
|
||||
result = maa_gpio_write(aio_gate, 0);
|
||||
|
||||
if (MAA_SUCCESS == result) {
|
||||
//For A4 and A5 Analog common gate pin should be high for the
|
||||
// Galileo board revision D
|
||||
if (A4 == aio_channel || A5 == aio_channel) {
|
||||
aio_gate = maa_gpio_init(ADC_COMMON_GATE_A4_A5);
|
||||
|
||||
//Set direction to output for the gate
|
||||
if (NULL == aio_gate) {
|
||||
fprintf(stderr, "Failed to initialise second gate pin %d "
|
||||
"for ADC channel %d !\n", ADC_COMMON_GATE_A4_A5,
|
||||
aio_channel);
|
||||
return(MAA_ERROR_INVALID_RESOURCE);
|
||||
}
|
||||
|
||||
result = maa_gpio_dir(aio_gate, MAA_GPIO_OUT);
|
||||
if (MAA_SUCCESS == result)
|
||||
// Write gate configuration output value
|
||||
result = maa_gpio_write(aio_gate, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != aio_gate)
|
||||
free(aio_gate);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
/** Initialise an Analog input, connected to the specified channel
|
||||
*
|
||||
* @param aio_channel Analog input channel to read
|
||||
@@ -109,27 +53,32 @@ maa_aio_context* maa_aio_init(unsigned int aio_channel)
|
||||
{
|
||||
maa_aio_context* dev;
|
||||
|
||||
// Validate input pins 0-5
|
||||
if (aio_channel > TOTAL_ANALOG_INPUTS_ON_BOARD) {
|
||||
fprintf(stderr, "Invalid Analog input channel %d specified!\n",
|
||||
aio_channel);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//Set-up multiplexer for the Analog input channel
|
||||
if (MAA_SUCCESS != maa_aio_set_mux(aio_channel)) {
|
||||
fprintf(stderr, "Failed to set-up Analog input channel %d "
|
||||
"multiplexer!\n", aio_channel); return NULL;
|
||||
unsigned int checked_pin = maa_check_aio(aio_channel);
|
||||
if (checked_pin < 0) {
|
||||
switch(checked_pin) {
|
||||
case -1:
|
||||
fprintf(stderr, "Invalid Analog input channel %d specified!\n",
|
||||
aio_channel);
|
||||
return NULL;
|
||||
case -2:
|
||||
fprintf(stderr, "Failed to set-up Analog input channel %d "
|
||||
"multiplexer!\n", aio_channel);
|
||||
return NULL;
|
||||
case -3:
|
||||
fprintf(stderr, "Platform Not Initialised");
|
||||
return NULL;
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//Create ADC device connected to specified channel
|
||||
dev = (maa_aio_context*) malloc(sizeof(maa_aio_context));
|
||||
if (NULL == dev) {
|
||||
fprintf(stderr, "Insufficient memory for specified Analog input channel "
|
||||
"%d !\n", aio_channel);
|
||||
fprintf(stderr, "Insufficient memory for specified Analog input channel "
|
||||
"%d !\n", aio_channel);
|
||||
return NULL;
|
||||
}
|
||||
dev->channel = aio_channel;
|
||||
dev->channel = checked_pin;
|
||||
|
||||
//Open valid analog input file and get the pointer.
|
||||
if (MAA_SUCCESS != aio_get_valid_fp(dev)) {
|
||||
|
||||
@@ -43,7 +43,7 @@ maa_intel_galileo_rev_d()
|
||||
strncpy(b->pins[0].name, "IO0", 8);
|
||||
b->pins[0].pin = 50;
|
||||
b->pins[0].parent_id = 0;
|
||||
b->pins[0].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0};
|
||||
b->pins[0].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0,0};
|
||||
b->pins[0].mux_total = 1;
|
||||
b->pins[0].mux[0].pin = 40;
|
||||
b->pins[0].mux[0].value = 1;
|
||||
@@ -51,7 +51,7 @@ maa_intel_galileo_rev_d()
|
||||
strncpy(b->pins[1].name, "IO1", 8);
|
||||
b->pins[1].pin = 51;
|
||||
b->pins[1].parent_id = 0;
|
||||
b->pins[1].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0};
|
||||
b->pins[1].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0,0};
|
||||
b->pins[1].mux_total = 1;
|
||||
b->pins[1].mux[0].pin = 41;
|
||||
b->pins[1].mux[0].value = 1;
|
||||
@@ -59,7 +59,7 @@ maa_intel_galileo_rev_d()
|
||||
strncpy(b->pins[2].name, "IO2", 8);
|
||||
b->pins[2].pin = 32;
|
||||
b->pins[2].parent_id = 0;
|
||||
b->pins[2].capabilites = (maa_pincapabilities_t) {1,1,0,1,0,0};
|
||||
b->pins[2].capabilites = (maa_pincapabilities_t) {1,1,0,1,0,0,0};
|
||||
b->pins[2].mux_total = 1;
|
||||
b->pins[2].mux[0].pin = 31;
|
||||
b->pins[2].mux[0].value = 1;
|
||||
@@ -67,7 +67,7 @@ maa_intel_galileo_rev_d()
|
||||
strncpy(b->pins[3].name, "IO3", 8);
|
||||
b->pins[3].pin = 18;
|
||||
b->pins[3].parent_id = 0;
|
||||
b->pins[3].capabilites = (maa_pincapabilities_t) {1,1,1,1,0,0};
|
||||
b->pins[3].capabilites = (maa_pincapabilities_t) {1,1,1,1,0,0,0};
|
||||
b->pins[3].mux_total = 1;
|
||||
b->pins[3].mux[0].pin = 30;
|
||||
b->pins[3].mux[0].value = 1;
|
||||
@@ -75,43 +75,43 @@ maa_intel_galileo_rev_d()
|
||||
strncpy(b->pins[4].name, "IO4", 8);
|
||||
b->pins[4].pin = 28;
|
||||
b->pins[4].parent_id = 0;
|
||||
b->pins[4].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0};
|
||||
b->pins[4].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0,0};
|
||||
b->pins[4].mux_total = 0;
|
||||
|
||||
strncpy(b->pins[5].name, "IO5", 8);
|
||||
b->pins[5].pin = 17;
|
||||
b->pins[5].parent_id = 0;
|
||||
b->pins[5].capabilites = (maa_pincapabilities_t) {1,1,1,0,0,0};
|
||||
b->pins[5].capabilites = (maa_pincapabilities_t) {1,1,1,0,0,0,0};
|
||||
b->pins[5].mux_total = 0;
|
||||
|
||||
strncpy(b->pins[6].name, "IO6", 8);
|
||||
b->pins[6].pin = 24;
|
||||
b->pins[6].parent_id = 0;
|
||||
b->pins[6].capabilites = (maa_pincapabilities_t) {1,1,1,0,0,0};
|
||||
b->pins[6].capabilites = (maa_pincapabilities_t) {1,1,1,0,0,0,0};
|
||||
b->pins[6].mux_total = 0;
|
||||
|
||||
strncpy(b->pins[7].name, "IO7", 8);
|
||||
b->pins[7].pin = 27;
|
||||
b->pins[7].parent_id = 0;
|
||||
b->pins[7].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0};
|
||||
b->pins[7].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0,0};
|
||||
b->pins[7].mux_total = 0;
|
||||
|
||||
strncpy(b->pins[8].name, "IO8", 8);
|
||||
b->pins[8].pin = 26;
|
||||
b->pins[8].parent_id = 0;
|
||||
b->pins[8].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0};
|
||||
b->pins[8].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0,0};
|
||||
b->pins[8].mux_total = 0;
|
||||
|
||||
strncpy(b->pins[9].name, "IO9", 8);
|
||||
b->pins[9].pin = 19;
|
||||
b->pins[9].parent_id = 0;
|
||||
b->pins[9].capabilites = (maa_pincapabilities_t) {1,1,1,0,0,0};
|
||||
b->pins[9].capabilites = (maa_pincapabilities_t) {1,1,1,0,0,0,0};
|
||||
b->pins[9].mux_total = 0;
|
||||
|
||||
strncpy(b->pins[10].name, "IO10", 8);
|
||||
b->pins[10].pin = 16;
|
||||
b->pins[10].parent_id = 0;
|
||||
b->pins[10].capabilites = (maa_pincapabilities_t) {1,1,1,0,1,0};
|
||||
b->pins[10].capabilites = (maa_pincapabilities_t) {1,1,1,0,1,0,0};
|
||||
b->pins[10].mux_total = 1;
|
||||
b->pins[10].mux[0].pin = 42;
|
||||
b->pins[10].mux[0].value = 1;
|
||||
@@ -119,7 +119,7 @@ maa_intel_galileo_rev_d()
|
||||
strncpy(b->pins[11].name, "IO11", 8);
|
||||
b->pins[11].pin = 25;
|
||||
b->pins[11].parent_id = 0;
|
||||
b->pins[11].capabilites = (maa_pincapabilities_t) {1,1,1,0,1,0};
|
||||
b->pins[11].capabilites = (maa_pincapabilities_t) {1,1,1,0,1,0,0};
|
||||
b->pins[11].mux_total = 1;
|
||||
b->pins[11].mux[0].pin = 43;
|
||||
b->pins[11].mux[0].value = 1;
|
||||
@@ -127,7 +127,7 @@ maa_intel_galileo_rev_d()
|
||||
strncpy(b->pins[12].name, "IO12", 8);
|
||||
b->pins[12].pin = 38;
|
||||
b->pins[12].parent_id = 0;
|
||||
b->pins[12].capabilites = (maa_pincapabilities_t) {1,1,1,0,1,0};
|
||||
b->pins[12].capabilites = (maa_pincapabilities_t) {1,1,1,0,1,0,0};
|
||||
b->pins[12].mux_total = 1;
|
||||
b->pins[12].mux[0].pin = 54;
|
||||
b->pins[12].mux[0].value = 1;
|
||||
@@ -135,10 +135,63 @@ maa_intel_galileo_rev_d()
|
||||
strncpy(b->pins[13].name, "IO13", 8);
|
||||
b->pins[13].pin = 39;
|
||||
b->pins[13].parent_id = 0;
|
||||
b->pins[13].capabilites = (maa_pincapabilities_t) {1,1,1,0,1,0};
|
||||
b->pins[13].capabilites = (maa_pincapabilities_t) {1,1,1,0,1,0,0};
|
||||
b->pins[13].mux_total = 1;
|
||||
b->pins[13].mux[0].pin = 55;
|
||||
b->pins[13].mux[0].value = 1;
|
||||
|
||||
//Analog in mapping and mux.
|
||||
strncpy(b->pins[14].name, "A0", 8);
|
||||
b->pins[14].pin = 0;
|
||||
b->pins[14].parent_id = 0;
|
||||
b->pins[14].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0,1};
|
||||
b->pins[14].mux_total = 1;
|
||||
b->pins[14].mux[0].pin = 37;
|
||||
b->pins[14].mux[0].value = 0;
|
||||
|
||||
strncpy(b->pins[15].name, "A1", 8);
|
||||
b->pins[15].pin = 1;
|
||||
b->pins[15].parent_id = 0;
|
||||
b->pins[15].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0,1};
|
||||
b->pins[15].mux_total = 1;
|
||||
b->pins[15].mux[0].pin = 36;
|
||||
b->pins[15].mux[0].value = 0;
|
||||
|
||||
strncpy(b->pins[16].name, "A2", 8);
|
||||
b->pins[16].pin = 2;
|
||||
b->pins[16].parent_id = 0;
|
||||
b->pins[16].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0,1};
|
||||
b->pins[16].mux_total = 1;
|
||||
b->pins[16].mux[0].pin = 23;
|
||||
b->pins[16].mux[0].value = 0;
|
||||
|
||||
strncpy(b->pins[17].name, "A3", 8);
|
||||
b->pins[17].pin = 3;
|
||||
b->pins[17].parent_id = 0;
|
||||
b->pins[17].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,0,1};
|
||||
b->pins[17].mux_total = 1;
|
||||
b->pins[17].mux[0].pin = 22;
|
||||
b->pins[17].mux[0].value = 0;
|
||||
|
||||
strncpy(b->pins[18].name, "A4", 8);
|
||||
b->pins[18].pin = 4;
|
||||
b->pins[18].parent_id = 0;
|
||||
b->pins[18].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,1,1};
|
||||
b->pins[18].mux_total = 2;
|
||||
b->pins[18].mux[0].pin = 29;
|
||||
b->pins[18].mux[0].value = 1;
|
||||
b->pins[18].mux[1].pin = 21;
|
||||
b->pins[18].mux[1].value = 0;
|
||||
|
||||
strncpy(b->pins[19].name, "A5", 8);
|
||||
b->pins[19].pin = 5;
|
||||
b->pins[19].parent_id = 0;
|
||||
b->pins[19].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,1,1};
|
||||
b->pins[19].mux_total = 2;
|
||||
b->pins[19].mux[0].pin = 29;
|
||||
b->pins[19].mux[0].value = 1;
|
||||
b->pins[19].mux[1].pin = 20;
|
||||
b->pins[19].mux[1].value = 0;
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
36
src/maa.c
36
src/maa.c
@@ -42,6 +42,9 @@ maa_get_version()
|
||||
maa_result_t
|
||||
maa_init()
|
||||
{
|
||||
/** Once more board definitions have been added,
|
||||
* A method for detecting them will need to be devised.
|
||||
*/
|
||||
plat = maa_intel_galileo_rev_d();
|
||||
return MAA_SUCCESS;
|
||||
}
|
||||
@@ -50,14 +53,14 @@ static maa_result_t
|
||||
maa_setup_mux_mapped(maa_pininfo_t meta)
|
||||
{
|
||||
int mi;
|
||||
for(mi = 0; mi < meta.mux_total; mi++) {
|
||||
for (mi = 0; mi < meta.mux_total; mi++) {
|
||||
maa_gpio_context* mux_i;
|
||||
mux_i = maa_gpio_init_raw(meta.mux[mi].pin);
|
||||
if(mux_i == NULL)
|
||||
if (mux_i == NULL)
|
||||
return MAA_ERROR_INVALID_HANDLE;
|
||||
if(maa_gpio_dir(mux_i, MAA_GPIO_OUT) != MAA_SUCCESS)
|
||||
if (maa_gpio_dir(mux_i, MAA_GPIO_OUT) != MAA_SUCCESS)
|
||||
return MAA_ERROR_INVALID_RESOURCE;
|
||||
if(maa_gpio_write(mux_i, meta.mux[mi].value) != MAA_SUCCESS)
|
||||
if (maa_gpio_write(mux_i, meta.mux[mi].value) != MAA_SUCCESS)
|
||||
return MAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
return MAA_SUCCESS;
|
||||
@@ -66,14 +69,31 @@ maa_setup_mux_mapped(maa_pininfo_t meta)
|
||||
unsigned int
|
||||
maa_check_gpio(int pin)
|
||||
{
|
||||
if(plat == NULL)
|
||||
if (plat == NULL)
|
||||
return -1;
|
||||
|
||||
if(pin < 0 || pin > plat->gpio_count)
|
||||
if (pin < 0 || pin > plat->gpio_count)
|
||||
return -1;
|
||||
if(plat->pins[pin].mux_total > 0)
|
||||
if(maa_setup_mux_mapped(plat->pins[pin]) != MAA_SUCCESS)
|
||||
if (plat->pins[pin].mux_total > 0)
|
||||
if (maa_setup_mux_mapped(plat->pins[pin]) != MAA_SUCCESS)
|
||||
return -1;
|
||||
return plat->pins[pin].pin;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
maa_check_aio(int aio)
|
||||
{
|
||||
if (plat == NULL)
|
||||
return -3;
|
||||
|
||||
if (aio < 0 || aio > plat->aio_count)
|
||||
return -1;
|
||||
|
||||
int pin = aio + plat->gpio_count;
|
||||
|
||||
if (plat->pins[pin].mux_total > 0)
|
||||
if (maa_setup_mux_mapped(plat->pins[pin]) != MAA_SUCCESS)
|
||||
return -2;
|
||||
|
||||
return plat->pins[pin].pin;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user