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

Adding protection for to the GPIO to only allow edge detection and call back on the XIO pins, clean up of the PWM, updated test code

This commit is contained in:
Robert Wolterman
2016-04-02 19:48:57 -05:00
parent cea44c287d
commit c2ab013a5d
3 changed files with 84 additions and 22 deletions

View File

@ -268,6 +268,12 @@ 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");
return NULL;
}
// check channel is set up as an input
if (!module_setup || gpio_direction[gpio] != INPUT)
{
@ -309,6 +315,12 @@ 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");
return NULL;
}
// check channel is set up as an input
if (!module_setup || gpio_direction[gpio] != INPUT)
{
@ -357,6 +369,12 @@ 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");
return NULL;
}
// remove all python callbacks for gpio
while (cb != NULL)
{
@ -413,6 +431,12 @@ 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");
return NULL;
}
// check channel is setup as an input
if (!module_setup || gpio_direction[gpio] != INPUT)
{

View File

@ -165,7 +165,7 @@ static PyObject *py_set_frequency(PyObject *self, PyObject *args, PyObject *kwar
}
static const char moduledocstring[] = "PWM functionality of a CHIP using Python";
static const char moduledocstring[] = "Hardware PWM functionality of a CHIP using Python";
PyMethodDef pwm_methods[] = {
{"start", (PyCFunction)py_start_channel, METH_VARARGS | METH_KEYWORDS, "Set up and start the PWM channel. channel can be in the form of 'PWM0', or 'U13_18'"},
@ -178,7 +178,7 @@ PyMethodDef pwm_methods[] = {
};
#if PY_MAJOR_VERSION > 2
static struct PyModuleDef bbpwmmodule = {
static struct PyModuleDef chippwmmodule = {
PyModuleDef_HEAD_INIT,
"PWM", // name of module
moduledocstring, // module documentation, may be NULL
@ -196,7 +196,7 @@ PyMODINIT_FUNC initPWM(void)
PyObject *module = NULL;
#if PY_MAJOR_VERSION > 2
if ((module = PyModule_Create(&bbpwmmodule)) == NULL)
if ((module = PyModule_Create(&chippwmmodule)) == NULL)
return NULL;
#else
if ((module = Py_InitModule3("PWM", pwm_methods, moduledocstring)) == NULL)