From 401f0cfe653a75f591e340376108a15ef4391156 Mon Sep 17 00:00:00 2001 From: Thomas Ingleby Date: Thu, 30 Oct 2014 19:08:15 +0000 Subject: [PATCH] gpio: move gpio setup from core into module Added syslog lines for easier fault investigation Signed-off-by: Thomas Ingleby --- include/mraa_internal.h | 7 ------- src/gpio/gpio.c | 21 ++++++++++++++++++--- src/mraa.c | 18 ------------------ 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/include/mraa_internal.h b/include/mraa_internal.h index 8b22520..e0df290 100644 --- a/include/mraa_internal.h +++ b/include/mraa_internal.h @@ -45,13 +45,6 @@ extern mraa_board_t* plat; */ mraa_result_t mraa_setup_mux_mapped(mraa_pin_t meta); -/** - * 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 mraa_setup_gpio(int pin); - /** * 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/ diff --git a/src/gpio/gpio.c b/src/gpio/gpio.c index 99a8c21..dd63183 100644 --- a/src/gpio/gpio.c +++ b/src/gpio/gpio.c @@ -55,11 +55,26 @@ mraa_gpio_get_valfp(mraa_gpio_context dev) mraa_gpio_context mraa_gpio_init(int pin) { - int pinm = mraa_setup_gpio(pin); - if (pinm < 0) + if (plat == NULL) { + syslog(LOG_ERR, "gpio: platform not initialised"); return NULL; + } + if (pin < 0 || pin > plat->phy_pin_count) { + syslog(LOG_ERR, "gpio: pin %i beyond platform definition", pin); + return NULL; + } + if (plat->pins[pin].capabilites.gpio != 1) { + syslog(LOG_ERR, "gpio: pin %i not capable of gpio", pin); + return NULL; + } + if (plat->pins[pin].gpio.mux_total > 0) { + if (mraa_setup_mux_mapped(plat->pins[pin].gpio) != MRAA_SUCCESS) { + syslog(LOG_ERR, "gpio: unable to setup muxes"); + return NULL; + } + } - mraa_gpio_context r = mraa_gpio_init_raw(pinm); + mraa_gpio_context r = mraa_gpio_init_raw(plat->pins[pin].gpio.pinmap); r->phy_pin = pin; if (advance_func->gpio_init_post != NULL) { diff --git a/src/mraa.c b/src/mraa.c index 966c366..377cc19 100644 --- a/src/mraa.c +++ b/src/mraa.c @@ -165,24 +165,6 @@ mraa_setup_mux_mapped(mraa_pin_t meta) return MRAA_SUCCESS; } -unsigned int -mraa_setup_gpio(int pin) -{ - if (plat == NULL) - return MRAA_PLATFORM_NO_INIT; - - if (pin < 0 || pin > plat->phy_pin_count) - return MRAA_NO_SUCH_IO; - - if(plat->pins[pin].capabilites.gpio != 1) - return MRAA_NO_SUCH_IO; - - if (plat->pins[pin].gpio.mux_total > 0) - if (mraa_setup_mux_mapped(plat->pins[pin].gpio) != MRAA_SUCCESS) - return MRAA_NO_SUCH_IO; - return plat->pins[pin].gpio.pinmap; -} - unsigned int mraa_setup_aio(int aio) {