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

11 Commits

Author SHA1 Message Date
6e93fad1de README updates following the merge of PR#70 into master 2017-06-08 20:06:52 -05:00
41d4b84c56 Merge pull request #70 from mzealey/master
Extern integer definitions in the header file
2017-06-08 19:19:17 -05:00
024e5d5797 Extern integer definitions in the header file
Integers are defined in both the .c and the common.h file leading to linking
issues with the library when used externally and potentially causing issues
within the code as well.
2017-06-08 15:23:32 +00:00
6ddd0e0b14 Closing out Issue #68 by adding 3 CHIP Pro pins able to be used as interrupts 2017-05-02 22:46:10 -05:00
d4b1d8a41c adding i2s pins as gpio capable for the chip pro, code to handle per pwm/softpwm cleanup to close #64 2017-05-01 22:50:17 -05:00
2b48571ee3 Updating setup to allow for repeated calls on a pin. Not totally sold on this, but it work and is what RPi.GPIO does. This will close #63 2017-03-20 23:06:09 -05:00
38a34e7edf Updating the README to clean up how to do callbacks for more clarification on #62 2017-03-07 07:22:09 -06:00
f32733bb07 Updating the Readme to add a note regarding one callback per pin 2017-03-06 17:53:34 -06:00
4da0812acd Fixing issue where using alt name for the XIO would cause a segfault when speficying the pin as an input. This will close #62 2017-03-06 17:08:05 -06:00
dcd8ea6f40 Re-enabled polarity set on the CHIP PWM, fixed issues that caused me to disable that feature to begin with. This could have been a 1 letter change, but I re-eabled tests in the unit test to validate. This will close #61 2017-03-05 00:49:16 -06:00
29377cf24d updates to the pytest tests to fix the issues with pwm, added 2 new tests that bring in 5 total unit tests. python3 unit tests are passing, this will close #42 and close #47 2017-02-26 21:04:40 -06:00
25 changed files with 458 additions and 182 deletions

View File

@ -1,3 +1,40 @@
0.5.9
---
* Merged PR#70 to enable the underlying C code to be used properly in C based code
* Updated README to add missing pins on the CHIP Pro that are available as GPIO
* Updated README to denote pins that are available for Edge Detection
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
0.5.4
---
* Re-enabled the polarity setting for PWM based upon Issue #61
* Fixed a 1 letter bug was trying to write inverted to polarity when it wants inversed (such facepalm)
* Cleaned up the polarity setting code to work when PWM is not enabled
* Fixed the unit test for pwm to verify we can set polarity
0.5.3
---
* Fixes to the PWM pytest
* Added pytest for LRADC and Utilities
* Makefile updates for all the things
0.5.2
---
* Updating Utilties to determine CHIP Pro better

View File

@ -20,7 +20,8 @@
import os
import shutil
import time
import Utilities as UT
import sys
from .Utilities import is_chip_pro
DEBUG = False
@ -162,7 +163,7 @@ def load(overlay, path=""):
return 1
# DETERMINE IF WE ARE A CHIP PRO AND WE ARE COMMANDED TO LOAD PWM0
if UT.is_chip_pro() and overlay.upper() == "PWM0":
if is_chip_pro() and overlay.upper() == "PWM0":
print("CHIP Pro supports PWM0 in base DTB, exiting")
return 1
@ -200,7 +201,7 @@ def unload(overlay):
print("UNLOAD OVERLAY: {0}".format(overlay))
# DETERMINE IF WE ARE A CHIP PRO AND WE ARE COMMANDED TO UNLOAD PWM0
if UT.is_chip_pro() and overlay.upper() == "PWM0":
if is_chip_pro() and overlay.upper() == "PWM0":
print("CHIP Pro supports PWM0 in base DTB, exiting")
return

View File

@ -1,25 +1,61 @@
# PyPi Packaging
package: clean
@echo " ** PACKAGING FOR PYPI **"
python setup.py sdist
# PyPi Publishing
publish: package
@echo " ** UPLOADING TO PYPI **"
twine upload dist/*
# Clean all the things
clean:
@echo " ** CLEANING CHIP_IO **"
rm -rf CHIP_IO.* build dist
rm -f *.pyo *.pyc
rm -f *.egg
rm -rf __pycache__
rm -rf test/__pycache__/
rm -rf debian/python-chip-io*
rm -rf debian/python3-chip-io*
tests:
py.test
# Run all the tests
tests: pytest2 pytest3
# Run the tests with Python 2
pytest2:
@echo " ** RUNING CHIP_IO TESTS UNDER PYTHON 2 **"
pushd test; python -m pytest; popd
# Run the tests with Python 3
pytest3:
@echo " ** RUNING CHIP_IO TESTS UNDER PYTHON 3 **"
pushd test; python3 -m pytest; popd
# Build all the things
build:
@echo " ** BUILDING CHIP_IO: PYTHON 2 **"
python setup.py build --force
# Install all the things
install: build
@echo " ** INSTALLING CHIP_IO: PYTHON 2 **"
python setup.py install --force
# Build for Python 3
build3:
@echo " ** BUILDING CHIP_IO: PYTHON 3 **"
python3 setup.py build --force
# Install for Python 3
install3: build3
@echo " ** INSTALLING CHIP_IO: PYTHON 3 **"
python3 setup.py install --force
# Install for both Python 2 and 3
all: install install3
# Create a deb file
debfile:
@echo " ** BUILDING DEBIAN PACKAGES **"
dpkg-buildpackage -rfakeroot -uc -b

View File

@ -46,116 +46,125 @@ All scripts that require GPIO, PWM (HW and/or SW), and Overlay Manager need to b
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.
+------------------+--------------------------+-------------+-----------------+
| CHIP (Name) | PocketCHIP/CHIP Pro Name | CHIP Key | HW Support |
+------------------+--------------------------+-------------+-----------------+
| TWI1-SDA | KPD-I2C-SDA | U13_9 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| TWI1-SCK | KPD-I2C-SCL | U13_11 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| LCD-D2 | UART2-TX | U13_17 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| PWM0 | PWM0 | U13_18 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| PWM1 | PWM1 | EINT13 | CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| LCD-D4 | UART2-CTS | U13_19 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| LCD-D3 | UART2-RX | U13_20 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| LCD-D6 | LCD-D6 | U13_21 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D5 | UART2-RTS | U13_22 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| LCD-D10 | LCD-D10 | U13_23 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D7 | LCD-D7 | U13_24 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D12 | LCD-D12 | U13_25 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D11 | LCD-D11 | U13_26 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D14 | LCD-D14 | U13_27 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D13 | LCD-D13 | U13_28 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D18 | LCD-D18 | U13_29 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D15 | LCD-D15 | U13_30 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D20 | LCD-D20 | U13_31 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D19 | LCD-D19 | U13_32 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D22 | LCD-D22 | U13_33 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D21 | LCD-D21 | U13_34 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-CLK | LCD-CLK | U13_35 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D23 | LCD-D23 | U13_36 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-VSYNC | LCD-VSYNC | U13_37 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-HSYNC | LCD-HSYNC | U13_38 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-DE | LCD-DE | U13_40 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| UART1-TX | UART-TX | U14_3 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| UART1-RX | UART-RX | U14_5 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| LRADC | ADC | U14_11 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| XIO-P0 | XIO-P0 | U14_13 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| XIO-P1 | XIO-P1 | U14_14 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| XIO-P2 | GPIO1 | U14_15 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| XIO-P3 | GPIO2 | U14_16 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| XIO-P4 | GPIO3 | U14_17 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| XIO-P5 | GPIO4 | U14_18 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| XIO-P6 | GPIO5 | U14_19 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| XIO-P7 | GPIO6 | U14_20 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| AP-EINT1 | KPD-INT | U14_23 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| AP-EINT3 | AP-INT3 | U14_24 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| TWI2-SDA | I2C-SDA | U14_25 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| TWI2-SCK | I2C-SCL | U14_26 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSIPCK | SPI-SEL | U14_27 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSICK | SPI-CLK | U14_28 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSIHSYNC | SPI-MOSI | U14_29 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSIVSYNC | SPI-MISO | U14_30 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSID0 | D0 | U14_31 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSID1 | D1 | U14_32 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSID2 | D2 | U14_33 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSID3 | D3 | U14_34 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSID4 | D4 | U14_35 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSID5 | D5 | U14_36 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSID6 | D6 | U14_37 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSID7 | D7 | U14_38 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
+------------------+--------------------------+----------------+-----------------+-----------------+
| CHIP (Main Name) | PocketCHIP/CHIP Pro Name | Key (Alt Name) | HW Support | Edge Detect |
+------------------+--------------------------+----------------+-----------------+-----------------+
| TWI1-SDA | KPD-I2C-SDA | U13_9 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| TWI1-SCK | KPD-I2C-SCL | U13_11 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D2 | UART2-TX | U13_17 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| PWM0 | PWM0 | U13_18 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| PWM1 | PWM1 | EINT13 | CHIP PRO | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D4 | UART2-CTS | U13_19 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D3 | UART2-RX | U13_20 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D6 | LCD-D6 | U13_21 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D5 | UART2-RTS | U13_22 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D10 | LCD-D10 | U13_23 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D7 | LCD-D7 | U13_24 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D12 | LCD-D12 | U13_25 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D11 | LCD-D11 | U13_26 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D14 | LCD-D14 | U13_27 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D13 | LCD-D13 | U13_28 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D18 | LCD-D18 | U13_29 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D15 | LCD-D15 | U13_30 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D20 | LCD-D20 | U13_31 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D19 | LCD-D19 | U13_32 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D22 | LCD-D22 | U13_33 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D21 | LCD-D21 | U13_34 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-CLK | LCD-CLK | U13_35 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D23 | LCD-D23 | U13_36 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-VSYNC | LCD-VSYNC | U13_37 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-HSYNC | LCD-HSYNC | U13_38 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-DE | LCD-DE | U13_40 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| UART1-TX | UART-TX | U14_3 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| UART1-RX | UART-RX | U14_5 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LRADC | ADC | U14_11 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| XIO-P0 | XIO-P0 | U14_13 | CHIP | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| XIO-P1 | XIO-P1 | U14_14 | CHIP | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| XIO-P2 | GPIO1 | U14_15 | CHIP | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| XIO-P3 | GPIO2 | U14_16 | CHIP | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| XIO-P4 | GPIO3 | U14_17 | CHIP | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| XIO-P5 | GPIO4 | U14_18 | CHIP | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| XIO-P6 | GPIO5 | U14_19 | CHIP | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| XIO-P7 | GPIO6 | U14_20 | CHIP | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| AP-EINT1 | KPD-INT | U14_23 | CHIP/CHIP PRO | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| AP-EINT3 | AP-INT3 | U14_24 | CHIP/CHIP PRO | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| TWI2-SDA | I2C-SDA | U14_25 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| TWI2-SCK | I2C-SCL | U14_26 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSIPCK | SPI-SEL | U14_27 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSICK | SPI-CLK | U14_28 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSIHSYNC | SPI-MOSI | U14_29 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSIVSYNC | SPI-MISO | U14_30 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSID0 | D0 | U14_31 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSID1 | D1 | U14_32 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSID2 | D2 | U14_33 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSID3 | D3 | U14_34 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSID4 | D4 | U14_35 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSID5 | D5 | U14_36 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSID6 | D6 | U14_37 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSID7 | D7 | U14_38 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| I2S-MCLK | EINT19 | 21 | CHIP PRO | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| I2S-BCLK | I2S-BCLK | 22 | CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| I2S-LCLK | I2S-LCLK | 23 | CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| I2S-DO | EINT19 | 24 | CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| I2S-DI | EINT24 | 25 | CHIP PRO | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
**GPIO Setup**
Import the library, and setup as GPIO.OUT or GPIO.IN::
@ -225,6 +234,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 +259,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")
@ -438,11 +459,12 @@ Install py.test to run the tests. You'll also need the python compiler package f
To run the tests, do the following.::
# If only one version of Python is installed
sudo py.test
# If more than one version of Python
cd test
sudo python2 -m pytest
sudo python3 -m pytest
# Python 2
sudo make pytest2
# Python 3
sudo make pytest3
# If more than one version of Python, run through both
sudo make test
**Credits**

52
debian/changelog vendored
View File

@ -1,3 +1,55 @@
chip-io (0.5.9-1) unstable; urgency=low
* Merged PR#70 to enable the underlying C code to be used properly in C based code
* Updated README to add missing pins on the CHIP Pro that are available as GPIO
* Updated README to denote pins that are available for Edge Detection
-- Robert Wolterman <robert.wolterman@gmail.com> Tue, 08 Jun 2017 20:03:00 -0600
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
-- Robert Wolterman <robert.wolterman@gmail.com> Mon, 6 Mar 2017 17:02:00 -0600
chip-io (0.5.4-1) unstable; urgency=low
* Re-enabled the polarity setting for PWM based upon Issue #61
* Fixed a 1 letter bug was trying to write inverted to polarity when it wants inversed (such facepalm)
* Cleaned up the polarity setting code to work when PWM is not enabled
* Fixed the unit test for pwm to verify we can set polarity
-- Robert Wolterman <robert.wolterman@gmail.com> Sat, 4 Mar 2017 20:46:00 -0600
chip-io (0.5.3-1) unstable; urgency=low
* Fixes to the PWM pytest
* Added pytest for LRADC and Utilities
* Makefile updates for all the things
-- Robert Wolterman <robert.wolterman@gmail.com> Sun, 26 Feb 2017 20:46:00 -0600
chip-io (0.5.2-1) unstable; urgency=low
* Updating Utilities to determine CHIP Pro better

4
debian/files vendored
View File

@ -1,2 +1,2 @@
python-chip-io_0.4.0-1_armhf.deb python optional
python3-chip-io_0.4.0-1_armhf.deb python optional
python-chip-io_0.5.8-1_armhf.deb python optional
python3-chip-io_0.5.8-1_armhf.deb python optional

View File

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

View File

@ -246,13 +246,14 @@ int pwm_set_polarity(const char *key, int polarity) {
return rtnval;
}
if (pwm->enable) {
// THIS ONLY WORKS WHEN PWM IS NOT ENABLED
if (pwm->enable == 0) {
if (polarity == 0) {
len = snprintf(buffer, sizeof(buffer), "%s", "normal"); BUF2SMALL(buffer);
}
else
{
len = snprintf(buffer, sizeof(buffer), "%s", "inverted"); BUF2SMALL(buffer);
len = snprintf(buffer, sizeof(buffer), "%s", "inversed"); BUF2SMALL(buffer);
}
ssize_t s = write(pwm->polarity_fd, buffer, len); e_no = errno;
if (DEBUG) {
@ -271,6 +272,7 @@ int pwm_set_polarity(const char *key, int polarity) {
} else {
rtnval = 0;
}
return rtnval;
}
@ -527,12 +529,12 @@ int pwm_start(const char *key, float duty, float freq, int polarity)
}
int rtnval = 0;
// Always set polarity first
if (iscpro == 1) {
rtnval = pwm_set_polarity(key, polarity);
}
rtnval = pwm_set_enable(key, ENABLE);
// Fix for issue #53
// Always set polarity first
rtnval = pwm_set_polarity(key, polarity);
if (rtnval != -1) {
rtnval = 0;
rtnval = pwm_set_enable(key, ENABLE);
if (rtnval != -1) {
rtnval = 0;
rtnval = pwm_set_frequency(key, freq);
@ -541,6 +543,7 @@ int pwm_start(const char *key, float duty, float freq, int polarity)
rtnval = pwm_set_duty_cycle(key, duty);
}
}
}
return rtnval;
}
@ -563,9 +566,7 @@ int pwm_disable(const char *key)
pwm_set_frequency(key, 0);
pwm_set_duty_cycle(key, 0);
pwm_set_enable(key, DISABLE);
if (pwm->iscpro == 1) {
pwm_set_polarity(key, 0);
}
if ((fd = open("/sys/class/pwm/pwmchip0/unexport", O_WRONLY)) < 0)
{

View File

@ -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}
};
@ -263,7 +268,7 @@ int gpio_allowed(int gpio)
// We have a CHIP and the pin is for CHIP/BOTH
if (((p->sbc_type == CHIP) || (p->sbc_type == BOTH)) && (is_this_chippro() == 0)) {
if (DEBUG)
printf(" ** gpio_allowed: pin allowed for chip or bth and we're a chip\n");
printf(" ** gpio_allowed: pin allowed for chip or both and we're a chip\n");
rtnval = 1;
// We have a CHIP Pro and the pin is for CHIPPRO/BOTH
} else if (((p->sbc_type == CHIPPRO) || (p->sbc_type == BOTH)) && (is_this_chippro() == 1)) {
@ -296,7 +301,7 @@ int pwm_allowed(const char *key)
// We have a CHIP and the pin is for CHIP/BOTH
if ((p->sbc_type == BOTH) && (is_this_chippro() == 0)) {
if (DEBUG)
printf(" ** pwm_allowed: pwm allowed for chip or bth and we're a chip\n");
printf(" ** pwm_allowed: pwm allowed for chip or both and we're a chip\n");
rtnval = 1;
// We have a CHIP Pro and the pin is for CHIPPRO/BOTH
} else if (((p->sbc_type == CHIPPRO) || (p->sbc_type == BOTH)) && (is_this_chippro() == 1)) {
@ -554,7 +559,7 @@ int compute_port_pin(const char *key, int gpio, int *port, int *pin)
if (capable < 0) {
capable = lookup_pud_capable_by_name(key);
if (capable < 0) {
capable = lookup_gpio_by_altname(key);
capable = lookup_pud_capable_by_altname(key);
if (capable < 0) {
capable = 0; // default to false
}

View File

@ -86,9 +86,9 @@ typedef struct dyn_int_array_s dyn_int_array_t;
#define FILENAME_BUFFER_SIZE 128
int setup_error;
int module_setup;
int DEBUG;
extern int setup_error;
extern int module_setup;
extern int DEBUG;
int get_xio_base(void);
int is_this_chippro(void);

View File

@ -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.2");
version = Py_BuildValue("s", "0.5.9");
PyModule_AddObject(module, "VERSION", version);
}

View File

@ -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

View File

@ -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;

View File

@ -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
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}

View File

@ -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
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}

View File

@ -0,0 +1,45 @@
#!/usr/bin/python
import CHIP_IO.SOFTPWM as PWM
import CHIP_IO.GPIO as GPIO
import CHIP_IO.OverlayManager as OM
import time
import datetime
if __name__ == "__main__":
# SETUP VARIABLES
PWMGPIO = "XIO-P7"
#PWMGPIO = "LCD-D4"
COUNT = 150
SLEEPTIME = 0.01
time.sleep(1)
# SETUP PWM
try:
print("PWM START")
#PWM.toggle_debug()
PWM.start(PWMGPIO, 50, 45, 1)
# UNCOMMENT FOR CRASH
print("PWM SET FREQUENCY")
PWM.set_frequency(PWMGPIO, 10)
# UNCOMMENT FOR CRASH
print("PWM SET DUTY CYCLE")
PWM.set_duty_cycle(PWMGPIO, 25)
#time.sleep(COUNT*SLEEPTIME + 1)
raw_input("PRESS ENTER WHEN DONE")
except:
raise
finally:
# CLEANUP
print("CLEANUP")
PWM.stop(PWMGPIO)
PWM.cleanup()
#OM.unload("PWM0")
#GPIO.cleanup()

14
test/test_lradc.py Normal file
View File

@ -0,0 +1,14 @@
import pytest
import CHIP_IO.LRADC as LRADC
class TestLRADC:
def test_scale_factor(self):
assert LRADC.get_scale_factor() == 31.25
def test_sample_rate_values(self):
assert LRADC.get_allowable_sample_rates() == (32.25, 62.5, 125, 250)
def test_set_sample_rate(self):
LRADC.set_sample_rate(32.25)
assert LRADC.get_sample_rate() == 32.25

View File

@ -4,12 +4,15 @@ import time
import CHIP_IO.PWM as PWM
import CHIP_IO.OverlayManager as OM
import CHIP_IO.Utilities as UT
def setup_module(module):
if not UT.is_chip_pro():
OM.load("PWM0")
def teardown_module(module):
PWM.cleanup()
if not UT.is_chip_pro():
OM.unload("PWM0")
class TestPwmSetup:
@ -17,16 +20,6 @@ class TestPwmSetup:
def setup_method(self, test_method):
time.sleep(0.5)
#def teardown_method(self, test_method):
# PWM.cleanup()
#OM.unload("PWM0")
#def setup_module(self, module):
# OM.load("PWM0")
#def teardown_module(self, module):
# OM.unload("PWM0")
def test_start_pwm(self):
PWM.start("PWM0", 0)
@ -38,27 +31,25 @@ class TestPwmSetup:
assert int(duty) == 0
assert int(period) == 500000
@pytest.mark.xfail(reason="pwm cleanup is doing weirdness for this test")
def test_start_pwm_with_polarity_one(self):
PWM.cleanup()
PWM.start("PWM0", 0, 2000, 1)
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
#assert os.path.exists(pwm_test) == True
duty = open(pwm_test + 'duty_cycle').readline().strip()
period = open(pwm_test + 'period').readline().strip()
polarity = open(pwm_test + 'polarity').readline().strip()
assert int(duty) == 0
assert int(period) == 500000
assert str(polarity) == "inverted"
assert str(polarity) == "inversed"
@pytest.mark.xfail(reason="pwm cleanup is doing weirdness for this test")
def test_start_pwm_with_polarity_default(self):
PWM.cleanup()
PWM.start("PWM0", 0, 2000, 0)
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
#assert os.path.exists(pwm_test) == True
duty = open(pwm_test + 'duty_cycle').readline().strip()
period = open(pwm_test + 'period').readline().strip()
polarity = open(pwm_test + 'polarity').readline().strip()
@ -66,13 +57,12 @@ class TestPwmSetup:
assert int(period) == 500000
assert str(polarity) == "normal"
@pytest.mark.xfail(reason="pwm cleanup is doing weirdness for this test")
def test_start_pwm_with_polarity_zero(self):
PWM.cleanup()
PWM.start("PWM0", 0, 2000, 0)
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
#assert os.path.exists(pwm_test) == True
duty = open(pwm_test + 'duty_cycle').readline().strip()
period = open(pwm_test + 'period').readline().strip()
polarity = open(pwm_test + 'polarity').readline().strip()
@ -90,11 +80,14 @@ class TestPwmSetup:
def test_pwm_start_valid_duty_cycle_min(self):
#testing an exception isn't thrown
PWM.cleanup()
PWM.start("PWM0", 0)
PWM.cleanup()
def test_pwm_start_valid_duty_cycle_max(self):
#testing an exception isn't thrown
PWM.start("PWM0", 100)
PWM.cleanup()
def test_pwm_start_invalid_duty_cycle_high(self):
with pytest.raises(ValueError):
@ -143,7 +136,8 @@ class TestPwmSetup:
assert int(period) == 500000
def test_pwm_duty_cycle_non_setup_key(self):
with pytest.raises(RuntimeError):
with pytest.raises(ValueError):
PWM.cleanup()
PWM.set_duty_cycle("PWM0", 100)
def test_pwm_duty_cycle_invalid_key(self):
@ -154,26 +148,31 @@ class TestPwmSetup:
PWM.start("PWM0", 0)
with pytest.raises(ValueError):
PWM.set_duty_cycle("PWM0", 101)
PWM.cleanup()
def test_pwm_duty_cycle_invalid_value_negative(self):
PWM.start("PWM0", 0)
with pytest.raises(ValueError):
PWM.set_duty_cycle("PWM0", -1)
PWM.cleanup()
def test_pwm_duty_cycle_invalid_value_string(self):
PWM.start("PWM0", 0)
with pytest.raises(TypeError):
PWM.set_duty_cycle("PWM0", "a")
PWM.cleanup()
def test_pwm_frequency_invalid_value_negative(self):
PWM.start("PWM0", 0)
with pytest.raises(ValueError):
PWM.set_frequency("PWM0", -1)
PWM.cleanup()
def test_pwm_frequency_invalid_value_string(self):
PWM.start("PWM0", 0)
with pytest.raises(TypeError):
PWM.set_frequency("PWM0", "11")
PWM.cleanup()
def test_pwm_freq_non_setup_key(self):
with pytest.raises(RuntimeError):

11
test/test_utilities.py Normal file
View File

@ -0,0 +1,11 @@
import pytest
import CHIP_IO.Utilities as UT
class TestUtilities:
def test_invalid_set_1v8_with_string(self):
assert not UT.set_1v8_pin_voltage("yaystring")
def test_invalid_set_1v8_with_outofbounds_value(self):
assert not UT.set_1v8_pin_voltage(0.5)
assert not UT.set_1v8_pin_voltage(4.5)