diff --git a/api/mraa/common.h b/api/mraa/common.h index 48495fe..18af987 100644 --- a/api/mraa/common.h +++ b/api/mraa/common.h @@ -26,6 +26,8 @@ #include "types.h" +#define MRAA_PLATFORM_NAME_MAX_SIZE 64 + /** @file * * This file defines the basic shared values for libmraa @@ -186,6 +188,8 @@ typedef struct { 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 */ + unsigned int platform_name_length; /**< Platform Name length */ + char* platform_name; /**< Platform Name pointer */ mraa_pininfo_t* pins; /**< Pointer to pin array */ /*@}*/ } mraa_board_t; @@ -247,6 +251,13 @@ unsigned int mraa_adc_supported_bits(); */ mraa_result_t mraa_set_log_level(int level); +/** + * Return the Platform's Name, If no platform detected return "Unknown" + * + * @return platform name + */ +char* mraa_get_platform_name(); + #ifdef __cplusplus } #endif diff --git a/api/mraa/common.hpp b/api/mraa/common.hpp index 1e8afd1..875d434 100644 --- a/api/mraa/common.hpp +++ b/api/mraa/common.hpp @@ -116,6 +116,17 @@ inline unsigned int adcSupportedBits() return mraa_adc_supported_bits(); } +/** + * Return Platform Name. "Unknown" if no platform inited. + * + * @return platform name + */ +inline std::string getPlatformName() +{ + std::string ret_val(mraa_get_platform_name()); + return ret_val; +} + /** * Sets the log level to use from 0-7 where 7 is very verbose. These are the * syslog log levels, see syslog(3) for more information on the levels. diff --git a/src/intel_de3815.c b/src/intel_de3815.c index 75fdc13..972c61a 100644 --- a/src/intel_de3815.c +++ b/src/intel_de3815.c @@ -28,6 +28,7 @@ #include "common.h" #include "intel_de3815.h" +#define PLATFORM_NAME "Intel DE3815" #define MAX_SIZE 64 #define SYSFS_CLASS_GPIO "/sys/class/gpio" @@ -38,6 +39,10 @@ mraa_intel_de3815() if (b == NULL) return NULL; + b->platform_name_length = strlen(PLATFORM_NAME) + 1; + b->platform_name = (char*) malloc(sizeof(char) * b->platform_name_length); + strncpy(b->platform_name, PLATFORM_NAME, b->platform_name_length); + b->phy_pin_count = 18; //b->gpio_count = 14; b->aio_count = 0; diff --git a/src/intel_edison_fab_c.c b/src/intel_edison_fab_c.c index 052c78c..9a3a1db 100644 --- a/src/intel_edison_fab_c.c +++ b/src/intel_edison_fab_c.c @@ -30,6 +30,7 @@ #include "common.h" #include "intel_edison_fab_c.h" +#define PLATFORM_NAME "Intel Edison" #define SYSFS_CLASS_GPIO "/sys/class/gpio" #define SYSFS_PINMODE_PATH "/sys/kernel/debug/gpio_debug/gpio" #define MAX_SIZE 64 @@ -972,6 +973,10 @@ mraa_intel_edison_fab_c() if (b == NULL) return NULL; + b->platform_name_length = strlen(PLATFORM_NAME) + 1; + b->platform_name = (char*) malloc(sizeof(char) * b->platform_name_length); + strncpy(b->platform_name, PLATFORM_NAME, b->platform_name_length); + // This seciton will also check if the arduino board is there tristate = mraa_gpio_init_raw(214); if (tristate == NULL) { diff --git a/src/intel_galileo_rev_d.c b/src/intel_galileo_rev_d.c index 1febb97..b11100e 100644 --- a/src/intel_galileo_rev_d.c +++ b/src/intel_galileo_rev_d.c @@ -30,6 +30,7 @@ #include "intel_galileo_rev_d.h" #define UIO_PATH "/dev/uio0" +#define PLATFORM_NAME "Intel Galileo Gen 1" static uint8_t *mmap_reg = NULL; static int mmap_fd = 0; @@ -123,6 +124,10 @@ mraa_intel_galileo_rev_d() if (b == NULL) return NULL; + b->platform_name_length = strlen(PLATFORM_NAME) + 1; + b->platform_name = (char*) malloc(sizeof(char) * b->platform_name_length); + strncpy(b->platform_name, PLATFORM_NAME, b->platform_name_length); + b->phy_pin_count = 20; b->gpio_count = 14; b->aio_count = 6; diff --git a/src/intel_galileo_rev_g.c b/src/intel_galileo_rev_g.c index 17ee77e..8062baa 100644 --- a/src/intel_galileo_rev_g.c +++ b/src/intel_galileo_rev_g.c @@ -32,6 +32,7 @@ #define MAX_SIZE 64 #define SYSFS_CLASS_GPIO "/sys/class/gpio" +#define PLATFORM_NAME "Intel Galileo Gen 2" #define UIO_PATH "/dev/uio0" @@ -275,6 +276,10 @@ mraa_intel_galileo_gen2() if (b == NULL) return NULL; + b->platform_name_length = strlen(PLATFORM_NAME) + 1; + b->platform_name = (char*) malloc(sizeof(char) * b->platform_name_length); + strncpy(b->platform_name, PLATFORM_NAME, b->platform_name_length); + b->phy_pin_count = 20; b->gpio_count = 14; b->aio_count = 6; diff --git a/src/intel_minnow_max.c b/src/intel_minnow_max.c index f450730..cc98b9f 100644 --- a/src/intel_minnow_max.c +++ b/src/intel_minnow_max.c @@ -28,6 +28,7 @@ #include "common.h" #include "intel_minnow_max.h" +#define PLATFORM_NAME "MinnowBoard MAX" #define I2C_BUS_COUNT 10 #define I2C_BUS_DEFAULT 7 @@ -76,6 +77,10 @@ mraa_intel_minnow_max() if (b == NULL) return NULL; + b->platform_name_length = strlen(PLATFORM_NAME) + 1; + b->platform_name = (char*) malloc(sizeof(char) * b->platform_name_length); + strncpy(b->platform_name, PLATFORM_NAME, b->platform_name_length); + b->phy_pin_count = MRAA_INTEL_MINNOW_MAX_PINCOUNT; //b->gpio_count = 14; b->aio_count = 0; diff --git a/src/mraa.c b/src/mraa.c index fbd8124..5b761f0 100644 --- a/src/mraa.c +++ b/src/mraa.c @@ -332,3 +332,11 @@ mraa_setup_uart(int index) return MRAA_SUCCESS; } + +char* +mraa_get_platform_name() +{ + if (plat == NULL) + return "Unknown"; + return plat->platform_name; +}