MAA_ERROR_UNSPECIFIED = 99 /**< Unknown Error */
} maa_result_t;
+/**
+ * MAA boolean type
+ * 1 For TRUE
+ */
typedef unsigned int maa_boolean_t;
+/**
+ * A bitfield representing the capabilities of a pin.
+ */
typedef struct {
- maa_boolean_t valid:1;
- maa_boolean_t gpio:1;
- maa_boolean_t pwm:1;
- maa_boolean_t fast_gpio:1;
- maa_boolean_t spi:1;
- maa_boolean_t i2c:1;
- }
- maa_pincapabilities_t;
+ /*@{*/
+ maa_boolean_t valid:1; /**< Is the pin valid at all */
+ maa_boolean_t gpio:1; /**< Is the pin gpio capable */
+ maa_boolean_t pwm:1; /**< Is the pin pwm capable */
+ maa_boolean_t fast_gpio:1; /**< Is the pin fast gpio capable */
+ maa_boolean_t spi:1; /**< Is the pin spi capable */
+ maa_boolean_t i2c:1; /**< Is the pin i2c capable */
+ maa_boolean_t aio:1; /**< Is the pin analog input capable */
+ /*@}*/
+} maa_pincapabilities_t;
+/**
+ * A Structure representing a multiplexer and the required value
+ */
typedef struct {
- unsigned int pin;
- unsigned int value;
+ /*@{*/
+ unsigned int pin; /**< Raw GPIO pin id */
+ unsigned int value; /**< Raw GPIO value */
+ /*@}*/
} maa_mux_t;
+/**
+ * A Structure representing a physical Pin.
+ */
typedef struct {
- char name[8];// do we need this
- unsigned int pin;
- int parent_id;
- maa_pincapabilities_t capabilites;
- maa_mux_t mux[4];
- unsigned int mux_total;
+ /*@{*/
+ char name[8]; /**< Pin's real world name */
+ unsigned int pin; /**< Pin ID */
+ int parent_id; /**< IO Parent ID*/
+ maa_pincapabilities_t capabilites; /**< Pin Capabiliites */
+ maa_mux_t mux[4]; /**< Multiplexer array */
+ unsigned int mux_total; /**< Total Multiplexors required */
+ /*@}*/
} maa_pininfo_t;
+/**
+ * A Structure representing a platform/board.
+ */
typedef struct {
- unsigned int gpio_count;
- unsigned int aio_count;
- unsigned int pwm_count;
- maa_pininfo_t* pins;
+ /*@{*/
+ unsigned int gpio_count; /**< GPIO Count */
+ unsigned int aio_count; /**< Analog In Count */
+ unsigned int pwm_count; /**< PWM Count */
+ maa_pininfo_t* pins; /**< Pointer to pin array */
+ /*@}*/
} maa_board_t;
+/** Initialise MAA
+ *
+ * Detects running platform and attempts to use included pinmap
+ * @return maa_result_t maa result
+ */
+maa_result_t maa_init();
+
+/** Check GPIO
+ *
+ * Will check input is valid for gpio and will also setup required multiplexers.
+ * @param pin the pin as read from the board surface. i.e IO3 would be 3/
+ * @return the pin as found in the pinmap
+ */
unsigned int maa_check_gpio(int pin);
-//unsigned int maa_check_aio(int pin);
+
+/** Check AIO
+ *
+ * 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 maa_check_aio(int pin);
+
//unsigned int maa_check_pwm(int pin);
/** Get the version string of maa autogenerated from git tag
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
{
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)) {
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;
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;
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;
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;
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;
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;
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;
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;
}