From d3bfb25e60ac89706e3b52206f1443c816d690ba Mon Sep 17 00:00:00 2001 From: Thomas Ingleby Date: Wed, 7 May 2014 15:12:44 +0100 Subject: [PATCH 1/3] pinmap: function to test mode of a pin. * Added enum to represent the supported modes. Signed-off-by: Thomas Ingleby --- api/maa.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/api/maa.h b/api/maa.h index a0a21a4..c6a9bb2 100644 --- a/api/maa.h +++ b/api/maa.h @@ -61,6 +61,19 @@ typedef enum { */ typedef unsigned int maa_boolean_t; +/** + * Enum representing different possible modes for a pin. + */ +typedef enum { + MAA_PIN_VALID = 0, /**< Pin Valid */ + MAA_PIN_GPIO = 1, /**< General Purpose IO */ + MAA_PIN_PWM = 2, /**< Pulse Width Modulation */ + MAA_PIN_FAST_GPIO = 3, /**< Faster GPIO */ + MAA_PIN_SPI = 4, /**< SPI */ + MAA_PIN_I2C = 5, /**< I2C */ + MAA_PIN_AIO = 6 /**< Analog in */ +} maa_pinmodes_t; + /** * A bitfield representing the capabilities of a pin. */ @@ -208,6 +221,14 @@ const char* maa_get_version(); */ void maa_result_print(maa_result_t result); +/** Checks if a pin is able to use the passed in mode. + * + * @param pin Physical Pin to be checked. + * @param mode the mode to be tested. + * @return boolean if the mode is supported, 0=false. + */ +maa_boolean_t maa_pin_mode_test(int pin, maa_pinmodes_t mode); + #ifdef __cplusplus } #endif From c3932736a6a670bf7b7b4a16564e349ebccf5af7 Mon Sep 17 00:00:00 2001 From: Thomas Ingleby Date: Wed, 7 May 2014 15:15:57 +0100 Subject: [PATCH 2/3] pwm: rev-d quirk worked-around. Signed-off-by: Thomas Ingleby --- src/maa.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/maa.c b/src/maa.c index 96fe872..70f188a 100644 --- a/src/maa.c +++ b/src/maa.c @@ -142,20 +142,20 @@ maa_check_pwm(int pin) 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].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; + // Current REV D quirk. //TODO GEN 2 + if (maa_gpio_write(mux_i, 1) != 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; From 445b7a58d9d732b1b6e101390589d0f30ede5e62 Mon Sep 17 00:00:00 2001 From: Thomas Ingleby Date: Wed, 7 May 2014 15:54:59 +0100 Subject: [PATCH 3/3] pinmap: Implemented maa_pin_mode_test Signed-off-by: Thomas Ingleby --- src/maa.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/maa.c b/src/maa.c index 70f188a..a2a3bc8 100644 --- a/src/maa.c +++ b/src/maa.c @@ -216,3 +216,45 @@ maa_result_print(maa_result_t result) break; } } + +maa_boolean_t +maa_pin_mode_test(int pin, maa_pinmodes_t mode) +{ + if (pin > plat->phy_pin_count || pin < 0) + return 0; + + switch(mode) { + case MAA_PIN_VALID: + if (plat->pins[pin].capabilites.valid == 1) + return 1; + break; + case MAA_PIN_GPIO: + if (plat->pins[pin].capabilites.gpio ==1) + return 1; + break; + case MAA_PIN_PWM: + if (plat->pins[pin].capabilites.pwm ==1) + return 1; + break; + case MAA_PIN_FAST_GPIO: + if (plat->pins[pin].capabilites.fast_gpio ==1) + return 1; + break; + case MAA_PIN_SPI: + if (plat->pins[pin].capabilites.spi ==1) + return 1; + break; + case MAA_PIN_I2C: + if (plat->pins[pin].capabilites.i2c ==1) + return 1; + break; + case MAA_PIN_AIO: + if (pin < plat->aio_count) + pin = pin + plat->gpio_count; + if (plat->pins[pin].capabilites.aio ==1) + return 1; + break; + default: break; + } + return 0; +}