Private
Public Access
2
0

maa: add support for enabling pins and pulldowns

* Not Complete

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
This commit is contained in:
Thomas Ingleby
2014-06-17 20:15:36 +01:00
parent ea88358164
commit fa4a302398
4 changed files with 69 additions and 4 deletions

View File

@@ -108,15 +108,23 @@ typedef struct {
/*@}*/
} maa_mux_t;
/**
* A Strucutre representing a singular I/O pin. i.e GPIO/PWM
*/
typedef struct {
maa_boolean_t complex_pin:1;
maa_boolean_t output_en:1;
maa_boolean_t output_en_high:1;
maa_boolean_t pullup_en:1;
maa_boolean_t pullup_en_hiz:1;
} maa_pin_cap_complex_t;
typedef struct {
/*@{*/
unsigned int pinmap; /**< sysfs pin */
unsigned int parent_id; /** parent chip id */
unsigned int mux_total; /** Numfer of muxes needed for operation of pin */
maa_mux_t mux[6]; /** Array holding information about mux */
unsigned int output_enable; /** Output Enable GPIO, for level shifting */
unsigned int pullup_enable; /** Pull-Up enable GPIO, inputs */
maa_pin_cap_complex_t complex_cap;
/*@}*/
} maa_pin_t;

View File

@@ -69,3 +69,10 @@ maa_pin_t* maa_setup_pwm(int pin);
* @return maa_mmap_pin_t
*/
maa_mmap_pin_t* maa_setup_mmap_gpio(int pin);
/** Swap Directional mode.
*
* @param pin physical pin to operate on
* @return out direction to setup. 1 for output 0 for input
*/
maa_result_t maa_swap_complex_gpio(int pin, int out);

View File

@@ -368,9 +368,11 @@ maa_gpio_dir(maa_gpio_context dev, gpio_dir_t dir)
char bu[MAX_SIZE];
int length;
int out_switch = 0;
switch(dir) {
case MAA_GPIO_OUT:
length = snprintf(bu, sizeof(bu), "out");
out_switch = 1;
break;
case MAA_GPIO_IN:
length = snprintf(bu, sizeof(bu), "in");
@@ -380,6 +382,12 @@ maa_gpio_dir(maa_gpio_context dev, gpio_dir_t dir)
return MAA_ERROR_FEATURE_NOT_IMPLEMENTED;
}
if (dev->phy_pin >= 0) {
maa_result_t swap_res = maa_swap_complex_gpio(dev->phy_pin, out_switch);
if (swap_res != MAA_SUCCESS)
return swap_res;
}
if (write(direction, bu, length*sizeof(char)) == -1) {
fprintf(stderr, "Failed to write to direction\n");
close(direction);

View File

@@ -36,6 +36,7 @@
//static maa_pininfo_t* pindata;
static maa_board_t* plat = NULL;
static maa_platform_t platform_type = 99;
const char *
maa_get_version()
@@ -63,7 +64,7 @@ maa_init()
Py_InitializeEx(0);
PyEval_InitThreads();
#endif
maa_platform_t platform_type = MAA_UNKNOWN_PLATFORM;
platform_type = MAA_UNKNOWN_PLATFORM;
// detect a galileo gen2 board
char *line = NULL;
@@ -375,3 +376,44 @@ maa_setup_mmap_gpio(int pin)
maa_mmap_pin_t *ret = &(plat->pins[pin].mmap);
return ret;
}
maa_result_t
maa_swap_complex_gpio(int pin, int out)
{
if (plat == NULL)
return MAA_ERROR_INVALID_PLATFORM;
printf("SWAP CALLED on %i with bool as %i", pin,out);
switch (platform_type) {
case MAA_INTEL_GALILEO_GEN2:
printf("Intel Galileo Gen 2\n");
if (plat->pins[pin].gpio.complex_cap.complex_pin != 1)
return MAA_SUCCESS;
if (plat->pins[pin].gpio.complex_cap.output_en == 1) {
maa_gpio_context output_e;
printf("Doing stuff here with %i", plat->pins[pin].gpio.output_enable);
output_e = maa_gpio_init_raw(plat->pins[pin].gpio.output_enable);
if (maa_gpio_dir(output_e, MAA_GPIO_OUT) != MAA_SUCCESS)
return MAA_ERROR_INVALID_RESOURCE;
int output_val;
if (plat->pins[pin].gpio.complex_cap.output_en_high == 1)
output_val = out;
else
if (out == 1)
output_val = 0;
else
output_val = 1;
if (maa_gpio_write(output_e, output_val) != MAA_SUCCESS)
return MAA_ERROR_INVALID_RESOURCE;
}
//if (plat->pins[pin].gpio.complex_cap.pullup_en == 1) {
// maa_gpio_context pullup_e;
// pullup_e = maa_gpio_init_raw(plat->pins[pin].gpio.pullup_enable);
// if (maa_gpio_mode(pullup_e, MAA_GPIO_HIZ) != MAA_SUCCESS)
// return MAA_ERROR_INVALID_RESOURCE;
//}
break;
default: return MAA_SUCCESS;
}
}