diff --git a/api/gpio.hpp b/api/gpio.hpp index 71d4e2a..7262d83 100644 --- a/api/gpio.hpp +++ b/api/gpio.hpp @@ -34,6 +34,26 @@ namespace maa { +// These enums must match the enums in gpio.h +typedef enum { + MODE_STRONG = 0, + MODE_PULLUP = 1, + MODE_PULLDOWN = 2, + MODE_HIZ = 3 +} Mode; + +typedef enum { + DIR_OUT = 0, + DIR_IN = 1 +} Dir; + +typedef enum { + EDGE_NONE = 0, + EDGE_BOTH = 1, + EDGE_RISING = 2, + EDGE_FALLING = 3 +} Edge; + class Gpio { public: Gpio(int pin, bool raw=false) { @@ -43,28 +63,28 @@ class Gpio { m_gpio = maa_gpio_init(pin); } ~Gpio() { - maa_gpio_close(m_gpio); + maa_result_t x = maa_gpio_close(m_gpio); } - maa_result_t edge(gpio_edge_t mode) { - return maa_gpio_edge_mode(m_gpio, mode); + maa_result_t edge(Edge mode) { + return maa_gpio_edge_mode(m_gpio, (gpio_edge_t) mode); } #if defined(SWIGPYTHON) - maa_result_t isr(gpio_edge_t mode, PyObject *pyfunc) { - return maa_gpio_isr(m_gpio, mode, (void (*) ()) pyfunc); + maa_result_t isr(Edge mode, PyObject *pyfunc) { + return maa_gpio_isr(m_gpio, (gpio_edge_t) mode, (void (*) ()) pyfunc); } #else - maa_result_t isr(gpio_edge_t mode, void (*fptr)(void)) { - return maa_gpio_isr(m_gpio, mode, fptr); + maa_result_t isr(Edge mode, void (*fptr)(void)) { + return maa_gpio_isr(m_gpio, (gpio_edge_t) 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 mode(Mode mode) { + return maa_gpio_mode(m_gpio, (gpio_mode_t) mode); } - maa_result_t dir(gpio_dir_t dir) { - return maa_gpio_dir(m_gpio, dir); + maa_result_t dir(Dir dir) { + return maa_gpio_dir(m_gpio, (gpio_dir_t) dir); } int read() { return maa_gpio_read(m_gpio); diff --git a/examples/c++/Blink-IO.cpp b/examples/c++/Blink-IO.cpp index 1e3066b..c06ea6d 100644 --- a/examples/c++/Blink-IO.cpp +++ b/examples/c++/Blink-IO.cpp @@ -57,7 +57,7 @@ int main (int argc, char **argv) if (gpio == NULL) { return MAA_ERROR_UNSPECIFIED; } - int response = gpio->dir(MAA_GPIO_OUT); + int response = gpio->dir(maa::DIR_OUT); if (response != MAA_SUCCESS) maa_result_print((maa_result_t) MAA_SUCCESS); diff --git a/examples/python/blink-io8.py b/examples/python/blink-io8.py index 70ab740..b7da552 100644 --- a/examples/python/blink-io8.py +++ b/examples/python/blink-io8.py @@ -26,7 +26,7 @@ import pymaa as maa import time x = maa.Gpio(8) -x.dir(maa.MAA_GPIO_OUT) +x.dir(maa.DIR_OUT) while True: x.write(1) diff --git a/examples/python/hello_gpio.py b/examples/python/hello_gpio.py index 0698c5b..5eb58a5 100644 --- a/examples/python/hello_gpio.py +++ b/examples/python/hello_gpio.py @@ -25,4 +25,3 @@ import pymaa x = pymaa.Gpio(13) -print(x.pin) diff --git a/examples/python/hello_isr.py b/examples/python/hello_isr.py index e0ba0c6..3afa44f 100644 --- a/examples/python/hello_isr.py +++ b/examples/python/hello_isr.py @@ -6,5 +6,5 @@ def test(): print("wooo") x = maa.Gpio(6) -x.dir(maa.MAA_GPIO_IN) -x.isr(maa.MAA_GPIO_EDGE_BOTH, test) +x.dir(maa.DIR_IN) +x.isr(maa.EDGE_BOTH, test) diff --git a/examples/python/readi2c.py b/examples/python/readi2c.py deleted file mode 100644 index 6f65806..0000000 --- a/examples/python/readi2c.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env python - -# Author: Brendan Le Foll -# 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. - -import pymaa as maa - -x = maa.I2c() -x.address(0x62) -y= " " -ret = x.read(y, 2) - -print(y) diff --git a/src/maa.i b/src/maa.i index 60ac1ee..5e9e46c 100644 --- a/src/maa.i +++ b/src/maa.i @@ -17,30 +17,7 @@ const char * maa_get_version(); #### GPIO #### -/** - * GPIO Output modes - */ -typedef enum { - MAA_GPIO_STRONG = 0, /**< Default. Strong high and low */ - MAA_GPIO_PULLUP = 1, /**< Resistive High */ - MAA_GPIO_PULLDOWN = 2, /**< Resistive Low */ - MAA_GPIO_HIZ = 3 /**< High Z State */ -} gpio_mode_t; - -/** - * GPIO Direction options. - */ -typedef enum { - MAA_GPIO_OUT = 0, /**< Output. A Mode can also be set */ - MAA_GPIO_IN = 1 /**< Input. */ -} gpio_dir_t; - -typedef enum { - MAA_GPIO_EDGE_NONE = 0, /**< No interrupt on GPIO */ - MAA_GPIO_EDGE_BOTH = 1, /**< Interupt on rising & falling */ - MAA_GPIO_EDGE_RISING = 2, /**< Interupt on rising only */ - MAA_GPIO_EDGE_FALLING = 3 /**< Interupt on falling only */ -} gpio_edge_t; +#### GPIO #### %include "gpio.hpp"