Private
Public Access
2
0

gpio: add ownership gaurd

* Will not unexport if the context did not export it. Can be forced.
* Checks if pin is already exported.

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Thomas Ingleby
2014-05-20 13:51:12 +01:00
committed by Brendan Le Foll
parent 5fa6f50edc
commit 7abd8f5529
3 changed files with 63 additions and 15 deletions

View File

@@ -159,6 +159,15 @@ maa_result_t maa_gpio_close(maa_gpio_context dev);
*/
maa_result_t maa_gpio_unexport(maa_gpio_context dev);
/** Unexport the GPIO context (maa_gpio_close() will call this function)
* Forces regardless to to ownership.
*
* @param dev The GPIO context.
*
* @return maa result type.
*/
maa_result_t maa_gpio_unexport_force(maa_gpio_context dev);
/** Read the GPIO value.
*
* @param dev The GPIO context.
@@ -176,6 +185,13 @@ int maa_gpio_read(maa_gpio_context dev);
*/
maa_result_t maa_gpio_write(maa_gpio_context dev, int value);
/** Change ownership of the context.
*
* @param dev gpio context
* @param owner does this context own the pin.
*/
maa_result_t maa_gpio_owner(maa_gpio_context dev, maa_boolean_t owner);
#ifdef __cplusplus
}
#endif

View File

@@ -56,11 +56,13 @@ typedef enum {
class Gpio {
public:
Gpio(int pin, bool raw=false) {
Gpio(int pin, bool owner=true, bool raw=false) {
if (raw)
m_gpio = maa_gpio_init_raw(pin);
else
m_gpio = maa_gpio_init(pin);
if (!owner)
maa_gpio_owner(m_gpio, 0);
}
~Gpio() {
maa_result_t x = maa_gpio_close(m_gpio);