diff --git a/include/mraa_internal.h b/include/mraa_internal.h index b5f7a3f..e2166e2 100644 --- a/include/mraa_internal.h +++ b/include/mraa_internal.h @@ -45,14 +45,6 @@ extern mraa_board_t* plat; */ mraa_result_t mraa_setup_mux_mapped(mraa_pin_t meta); -/** - * Setup uart muxes to exposes the pins physically. - * - * @param index of the uart in the board definition to expose physically - * @return mraa_result_t of operation - */ -mraa_result_t mraa_setup_uart(int index); - /** * runtime detect running x86 platform * diff --git a/src/mraa.c b/src/mraa.c index 863af60..9076316 100644 --- a/src/mraa.c +++ b/src/mraa.c @@ -300,35 +300,6 @@ mraa_adc_supported_bits() return plat->adc_supported; } -mraa_result_t -mraa_setup_uart(int index) -{ - if (plat == NULL) - return MRAA_ERROR_PLATFORM_NOT_INITIALISED; - - if (plat->uart_dev_count == 0) - return MRAA_ERROR_FEATURE_NOT_SUPPORTED; - - if (plat->uart_dev_count <= index) - return MRAA_ERROR_NO_RESOURCES; - - int pos = plat->uart_dev[index].rx; - if (pos >= 0) { - if (plat->pins[pos].uart.mux_total > 0) - if (mraa_setup_mux_mapped(plat->pins[pos].uart) != MRAA_SUCCESS) - return MRAA_ERROR_INVALID_RESOURCE; - } - - if (pos >= 0) { - pos = plat->uart_dev[index].tx; - if (plat->pins[pos].uart.mux_total > 0) - if (mraa_setup_mux_mapped(plat->pins[pos].uart) != MRAA_SUCCESS) - return MRAA_ERROR_INVALID_RESOURCE; - } - - return MRAA_SUCCESS; -} - char* mraa_get_platform_name() { diff --git a/src/uart/uart.c b/src/uart/uart.c index 1ea0150..2828986 100644 --- a/src/uart/uart.c +++ b/src/uart/uart.c @@ -33,15 +33,53 @@ mraa_uart_context mraa_uart_init(int index) { - if (advance_func->uart_init_pre != NULL) { - if (advance_func->uart_init_pre(index) != MRAA_SUCCESS) - return NULL; + if (plat == NULL) { + syslog(LOG_ERR, "uart: platform not initialised"); + return NULL; } - if (mraa_setup_uart(index) != MRAA_SUCCESS) + if (advance_func->uart_init_pre != NULL) { + if (advance_func->uart_init_pre(index) != MRAA_SUCCESS) { + syslog(LOG_ERR, "uart: failure in pre-init platform hook"); + return NULL; + } + } + + if (plat->uart_dev_count == 0) { + syslog(LOG_ERR, "uart: platform has no UARTs defined"); return NULL; + } + + if (plat->uart_dev_count <= index) { + syslog(LOG_ERR, "uart: platform has only %i", plat->uart_dev_count); + return NULL; + } + + int pos = plat->uart_dev[index].rx; + if (pos >= 0) { + if (plat->pins[pos].uart.mux_total > 0) { + if (mraa_setup_mux_mapped(plat->pins[pos].uart) != MRAA_SUCCESS) { + syslog(LOG_ERR, "uart: failed to setup muxes for RX pin"); + return NULL; + } + } + } + + if (pos >= 0) { + pos = plat->uart_dev[index].tx; + if (plat->pins[pos].uart.mux_total > 0) { + if (mraa_setup_mux_mapped(plat->pins[pos].uart) != MRAA_SUCCESS) { + syslog(LOG_ERR, "uart: failed to setup muxes for TX pin"); + return NULL; + } + } + } mraa_uart_context dev = (mraa_uart_context) malloc(sizeof(struct _uart)); + if (dev == NULL) { + syslog(LOG_CRIT, "uart: Failed to allocate memory for context"); + return NULL; + } memset(dev, 0, sizeof(struct _uart)); dev->index = index;