mirror of
https://github.com/xtacocorex/CHIP_IO
synced 2025-07-20 04:43:21 +00:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
6ddd0e0b14 | |||
d4b1d8a41c | |||
2b48571ee3 | |||
38a34e7edf | |||
f32733bb07 |
@ -1,3 +1,17 @@
|
||||
0.5.8
|
||||
---
|
||||
* Added 3 pins for the CHIP Pro as allowable for setting callbacks and edge detection to close out Issue #68
|
||||
|
||||
0.5.7
|
||||
---
|
||||
* Added the I2S pins on the CHIP Pro as GPIO capable
|
||||
* Added per PWM/SoftPWM cleanup per Issue #64
|
||||
|
||||
0.5.6
|
||||
---
|
||||
* Fix for Issue #63 where re-setting up a pin wasn't lining up with RPi.GPIO standards. Calling setup after the first time will now update direction.
|
||||
* README updates to point out the direction() function since that was missing
|
||||
|
||||
0.5.5
|
||||
---
|
||||
* Fix for Issue #62 where using alternate name of an XIO would cause a segfault due to trying to set pull up/down resistor setting
|
||||
|
28
README.rst
28
README.rst
@ -225,6 +225,16 @@ Read lots of data::
|
||||
|
||||
This code was initially added by brettcvz and I cleaned it up and expanded it.
|
||||
|
||||
You can quickly change a pins direction::
|
||||
|
||||
GPIO.direction("XIO-P3", GPIO.OUT)
|
||||
GPIO.direction("XIO-P3", GPIO.IN)
|
||||
|
||||
You can also re-setup a pin in order to change direction, not that this is a slower operation::
|
||||
|
||||
GPIO.setup("XIO-P3", GPIO.OUT)
|
||||
GPIO.setup("XIO-P3", GPIO.IN)
|
||||
|
||||
The edge detection code below only works for the AP-EINT1, AP-EINT3, and XPO Pins on the CHIP.
|
||||
|
||||
Waiting for an edge (GPIO.RISING, GPIO.FALLING, or GPIO.BOTH::
|
||||
@ -240,19 +250,21 @@ Detecting events::
|
||||
if GPIO.event_detected("XIO-P0"):
|
||||
print "event detected!"
|
||||
|
||||
CHIP_IO can also handle adding callback functions on any pin that supports edge detection.::
|
||||
CHIP_IO can also handle adding callback functions on any pin that supports edge detection. Note that only one callback function can be specified per Pin, if you try to set more, an exception will be thrown.::
|
||||
|
||||
def mycallback(channel):
|
||||
print("we hit the edge we want")
|
||||
|
||||
GPIO.setup("GPIO3", GPIO.IN)
|
||||
# Add Callback: Falling Edge
|
||||
GPIO.add_event_callback("GPIO3", GPIO.FALLING, mycallback)
|
||||
# Add Callback: Rising Edge
|
||||
GPIO.add_event_callback("GPIO3", GPIO.RISING, mycallback)
|
||||
# Add Callback: Both Edges
|
||||
GPIO.add_event_callback("GPIO3", GPIO.BOTH, mycallback)
|
||||
# Remove callback
|
||||
# Add Event Detect and Callback Separately for Falling Edge
|
||||
GPIO.add_event_detect("GPIO3", GPIO.FALLING)
|
||||
GPIO.add_event_callback("GPIO3", mycallback)
|
||||
# Add Event Detect and Callback Separately for Rising Edge
|
||||
GPIO.add_event_detect("GPIO3", GPIO.RISING)
|
||||
GPIO.add_event_callback("GPIO3", mycallback)
|
||||
# Add Callback for Both Edges using the add_event_detect() method
|
||||
GPIO.add_event_detect("GPIO3", GPIO.BOTH, mycallback)
|
||||
# Remove callback with the following
|
||||
GPIO.remove_event_detect("GPIO3")
|
||||
|
||||
|
||||
|
21
debian/changelog
vendored
21
debian/changelog
vendored
@ -1,3 +1,24 @@
|
||||
chip-io (0.5.8-1) unstable; urgency=low
|
||||
|
||||
* Added 3 pins for the CHIP Pro as allowable for setting callbacks and edge
|
||||
detection to close out Issue #68
|
||||
|
||||
-- Robert Wolterman <robert.wolterman@gmail.com> Tue, 02 May 2017 22:43:00 -0600
|
||||
|
||||
chip-io (0.5.7-1) unstable; urgency=low
|
||||
|
||||
* Added the I2S pins on the CHIP Pro as GPIO capable
|
||||
* Added per PWM/SoftPWM cleanup per Issue #64
|
||||
|
||||
-- Robert Wolterman <robert.wolterman@gmail.com> Mon, 01 May 2017 22:47:00 -0600
|
||||
|
||||
chip-io (0.5.6-1) unstable; urgency=low
|
||||
|
||||
* Fix for Issue #63 where re-setting up a pin wasn't lining up with RPi.GPIO standards. Calling setup after the first time will now update direction.
|
||||
* README updates to point out the direction() function since that was missing
|
||||
|
||||
-- Robert Wolterman <robert.wolterman@gmail.com> Mon, 20 Mar 2017 23:04:00 -0600
|
||||
|
||||
chip-io (0.5.5-1) unstable; urgency=low
|
||||
|
||||
* Fix for Issue #62 where using alternate name of an XIO would cause a segfault due to trying to set pull up/down resistor setting
|
||||
|
4
debian/files
vendored
4
debian/files
vendored
@ -1,2 +1,2 @@
|
||||
python-chip-io_0.5.4-1_armhf.deb python optional
|
||||
python3-chip-io_0.5.4-1_armhf.deb python optional
|
||||
python-chip-io_0.5.7-1_armhf.deb python optional
|
||||
python3-chip-io_0.5.7-1_armhf.deb python optional
|
||||
|
2
setup.py
2
setup.py
@ -13,7 +13,7 @@ classifiers = ['Development Status :: 3 - Alpha',
|
||||
'Topic :: System :: Hardware']
|
||||
|
||||
setup(name = 'CHIP_IO',
|
||||
version = '0.5.5',
|
||||
version = '0.5.8',
|
||||
author = 'Robert Wolterman',
|
||||
author_email = 'robert.wolterman@gmail.com',
|
||||
description = 'A module to control CHIP IO channels',
|
||||
|
@ -138,6 +138,11 @@ pins_t pins_info[] = {
|
||||
{ "CSID7", "D7", "U14_38", 139, BASE_METHOD_AS_IS, -1, -1, BOTH},
|
||||
{ "GND", "GND", "U14_39", -1, BASE_METHOD_AS_IS, -1, -1, BOTH},
|
||||
{ "GND", "GND", "U14_40", -1, BASE_METHOD_AS_IS, -1, -1, BOTH},
|
||||
{ "I2S-MCLK", "EINT19", "21", 37, BASE_METHOD_AS_IS, -1, -1, CHIPPRO},
|
||||
{ "I2S-BCLK", "I2S-BCLK", "22", 38, BASE_METHOD_AS_IS, -1, -1, CHIPPRO},
|
||||
{ "I2S-LCLK", "I2S-LCLK", "23", 39, BASE_METHOD_AS_IS, -1, -1, CHIPPRO},
|
||||
{ "I2S-DO", "I2S-DO", "24", 40, BASE_METHOD_AS_IS, -1, -1, CHIPPRO},
|
||||
{ "I2S-DI", "EINT24", "25", 41, BASE_METHOD_AS_IS, -1, -1, CHIPPRO},
|
||||
{ NULL, NULL, NULL, -1, 0, -1, -1, -1}
|
||||
};
|
||||
|
||||
|
@ -85,6 +85,6 @@ void define_constants(PyObject *module)
|
||||
bcm = Py_BuildValue("i", BCM);
|
||||
PyModule_AddObject(module, "BCM", bcm);
|
||||
|
||||
version = Py_BuildValue("s", "0.5.5");
|
||||
version = Py_BuildValue("s", "0.5.8");
|
||||
PyModule_AddObject(module, "VERSION", version);
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ int gpio_export(int gpio)
|
||||
char err[256];
|
||||
snprintf(err, sizeof(err), "gpio_export: could not write '%s' to %s (%s)", str_gpio, filename, strerror(e_no));
|
||||
add_error_msg(err);
|
||||
return -1;
|
||||
return -2;
|
||||
}
|
||||
|
||||
// add to list
|
||||
|
@ -215,11 +215,16 @@ static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwar
|
||||
init_r8_gpio_mem();
|
||||
}
|
||||
|
||||
if (gpio_export(gpio) < 0) {
|
||||
int exprtn = gpio_export(gpio);
|
||||
if (exprtn == -1) {
|
||||
char err[2000];
|
||||
snprintf(err, sizeof(err), "Error setting up channel %s, maybe already exported? (%s)", channel, get_error_msg());
|
||||
PyErr_SetString(PyExc_RuntimeError, err);
|
||||
return NULL;
|
||||
} else if (exprtn == -2 && gpio_warnings) {
|
||||
char warn[2000];
|
||||
snprintf(warn, sizeof(warn), "Channel %s may already be exported, proceeding with rest of setup", channel);
|
||||
PyErr_WarnEx(PyExc_Warning, warn, 1);
|
||||
}
|
||||
if (gpio_set_direction(gpio, direction) < 0) {
|
||||
char err[2000];
|
||||
@ -591,6 +596,9 @@ static PyObject *py_add_event_callback(PyObject *self, PyObject *args, PyObject
|
||||
// check to ensure gpio is one of the allowed pins
|
||||
if (gpio != lookup_gpio_by_name("AP-EINT3")
|
||||
&& gpio != lookup_gpio_by_name("AP-EINT1")
|
||||
&& gpio != lookup_gpio_by_name("I2S-MCLK") // CHIP PRO
|
||||
&& gpio != lookup_gpio_by_name("I2S-DI") // CHIP PRO
|
||||
&& gpio != lookup_gpio_by_name("PWM1") // CHIP PRO
|
||||
&& !(gpio >= lookup_gpio_by_name("XIO-P0") && gpio <= lookup_gpio_by_name("XIO-P7"))) {
|
||||
PyErr_SetString(PyExc_ValueError, "Callbacks currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only");
|
||||
return NULL;
|
||||
@ -660,6 +668,9 @@ static PyObject *py_add_event_detect(PyObject *self, PyObject *args, PyObject *k
|
||||
// check to ensure gpio is one of the allowed pins
|
||||
if (gpio != lookup_gpio_by_name("AP-EINT3")
|
||||
&& gpio != lookup_gpio_by_name("AP-EINT1")
|
||||
&& gpio != lookup_gpio_by_name("I2S-MCLK") // CHIP PRO
|
||||
&& gpio != lookup_gpio_by_name("I2S-DI") // CHIP PRO
|
||||
&& gpio != lookup_gpio_by_name("PWM1") // CHIP PRO
|
||||
&& !(gpio >= lookup_gpio_by_name("XIO-P0") && gpio <= lookup_gpio_by_name("XIO-P7"))) {
|
||||
PyErr_SetString(PyExc_ValueError, "Edge Detection currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only");
|
||||
return NULL;
|
||||
@ -736,6 +747,9 @@ static PyObject *py_remove_event_detect(PyObject *self, PyObject *args)
|
||||
// check to ensure gpio is one of the allowed pins
|
||||
if (gpio != lookup_gpio_by_name("AP-EINT3")
|
||||
&& gpio != lookup_gpio_by_name("AP-EINT1")
|
||||
&& gpio != lookup_gpio_by_name("I2S-MCLK") // CHIP PRO
|
||||
&& gpio != lookup_gpio_by_name("I2S-DI") // CHIP PRO
|
||||
&& gpio != lookup_gpio_by_name("PWM1") // CHIP PRO
|
||||
&& !(gpio >= lookup_gpio_by_name("XIO-P0") && gpio <= lookup_gpio_by_name("XIO-P7"))) {
|
||||
PyErr_SetString(PyExc_ValueError, "Edge Detection currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only");
|
||||
return NULL;
|
||||
@ -840,6 +854,9 @@ static PyObject *py_wait_for_edge(PyObject *self, PyObject *args)
|
||||
// check to ensure gpio is one of the allowed pins
|
||||
if (gpio != lookup_gpio_by_name("AP-EINT3")
|
||||
&& gpio != lookup_gpio_by_name("AP-EINT1")
|
||||
&& gpio != lookup_gpio_by_name("I2S-MCLK") // CHIP PRO
|
||||
&& gpio != lookup_gpio_by_name("I2S-DI") // CHIP PRO
|
||||
&& gpio != lookup_gpio_by_name("PWM1") // CHIP PRO
|
||||
&& !(gpio >= lookup_gpio_by_name("XIO-P0") && gpio <= lookup_gpio_by_name("XIO-P7"))) {
|
||||
PyErr_SetString(PyExc_ValueError, "Edge Detection currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only");
|
||||
return NULL;
|
||||
|
@ -34,11 +34,29 @@ SOFTWARE.
|
||||
#include "common.h"
|
||||
#include "c_pwm.h"
|
||||
|
||||
// python function cleanup()
|
||||
static PyObject *py_cleanup(PyObject *self, PyObject *args)
|
||||
// python function cleanup(channel)
|
||||
static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
// unexport the PWM
|
||||
pwm_cleanup();
|
||||
char key[8];
|
||||
char *channel;
|
||||
static char *kwlist[] = {"channel", NULL};
|
||||
|
||||
clear_error_msg();
|
||||
|
||||
// Channel is optional
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &channel)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// The !channel fixes issues #50
|
||||
if (channel == NULL || strcmp(channel, "\0") == 0) {
|
||||
pwm_cleanup();
|
||||
} else {
|
||||
if (!get_pwm_key(channel, key)) {
|
||||
pwm_cleanup();
|
||||
}
|
||||
pwm_disable(key);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
@ -395,7 +413,7 @@ PyMethodDef pwm_methods[] = {
|
||||
{"set_frequency", (PyCFunction)py_set_frequency, METH_VARARGS, "Change the frequency\nfrequency - frequency in Hz (freq > 0.0)" },
|
||||
{"set_period_ns", (PyCFunction)py_set_period_ns, METH_VARARGS, "Change the period\nperiod_ns - period in nanoseconds" },
|
||||
{"set_pulse_width_ns", (PyCFunction)py_set_pulse_width_ns, METH_VARARGS, "Change the period\npulse_width_ns - pulse width in nanoseconds" },
|
||||
{"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", (PyCFunction)py_cleanup, METH_VARARGS | METH_KEYWORDS, "Clean up by resetting PWM channel(s) that have been used by this program to be disabled"},
|
||||
{"toggle_debug", py_toggle_debug, METH_VARARGS, "Toggles the enabling/disabling of Debug print output"},
|
||||
{"is_chip_pro", py_is_chip_pro, METH_VARARGS, "Is hardware a CHIP Pro? Boolean False for normal CHIP/PocketCHIP (R8 SOC)"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
|
@ -43,11 +43,29 @@ static PyObject *py_toggle_debug(PyObject *self, PyObject *args)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
// python function cleanup()
|
||||
static PyObject *py_cleanup(PyObject *self, PyObject *args)
|
||||
// python function cleanup(channel)
|
||||
static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
// unexport the PWM
|
||||
softpwm_cleanup();
|
||||
char key[8];
|
||||
char *channel;
|
||||
static char *kwlist[] = {"channel", NULL};
|
||||
|
||||
clear_error_msg();
|
||||
|
||||
// Channel is optional
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &channel)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// The !channel fixes issues #50
|
||||
if (channel == NULL || strcmp(channel, "\0") == 0) {
|
||||
softpwm_cleanup();
|
||||
} else {
|
||||
if (!get_key(channel, key)) {
|
||||
softpwm_cleanup();
|
||||
}
|
||||
softpwm_disable(key);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
@ -300,7 +318,7 @@ PyMethodDef pwm_methods[] = {
|
||||
{"stop", (PyCFunction)py_stop_channel, METH_VARARGS | METH_KEYWORDS, "Stop the PWM channel. channel can be in the form of 'XIO-P0', or 'U14_13'"},
|
||||
{"set_duty_cycle", (PyCFunction)py_set_duty_cycle, METH_VARARGS, "Change the duty cycle\ndutycycle - between 0.0 and 100.0" },
|
||||
{"set_frequency", (PyCFunction)py_set_frequency, METH_VARARGS, "Change the frequency\nfrequency - frequency in Hz (freq > 0.0)" },
|
||||
{"cleanup", (PyCFunction)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", (PyCFunction)py_cleanup, METH_VARARGS | METH_KEYWORDS, "Clean up by resetting all GPIO channels that have been used by this program to INPUT with no pullup/pulldown and no event detection"},
|
||||
{"toggle_debug", py_toggle_debug, METH_VARARGS, "Toggles the enabling/disabling of Debug print output"},
|
||||
{"is_chip_pro", py_is_chip_pro, METH_VARARGS, "Is hardware a CHIP Pro? Boolean False for normal CHIP/PocketCHIP (R8 SOC)"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
|
Reference in New Issue
Block a user