Private
Public Access
2
0

periphmraa: Create IndexLookup functions for GPIO, I2C, SPI, PWM

These lookups provide the MRAA index with the Pin/Bus name as input

Signed-off-by: Vineela Tummalapalli <vineela.tummalapalli@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Vineela Tummalapalli
2017-04-06 17:38:44 -07:00
committed by Noel Eck
parent 7bc069a8fd
commit 913eaf2440
5 changed files with 209 additions and 2 deletions

View File

@@ -233,6 +233,42 @@ unsigned int mraa_get_platform_pin_count(uint8_t platform_offset);
*/
char* mraa_get_pin_name(int pin);
/**
* Get pin number, board must be initialised.
*
* @param pin_name: GPIO Pin Name. Eg: IO0
* @return int of MRAA index for gpio
*/
int mraa_gpio_lookup(const char* pin_name);
/**
* Get pin number, board must be initialised.
*
* @param i2c_name: I2c Bus Name. Eg: I2C6
* @return int of MRAA index of i2c bus
*/
int mraa_i2c_lookup(const char* i2c_name);
/**
* Get pin number, board must be initialised.
*
* @param spi_name: Name of spi bus. Eg: SPI2
* @return int for MRAA index of spi bus
*/
int mraa_spi_lookup(const char* spi_name);
/**
* Get pin number, board must be initialised.
*
* @param pwm_name: Name of pwm. Eg:PWM0
* @return int of MRAA index for pwm bus
*/
int mraa_pwm_lookup(const char* pwm_name);
/**
* Get default i2c bus, board must be initialised.
*

View File

@@ -27,6 +27,8 @@
#include "common.h"
#include "types.hpp"
#include <string>
#include <sstream>
#include <stdexcept>
/**
* @namespace mraa namespace
@@ -214,6 +216,90 @@ getPinName(int pin)
return ret_val;
}
/**
* Get pin number, board must be initialised.
*
* @param pin_name: GPIO Pin Name. Eg: IO0
* @throws std::invalid_argument if name is not valid
* @return int of MRAA index for gpio
*/
inline int
getGpioLookup(std::string pin_name)
{
int index = mraa_gpio_lookup(pin_name.c_str());
if (index < 0){
std::ostringstream oss;
oss << "Gpio name " << pin_name << " is not valid";
throw std::invalid_argument(oss.str());
}
return index;
}
/**
* Get pin number, board must be initialised.
*
* @param i2c_name: I2c Bus Name. Eg: I2C6
* @throws std::invalid_argument if name is not valid
* @return int of MRAA index of i2c bus
*/
inline int
getI2cLookup(std::string i2c_name)
{
int index = mraa_i2c_lookup(i2c_name.c_str());
if (index < 0){
std::ostringstream oss;
oss << "i2c name " << i2c_name << " is not valid";
throw std::invalid_argument(oss.str());
}
return index;
}
/**
* Get pin number, board must be initialised.
*
* @param spi_name: Name of spi bus. Eg: SPI2
* @throws std::invalid_argument if name is not valid
* @return int for MRAA index of spi bus
*/
inline int
getSpiLookup(std::string spi_name)
{
int index = mraa_spi_lookup(spi_name.c_str());
if (index < 0){
std::ostringstream oss;
oss << "Spi name " << spi_name << " is not valid";
throw std::invalid_argument(oss.str());
}
return index;
}
/**
* Get pin number, board must be initialised.
*
* @param pwm_name: Name of pwm. Eg:PWM0
* @throws std::invalid_argument if name is not valid
* @return int of MRAA index for pwm bus
*/
inline int
getPwmLookup(std::string pwm_name)
{
int index = mraa_pwm_lookup(pwm_name.c_str());
if (index < 0){
std::ostringstream oss;
oss << "PWM name " << pwm_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.