From 352e1e084db3c1e361e6bcdb2ebeeafcdcc3f860 Mon Sep 17 00:00:00 2001 From: Thomas Ingleby Date: Wed, 14 May 2014 16:06:57 +0100 Subject: [PATCH] spi-pinmap: added spi checking functions. Signed-off-by: Thomas Ingleby --- api/maa.h | 6 ++++++ src/maa.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/api/maa.h b/api/maa.h index fbd37c4..3bd5efc 100644 --- a/api/maa.h +++ b/api/maa.h @@ -205,6 +205,12 @@ unsigned int maa_check_aio(int pin); */ unsigned int maa_check_i2c(); +/** Check spi interface, sets up multiplexer on device. + * + * @return unsigned int if using /dev/spi-1.0 returned would be 1.0 + */ +double maa_check_spi(); + /** Check PWM * * Will check input is valid for pwm and will also setup required multiplexers. diff --git a/src/maa.c b/src/maa.c index d1b199a..9ab9322 100644 --- a/src/maa.c +++ b/src/maa.c @@ -143,6 +143,36 @@ maa_check_i2c(int bus_s) return plat->i2c_bus[bus].bus_id; } +double +maa_check_spi(int bus_s) +{ + if (plat == NULL) + return -3; + + if (plat->i2c_bus_count >! 0) { + fprintf(stderr, "No spi buses defined in platform"); + return -1; + } + int bus = 0; + + int pos = plat->spi_bus[0].sclk; + if (plat->pins[pos].spi.mux_total > 0) + if (maa_setup_mux_mapped(plat->pins[pos].spi) != MAA_SUCCESS) + return -2; + + pos = plat->spi_bus[0].mosi; + if (plat->pins[pos].spi.mux_total > 0) + if (maa_setup_mux_mapped(plat->pins[pos].spi) != MAA_SUCCESS) + return -2; + + pos = plat->spi_bus[0].miso; + if (plat->pins[pos].spi.mux_total > 0) + if (maa_setup_mux_mapped(plat->pins[pos].spi) != MAA_SUCCESS) + return -2; + + return plat->spi_bus[bus].bus_id; +} + maa_pin_t* maa_check_pwm(int pin) { -- 2.7.4