diff --git a/examples/mraa-i2c.c b/examples/mraa-i2c.c index 3bde860..7ebfd0a 100644 --- a/examples/mraa-i2c.c +++ b/examples/mraa-i2c.c @@ -66,7 +66,7 @@ print_bus(mraa_board_t* board) int i, bus; for (i = 0; i < board->i2c_bus_count; ++i) { char* busType; - switch (mraa_get_platform_type()) { + switch (board->platform_type) { case MRAA_INTEL_GALILEO_GEN1: case MRAA_INTEL_GALILEO_GEN2: case MRAA_INTEL_EDISON_FAB_C: @@ -86,9 +86,13 @@ print_bus(mraa_board_t* board) busType = "unknown"; break; } - fprintf(stdout, "Bus %2d: id=%02d type=%s ", bus, plat->i2c_bus[bus].bus_id, busType); - if (i == plat->def_i2c_bus) + int id = board->i2c_bus[bus].bus_id; + fprintf(stdout, "Bus %3d: id=%02d type=%s ", bus, id, busType); + if (i == board->def_i2c_bus) fprintf(stdout, " default", i); + if (id == -1) + fprintf(stdout, " disabled", i); + fprintf(stdout, "\n"); } } diff --git a/include/mraa_internal_types.h b/include/mraa_internal_types.h index a140c86..155f147 100644 --- a/include/mraa_internal_types.h +++ b/include/mraa_internal_types.h @@ -247,6 +247,7 @@ typedef struct _board_t { int pwm_default_period; /**< The default PWM period is US */ int pwm_max_period; /**< Maximum period in us */ int pwm_min_period; /**< Minimum period in us */ + mraa_platform_t platform_type; const char* platform_name; /**< Platform Name pointer */ mraa_pininfo_t* pins; /**< Pointer to pin array */ mraa_adv_func_t* adv_func; /**< Pointer to advanced function disptach table */ diff --git a/src/mraa.c b/src/mraa.c index fbba808..5f57147 100644 --- a/src/mraa.c +++ b/src/mraa.c @@ -46,7 +46,6 @@ #include "version.h" mraa_board_t* plat = NULL; -static mraa_platform_t platform_type = MRAA_UNKNOWN_PLATFORM; mraa_adv_func_t* advance_func; const char* @@ -101,6 +100,7 @@ mraa_init() advance_func = (mraa_adv_func_t*) malloc(sizeof(mraa_adv_func_t)); memset(advance_func, 0, sizeof(mraa_adv_func_t)); + mraa_platform_t platform_type; #if defined(X86PLAT) // Use runtime x86 platform detection platform_type = mraa_x86_platform(); @@ -111,16 +111,23 @@ mraa_init() #error mraa_ARCH NOTHING #endif + if (plat != NULL) + plat->platform_type = platform_type; + #ifdef USBPLAT // This is a platform extender so create null base platform if one doesn't already exist if (plat == NULL) { plat = (mraa_board_t*) calloc(1, sizeof(mraa_board_t)); - plat->platform_name = "Unknown platform"; if (plat != NULL) { - int usb_platform_type = mraa_usb_platform_extender(plat); - if (platform_type == MRAA_UNKNOWN_PLATFORM) { - platform_type = usb_platform_type; - } + plat->platform_type = MRAA_UNKNOWN_PLATFORM; + plat->platform_name = "Unknown platform"; + } + } + // Now detect sub platform + if (plat != NULL) { + mraa_platform_t usb_platform_type = mraa_usb_platform_extender(plat); + if (plat->platform_type == MRAA_UNKNOWN_PLATFORM) { + plat->platform_type = usb_platform_type; } } if (plat == NULL) { @@ -129,7 +136,7 @@ mraa_init() } #endif - syslog(LOG_NOTICE, "libmraa initialised for platform '%s' of type %d", mraa_get_platform_name(), platform_type); + syslog(LOG_NOTICE, "libmraa initialised for platform '%s' of type %d", mraa_get_platform_name(), mraa_get_platform_type()); return MRAA_SUCCESS; } @@ -290,7 +297,9 @@ mraa_pin_mode_test(int pin, mraa_pinmodes_t mode) mraa_platform_t mraa_get_platform_type() { - return platform_type; + if (plat == NULL) + return MRAA_UNKNOWN_PLATFORM; + return plat->platform_type; } unsigned int @@ -590,7 +599,7 @@ mraa_find_i2c_bus(const char* devname, int startfrom) mraa_boolean_t mraa_is_on_sub_platform(int pin_or_bus) { - return (pin_or_bus | MRAA_SUB_PLATFORM_MASK) != 0; + return (pin_or_bus & MRAA_SUB_PLATFORM_MASK) != 0; } int diff --git a/src/usb/ftdi_ft4222.c b/src/usb/ftdi_ft4222.c index b7a963f..bd57f52 100644 --- a/src/usb/ftdi_ft4222.c +++ b/src/usb/ftdi_ft4222.c @@ -332,6 +332,7 @@ mraa_ftdi_ft4222(mraa_board_t* board) int pinIndex = 0; int numUsbGpio = 0; int numUsbPins = numUsbGpio + 2; // Add SDA and SCL + sub_plat->platform_type = MRAA_FTDI_FT4222; sub_plat->platform_name = PLATFORM_NAME; sub_plat->phy_pin_count = numUsbPins; sub_plat->gpio_count = numUsbGpio;