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);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
||||
@@ -300,6 +300,27 @@ getPwmLookup(std::string pwm_name)
|
||||
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
|
||||
* syslog log levels, see syslog(3) for more information on the levels.
|
||||
|
||||
Reference in New Issue
Block a user