From 171f66208e306c02dfc65e3070a88840aeaa9819 Mon Sep 17 00:00:00 2001 From: Thomas Ingleby Date: Tue, 6 May 2014 15:01:44 +0100 Subject: [PATCH] pwm: Use pinmap functions for setting up pwm. * Intended function of check_pwm also checks for conflicting gpio, due * to quirk on galileo rev d, functionality commented. Signed-off-by: Thomas Ingleby --- api/maa.h | 9 +++++++++ src/maa.c | 38 ++++++++++++++++++++++++++++++++++++-- src/pwm/pwm.c | 13 +++++++++---- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/api/maa.h b/api/maa.h index e2e01c0..6b15b64 100644 --- a/api/maa.h +++ b/api/maa.h @@ -185,6 +185,15 @@ unsigned int maa_check_aio(int pin); */ unsigned int maa_check_i2c(); +/** Check PWM + * + * Will check input is valid for pwm and will also setup required multiplexers. + * IF the pin also does gpio (strong chance), DO NOTHING, REV D is strange. + * @param pin the pin as read from the board surface. + * @return the pwm pin_info_t of that IO pin + */ +maa_pin_t* maa_check_pwm(int pin); + /** Get the version string of maa autogenerated from git tag * * The version returned may not be what is expected however it is a reliable diff --git a/src/maa.c b/src/maa.c index 31e3f95..9244c8c 100644 --- a/src/maa.c +++ b/src/maa.c @@ -24,6 +24,7 @@ */ #include +#include #include "maa.h" #include "intel_galileo_rev_d.h" @@ -98,14 +99,13 @@ maa_check_aio(int aio) int pin = aio + plat->gpio_count; - if(plat->pins[pin].capabilites.aio != 1) + if (plat->pins[pin].capabilites.aio != 1) return -1; if (plat->pins[pin].aio.mux_total > 0) if (maa_setup_mux_mapped(plat->pins[pin].aio) != MAA_SUCCESS) return -1; return plat->pins[pin].aio.pinmap; - } unsigned int @@ -132,3 +132,37 @@ maa_check_i2c(int bus_s) return plat->i2c_bus[bus].bus_id; } + +maa_pin_t* +maa_check_pwm(int pin) +{ + if (plat == NULL) + return NULL; + + if (plat->pins[pin].capabilites.pwm != 1) + return NULL; + + /** quirk in rev d, this messes with pwm on that pin + * if (plat->pins[pin].capabilites.gpio == 1) { + * maa_gpio_context* mux_i; + * mux_i = maa_gpio_init_raw(plat->pins[pin].gpio.pinmap); + * if (mux_i == NULL) + * return NULL; + * if (maa_gpio_dir(mux_i, MAA_GPIO_OUT) != MAA_SUCCESS) + * return NULL; + * if (maa_gpio_write(mux_i, 0) != MAA_SUCCESS) + * return NULL; + * if (maa_gpio_close(mux_i) != MAA_SUCCESS) + * return NULL; + * } + */ + if (plat->pins[pin].pwm.mux_total > 0) + if (maa_setup_mux_mapped(plat->pins[pin].pwm) != MAA_SUCCESS) + return NULL; + + maa_pin_t *ret; + ret = (maa_pin_t*) malloc(sizeof(maa_pin_t)); + ret->pinmap = plat->pins[pin].pwm.pinmap; + ret->parent_id = plat->pins[pin].pwm.parent_id; + return ret; +} diff --git a/src/pwm/pwm.c b/src/pwm/pwm.c index 6c31594..9c63502 100644 --- a/src/pwm/pwm.c +++ b/src/pwm/pwm.c @@ -101,8 +101,13 @@ maa_pwm_get_duty(maa_pwm_context* dev) maa_pwm_context* maa_pwm_init(int pin) { - //TODO - return maa_pwm_init_raw(0, pin); + maa_pin_t* pinm = maa_check_pwm(pin); + if (pinm == NULL) + return NULL; + int chip = pinm->parent_id; + int pinn = pinm->pinmap; + free(pinm); + return maa_pwm_init_raw(chip,pinn); } maa_pwm_context* @@ -121,8 +126,8 @@ maa_pwm_init_raw(int chipin, int pin) if ((export_f = fopen(buffer, "w")) == NULL) { fprintf(stderr, "Failed to open export for writing!\n"); - free(dev); - return NULL; + free(dev); + return NULL; } else { fprintf(export_f, "%d", dev->pin); fclose(export_f); -- 2.7.4