1
0
mirror of https://github.com/xtacocorex/CHIP_IO synced 2025-07-20 12:53:22 +00:00

4 Commits

11 changed files with 106 additions and 24 deletions

View File

@ -1,3 +1,13 @@
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 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 * 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

View File

@ -225,6 +225,16 @@ Read lots of data::
This code was initially added by brettcvz and I cleaned it up and expanded it. 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. 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:: Waiting for an edge (GPIO.RISING, GPIO.FALLING, or GPIO.BOTH::
@ -240,19 +250,21 @@ Detecting events::
if GPIO.event_detected("XIO-P0"): if GPIO.event_detected("XIO-P0"):
print "event detected!" 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): def mycallback(channel):
print("we hit the edge we want") print("we hit the edge we want")
GPIO.setup("GPIO3", GPIO.IN) GPIO.setup("GPIO3", GPIO.IN)
# Add Callback: Falling Edge # Add Event Detect and Callback Separately for Falling Edge
GPIO.add_event_callback("GPIO3", GPIO.FALLING, mycallback) GPIO.add_event_detect("GPIO3", GPIO.FALLING)
# Add Callback: Rising Edge GPIO.add_event_callback("GPIO3", mycallback)
GPIO.add_event_callback("GPIO3", GPIO.RISING, mycallback) # Add Event Detect and Callback Separately for Rising Edge
# Add Callback: Both Edges GPIO.add_event_detect("GPIO3", GPIO.RISING)
GPIO.add_event_callback("GPIO3", GPIO.BOTH, mycallback) GPIO.add_event_callback("GPIO3", mycallback)
# Remove callback # 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") GPIO.remove_event_detect("GPIO3")

14
debian/changelog vendored
View File

@ -1,3 +1,17 @@
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 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 * 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
View File

@ -1,2 +1,2 @@
python-chip-io_0.5.4-1_armhf.deb python optional python-chip-io_0.5.6-1_armhf.deb python optional
python3-chip-io_0.5.4-1_armhf.deb python optional python3-chip-io_0.5.6-1_armhf.deb python optional

View File

@ -13,7 +13,7 @@ classifiers = ['Development Status :: 3 - Alpha',
'Topic :: System :: Hardware'] 'Topic :: System :: Hardware']
setup(name = 'CHIP_IO', setup(name = 'CHIP_IO',
version = '0.5.5', version = '0.5.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',

View File

@ -138,6 +138,11 @@ pins_t pins_info[] = {
{ "CSID7", "D7", "U14_38", 139, BASE_METHOD_AS_IS, -1, -1, BOTH}, { "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_39", -1, BASE_METHOD_AS_IS, -1, -1, BOTH},
{ "GND", "GND", "U14_40", -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} { NULL, NULL, NULL, -1, 0, -1, -1, -1}
}; };

View File

@ -85,6 +85,6 @@ void define_constants(PyObject *module)
bcm = Py_BuildValue("i", BCM); bcm = Py_BuildValue("i", BCM);
PyModule_AddObject(module, "BCM", bcm); PyModule_AddObject(module, "BCM", bcm);
version = Py_BuildValue("s", "0.5.5"); version = Py_BuildValue("s", "0.5.7");
PyModule_AddObject(module, "VERSION", version); PyModule_AddObject(module, "VERSION", version);
} }

View File

@ -177,7 +177,7 @@ int gpio_export(int gpio)
char err[256]; char err[256];
snprintf(err, sizeof(err), "gpio_export: could not write '%s' to %s (%s)", str_gpio, filename, strerror(e_no)); snprintf(err, sizeof(err), "gpio_export: could not write '%s' to %s (%s)", str_gpio, filename, strerror(e_no));
add_error_msg(err); add_error_msg(err);
return -1; return -2;
} }
// add to list // add to list

View File

@ -215,11 +215,16 @@ static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwar
init_r8_gpio_mem(); init_r8_gpio_mem();
} }
if (gpio_export(gpio) < 0) { int exprtn = gpio_export(gpio);
if (exprtn == -1) {
char err[2000]; char err[2000];
snprintf(err, sizeof(err), "Error setting up channel %s, maybe already exported? (%s)", channel, get_error_msg()); snprintf(err, sizeof(err), "Error setting up channel %s, maybe already exported? (%s)", channel, get_error_msg());
PyErr_SetString(PyExc_RuntimeError, err); PyErr_SetString(PyExc_RuntimeError, err);
return NULL; 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) { if (gpio_set_direction(gpio, direction) < 0) {
char err[2000]; char err[2000];

View File

@ -34,11 +34,29 @@ SOFTWARE.
#include "common.h" #include "common.h"
#include "c_pwm.h" #include "c_pwm.h"
// python function cleanup() // python function cleanup(channel)
static PyObject *py_cleanup(PyObject *self, PyObject *args) static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs)
{ {
// unexport the PWM char key[8];
pwm_cleanup(); 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; 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_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_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" }, {"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"}, {"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)"}, {"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} {NULL, NULL, 0, NULL}

View File

@ -43,11 +43,29 @@ static PyObject *py_toggle_debug(PyObject *self, PyObject *args)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
// python function cleanup() // python function cleanup(channel)
static PyObject *py_cleanup(PyObject *self, PyObject *args) static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs)
{ {
// unexport the PWM char key[8];
softpwm_cleanup(); 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; 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'"}, {"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_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)" }, {"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"}, {"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)"}, {"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} {NULL, NULL, 0, NULL}