From ea31104db0f2d703f40e83d09096f7b4c2f6cda0 Mon Sep 17 00:00:00 2001 From: Alex Tereschenko Date: Mon, 15 Jun 2015 21:20:02 +0200 Subject: [PATCH] intel_edison_fab_c.c: added spi_lsbmode_replace to return proper status Edison SPI driver doesn't support LSB_FIRST mode, we will now return _FEATURE_NOT_SUPPORTED instead of _INVALID_RESOURCE for attempts to enable it. Closes #22. Signed-off-by: Alex Tereschenko Signed-off-by: Brendan Le Foll --- src/x86/intel_edison_fab_c.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/x86/intel_edison_fab_c.c b/src/x86/intel_edison_fab_c.c index ee9df88..809c6c7 100644 --- a/src/x86/intel_edison_fab_c.c +++ b/src/x86/intel_edison_fab_c.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include "common.h" #include "x86/intel_edison_fab_c.h" @@ -72,6 +74,29 @@ static int mmap_fd = 0; static int mmap_size; static unsigned int mmap_count = 0; +mraa_result_t +mraa_intel_edison_spi_lsbmode_replace(mraa_spi_context dev, mraa_boolean_t lsb) +{ + uint8_t lsb_mode = (uint8_t) lsb; + + // Edison doesn't support LSB_FIRST, we need to react appropriately + if (!lsb) { + if (ioctl(dev->devfd, SPI_IOC_WR_LSB_FIRST, &lsb_mode) < 0) { + syslog(LOG_ERR, "spi: Failed to set bit order"); + return MRAA_ERROR_INVALID_RESOURCE; + } + if (ioctl(dev->devfd, SPI_IOC_RD_LSB_FIRST, &lsb_mode) < 0) { + syslog(LOG_ERR, "spi: Failed to set bit order"); + return MRAA_ERROR_INVALID_RESOURCE; + } + } else { + return MRAA_ERROR_FEATURE_NOT_SUPPORTED; + } + + dev->lsb = lsb; + return MRAA_SUCCESS; +} + static mraa_result_t mraa_intel_edison_pinmode_change(int sysfs, int mode) { @@ -1122,6 +1147,7 @@ mraa_intel_edison_fab_c() advance_func->uart_init_pre = &mraa_intel_edison_uart_init_pre; advance_func->uart_init_post = &mraa_intel_edison_uart_init_post; advance_func->gpio_mmap_setup = &mraa_intel_edison_mmap_setup; + advance_func->spi_lsbmode_replace = &mraa_intel_edison_spi_lsbmode_replace; b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * MRAA_INTEL_EDISON_PINCOUNT); if (b->pins == NULL) { -- 2.7.4