diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 81159cd..59ea5df 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,12 @@ +0.0.7 +---- +* GPIO edge detection expanded to include AP-EINT1 and AP-EINT3 as those are the only other pins that support edge detection + +0.0.6 +---- +* Initial PWM +* GPIO edge detection and callback for XIO-P0 to XIO-P7 working + 0.0.4 ____ * Initial Commit diff --git a/setup.py b/setup.py index 10c9668..54b441d 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ classifiers = ['Development Status :: 3 - Alpha', 'Topic :: System :: Hardware'] setup(name = 'CHIP_IO', - version = '0.0.6', + version = '0.0.7', author = 'Robert Wolterman', author_email = 'robert.wolterman@gmail.com', description = 'A module to control CHIP IO channels', @@ -33,4 +33,3 @@ setup(name = 'CHIP_IO', ext_modules = [Extension('CHIP_IO.GPIO', ['source/py_gpio.c', 'source/event_gpio.c', 'source/constants.c', 'source/common.c'], extra_compile_args=['-Wno-format-security']), Extension('CHIP_IO.PWM', ['source/py_pwm.c', 'source/c_pwm.c', 'source/constants.c', 'source/common.c'], extra_compile_args=['-Wno-format-security'])]) #, # Extension('CHIP_IO.ADC', ['source/py_adc.c', 'source/c_adc.c', 'source/constants.c', 'source/common.c'], extra_compile_args=['-Wno-format-security']), -# Extension('CHIP_IO.SPI', ['source/spimodule.c', 'source/constants.c', 'source/common.c'], extra_compile_args=['-Wno-format-security'])]) diff --git a/source/constants.c b/source/constants.c index bec6d8d..8254a51 100644 --- a/source/constants.c +++ b/source/constants.c @@ -76,6 +76,6 @@ void define_constants(PyObject *module) both_edge = Py_BuildValue("i", BOTH_EDGE); PyModule_AddObject(module, "BOTH", both_edge); - version = Py_BuildValue("s", "0.0.6"); + version = Py_BuildValue("s", "0.0.7"); PyModule_AddObject(module, "VERSION", version); } diff --git a/source/py_gpio.c b/source/py_gpio.c index ec13fb8..510ddf1 100644 --- a/source/py_gpio.c +++ b/source/py_gpio.c @@ -268,9 +268,9 @@ static PyObject *py_add_event_callback(PyObject *self, PyObject *args, PyObject if (get_gpio_number(channel, &gpio)) return NULL; - // check to ensure gpio is on the expanded pins as those are the only ones that allow for edge settings - if (gpio < 408) { - PyErr_SetString(PyExc_RuntimeError, "Callbacks currently available on XIO-P0 to XIO-P7 only"); + // check to ensure gpio is one of the allowed pins + if (gpio != 35 && gpio != 193 && (gpio <= 415 && gpio >= 408)) { + PyErr_SetString(PyExc_RuntimeError, "Callbacks currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only"); return NULL; } @@ -315,9 +315,9 @@ static PyObject *py_add_event_detect(PyObject *self, PyObject *args, PyObject *k if (get_gpio_number(channel, &gpio)) return NULL; - // check to ensure gpio is on the expanded pins as those are the only ones that allow for edge settings - if (gpio < 408) { - PyErr_SetString(PyExc_RuntimeError, "Edge Detection currently available on XIO-P0 to XIO-P7 only"); + // check to ensure gpio is one of the allowed pins + if (gpio != 35 && gpio != 193 && (gpio <= 415 && gpio >= 408)) { + PyErr_SetString(PyExc_RuntimeError, "Edge Detection currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only"); return NULL; } @@ -369,9 +369,9 @@ static PyObject *py_remove_event_detect(PyObject *self, PyObject *args) if (get_gpio_number(channel, &gpio)) return NULL; - // check to ensure gpio is on the expanded pins as those are the only ones that allow for edge settings - if (gpio < 408) { - PyErr_SetString(PyExc_RuntimeError, "Edge Detection currently available on XIO-P0 to XIO-P7 only"); + // check to ensure gpio is one of the allowed pins + if (gpio != 35 && gpio != 193 && (gpio <= 415 && gpio >= 408)) { + PyErr_SetString(PyExc_RuntimeError, "Edge Detection currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only"); return NULL; } @@ -431,9 +431,9 @@ static PyObject *py_wait_for_edge(PyObject *self, PyObject *args) if (get_gpio_number(channel, &gpio)) return NULL; - // check to ensure gpio is on the expanded pins as those are the only ones that allow for edge settings - if (gpio < 408) { - PyErr_SetString(PyExc_RuntimeError, "Edge Detection currently available on XIO-P0 to XIO-P7 only"); + // check to ensure gpio is one of the allowed pins + if (gpio != 35 && gpio != 193 && (gpio <= 415 && gpio >= 408)) { + PyErr_SetString(PyExc_RuntimeError, "Edge Detection currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only"); return NULL; } @@ -514,7 +514,7 @@ static PyObject *py_setwarnings(PyObject *self, PyObject *args) static const char moduledocstring[] = "GPIO functionality of a CHIP using Python"; PyMethodDef gpio_methods[] = { - {"setup", (PyCFunction)py_setup_channel, METH_VARARGS | METH_KEYWORDS, "Set up the GPIO channel, direction and (optional) pull/up down control\nchannel - Either: RPi board pin number (not BCM GPIO 00..nn number). Pins start from 1\n or : BCM GPIO number\ndirection - INPUT or OUTPUT\n[pull_up_down] - PUD_OFF (default), PUD_UP or PUD_DOWN\n[initial] - Initial value for an output channel"}, + {"setup", (PyCFunction)py_setup_channel, METH_VARARGS | METH_KEYWORDS, "Set up the GPIO channel, direction and (optional) pull/up down control\nchannel - Either: CHIP board pin number (not R8 GPIO 00..nn number). Pins start from 1\n or : CHIP GPIO name\ndirection - INPUT or OUTPUT\n[pull_up_down] - PUD_OFF (default), PUD_UP or PUD_DOWN\n[initial] - Initial value for an output channel"}, {"cleanup", py_cleanup, METH_VARARGS, "Clean up by resetting all GPIO channels that have been used by this program to INPUT with no pullup/pulldown and no event detection"}, {"output", py_output_gpio, METH_VARARGS, "Output to a GPIO channel\ngpio - gpio channel\nvalue - 0/1 or False/True or LOW/HIGH"}, {"input", py_input_gpio, METH_VARARGS, "Input from a GPIO channel. Returns HIGH=1=True or LOW=0=False\ngpio - gpio channel"}, diff --git a/test/gptest.py b/test/gptest.py index 56dfeb6..58750a2 100755 --- a/test/gptest.py +++ b/test/gptest.py @@ -34,9 +34,35 @@ print "HIGH", GPIO.input("XIO-P0") GPIO.output("CSID0", GPIO.LOW) print "LOW", GPIO.input("XIO-P0") +# ============================================== +# EDGE DETECTION - AP-EINT1 +print "SETTING UP EDGE DETECTION ON AP-EINT1" +GPIO.setup("AP-EINT1", GPIO.IN) +GPIO.add_event_detect("AP-EINT1",GPIO.FALLING) + +print "VERIFYING EDGE DETECT" +f = open("/sys/class/gpio/gpio193/edge","r") +edge = f.read() +f.close() +print "EDGE: %s" % edge +GPIO.remove_event_detect("AP-EINT1") + +# ============================================== +# EDGE DETECTION - AP-EINT3 +print "SETTING UP EDGE DETECTION ON AP-EINT3" +GPIO.setup("AP-EINT3", GPIO.IN) +GPIO.add_event_detect("AP-EINT3",GPIO.FALLING) + +print "VERIFYING EDGE DETECT" +f = open("/sys/class/gpio/gpio35/edge","r") +edge = f.read() +f.close() +print "EDGE: %s" % edge +GPIO.remove_event_detect("AP-EINT3") + # ============================================== # EDGE DETECTION - EXPANDED GPIO -print "SETTING UP EDGE DETECTION" +print "SETTING UP EDGE DETECTION ON XIO-P0" GPIO.add_event_detect("XIO-P0",GPIO.FALLING,myfuncallback) print "VERIFYING EDGE DETECT"