1
0
mirror of https://github.com/xtacocorex/CHIP_IO synced 2025-07-21 13:23:21 +00:00

4 Commits
0.2.6 ... 0.3.0

10 changed files with 199 additions and 130 deletions

View File

@ -1,3 +1,15 @@
0.3.0
----
* Added setmode() function for GPIO to maintain compatibility with Raspberry Pi scripts, this function literally does nothing
* Added per pin cleanup functionality for GPIO and SoftPWM so you can unexport a pin without unexporting every pin
* Updated README to make edge detection wording a little better and to add the per pin cleanup code
* Version update since I blasted through 3 issues on github and feel like we need a nice bump to 0.3
0.2.7
----
* Fix to the Enable 1.8V Pin code as it wasn't working due to bit shifting isn't allowed on a float.
* Updated README to denote the PocketCHIP Pin names better
0.2.6
----
* Fix to keep the GPIO value file open until the pin is unexported (issue #34)

View File

@ -35,7 +35,7 @@ def set_1v8_pin_voltage(voltage):
return False
if voltage < 1.8 or voltage > 3.3:
return False
voltage=round((voltage - 1.8) / 0.1) << 4
voltage=int(round((voltage - 1.8) / 0.1)) << 4
if subprocess.call(["/usr/sbin/i2cset", "-f", "-y" ,"0", "0x34", "0x90", "0x03"]):
return False
if subprocess.call(["/usr/sbin/i2cset", "-f", "-y", "0", "0x34", "0x91", str(voltage)]):

View File

@ -6,7 +6,7 @@ publish: package
clean:
rm -rf CHIP_IO.* build dist
rm -f *.pyo
rm -f *.pyo *.pyc
rm -f *.egg
rm -f overlays/*.pyo overlays/*.pyc
tests:

View File

@ -44,115 +44,115 @@ All scripts that require GPIO, PWM (HW and/or SW), and Overlay Manager need to b
**Allowable Pin Names for the Library**
The following "table" is the allowable pin names that are able to be used by the library.
The following "table" is the allowable pin names that are able to be used by the library. The Name column is the normal name used on the CHIP Headers, the Alt Name column is the value used by the PocketCHIP header (if it's broken out), and the Key is the Header and Pin Number the the Pin is physically located. Either of these 3 means is able to specify a pin in CHIP_IO.
+-----------+-------------+--------+
| Name | Alt Name | Key |
+-----------+-------------+--------+
| TWI1-SDA | KPD-I2C-SDA | U13_9 |
+-----------+-------------+--------+
| TWI1-SCK | KPD-I2C-SCL | U13_11 |
+-----------+-------------+--------+
| LCD-D2 | LCD-D2 | U13_17 |
+-----------+-------------+--------+
| PWM0 | PWM0 | U13_18 |
+-----------+-------------+--------+
| LCD-D4 | LCD-D4 | U13_19 |
+-----------+-------------+--------+
| LCD-D3 | LCD-D3 | U13_20 |
+-----------+-------------+--------+
| LCD-D6 | LCD-D6 | U13_21 |
+-----------+-------------+--------+
| LCD-D5 | LCD-D5 | U13_22 |
+-----------+-------------+--------+
| LCD-D10 | LCD-D10 | U13_23 |
+-----------+-------------+--------+
| LCD-D7 | LCD-D7 | U13_24 |
+-----------+-------------+--------+
| LCD-D12 | LCD-D12 | U13_25 |
+-----------+-------------+--------+
| LCD-D11 | LCD-D11 | U13_26 |
+-----------+-------------+--------+
| LCD-D14 | LCD-D14 | U13_27 |
+-----------+-------------+--------+
| LCD-D13 | LCD-D13 | U13_28 |
+-----------+-------------+--------+
| LCD-D18 | LCD-D18 | U13_29 |
+-----------+-------------+--------+
| LCD-D15 | LCD-D15 | U13_30 |
+-----------+-------------+--------+
| LCD-D20 | LCD-D20 | U13_31 |
+-----------+-------------+--------+
| LCD-D19 | LCD-D19 | U13_32 |
+-----------+-------------+--------+
| LCD-D22 | LCD-D22 | U13_33 |
+-----------+-------------+--------+
| LCD-D21 | LCD-D21 | U13_34 |
+-----------+-------------+--------+
| LCD-CLK | LCD-CLK | U13_35 |
+-----------+-------------+--------+
| LCD-D23 | LCD-D23 | U13_36 |
+-----------+-------------+--------+
| LCD-VSYNC | LCD-VSYNC | U13_37 |
+-----------+-------------+--------+
| LCD-HSYNC | LCD-HSYNC | U13_38 |
+-----------+-------------+--------+
| LCD-DE | LCD-DE | U13_40 |
+-----------+-------------+--------+
| UART1-TX | UART-TX | U14_3 |
+-----------+-------------+--------+
| UART1-RX | UART-RX | U14_5 |
+-----------+-------------+--------+
| LRADC | ADC | U14_11 |
+-----------+-------------+--------+
| XIO-P0 | XIO-P0 | U14_13 |
+-----------+-------------+--------+
| XIO-P1 | XIO-P1 | U14_14 |
+-----------+-------------+--------+
| XIO-P2 | GPIO1 | U14_15 |
+-----------+-------------+--------+
| XIO-P3 | GPIO2 | U14_16 |
+-----------+-------------+--------+
| XIO-P4 | GPIO3 | U14_17 |
+-----------+-------------+--------+
| XIO-P5 | GPIO4 | U14_18 |
+-----------+-------------+--------+
| XIO-P6 | GPIO5 | U14_19 |
+-----------+-------------+--------+
| XIO-P7 | GPIO6 | U14_20 |
+-----------+-------------+--------+
| AP-EINT1 | KPD-INT | U14_23 |
+-----------+-------------+--------+
| AP-EINT3 | AP-INT3 | U14_24 |
+-----------+-------------+--------+
| TWI2-SDA | I2C-SDA | U14_25 |
+-----------+-------------+--------+
| TWI2-SCK | I2C-SCL | U14_26 |
+-----------+-------------+--------+
| CSIPCK | SPI-SEL | U14_27 |
+-----------+-------------+--------+
| CSICK | SPI-CLK | U14_28 |
+-----------+-------------+--------+
| CSIHSYNC | SPI-MOSI | U14_29 |
+-----------+-------------+--------+
| CSIVSYNC | SPI-MISO | U14_30 |
+-----------+-------------+--------+
| CSID0 | CSID0 | U14_31 |
+-----------+-------------+--------+
| CSID1 | CSID1 | U14_32 |
+-----------+-------------+--------+
| CSID2 | CSID2 | U14_33 |
+-----------+-------------+--------+
| CSID3 | CSID3 | U14_34 |
+-----------+-------------+--------+
| CSID4 | CSID4 | U14_35 |
+-----------+-------------+--------+
| CSID5 | CSID5 | U14_36 |
+-----------+-------------+--------+
| CSID6 | CSID6 | U14_37 |
+-----------+-------------+--------+
| CSID7 | CSID7 | U14_38 |
+-----------+-------------+--------+
+------------------+--------------------------+--------+
| CHIP (Name) | PocketCHIP (Alt Name) | Key |
+------------------+--------------------------+--------+
| TWI1-SDA | KPD-I2C-SDA | U13_9 |
+------------------+--------------------------+--------+
| TWI1-SCK | KPD-I2C-SCL | U13_11 |
+------------------+--------------------------+--------+
| LCD-D2 | LCD-D2 | U13_17 |
+------------------+--------------------------+--------+
| PWM0 | PWM0 | U13_18 |
+------------------+--------------------------+--------+
| LCD-D4 | LCD-D4 | U13_19 |
+------------------+--------------------------+--------+
| LCD-D3 | LCD-D3 | U13_20 |
+------------------+--------------------------+--------+
| LCD-D6 | LCD-D6 | U13_21 |
+------------------+--------------------------+--------+
| LCD-D5 | LCD-D5 | U13_22 |
+------------------+--------------------------+--------+
| LCD-D10 | LCD-D10 | U13_23 |
+------------------+--------------------------+--------+
| LCD-D7 | LCD-D7 | U13_24 |
+------------------+--------------------------+--------+
| LCD-D12 | LCD-D12 | U13_25 |
+------------------+--------------------------+--------+
| LCD-D11 | LCD-D11 | U13_26 |
+------------------+--------------------------+--------+
| LCD-D14 | LCD-D14 | U13_27 |
+------------------+--------------------------+--------+
| LCD-D13 | LCD-D13 | U13_28 |
+------------------+--------------------------+--------+
| LCD-D18 | LCD-D18 | U13_29 |
+------------------+--------------------------+--------+
| LCD-D15 | LCD-D15 | U13_30 |
+------------------+--------------------------+--------+
| LCD-D20 | LCD-D20 | U13_31 |
+------------------+--------------------------+--------+
| LCD-D19 | LCD-D19 | U13_32 |
+------------------+--------------------------+--------+
| LCD-D22 | LCD-D22 | U13_33 |
+------------------+--------------------------+--------+
| LCD-D21 | LCD-D21 | U13_34 |
+------------------+--------------------------+--------+
| LCD-CLK | LCD-CLK | U13_35 |
+------------------+--------------------------+--------+
| LCD-D23 | LCD-D23 | U13_36 |
+------------------+--------------------------+--------+
| LCD-VSYNC | LCD-VSYNC | U13_37 |
+------------------+--------------------------+--------+
| LCD-HSYNC | LCD-HSYNC | U13_38 |
+------------------+--------------------------+--------+
| LCD-DE | LCD-DE | U13_40 |
+------------------+--------------------------+--------+
| UART1-TX | UART-TX | U14_3 |
+------------------+--------------------------+--------+
| UART1-RX | UART-RX | U14_5 |
+------------------+--------------------------+--------+
| LRADC | ADC | U14_11 |
+------------------+--------------------------+--------+
| XIO-P0 | XIO-P0 | U14_13 |
+------------------+--------------------------+--------+
| XIO-P1 | XIO-P1 | U14_14 |
+------------------+--------------------------+--------+
| XIO-P2 | GPIO1 | U14_15 |
+------------------+--------------------------+--------+
| XIO-P3 | GPIO2 | U14_16 |
+------------------+--------------------------+--------+
| XIO-P4 | GPIO3 | U14_17 |
+------------------+--------------------------+--------+
| XIO-P5 | GPIO4 | U14_18 |
+------------------+--------------------------+--------+
| XIO-P6 | GPIO5 | U14_19 |
+------------------+--------------------------+--------+
| XIO-P7 | GPIO6 | U14_20 |
+------------------+--------------------------+--------+
| AP-EINT1 | KPD-INT | U14_23 |
+------------------+--------------------------+--------+
| AP-EINT3 | AP-INT3 | U14_24 |
+------------------+--------------------------+--------+
| TWI2-SDA | I2C-SDA | U14_25 |
+------------------+--------------------------+--------+
| TWI2-SCK | I2C-SCL | U14_26 |
+------------------+--------------------------+--------+
| CSIPCK | SPI-SEL | U14_27 |
+------------------+--------------------------+--------+
| CSICK | SPI-CLK | U14_28 |
+------------------+--------------------------+--------+
| CSIHSYNC | SPI-MOSI | U14_29 |
+------------------+--------------------------+--------+
| CSIVSYNC | SPI-MISO | U14_30 |
+------------------+--------------------------+--------+
| CSID0 | CSID0 | U14_31 |
+------------------+--------------------------+--------+
| CSID1 | CSID1 | U14_32 |
+------------------+--------------------------+--------+
| CSID2 | CSID2 | U14_33 |
+------------------+--------------------------+--------+
| CSID3 | CSID3 | U14_34 |
+------------------+--------------------------+--------+
| CSID4 | CSID4 | U14_35 |
+------------------+--------------------------+--------+
| CSID5 | CSID5 | U14_36 |
+------------------+--------------------------+--------+
| CSID6 | CSID6 | U14_37 |
+------------------+--------------------------+--------+
| CSID7 | CSID7 | U14_38 |
+------------------+--------------------------+--------+
**GPIO Setup**
@ -191,12 +191,12 @@ Polling inputs::
else:
print("LOW")
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::
GPIO.wait_for_edge(channel, GPIO.RISING)
This only works for the AP-EINT1, AP-EINT3, and XPO Pins on the CHIP
Detecting events::
GPIO.setup("XIO-P0", GPIO.IN)
@ -206,11 +206,16 @@ 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.
**GPIO Cleanup**
To clean up the GPIO when done, do the following::
# Clean up every exported GPIO Pin
GPIO.cleanup()
# Clean up a single pin (keeping everything else intact)
GPIO.cleanup("XIO-P0")
**PWM**::
@ -239,7 +244,10 @@ Hardware PWM requires a DTB Overlay loaded on the CHIP to allow the kernel to kn
SPWM.set_frequency("XIO-P7", 10)
# To Stop SPWM
SPWM.stop("XIO-P7")
# Cleanup can have no argument to clean up all SoftPWM outputs
SPWM.cleanup()
# Or you can specify a single SoftPWM output to cleanup (keeping the rest intact)
SPWM.cleanup("XIO-P7")
#For specific polarity: this example sets polarity to 1 on start:
SPWM.start("XIO-P7", 50, 2000, 1)

View File

@ -20,7 +20,7 @@ classifiers = ['Development Status :: 3 - Alpha',
'Topic :: System :: Hardware']
setup(name = 'CHIP_IO',
version = '0.2.6',
version = '0.3.0',
author = 'Robert Wolterman',
author_email = 'robert.wolterman@gmail.com',
description = 'A module to control CHIP IO channels',

View File

@ -52,6 +52,8 @@ SOFTWARE.
} while (0)
#define MODE_UNKNOWN -1
#define BOARD 10
#define BCM 11
#define CHIP 0
#define CHIPPRO 1

View File

@ -76,6 +76,15 @@ void define_constants(PyObject *module)
both_edge = Py_BuildValue("i", BOTH_EDGE);
PyModule_AddObject(module, "BOTH", both_edge);
version = Py_BuildValue("s", "0.2.6");
unknown = Py_BuildValue("i", MODE_UNKNOWN);
PyModule_AddObject(module, "UNKNOWN", unknown);
board = Py_BuildValue("i", BOARD);
PyModule_AddObject(module, "BOARD", board);
bcm = Py_BuildValue("i", BCM);
PyModule_AddObject(module, "BCM", bcm);
version = Py_BuildValue("s", "0.3.0");
PyModule_AddObject(module, "VERSION", version);
}

View File

@ -10,5 +10,8 @@ PyObject *rising_edge;
PyObject *falling_edge;
PyObject *both_edge;
PyObject *version;
PyObject *unknown;
PyObject *board;
PyObject *bcm;
void define_constants(PyObject *module);

View File

@ -71,13 +71,36 @@ static void remember_gpio_direction(int gpio, int direction)
dyn_int_array_set(&gpio_direction, gpio, direction, -1);
}
// python function cleanup()
// Dummy function to mimic RPi.GPIO for easier porting.
// python function setmode(mode)
static PyObject *py_setmode(PyObject *self, PyObject *args)
{
Py_RETURN_NONE;
}
// python function cleanup(channel=None)
static PyObject *py_cleanup(PyObject *self, PyObject *args)
{
int gpio;
char *channel;
clear_error_msg();
// clean up any exports
event_cleanup();
// Channel is optional
if (!PyArg_ParseTuple(args, "|s", &channel))
return NULL;
if (strcmp(channel, "") == 0) {
event_cleanup();
} else {
if (get_gpio_number(channel, &gpio) < 0) {
char err[2000];
snprintf(err, sizeof(err), "Invalid channel %s. (%s)", channel, get_error_msg());
PyErr_SetString(PyExc_ValueError, err);
return NULL;
}
gpio_unexport(gpio);
}
Py_RETURN_NONE;
}
@ -749,9 +772,6 @@ static PyObject *py_selftest(PyObject *self, PyObject *args)
static const char moduledocstring[] = "GPIO functionality of a CHIP using Python";
/*
mine for changing pin directipn
*/
@ -811,7 +831,8 @@ PyMethodDef gpio_methods[] = {
{"setwarnings", py_setwarnings, METH_VARARGS, "Enable or disable warning messages"},
{"get_gpio_base", py_gpio_base, METH_VARARGS, "Get the XIO base number for sysfs"},
{"selftest", py_selftest, METH_VARARGS, "Internal unit tests"},
{ "direction", (PyCFunction)py_set_direction, METH_VARARGS, "Change direction of gpio channel. Either INPUT or OUTPUT\n" },
{"direction", (PyCFunction)py_set_direction, METH_VARARGS, "Change direction of gpio channel. Either INPUT or OUTPUT\n" },
{"setmode", (PyCFunction)py_setmode, METH_VARARGS, "Dummy function that does nothing but maintain compatibility with RPi.GPIO\n" },
{NULL, NULL, 0, NULL}
};

View File

@ -34,11 +34,26 @@ SOFTWARE.
#include "common.h"
#include "c_softpwm.h"
// python function cleanup()
// python function cleanup(channel=None)
static PyObject *py_cleanup(PyObject *self, PyObject *args)
{
// unexport the PWM
softpwm_cleanup();
char key[8];
char *channel = NULL;
// Channel is optional
if (!PyArg_ParseTuple(args, "|s", &channel))
return NULL;
if (strcmp(channel, "") == 0) {
softpwm_cleanup();
} else {
if (!get_key(channel, key)) {
PyErr_SetString(PyExc_ValueError, "Invalid SOFTPWM key or name.");
return NULL;
}
softpwm_disable(key);
}
Py_RETURN_NONE;
}
@ -171,15 +186,14 @@ static PyObject *py_set_frequency(PyObject *self, PyObject *args, PyObject *kwar
Py_RETURN_NONE;
}
static const char moduledocstring[] = "Software 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 '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'"},
{ "start", (PyCFunction)py_start_channel, METH_VARARGS | METH_KEYWORDS, "Set up and start 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_frequency", (PyCFunction)py_set_frequency, METH_VARARGS, "Change the frequency\nfrequency - frequency in Hz (freq > 0.0)" },
{"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, "Clean up by resetting all GPIO channels that have been used by this program to INPUT with no pullup/pulldown and no event detection"},
//{"setwarnings", py_setwarnings, METH_VARARGS, "Enable or disable warning messages"},
{NULL, NULL, 0, NULL}
};