usb: Converted sub-platform bus/pin helper macros to functions.
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
1c9b87bfd3
commit
4a6bf832bc
@@ -31,9 +31,6 @@
|
|||||||
|
|
||||||
#define MRAA_SUB_PLATFORM_BIT_SHIFT 9
|
#define MRAA_SUB_PLATFORM_BIT_SHIFT 9
|
||||||
#define MRAA_SUB_PLATFORM_MASK (1<<MRAA_SUB_PLATFORM_BIT_SHIFT)
|
#define MRAA_SUB_PLATFORM_MASK (1<<MRAA_SUB_PLATFORM_BIT_SHIFT)
|
||||||
#define MRAA_IS_ON_SUB_PLATFORM(pin_or_bus) (((pin_or_bus)|MRAA_SUB_PLATFORM_MASK) != 0)
|
|
||||||
#define MRAA_USE_SUB_PLATFORM(pin_or_bus) ((pin_or_bus)|MRAA_SUB_PLATFORM_MASK)
|
|
||||||
#define MRAA_GET_SUB_PLATFORM_INDEX(pin_or_bus) ((pin_or_bus)&(~MRAA_SUB_PLATFORM_MASK))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -191,6 +188,34 @@ char* mraa_get_pin_name(int pin);
|
|||||||
*/
|
*/
|
||||||
int mraa_get_default_2c_bus();
|
int mraa_get_default_2c_bus();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if pin or bus id includes sub platform mask.
|
||||||
|
*
|
||||||
|
* @param int pin or bus number
|
||||||
|
*
|
||||||
|
* @return mraa_boolean_t 1 if pin or bus is for sub platform, 0 otherwise
|
||||||
|
*/
|
||||||
|
mraa_boolean_t mraa_is_on_sub_platform(int pin_or_bus);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert pin or bus id to corresponding sub platform id.
|
||||||
|
*
|
||||||
|
* @param int pin or bus number
|
||||||
|
*
|
||||||
|
* @return int sub platform pin or bus number
|
||||||
|
*/
|
||||||
|
int mraa_use_sub_platform(int pin_or_bus);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert pin or bus sub platform id to base platform id.
|
||||||
|
*
|
||||||
|
* @param int sub platform pin or bus number
|
||||||
|
*
|
||||||
|
* @return int base platform pin or bus number
|
||||||
|
*/
|
||||||
|
int mraa_get_sub_platform_index(int pin_or_bus);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,9 +63,8 @@ print_command_error()
|
|||||||
void
|
void
|
||||||
print_bus(mraa_board_t* board)
|
print_bus(mraa_board_t* board)
|
||||||
{
|
{
|
||||||
int bus_index;
|
int i, bus;
|
||||||
int bus;
|
for (i = 0; i < board->i2c_bus_count; ++i) {
|
||||||
for (bus = 0; bus < board->i2c_bus_count; ++bus) {
|
|
||||||
char* busType;
|
char* busType;
|
||||||
switch (mraa_get_platform_type()) {
|
switch (mraa_get_platform_type()) {
|
||||||
case MRAA_INTEL_GALILEO_GEN1:
|
case MRAA_INTEL_GALILEO_GEN1:
|
||||||
@@ -76,21 +75,21 @@ print_bus(mraa_board_t* board)
|
|||||||
case MRAA_RASPBERRY_PI:
|
case MRAA_RASPBERRY_PI:
|
||||||
case MRAA_BEAGLEBONE:
|
case MRAA_BEAGLEBONE:
|
||||||
case MRAA_BANANA:
|
case MRAA_BANANA:
|
||||||
bus_index = bus;
|
bus = i;
|
||||||
busType = "stdapi";
|
busType = "stdapi";
|
||||||
break;
|
break;
|
||||||
case MRAA_FTDI_FT4222:
|
case MRAA_FTDI_FT4222:
|
||||||
busType = "ft4222";
|
busType = "ft4222";
|
||||||
bus_index = MRAA_USE_SUB_PLATFORM(bus);
|
bus = mraa_use_sub_platform(i);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
busType = "unknown";
|
busType = "unknown";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fprintf(stdout, "Bus %2d: id=%02d type=%s ", bus_index, plat->i2c_bus[bus].bus_id, busType);
|
fprintf(stdout, "Bus %2d: id=%02d type=%s ", bus, plat->i2c_bus[bus].bus_id, busType);
|
||||||
if (bus == plat->def_i2c_bus)
|
if (i == plat->def_i2c_bus)
|
||||||
fprintf(stdout, " default", bus);
|
fprintf(stdout, " default", i);
|
||||||
fprintf(stdout, "\n", bus);
|
fprintf(stdout, "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,14 +80,14 @@ mraa_i2c_init(int bus)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MRAA_IS_ON_SUB_PLATFORM(bus)) {
|
if (mraa_is_on_sub_platform(bus)) {
|
||||||
syslog(LOG_NOTICE, "i2c: Using sub platform");
|
syslog(LOG_NOTICE, "i2c: Using sub platform");
|
||||||
board = board->sub_platform;
|
board = board->sub_platform;
|
||||||
if (board == NULL) {
|
if (board == NULL) {
|
||||||
syslog(LOG_ERR, "i2c: Sub platform Not Initialised");
|
syslog(LOG_ERR, "i2c: Sub platform Not Initialised");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
bus = MRAA_GET_SUB_PLATFORM_INDEX(bus);
|
bus = mraa_get_sub_platform_index(bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (board->i2c_bus_count == 0) {
|
if (board->i2c_bus_count == 0) {
|
||||||
|
|||||||
18
src/mraa.c
18
src/mraa.c
@@ -586,3 +586,21 @@ mraa_find_i2c_bus(const char* devname, int startfrom)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mraa_boolean_t
|
||||||
|
mraa_is_on_sub_platform(int pin_or_bus)
|
||||||
|
{
|
||||||
|
return (pin_or_bus | MRAA_SUB_PLATFORM_MASK) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
mraa_use_sub_platform(int pin_or_bus)
|
||||||
|
{
|
||||||
|
return pin_or_bus | MRAA_SUB_PLATFORM_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
mraa_get_sub_platform_index(int pin_or_bus)
|
||||||
|
{
|
||||||
|
return pin_or_bus & (~MRAA_SUB_PLATFORM_MASK);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user