platform_type: platform_type now in mraa_board_t
Now platform_type is no longer global it tracks with board instance so that platform and sub-platform can report different types. Signed-off-by: Henry Bruce <henry.bruce@intel.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
committed by
Brendan Le Foll
parent
6302b635aa
commit
7ada55982d
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
27
src/mraa.c
27
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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user