gpio.hpp: Add C++ wrapper around Gpio
* maa_gpio_context bcomes an opaque pointer * C++ wrapper class Gpio created * swig now uses C++ wrapper Gpio to generate API Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
39
api/gpio.h
39
api/gpio.h
@@ -46,19 +46,10 @@ extern "C" {
|
||||
* A strucutre representing a gpio pin.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
/*@{*/
|
||||
int pin; /**< the pin number, as known to the os. */
|
||||
int value_fp; /**< the file pointer to the value of the gpio */
|
||||
#ifdef SWIGPYTHON
|
||||
PyObject *isr; /**< the interupt service request */
|
||||
#else
|
||||
void (* isr)(); /**< the interupt service request */
|
||||
#endif
|
||||
pthread_t thread_id; /**< the isr handler thread id */
|
||||
int isr_value_fp; /**< the isr file pointer on the value */
|
||||
/*@}*/
|
||||
} maa_gpio_context;
|
||||
/**
|
||||
* Opaque pointer definition to the internal struct _gpio
|
||||
*/
|
||||
typedef struct _gpio* maa_gpio_context;
|
||||
|
||||
/**
|
||||
* GPIO Output modes
|
||||
@@ -91,7 +82,7 @@ typedef enum {
|
||||
*
|
||||
* @returns maa_gpio_context based on the IO pin
|
||||
*/
|
||||
maa_gpio_context* maa_gpio_init(int pin);
|
||||
maa_gpio_context maa_gpio_init(int pin);
|
||||
|
||||
/** Initialise gpio context without any mapping to a pin.
|
||||
* - For more expert users
|
||||
@@ -100,7 +91,7 @@ maa_gpio_context* maa_gpio_init(int pin);
|
||||
*
|
||||
* @return gpio context
|
||||
*/
|
||||
maa_gpio_context* maa_gpio_init_raw(int gpiopin);
|
||||
maa_gpio_context maa_gpio_init_raw(int gpiopin);
|
||||
|
||||
/** Set the edge mode on the gpio
|
||||
*
|
||||
@@ -109,7 +100,7 @@ maa_gpio_context* maa_gpio_init_raw(int gpiopin);
|
||||
*
|
||||
* @return maa result type.
|
||||
*/
|
||||
maa_result_t maa_gpio_edge_mode(maa_gpio_context *dev, gpio_edge_t mode);
|
||||
maa_result_t maa_gpio_edge_mode(maa_gpio_context dev, gpio_edge_t mode);
|
||||
|
||||
/** Set an interupt on pin
|
||||
*
|
||||
@@ -121,7 +112,7 @@ maa_result_t maa_gpio_edge_mode(maa_gpio_context *dev, gpio_edge_t mode);
|
||||
* @return maa result type.
|
||||
*/
|
||||
maa_result_t
|
||||
maa_gpio_isr(maa_gpio_context *dev, gpio_edge_t edge, void (*fptr)(void));
|
||||
maa_gpio_isr(maa_gpio_context dev, gpio_edge_t edge, void (*fptr)(void));
|
||||
|
||||
/** Stop the current interupt watcher on this GPIO, and set the GPIO edge mode
|
||||
* to MAA_GPIO_EDGE_NONE.
|
||||
@@ -131,7 +122,7 @@ maa_gpio_isr(maa_gpio_context *dev, gpio_edge_t edge, void (*fptr)(void));
|
||||
* @return maa result type.
|
||||
*/
|
||||
maa_result_t
|
||||
maa_gpio_isr_exit(maa_gpio_context *dev);
|
||||
maa_gpio_isr_exit(maa_gpio_context dev);
|
||||
|
||||
/** Set GPIO Output Mode,
|
||||
*
|
||||
@@ -140,7 +131,7 @@ maa_gpio_isr_exit(maa_gpio_context *dev);
|
||||
*
|
||||
* @return maa result type.
|
||||
*/
|
||||
maa_result_t maa_gpio_mode(maa_gpio_context *dev, gpio_mode_t mode);
|
||||
maa_result_t maa_gpio_mode(maa_gpio_context dev, gpio_mode_t mode);
|
||||
|
||||
/** Set GPIO direction
|
||||
*
|
||||
@@ -149,7 +140,7 @@ maa_result_t maa_gpio_mode(maa_gpio_context *dev, gpio_mode_t mode);
|
||||
*
|
||||
* @return maa result type.
|
||||
*/
|
||||
maa_result_t maa_gpio_dir(maa_gpio_context *dev, gpio_dir_t dir);
|
||||
maa_result_t maa_gpio_dir(maa_gpio_context dev, gpio_dir_t dir);
|
||||
|
||||
/** Close the GPIO context
|
||||
* - Will free the memory for the context and unexport the GPIO
|
||||
@@ -158,7 +149,7 @@ maa_result_t maa_gpio_dir(maa_gpio_context *dev, gpio_dir_t dir);
|
||||
*
|
||||
* @return maa result type.
|
||||
*/
|
||||
maa_result_t maa_gpio_close(maa_gpio_context *dev);
|
||||
maa_result_t maa_gpio_close(maa_gpio_context dev);
|
||||
|
||||
/** Unexport the GPIO context (maa_gpio_close() will call this function)
|
||||
*
|
||||
@@ -166,7 +157,7 @@ maa_result_t maa_gpio_close(maa_gpio_context *dev);
|
||||
*
|
||||
* @return maa result type.
|
||||
*/
|
||||
maa_result_t maa_gpio_unexport(maa_gpio_context *dev);
|
||||
maa_result_t maa_gpio_unexport(maa_gpio_context dev);
|
||||
|
||||
/** Read the GPIO value.
|
||||
*
|
||||
@@ -174,7 +165,7 @@ maa_result_t maa_gpio_unexport(maa_gpio_context *dev);
|
||||
*
|
||||
* @return the integer value of the GPIO
|
||||
*/
|
||||
int maa_gpio_read(maa_gpio_context *dev);
|
||||
int maa_gpio_read(maa_gpio_context dev);
|
||||
|
||||
/** Write to the GPIO Value.
|
||||
*
|
||||
@@ -183,7 +174,7 @@ int maa_gpio_read(maa_gpio_context *dev);
|
||||
*
|
||||
* @return maa result type
|
||||
*/
|
||||
maa_result_t maa_gpio_write(maa_gpio_context *dev, int value);
|
||||
maa_result_t maa_gpio_write(maa_gpio_context dev, int value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
79
api/gpio.hpp
Normal file
79
api/gpio.hpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/** @file
|
||||
*
|
||||
* This file defines the gpio C++ interface for libmaa
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gpio.h"
|
||||
|
||||
namespace maa {
|
||||
|
||||
class Gpio {
|
||||
public:
|
||||
Gpio(int pin, bool raw=false) {
|
||||
if (raw)
|
||||
m_gpio = maa_gpio_init_raw(pin);
|
||||
else
|
||||
m_gpio = maa_gpio_init(pin);
|
||||
}
|
||||
~Gpio() {
|
||||
maa_gpio_close(m_gpio);
|
||||
}
|
||||
maa_result_t edge(gpio_edge_t mode) {
|
||||
return maa_gpio_edge_mode(m_gpio, mode);
|
||||
}
|
||||
#if defined(SWIGPYTHON)
|
||||
maa_result_t isr(gpio_edge_t mode, PyObject *pyfunc) {
|
||||
return maa_gpio_isr(m_gpio, mode, (void (*) ()) pyfunc);
|
||||
}
|
||||
#else
|
||||
maa_result_t isr(gpio_edge_t mode, void (*fptr)(void)) {
|
||||
return maa_gpio_isr(m_gpio, mode, fptr);
|
||||
}
|
||||
#endif
|
||||
maa_result_t isr_exit() {
|
||||
return maa_gpio_isr_exit(m_gpio);
|
||||
}
|
||||
maa_result_t mode(gpio_mode_t mode) {
|
||||
return maa_gpio_mode(m_gpio, mode);
|
||||
}
|
||||
maa_result_t dir(gpio_dir_t dir) {
|
||||
return maa_gpio_dir(m_gpio, dir);
|
||||
}
|
||||
int read() {
|
||||
return maa_gpio_read(m_gpio);
|
||||
}
|
||||
int write(int value) {
|
||||
return maa_gpio_write(m_gpio, value);
|
||||
}
|
||||
private:
|
||||
maa_gpio_context m_gpio;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user