1
0
mirror of https://github.com/xtacocorex/CHIP_IO synced 2025-07-20 04:43:21 +00:00

Addressing Issue #1, adding the ability to set the AP-EINT1 and AP-EINT3 pins as useable for edge detection and callbacks

This commit is contained in:
Robert Wolterman
2016-04-08 21:47:42 -05:00
parent c2ab013a5d
commit 0e1cf46c4e
5 changed files with 51 additions and 17 deletions

View File

@ -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 0.0.4
____ ____
* Initial Commit * Initial Commit

View File

@ -20,7 +20,7 @@ classifiers = ['Development Status :: 3 - Alpha',
'Topic :: System :: Hardware'] 'Topic :: System :: Hardware']
setup(name = 'CHIP_IO', setup(name = 'CHIP_IO',
version = '0.0.6', version = '0.0.7',
author = 'Robert Wolterman', author = 'Robert Wolterman',
author_email = 'robert.wolterman@gmail.com', author_email = 'robert.wolterman@gmail.com',
description = 'A module to control CHIP IO channels', 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']), 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.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.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'])])

View File

@ -76,6 +76,6 @@ void define_constants(PyObject *module)
both_edge = Py_BuildValue("i", BOTH_EDGE); both_edge = Py_BuildValue("i", BOTH_EDGE);
PyModule_AddObject(module, "BOTH", 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); PyModule_AddObject(module, "VERSION", version);
} }

View File

@ -268,9 +268,9 @@ static PyObject *py_add_event_callback(PyObject *self, PyObject *args, PyObject
if (get_gpio_number(channel, &gpio)) if (get_gpio_number(channel, &gpio))
return NULL; return NULL;
// check to ensure gpio is on the expanded pins as those are the only ones that allow for edge settings // check to ensure gpio is one of the allowed pins
if (gpio < 408) { if (gpio != 35 && gpio != 193 && (gpio <= 415 && gpio >= 408)) {
PyErr_SetString(PyExc_RuntimeError, "Callbacks currently available on XIO-P0 to XIO-P7 only"); PyErr_SetString(PyExc_RuntimeError, "Callbacks currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only");
return NULL; return NULL;
} }
@ -315,9 +315,9 @@ static PyObject *py_add_event_detect(PyObject *self, PyObject *args, PyObject *k
if (get_gpio_number(channel, &gpio)) if (get_gpio_number(channel, &gpio))
return NULL; return NULL;
// check to ensure gpio is on the expanded pins as those are the only ones that allow for edge settings // check to ensure gpio is one of the allowed pins
if (gpio < 408) { if (gpio != 35 && gpio != 193 && (gpio <= 415 && gpio >= 408)) {
PyErr_SetString(PyExc_RuntimeError, "Edge Detection currently available on XIO-P0 to XIO-P7 only"); PyErr_SetString(PyExc_RuntimeError, "Edge Detection currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only");
return NULL; return NULL;
} }
@ -369,9 +369,9 @@ static PyObject *py_remove_event_detect(PyObject *self, PyObject *args)
if (get_gpio_number(channel, &gpio)) if (get_gpio_number(channel, &gpio))
return NULL; return NULL;
// check to ensure gpio is on the expanded pins as those are the only ones that allow for edge settings // check to ensure gpio is one of the allowed pins
if (gpio < 408) { if (gpio != 35 && gpio != 193 && (gpio <= 415 && gpio >= 408)) {
PyErr_SetString(PyExc_RuntimeError, "Edge Detection currently available on XIO-P0 to XIO-P7 only"); PyErr_SetString(PyExc_RuntimeError, "Edge Detection currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only");
return NULL; return NULL;
} }
@ -431,9 +431,9 @@ static PyObject *py_wait_for_edge(PyObject *self, PyObject *args)
if (get_gpio_number(channel, &gpio)) if (get_gpio_number(channel, &gpio))
return NULL; return NULL;
// check to ensure gpio is on the expanded pins as those are the only ones that allow for edge settings // check to ensure gpio is one of the allowed pins
if (gpio < 408) { if (gpio != 35 && gpio != 193 && (gpio <= 415 && gpio >= 408)) {
PyErr_SetString(PyExc_RuntimeError, "Edge Detection currently available on XIO-P0 to XIO-P7 only"); PyErr_SetString(PyExc_RuntimeError, "Edge Detection currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only");
return NULL; 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"; static const char moduledocstring[] = "GPIO functionality of a CHIP using Python";
PyMethodDef gpio_methods[] = { 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"}, {"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"}, {"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"}, {"input", py_input_gpio, METH_VARARGS, "Input from a GPIO channel. Returns HIGH=1=True or LOW=0=False\ngpio - gpio channel"},

View File

@ -34,9 +34,35 @@ print "HIGH", GPIO.input("XIO-P0")
GPIO.output("CSID0", GPIO.LOW) GPIO.output("CSID0", GPIO.LOW)
print "LOW", GPIO.input("XIO-P0") 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 # 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) GPIO.add_event_detect("XIO-P0",GPIO.FALLING,myfuncallback)
print "VERIFYING EDGE DETECT" print "VERIFYING EDGE DETECT"