Private
Public Access
2
0

gpio: add function to get raw gpio number.

Will return the GPIO number used within SYSFS
Closes #63

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
This commit is contained in:
Thomas Ingleby
2015-01-20 18:24:57 +00:00
parent 4e5991779a
commit c3980c217c
3 changed files with 27 additions and 2 deletions

View File

@@ -202,6 +202,14 @@ mraa_result_t mraa_gpio_use_mmaped(mraa_gpio_context dev, mraa_boolean_t mmap);
*/
int mraa_gpio_get_pin(mraa_gpio_context dev);
/**
* Get a gpio number as used within sysfs
*
* @param dev The Gpio context
* @return gpio number
*/
int mraa_gpio_get_pin_raw(mraa_gpio_context dev);
#ifdef __cplusplus
}
#endif

View File

@@ -186,11 +186,16 @@ class Gpio {
return mraa_gpio_use_mmaped(m_gpio, (mraa_boolean_t) enable);
}
/**
* Get pin number of Gpio
* Get pin number of Gpio. If raw param is True will return the
* number as used within sysfs
*
* @param raw (optional) get the raw gpio number.
* @return Pin number
*/
int getPin() {
int getPin(bool raw = false) {
if (raw) {
return mraa_gpio_get_pin_raw(m_gpio);
}
return mraa_gpio_get_pin(m_gpio);
}
private:

View File

@@ -583,5 +583,17 @@ mraa_gpio_use_mmaped(mraa_gpio_context dev, mraa_boolean_t mmap_en)
int
mraa_gpio_get_pin(mraa_gpio_context dev)
{
if (dev == NULL) {
syslog(LOG_ERR, "gpio: context is invalid");
}
return dev->phy_pin;
}
int
mraa_gpio_get_pin_raw(mraa_gpio_context dev)
{
if (dev == NULL) {
syslog(LOG_ERR, "gpio: context is invalid");
}
return dev->pin;
}