diff --git a/include/mraa_adv_func.h b/include/mraa_adv_func.h index 312a2d9..94db32a 100644 --- a/include/mraa_adv_func.h +++ b/include/mraa_adv_func.h @@ -106,4 +106,6 @@ typedef struct { int (*uart_read_replace) (mraa_uart_context dev, char* buf, size_t len); int (*uart_write_replace)(mraa_uart_context dev, const char* buf, size_t len); mraa_boolean_t (*uart_data_available_replace) (mraa_uart_context dev, unsigned int millis); + + mraa_result_t (*mux_init_reg) (int phy_pin, int mode); } mraa_adv_func_t; diff --git a/include/mraa_internal_types.h b/include/mraa_internal_types.h index 882ce4a..63f2b94 100644 --- a/include/mraa_internal_types.h +++ b/include/mraa_internal_types.h @@ -312,6 +312,19 @@ typedef enum { } pincmd_t; +/** + * Enum representing different mux register mode + */ + typedef enum { + MUX_REGISTER_MODE_GPIO = 0, /**< GPIO mode */ + MUX_REGISTER_MODE_UART = 1, /**< UART mode */ + MUX_REGISTER_MODE_I2C = 2, /**< I2C mode */ + MUX_REGISTER_MODE_SPI = 3, /**< SPI mode */ + MUX_REGISTER_MODE_PWM = 4, /**< PWM mode */ + MUX_REGISTER_MODE_AIO = 5, /**< AIO mode */ + MAX_MUX_REGISTER_MODE + } mux_register_mode_t; + /** * A Structure representing a multiplexer and the required value */ diff --git a/src/aio/aio.c b/src/aio/aio.c index 753aff8..9beeb4c 100644 --- a/src/aio/aio.c +++ b/src/aio/aio.c @@ -119,7 +119,12 @@ mraa_aio_init(unsigned int aio) return NULL; } } - + if (board->adv_func->mux_init_reg) { + if(board->adv_func->mux_init_reg(pin, MUX_REGISTER_MODE_AIO) != MRAA_SUCCESS) { + syslog(LOG_ERR, "aio: unable to setup multiplex register for pin"); + return NULL; + } + } // Create ADC device connected to specified channel mraa_aio_context dev = mraa_aio_init_internal(board->adv_func, aio, board->pins[pin].aio.pinmap); if (dev == NULL) { diff --git a/src/gpio/gpio.c b/src/gpio/gpio.c index 62ffe9a..f13081f 100644 --- a/src/gpio/gpio.c +++ b/src/gpio/gpio.c @@ -309,7 +309,12 @@ mraa_gpio_init(int pin) return NULL; } } - + if (board->adv_func->mux_init_reg) { + if(board->adv_func->mux_init_reg(pin, MUX_REGISTER_MODE_GPIO) != MRAA_SUCCESS) { + syslog(LOG_ERR, "gpio%i: init: unable to setup multiplex register", pin); + return NULL; + } + } mraa_gpio_context r = mraa_gpio_init_internal(board->adv_func, board->pins[pin].gpio.pinmap); if (r == NULL) { @@ -408,6 +413,13 @@ mraa_gpio_chardev_init(int pins[], int num_pins) } } + if (board->adv_func->mux_init_reg) { + if(board->adv_func->mux_init_reg(pins[i], MUX_REGISTER_MODE_GPIO) != MRAA_SUCCESS) { + syslog(LOG_ERR, "[GPIOD_INTERFACE]: init: unable to setup mux register for pin %d", pins[i]); + mraa_gpio_close(dev); + return NULL; + } + } chip_id = board->pins[pins[i]].gpio.gpio_chip; line_offset = board->pins[pins[i]].gpio.gpio_line; diff --git a/src/i2c/i2c.c b/src/i2c/i2c.c index 5301929..08ef9cc 100644 --- a/src/i2c/i2c.c +++ b/src/i2c/i2c.c @@ -156,7 +156,12 @@ mraa_i2c_init(int bus) return NULL; } } - + if (pos >= 0 && board->adv_func->mux_init_reg) { + if(board->adv_func->mux_init_reg(pos, MUX_REGISTER_MODE_I2C) != MRAA_SUCCESS) { + syslog(LOG_ERR, "i2c%i_init: Failed to set-up i2c sda multiplex register", bus); + return NULL; + } + } pos = board->i2c_bus[bus].scl; if (pos >=0 && board->pins[pos].i2c.mux_total > 0) { if (mraa_setup_mux_mapped(board->pins[pos].i2c) != MRAA_SUCCESS) { @@ -164,6 +169,12 @@ mraa_i2c_init(int bus) return NULL; } } + if (pos >= 0 && board->adv_func->mux_init_reg) { + if(board->adv_func->mux_init_reg(pos, MUX_REGISTER_MODE_I2C) != MRAA_SUCCESS) { + syslog(LOG_ERR, "i2c%i_init: Failed to set-up scl sda multiplex register", bus); + return NULL; + } + } } return mraa_i2c_init_internal(board->adv_func, (unsigned int) board->i2c_bus[bus].bus_id); diff --git a/src/pwm/pwm.c b/src/pwm/pwm.c index 651d086..cdf57f3 100644 --- a/src/pwm/pwm.c +++ b/src/pwm/pwm.c @@ -240,6 +240,13 @@ mraa_pwm_init(int pin) } } + if (board->adv_func->mux_init_reg) { + if(board->adv_func->mux_init_reg(pin, MUX_REGISTER_MODE_PWM) != MRAA_SUCCESS) { + syslog(LOG_ERR, "pwm_init: Failed to set-up pwm%i multiplex register", pin); + return NULL; + } + } + int chip = board->pins[pin].pwm.parent_id; int pinn = board->pins[pin].pwm.pinmap; diff --git a/src/spi/spi.c b/src/spi/spi.c index 274af67..3627799 100644 --- a/src/spi/spi.c +++ b/src/spi/spi.c @@ -81,6 +81,13 @@ mraa_spi_init(int bus) } } + if (pos >= 0 && plat->adv_func->mux_init_reg) { + if(plat->adv_func->mux_init_reg(pos, MUX_REGISTER_MODE_SPI) != MRAA_SUCCESS) { + syslog(LOG_ERR, "spi: failed to set-up spi sclk multiplex register"); + return NULL; + } + } + pos = plat->spi_bus[bus].mosi; if (pos >= 0 && plat->pins[pos].spi.mux_total > 0) { if (mraa_setup_mux_mapped(plat->pins[pos].spi) != MRAA_SUCCESS) { @@ -89,6 +96,13 @@ mraa_spi_init(int bus) } } + if (pos >= 0 && plat->adv_func->mux_init_reg) { + if(plat->adv_func->mux_init_reg(pos, MUX_REGISTER_MODE_SPI) != MRAA_SUCCESS) { + syslog(LOG_ERR, "spi: failed to set-up spi mosi multiplex register"); + return NULL; + } + } + pos = plat->spi_bus[bus].miso; if (pos >= 0 && plat->pins[pos].spi.mux_total > 0) { if (mraa_setup_mux_mapped(plat->pins[pos].spi) != MRAA_SUCCESS) { @@ -97,6 +111,13 @@ mraa_spi_init(int bus) } } + if (pos >= 0 && plat->adv_func->mux_init_reg) { + if(plat->adv_func->mux_init_reg(pos, MUX_REGISTER_MODE_SPI) != MRAA_SUCCESS) { + syslog(LOG_ERR, "spi: failed to set-up spi miso multiplex register"); + return NULL; + } + } + pos = plat->spi_bus[bus].cs; if (pos >= 0 && plat->pins[pos].spi.mux_total > 0) { if (mraa_setup_mux_mapped(plat->pins[pos].spi) != MRAA_SUCCESS) { @@ -104,6 +125,13 @@ mraa_spi_init(int bus) return NULL; } } + + if (pos >= 0 && plat->adv_func->mux_init_reg) { + if(plat->adv_func->mux_init_reg(pos, MUX_REGISTER_MODE_SPI) != MRAA_SUCCESS) { + syslog(LOG_ERR, "spi: failed to set-up spi cs multiplex register"); + return NULL; + } + } } mraa_spi_context dev = mraa_spi_init_raw(plat->spi_bus[bus].bus_id, plat->spi_bus[bus].slave_s); diff --git a/src/uart/uart.c b/src/uart/uart.c index 36517fa..4cfd81a 100644 --- a/src/uart/uart.c +++ b/src/uart/uart.c @@ -201,6 +201,12 @@ mraa_uart_init(int index) return NULL; } } + if (plat->adv_func->mux_init_reg) { + if(plat->adv_func->mux_init_reg(pos, MUX_REGISTER_MODE_UART) != MRAA_SUCCESS) { + syslog(LOG_ERR, "uart%i: init: failed to setup mux register for RX pin", index); + return NULL; + } + } } pos = plat->uart_dev[index].tx; @@ -211,6 +217,12 @@ mraa_uart_init(int index) return NULL; } } + if (plat->adv_func->mux_init_reg) { + if(plat->adv_func->mux_init_reg(pos, MUX_REGISTER_MODE_UART) != MRAA_SUCCESS) { + syslog(LOG_ERR, "uart%i: init: failed to setup mux register for TX pin", index); + return NULL; + } + } } } @@ -606,12 +618,24 @@ mraa_uart_set_flowcontrol(mraa_uart_context dev, mraa_boolean_t xonxoff, mraa_bo return MRAA_ERROR_FEATURE_NOT_SUPPORTED; } } + if (plat->adv_func->mux_init_reg) { + if(plat->adv_func->mux_init_reg(pos_cts, MUX_REGISTER_MODE_UART) != MRAA_SUCCESS) { + syslog(LOG_ERR, "uart%i: init: failed to setup mux register for CTS pin", dev->index); + return MRAA_ERROR_FEATURE_NOT_SUPPORTED; + } + } if (plat->pins[pos_rts].uart.mux_total > 0) { if (mraa_setup_mux_mapped(plat->pins[pos_rts].uart) != MRAA_SUCCESS) { syslog(LOG_ERR, "uart%i: init: failed to setup muxes for RTS pin", dev->index); return MRAA_ERROR_FEATURE_NOT_SUPPORTED; } } + if (plat->adv_func->mux_init_reg) { + if(plat->adv_func->mux_init_reg(pos_rts, MUX_REGISTER_MODE_UART) != MRAA_SUCCESS) { + syslog(LOG_ERR, "uart%i: init: failed to setup mux register for RTS pin", dev->index); + return MRAA_ERROR_FEATURE_NOT_SUPPORTED; + } + } } } }