From d4b1d8a41c84c62363023852c83de6525bfeec3e Mon Sep 17 00:00:00 2001 From: Robert Wolterman Date: Mon, 1 May 2017 22:50:17 -0500 Subject: [PATCH] adding i2s pins as gpio capable for the chip pro, code to handle per pwm/softpwm cleanup to close #64 --- CHANGELOG.rst | 5 +++++ debian/changelog | 7 +++++++ debian/files | 4 ++-- setup.py | 2 +- source/common.c | 5 +++++ source/constants.c | 2 +- source/py_pwm.c | 28 +++++++++++++++++++++++----- source/py_softpwm.c | 28 +++++++++++++++++++++++----- 8 files changed, 67 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4ca7c8a..d563191 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,8 @@ +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. diff --git a/debian/changelog b/debian/changelog index 2cfece1..85954ff 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +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 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. diff --git a/debian/files b/debian/files index 816e918..c294cb9 100644 --- a/debian/files +++ b/debian/files @@ -1,2 +1,2 @@ -python-chip-io_0.5.5-1_armhf.deb python optional -python3-chip-io_0.5.5-1_armhf.deb python optional +python-chip-io_0.5.6-1_armhf.deb python optional +python3-chip-io_0.5.6-1_armhf.deb python optional diff --git a/setup.py b/setup.py index af9f095..04bc7a8 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ classifiers = ['Development Status :: 3 - Alpha', 'Topic :: System :: Hardware'] setup(name = 'CHIP_IO', - version = '0.5.6', + version = '0.5.7', author = 'Robert Wolterman', author_email = 'robert.wolterman@gmail.com', description = 'A module to control CHIP IO channels', diff --git a/source/common.c b/source/common.c index 2c10e7f..60b922f 100644 --- a/source/common.c +++ b/source/common.c @@ -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} }; diff --git a/source/constants.c b/source/constants.c index b30b3d4..60a209d 100644 --- a/source/constants.c +++ b/source/constants.c @@ -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.6"); + version = Py_BuildValue("s", "0.5.7"); PyModule_AddObject(module, "VERSION", version); } diff --git a/source/py_pwm.c b/source/py_pwm.c index 2cf4277..3466b2e 100644 --- a/source/py_pwm.c +++ b/source/py_pwm.c @@ -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} diff --git a/source/py_softpwm.c b/source/py_softpwm.c index 10aea16..5afc39e 100644 --- a/source/py_softpwm.c +++ b/source/py_softpwm.c @@ -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}