Private
Public Access
2
0

mraa.c: Added mainn and sub-platform select API calls.

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:
Henry Bruce
2015-07-27 09:32:39 -07:00
committed by Brendan Le Foll
parent 99593ec640
commit 7058fea8bd
2 changed files with 88 additions and 43 deletions

View File

@@ -150,13 +150,6 @@ void mraa_result_print(mraa_result_t result);
*/ */
mraa_platform_t mraa_get_platform_type(); mraa_platform_t mraa_get_platform_type();
/**
* Get sub platform type, board must be initialised.
*
* @return mraa_platform_t Platform type enum
*/
mraa_platform_t mraa_get_sub_platform_type();
/** /**
* Get platform pincount, board must be initialised. * Get platform pincount, board must be initialised.
* *
@@ -195,6 +188,27 @@ char* mraa_get_pin_name(int pin);
*/ */
int mraa_get_default_2c_bus(); int mraa_get_default_2c_bus();
/**
* Select main platform for platform info calls.
*
* @return mraa_boolean_t 1 if main platform is available, 0 otherwise
*/
mraa_boolean_t mraa_select_main_platform();
/**
* Select sub platform for platform info calls.
*
* @return mraa_boolean_t 1 if sub platform is available, 0 otherwise
*/
mraa_boolean_t mraa_select_sub_platform();
/**
* Check if sub platform is currently available and selected for platform info calls.
*
* @return mraa_boolean_t 1 if sub platform is selected, 0 otherwise
*/
mraa_boolean_t mraa_is_sub_platform_selected();
/** /**
* Check if pin or bus id includes sub platform mask. * Check if pin or bus id includes sub platform mask.
* *

View File

@@ -46,6 +46,7 @@
#include "version.h" #include "version.h"
mraa_board_t* plat = NULL; mraa_board_t* plat = NULL;
static mraa_board_t* current_plat = NULL;
mraa_adv_func_t* advance_func; mraa_adv_func_t* advance_func;
const char* const char*
@@ -104,7 +105,7 @@ mraa_init()
#if defined(X86PLAT) #if defined(X86PLAT)
// Use runtime x86 platform detection // Use runtime x86 platform detection
platform_type = mraa_x86_platform(); platform_type = mraa_x86_platform();
// x86 platforms have advanced_func stable in board config structure // x86 platforms have advanced_func table in board config structure
free(advance_func); free(advance_func);
if (plat != NULL) if (plat != NULL)
advance_func = plat->adv_func; advance_func = plat->adv_func;
@@ -141,6 +142,7 @@ mraa_init()
#endif #endif
syslog(LOG_NOTICE, "libmraa initialised for platform '%s' of type %d", mraa_get_platform_name(), mraa_get_platform_type()); syslog(LOG_NOTICE, "libmraa initialised for platform '%s' of type %d", mraa_get_platform_name(), mraa_get_platform_type());
current_plat = plat;
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
@@ -151,7 +153,15 @@ mraa_deinit()
if (plat->pins != NULL) { if (plat->pins != NULL) {
free(plat->pins); free(plat->pins);
} }
mraa_board_t* sub_plat = plat->sub_platform;
if (sub_plat != NULL) {
if (sub_plat->pins != NULL) {
free(sub_plat->pins);
}
free(sub_plat);
}
free(plat); free(plat);
} }
closelog(); closelog();
} }
@@ -249,46 +259,75 @@ mraa_result_print(mraa_result_t result)
} }
} }
mraa_boolean_t
mraa_select_main_platform()
{
if (plat != NULL) {
current_plat = plat;
return 1;
} else
return 0;
}
mraa_boolean_t
mraa_select_sub_platform()
{
if (plat->sub_platform != NULL) {
current_plat = plat->sub_platform;
return 1;
} else
return 0;
}
mraa_boolean_t
mraa_is_sub_platform_selected()
{
return (plat->sub_platform != NULL) && (current_plat == plat->sub_platform);
}
mraa_boolean_t mraa_boolean_t
mraa_pin_mode_test(int pin, mraa_pinmodes_t mode) mraa_pin_mode_test(int pin, mraa_pinmodes_t mode)
{ {
if (plat == NULL) { if (current_plat == NULL) {
return 0; return 0;
} }
if (pin > (plat->phy_pin_count - 1) || pin < 0) if (pin > (current_plat->phy_pin_count - 1) || pin < 0)
return 0; return 0;
switch (mode) { switch (mode) {
case MRAA_PIN_VALID: case MRAA_PIN_VALID:
if (plat->pins[pin].capabilites.valid == 1) if (current_plat->pins[pin].capabilites.valid == 1)
return 1; return 1;
break; break;
case MRAA_PIN_GPIO: case MRAA_PIN_GPIO:
if (plat->pins[pin].capabilites.gpio == 1) if (current_plat->pins[pin].capabilites.gpio == 1)
return 1; return 1;
break; break;
case MRAA_PIN_PWM: case MRAA_PIN_PWM:
if (plat->pins[pin].capabilites.pwm == 1) if (current_plat->pins[pin].capabilites.pwm == 1)
return 1; return 1;
break; break;
case MRAA_PIN_FAST_GPIO: case MRAA_PIN_FAST_GPIO:
if (plat->pins[pin].capabilites.fast_gpio == 1) if (current_plat->pins[pin].capabilites.fast_gpio == 1)
return 1; return 1;
break; break;
case MRAA_PIN_SPI: case MRAA_PIN_SPI:
if (plat->pins[pin].capabilites.spi == 1) if (current_plat->pins[pin].capabilites.spi == 1)
return 1; return 1;
break; break;
case MRAA_PIN_I2C: case MRAA_PIN_I2C:
if (plat->pins[pin].capabilites.i2c == 1) if (current_plat->pins[pin].capabilites.i2c == 1)
return 1; return 1;
break; break;
case MRAA_PIN_AIO: case MRAA_PIN_AIO:
if (plat->pins[pin].capabilites.aio == 1) if (current_plat->pins[pin].capabilites.aio == 1)
return 1; return 1;
break; break;
case MRAA_PIN_UART: case MRAA_PIN_UART:
if (plat->pins[pin].capabilites.uart == 1) if (current_plat->pins[pin].capabilites.uart == 1)
return 1; return 1;
break; break;
default: default:
@@ -301,52 +340,44 @@ mraa_pin_mode_test(int pin, mraa_pinmodes_t mode)
mraa_platform_t mraa_platform_t
mraa_get_platform_type() mraa_get_platform_type()
{ {
if (plat == NULL) if (current_plat == NULL)
return MRAA_UNKNOWN_PLATFORM; return MRAA_UNKNOWN_PLATFORM;
return plat->platform_type; return current_plat->platform_type;
} }
mraa_platform_t
mraa_get_sub_platform_type()
{
if (plat == NULL || plat->sub_platform == NULL)
return MRAA_UNKNOWN_PLATFORM;
return plat->sub_platform->platform_type;
}
unsigned int unsigned int
mraa_adc_raw_bits() mraa_adc_raw_bits()
{ {
if (plat == NULL) if (current_plat == NULL)
return 0; return 0;
if (plat->aio_count == 0) if (current_plat->aio_count == 0)
return 0; return 0;
return plat->adc_raw; return current_plat->adc_raw;
} }
unsigned int unsigned int
mraa_adc_supported_bits() mraa_adc_supported_bits()
{ {
if (plat == NULL) if (current_plat == NULL)
return 0; return 0;
if (plat->aio_count == 0) if (current_plat->aio_count == 0)
return 0; return 0;
return plat->adc_supported; return current_plat->adc_supported;
} }
char* char*
mraa_get_platform_name() mraa_get_platform_name()
{ {
if (plat == NULL) { if (current_plat == NULL) {
return NULL; return NULL;
} }
return (char*) plat->platform_name; return (char*) current_plat->platform_name;
} }
int int
@@ -375,30 +406,30 @@ mraa_get_i2c_bus_id(unsigned i2c_bus)
unsigned int unsigned int
mraa_get_pin_count() mraa_get_pin_count()
{ {
if (plat == NULL) { if (current_plat == NULL) {
return 0; return 0;
} }
return plat->phy_pin_count; return current_plat->phy_pin_count;
} }
char* char*
mraa_get_pin_name(int pin) mraa_get_pin_name(int pin)
{ {
if (plat == NULL) { if (current_plat == NULL) {
return NULL; return NULL;
} }
if (pin > (plat->phy_pin_count - 1) || pin < 0) if (pin > (current_plat->phy_pin_count - 1) || pin < 0)
return NULL; return NULL;
return (char*) plat->pins[pin].name; return (char*) current_plat->pins[pin].name;
} }
int int
mraa_get_default_i2c_bus() mraa_get_default_i2c_bus()
{ {
if (plat == NULL) { if (current_plat == NULL) {
return -1; return -1;
} else } else
return plat->def_i2c_bus; return current_plat->def_i2c_bus;
} }