mraa.c: add a by-name lookup function also for UARTs
Signed-off-by: Tapani Utriainen <tapani@technexion.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
committed by
Brendan Le Foll
parent
9479843cde
commit
5ef3f3ea29
@@ -265,6 +265,14 @@ int mraa_spi_lookup(const char* spi_name);
|
|||||||
*/
|
*/
|
||||||
int mraa_pwm_lookup(const char* pwm_name);
|
int mraa_pwm_lookup(const char* pwm_name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get UART index by name, board must be initialised.
|
||||||
|
*
|
||||||
|
* @param uart_name: Name of UART. Eg:UART1
|
||||||
|
* @return int of MRAA index for UART, or -1 if not found.
|
||||||
|
*/
|
||||||
|
int mraa_uart_lookup(const char* uart_name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get default i2c bus, board must be initialised.
|
* Get default i2c bus, board must be initialised.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -300,6 +300,27 @@ getPwmLookup(std::string pwm_name)
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get UART index by UART name, board must be initialised.
|
||||||
|
*
|
||||||
|
* @param pwm_name: Name of the UART. Eg: UART2
|
||||||
|
* @throws std::invalid_argument if name is not found
|
||||||
|
* @return MRAA index for the UART
|
||||||
|
*/
|
||||||
|
inline int
|
||||||
|
getUartLookup(std::string uart_name)
|
||||||
|
{
|
||||||
|
int index = mraa_uart_lookup(uart_name.c_str());
|
||||||
|
|
||||||
|
if (index < 0) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "UART name " << uart_name << " is not valid";
|
||||||
|
throw std::invalid_argument(oss.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the log level to use from 0-7 where 7 is very verbose. These are the
|
* 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.
|
* syslog log levels, see syslog(3) for more information on the levels.
|
||||||
|
|||||||
21
src/mraa.c
21
src/mraa.c
@@ -903,6 +903,27 @@ mraa_pwm_lookup(const char* pwm_name)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
mraa_uart_lookup(const char* uart_name)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (plat == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uart_name == NULL || strlen(uart_name) == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < plat->uart_dev_count; i++) {
|
||||||
|
if (plat->uart_dev[i].name != NULL && strcmp(uart_name, plat->uart_dev[i].name) == 0) {
|
||||||
|
return plat->uart_dev[i].index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
mraa_get_default_i2c_bus(uint8_t platform_offset)
|
mraa_get_default_i2c_bus(uint8_t platform_offset)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user