mirror of
https://github.com/xtacocorex/CHIP_IO
synced 2025-07-20 21:03:22 +00:00
Compare commits
40 Commits
Author | SHA1 | Date | |
---|---|---|---|
84df4376f8 | |||
906beb0257 | |||
00cd5c09ad | |||
c87b0ca72a | |||
ff7bf2fa1c | |||
af9555fcdf | |||
e7db735a2f | |||
e3a077bf82 | |||
a0b2ac12a6 | |||
6af974c113 | |||
4670e44758 | |||
2247e9d234 | |||
ff91bcd0d1 | |||
35619e5baf | |||
1e3935c8ea | |||
e038fc9c89 | |||
5b016887fe | |||
aa76edb7b3 | |||
d84c3c03d7 | |||
c47fb197f5 | |||
a6111d8245 | |||
71923f5739 | |||
c9b0ae4229 | |||
5aef829dd1 | |||
3c3ec494dd | |||
bb5f0083e8 | |||
408bf60ffa | |||
310c4a9ae4 | |||
014dcb8a36 | |||
6e93fad1de | |||
41d4b84c56 | |||
024e5d5797 | |||
6ddd0e0b14 | |||
d4b1d8a41c | |||
2b48571ee3 | |||
38a34e7edf | |||
f32733bb07 | |||
4da0812acd | |||
dcd8ea6f40 | |||
29377cf24d |
@ -1,3 +1,66 @@
|
|||||||
|
0.7.1
|
||||||
|
---
|
||||||
|
* Merged in PR #79
|
||||||
|
* Merged in PR #80
|
||||||
|
* Added message notifying user of the gpio set direction retry
|
||||||
|
|
||||||
|
0.7.0
|
||||||
|
---
|
||||||
|
* Added ability to specify GPIO only as a number, this doesn't work for PWM/SPWM/LRADC/SERVO
|
||||||
|
|
||||||
|
0.6.2
|
||||||
|
---
|
||||||
|
* Implementation for #77 - ability to push up binary pypi
|
||||||
|
* Implementation for #75 - wait_for_edge timeout
|
||||||
|
|
||||||
|
0.6.1
|
||||||
|
---
|
||||||
|
* Fixing implementation for #76
|
||||||
|
|
||||||
|
0.6
|
||||||
|
---
|
||||||
|
* Random comment cleanup
|
||||||
|
* Implement fix for #76
|
||||||
|
* API documentation added
|
||||||
|
* Closing #74
|
||||||
|
|
||||||
|
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
|
0.5.2
|
||||||
---
|
---
|
||||||
* Updating Utilties to determine CHIP Pro better
|
* Updating Utilties to determine CHIP Pro better
|
||||||
|
@ -20,7 +20,8 @@
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import time
|
import time
|
||||||
import Utilities as UT
|
import sys
|
||||||
|
from .Utilities import is_chip_pro
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
|
||||||
@ -162,7 +163,7 @@ def load(overlay, path=""):
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
# DETERMINE IF WE ARE A CHIP PRO AND WE ARE COMMANDED TO LOAD PWM0
|
# 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")
|
print("CHIP Pro supports PWM0 in base DTB, exiting")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@ -200,7 +201,7 @@ def unload(overlay):
|
|||||||
print("UNLOAD OVERLAY: {0}".format(overlay))
|
print("UNLOAD OVERLAY: {0}".format(overlay))
|
||||||
|
|
||||||
# DETERMINE IF WE ARE A CHIP PRO AND WE ARE COMMANDED TO UNLOAD PWM0
|
# 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")
|
print("CHIP Pro supports PWM0 in base DTB, exiting")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
50
Makefile
50
Makefile
@ -1,25 +1,67 @@
|
|||||||
|
# PyPi Packaging
|
||||||
package: clean
|
package: clean
|
||||||
python setup.py sdist
|
@echo " ** PACKAGING FOR PYPI **"
|
||||||
|
python setup.py sdist bdist_wheel
|
||||||
|
python3 setup.py bdist_wheel
|
||||||
|
|
||||||
publish: package
|
# PyPi Packaging
|
||||||
|
package3: package
|
||||||
|
@echo " ** PACKAGING FOR PYPI **"
|
||||||
|
python3 setup.py bdist_wheel
|
||||||
|
|
||||||
|
# PyPi Publishing
|
||||||
|
publish: package package3
|
||||||
|
@echo " ** UPLOADING TO PYPI **"
|
||||||
twine upload dist/*
|
twine upload dist/*
|
||||||
|
|
||||||
|
# Clean all the things
|
||||||
clean:
|
clean:
|
||||||
|
@echo " ** CLEANING CHIP_IO **"
|
||||||
rm -rf CHIP_IO.* build dist
|
rm -rf CHIP_IO.* build dist
|
||||||
rm -f *.pyo *.pyc
|
rm -f *.pyo *.pyc
|
||||||
rm -f *.egg
|
rm -f *.egg
|
||||||
rm -rf __pycache__
|
rm -rf __pycache__
|
||||||
|
rm -rf test/__pycache__/
|
||||||
rm -rf debian/python-chip-io*
|
rm -rf debian/python-chip-io*
|
||||||
rm -rf debian/python3-chip-io*
|
rm -rf debian/python3-chip-io*
|
||||||
|
|
||||||
tests:
|
# Run all the tests
|
||||||
py.test
|
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:
|
build:
|
||||||
|
@echo " ** BUILDING CHIP_IO: PYTHON 2 **"
|
||||||
python setup.py build --force
|
python setup.py build --force
|
||||||
|
|
||||||
|
# Install all the things
|
||||||
install: build
|
install: build
|
||||||
|
@echo " ** INSTALLING CHIP_IO: PYTHON 2 **"
|
||||||
python setup.py install --force
|
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:
|
debfile:
|
||||||
|
@echo " ** BUILDING DEBIAN PACKAGES **"
|
||||||
dpkg-buildpackage -rfakeroot -uc -b
|
dpkg-buildpackage -rfakeroot -uc -b
|
||||||
|
327
README.rst
327
README.rst
@ -2,6 +2,19 @@ CHIP_IO
|
|||||||
============================
|
============================
|
||||||
A CHIP GPIO library
|
A CHIP GPIO library
|
||||||
|
|
||||||
|
Debian File Installation:
|
||||||
|
|
||||||
|
There are now pre-compiled binary deb files for the CHIP that do not require any build tools on a CHIP/CHIP Pro.
|
||||||
|
|
||||||
|
Go to this page: https://github.com/xtacocorex/CHIP_IO/releases/latest
|
||||||
|
Or
|
||||||
|
Go to this page: https://xtacocorex.github.io/chip_io_releases/index.html
|
||||||
|
|
||||||
|
Download the .deb file for the version of Python you are running.
|
||||||
|
Then install with dpkg, like the following example:
|
||||||
|
|
||||||
|
sudo dpkg -i python-chip-io_0.5.9-1_armhf.deb
|
||||||
|
|
||||||
Manual Installation::
|
Manual Installation::
|
||||||
|
|
||||||
For Python2.7::
|
For Python2.7::
|
||||||
@ -46,115 +59,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.
|
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 |
|
| CHIP (Main Name) | PocketCHIP/CHIP Pro Name | Key (Alt Name) | HW Support | Edge Detect |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| TWI1-SDA | KPD-I2C-SDA | U13_9 | CHIP/CHIP PRO |
|
| TWI1-SDA | KPD-I2C-SDA | U13_9 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| TWI1-SCK | KPD-I2C-SCL | U13_11 | CHIP/CHIP PRO |
|
| TWI1-SCK | KPD-I2C-SCL | U13_11 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D2 | UART2-TX | U13_17 | CHIP/CHIP PRO |
|
| LCD-D2 | UART2-TX | U13_17 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| PWM0 | PWM0 | U13_18 | CHIP/CHIP PRO |
|
| PWM0 | PWM0 | U13_18 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| PWM1 | PWM1 | EINT13 | CHIP PRO |
|
| PWM1 | PWM1 | EINT13 | CHIP PRO | YES |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D4 | UART2-CTS | U13_19 | CHIP/CHIP PRO |
|
| LCD-D4 | UART2-CTS | U13_19 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D3 | UART2-RX | U13_20 | CHIP/CHIP PRO |
|
| LCD-D3 | UART2-RX | U13_20 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D6 | LCD-D6 | U13_21 | CHIP |
|
| LCD-D6 | LCD-D6 | U13_21 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D5 | UART2-RTS | U13_22 | CHIP/CHIP PRO |
|
| LCD-D5 | UART2-RTS | U13_22 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D10 | LCD-D10 | U13_23 | CHIP |
|
| LCD-D10 | LCD-D10 | U13_23 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D7 | LCD-D7 | U13_24 | CHIP |
|
| LCD-D7 | LCD-D7 | U13_24 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D12 | LCD-D12 | U13_25 | CHIP |
|
| LCD-D12 | LCD-D12 | U13_25 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D11 | LCD-D11 | U13_26 | CHIP |
|
| LCD-D11 | LCD-D11 | U13_26 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D14 | LCD-D14 | U13_27 | CHIP |
|
| LCD-D14 | LCD-D14 | U13_27 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D13 | LCD-D13 | U13_28 | CHIP |
|
| LCD-D13 | LCD-D13 | U13_28 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D18 | LCD-D18 | U13_29 | CHIP |
|
| LCD-D18 | LCD-D18 | U13_29 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D15 | LCD-D15 | U13_30 | CHIP |
|
| LCD-D15 | LCD-D15 | U13_30 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D20 | LCD-D20 | U13_31 | CHIP |
|
| LCD-D20 | LCD-D20 | U13_31 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D19 | LCD-D19 | U13_32 | CHIP |
|
| LCD-D19 | LCD-D19 | U13_32 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D22 | LCD-D22 | U13_33 | CHIP |
|
| LCD-D22 | LCD-D22 | U13_33 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D21 | LCD-D21 | U13_34 | CHIP |
|
| LCD-D21 | LCD-D21 | U13_34 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-CLK | LCD-CLK | U13_35 | CHIP |
|
| LCD-CLK | LCD-CLK | U13_35 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-D23 | LCD-D23 | U13_36 | CHIP |
|
| LCD-D23 | LCD-D23 | U13_36 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-VSYNC | LCD-VSYNC | U13_37 | CHIP |
|
| LCD-VSYNC | LCD-VSYNC | U13_37 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-HSYNC | LCD-HSYNC | U13_38 | CHIP |
|
| LCD-HSYNC | LCD-HSYNC | U13_38 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LCD-DE | LCD-DE | U13_40 | CHIP |
|
| LCD-DE | LCD-DE | U13_40 | CHIP | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| UART1-TX | UART-TX | U14_3 | CHIP/CHIP PRO |
|
| UART1-TX | UART-TX | U14_3 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| UART1-RX | UART-RX | U14_5 | CHIP/CHIP PRO |
|
| UART1-RX | UART-RX | U14_5 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| LRADC | ADC | U14_11 | CHIP/CHIP PRO |
|
| LRADC | ADC | U14_11 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| XIO-P0 | XIO-P0 | U14_13 | CHIP |
|
| XIO-P0 | XIO-P0 | U14_13 | CHIP | YES |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| XIO-P1 | XIO-P1 | U14_14 | CHIP |
|
| XIO-P1 | XIO-P1 | U14_14 | CHIP | YES |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| XIO-P2 | GPIO1 | U14_15 | CHIP |
|
| XIO-P2 | GPIO1 | U14_15 | CHIP | YES |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| XIO-P3 | GPIO2 | U14_16 | CHIP |
|
| XIO-P3 | GPIO2 | U14_16 | CHIP | YES |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| XIO-P4 | GPIO3 | U14_17 | CHIP |
|
| XIO-P4 | GPIO3 | U14_17 | CHIP | YES |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| XIO-P5 | GPIO4 | U14_18 | CHIP |
|
| XIO-P5 | GPIO4 | U14_18 | CHIP | YES |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| XIO-P6 | GPIO5 | U14_19 | CHIP |
|
| XIO-P6 | GPIO5 | U14_19 | CHIP | YES |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| XIO-P7 | GPIO6 | U14_20 | CHIP |
|
| XIO-P7 | GPIO6 | U14_20 | CHIP | YES |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| AP-EINT1 | KPD-INT | U14_23 | CHIP/CHIP PRO |
|
| AP-EINT1 | KPD-INT | U14_23 | CHIP/CHIP PRO | YES |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| AP-EINT3 | AP-INT3 | U14_24 | CHIP/CHIP PRO |
|
| AP-EINT3 | AP-INT3 | U14_24 | CHIP/CHIP PRO | YES |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| TWI2-SDA | I2C-SDA | U14_25 | CHIP/CHIP PRO |
|
| TWI2-SDA | I2C-SDA | U14_25 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| TWI2-SCK | I2C-SCL | U14_26 | CHIP/CHIP PRO |
|
| TWI2-SCK | I2C-SCL | U14_26 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| CSIPCK | SPI-SEL | U14_27 | CHIP/CHIP PRO |
|
| CSIPCK | SPI-SEL | U14_27 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| CSICK | SPI-CLK | U14_28 | CHIP/CHIP PRO |
|
| CSICK | SPI-CLK | U14_28 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| CSIHSYNC | SPI-MOSI | U14_29 | CHIP/CHIP PRO |
|
| CSIHSYNC | SPI-MOSI | U14_29 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| CSIVSYNC | SPI-MISO | U14_30 | CHIP/CHIP PRO |
|
| CSIVSYNC | SPI-MISO | U14_30 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| CSID0 | D0 | U14_31 | CHIP/CHIP PRO |
|
| CSID0 | D0 | U14_31 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| CSID1 | D1 | U14_32 | CHIP/CHIP PRO |
|
| CSID1 | D1 | U14_32 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| CSID2 | D2 | U14_33 | CHIP/CHIP PRO |
|
| CSID2 | D2 | U14_33 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| CSID3 | D3 | U14_34 | CHIP/CHIP PRO |
|
| CSID3 | D3 | U14_34 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| CSID4 | D4 | U14_35 | CHIP/CHIP PRO |
|
| CSID4 | D4 | U14_35 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| CSID5 | D5 | U14_36 | CHIP/CHIP PRO |
|
| CSID5 | D5 | U14_36 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| CSID6 | D6 | U14_37 | CHIP/CHIP PRO |
|
| CSID6 | D6 | U14_37 | CHIP/CHIP PRO | NO |
|
||||||
+------------------+--------------------------+-------------+-----------------+
|
+------------------+--------------------------+----------------+-----------------+-----------------+
|
||||||
| CSID7 | D7 | U14_38 | CHIP/CHIP PRO |
|
| 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**
|
**GPIO Setup**
|
||||||
|
|
||||||
@ -204,6 +227,7 @@ Other options when setting up pins::
|
|||||||
|
|
||||||
# Specify pull up/pull down settings on a pin
|
# Specify pull up/pull down settings on a pin
|
||||||
GPIO.setup("CSID0", GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
GPIO.setup("CSID0", GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||||
|
|
||||||
# Specify initial value for an output
|
# Specify initial value for an output
|
||||||
GPIO.setup("CSID0", GPIO.OUT, initial=1)
|
GPIO.setup("CSID0", GPIO.OUT, initial=1)
|
||||||
|
|
||||||
@ -220,11 +244,22 @@ Read lots of data::
|
|||||||
|
|
||||||
# Get 8 bits of data in one shot
|
# Get 8 bits of data in one shot
|
||||||
mybyte = GPIO.read_byte("LCD-D3")
|
mybyte = GPIO.read_byte("LCD-D3")
|
||||||
|
|
||||||
# Get 16 bits of data in one shot
|
# Get 16 bits of data in one shot
|
||||||
myword = GPIO.read_word("XIO-P4")
|
myword = GPIO.read_word("XIO-P4")
|
||||||
|
|
||||||
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, note 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::
|
||||||
@ -236,25 +271,35 @@ Detecting events::
|
|||||||
GPIO.setup("XIO-P0", GPIO.IN)
|
GPIO.setup("XIO-P0", GPIO.IN)
|
||||||
GPIO.add_event_detect("XIO-P0", GPIO.FALLING)
|
GPIO.add_event_detect("XIO-P0", GPIO.FALLING)
|
||||||
#your amazing code here
|
#your amazing code here
|
||||||
|
|
||||||
#detect wherever:
|
#detect wherever:
|
||||||
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
|
|
||||||
GPIO.add_event_callback("GPIO3", GPIO.FALLING, mycallback)
|
# Add Event Detect and Callback Separately for Falling Edge
|
||||||
# Add Callback: Rising Edge
|
GPIO.add_event_detect("GPIO3", GPIO.FALLING)
|
||||||
GPIO.add_event_callback("GPIO3", GPIO.RISING, mycallback)
|
GPIO.add_event_callback("GPIO3", mycallback)
|
||||||
# Add Callback: Both Edges
|
|
||||||
GPIO.add_event_callback("GPIO3", GPIO.BOTH, mycallback)
|
# Add Event Detect and Callback Separately for Rising Edge
|
||||||
# Remove callback
|
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")
|
GPIO.remove_event_detect("GPIO3")
|
||||||
|
|
||||||
|
# bouncetime is also able to be set for both GPIO.add_event_detect() and GPIO.add_event_callback()
|
||||||
|
GPIO.add_event_detect("GPIO3", GPIO.FALLING, bouncetime=300)
|
||||||
|
GPIO.add_event_callback("GPIO3", GPIO.RISING, mycallback, bouncetime=300)
|
||||||
|
|
||||||
**GPIO Cleanup**
|
**GPIO Cleanup**
|
||||||
|
|
||||||
@ -262,6 +307,7 @@ To clean up the GPIO when done, do the following::
|
|||||||
|
|
||||||
# Clean up every exported GPIO Pin
|
# Clean up every exported GPIO Pin
|
||||||
GPIO.cleanup()
|
GPIO.cleanup()
|
||||||
|
|
||||||
# Clean up a single pin (keeping everything else intact)
|
# Clean up a single pin (keeping everything else intact)
|
||||||
GPIO.cleanup("XIO-P0")
|
GPIO.cleanup("XIO-P0")
|
||||||
|
|
||||||
@ -274,16 +320,20 @@ Hardware PWM requires a DTB Overlay loaded on the CHIP to allow the kernel to kn
|
|||||||
# 0 For CHIP
|
# 0 For CHIP
|
||||||
# 1 For CHIP Pro
|
# 1 For CHIP Pro
|
||||||
PWM.is_chip_pro()
|
PWM.is_chip_pro()
|
||||||
|
|
||||||
# Enable/Disable Debug
|
# Enable/Disable Debug
|
||||||
PWM.toggle_debug()
|
PWM.toggle_debug()
|
||||||
|
|
||||||
#PWM.start(channel, duty, freq=2000, polarity=0)
|
#PWM.start(channel, duty, freq=2000, polarity=0)
|
||||||
#duty values are valid 0 (off) to 100 (on)
|
#duty values are valid 0 (off) to 100 (on)
|
||||||
PWM.start("PWM0", 50)
|
PWM.start("PWM0", 50)
|
||||||
PWM.set_duty_cycle("PWM0", 25.5)
|
PWM.set_duty_cycle("PWM0", 25.5)
|
||||||
PWM.set_frequency("PWM0", 10)
|
PWM.set_frequency("PWM0", 10)
|
||||||
|
|
||||||
# To stop PWM
|
# To stop PWM
|
||||||
PWM.stop("PWM0")
|
PWM.stop("PWM0")
|
||||||
PWM.cleanup()
|
PWM.cleanup()
|
||||||
|
|
||||||
#For specific polarity: this example sets polarity to 1 on start:
|
#For specific polarity: this example sets polarity to 1 on start:
|
||||||
PWM.start("PWM0", 50, 2000, 1)
|
PWM.start("PWM0", 50, 2000, 1)
|
||||||
|
|
||||||
@ -294,18 +344,23 @@ Hardware PWM requires a DTB Overlay loaded on the CHIP to allow the kernel to kn
|
|||||||
# 0 For CHIP
|
# 0 For CHIP
|
||||||
# 1 For CHIP Pro
|
# 1 For CHIP Pro
|
||||||
SPWM.is_chip_pro()
|
SPWM.is_chip_pro()
|
||||||
|
|
||||||
# Enable/Disable Debug
|
# Enable/Disable Debug
|
||||||
SPWM.toggle_debug()
|
SPWM.toggle_debug()
|
||||||
|
|
||||||
#SPWM.start(channel, duty, freq=2000, polarity=0)
|
#SPWM.start(channel, duty, freq=2000, polarity=0)
|
||||||
#duty values are valid 0 (off) to 100 (on)
|
#duty values are valid 0 (off) to 100 (on)
|
||||||
#you can choose any pin
|
#you can choose any pin
|
||||||
SPWM.start("XIO-P7", 50)
|
SPWM.start("XIO-P7", 50)
|
||||||
SPWM.set_duty_cycle("XIO-P7", 25.5)
|
SPWM.set_duty_cycle("XIO-P7", 25.5)
|
||||||
SPWM.set_frequency("XIO-P7", 10)
|
SPWM.set_frequency("XIO-P7", 10)
|
||||||
|
|
||||||
# To Stop SPWM
|
# To Stop SPWM
|
||||||
SPWM.stop("XIO-P7")
|
SPWM.stop("XIO-P7")
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
SPWM.cleanup()
|
SPWM.cleanup()
|
||||||
|
|
||||||
#For specific polarity: this example sets polarity to 1 on start:
|
#For specific polarity: this example sets polarity to 1 on start:
|
||||||
SPWM.start("XIO-P7", 50, 2000, 1)
|
SPWM.start("XIO-P7", 50, 2000, 1)
|
||||||
|
|
||||||
@ -320,16 +375,20 @@ If using SOFTPWM and PWM at the same time, import CHIP_IO.SOFTPWM as SPWM or som
|
|||||||
# 0 For CHIP
|
# 0 For CHIP
|
||||||
# 1 For CHIP Pro
|
# 1 For CHIP Pro
|
||||||
SERVO.is_chip_pro()
|
SERVO.is_chip_pro()
|
||||||
|
|
||||||
# Enable/Disable Debug
|
# Enable/Disable Debug
|
||||||
SERVO.toggle_debug()
|
SERVO.toggle_debug()
|
||||||
|
|
||||||
#SPWM.start(channel, angle=0, range=180)
|
#SPWM.start(channel, angle=0, range=180)
|
||||||
#angle values are between +/- range/2)
|
#angle values are between +/- range/2)
|
||||||
#you can choose any pin except the XIO's
|
#you can choose any pin except the XIO's
|
||||||
SERVO.start("CSID4", 50)
|
SERVO.start("CSID4", 50)
|
||||||
SERVO.set_angle("CSID4", 25.5)
|
SERVO.set_angle("CSID4", 25.5)
|
||||||
SERVO.set_range("CSID4", 90)
|
SERVO.set_range("CSID4", 90)
|
||||||
|
|
||||||
# To Stop Servo
|
# To Stop Servo
|
||||||
SERVO.stop("CSID4")
|
SERVO.stop("CSID4")
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
SERVO.cleanup()
|
SERVO.cleanup()
|
||||||
|
|
||||||
@ -343,23 +402,31 @@ Sample code below details how to talk to the LRADC.::
|
|||||||
import CHIP_IO.LRADC as ADC
|
import CHIP_IO.LRADC as ADC
|
||||||
# Enable/Disable Debug
|
# Enable/Disable Debug
|
||||||
ADC.toggle_debug()
|
ADC.toggle_debug()
|
||||||
|
|
||||||
# Check to see if the LRADC Device exists
|
# Check to see if the LRADC Device exists
|
||||||
# Returns True/False
|
# Returns True/False
|
||||||
ADC.get_device_exists()
|
ADC.get_device_exists()
|
||||||
|
|
||||||
# Setup the LRADC
|
# Setup the LRADC
|
||||||
# Specify a sampling rate if needed
|
# Specify a sampling rate if needed
|
||||||
ADC.setup(rate)
|
ADC.setup(rate)
|
||||||
|
|
||||||
# Get the Scale Factor
|
# Get the Scale Factor
|
||||||
factor = ADC.get_scale_factor()
|
factor = ADC.get_scale_factor()
|
||||||
|
|
||||||
# Get the allowable Sampling Rates
|
# Get the allowable Sampling Rates
|
||||||
sampleratestuple = ADC.get_allowable_sample_rates()
|
sampleratestuple = ADC.get_allowable_sample_rates()
|
||||||
|
|
||||||
# Set the sampling rate
|
# Set the sampling rate
|
||||||
ADC.set_sample_rate(rate)
|
ADC.set_sample_rate(rate)
|
||||||
|
|
||||||
# Get the current sampling rate
|
# Get the current sampling rate
|
||||||
currentrate = ADC.get_sample_rate()
|
currentrate = ADC.get_sample_rate()
|
||||||
|
|
||||||
# Get the Raw Channel 0 or 1 data
|
# Get the Raw Channel 0 or 1 data
|
||||||
raw = ADC.get_chan0_raw()
|
raw = ADC.get_chan0_raw()
|
||||||
raw = ADC.get_chan1_raw()
|
raw = ADC.get_chan1_raw()
|
||||||
|
|
||||||
# Get the factored ADC Channel data
|
# Get the factored ADC Channel data
|
||||||
fulldata = ADC.get_chan0()
|
fulldata = ADC.get_chan0()
|
||||||
fulldata = ADC.get_chan1()
|
fulldata = ADC.get_chan1()
|
||||||
@ -377,12 +444,15 @@ Only one of each type of overlay can be loaded at a time, but all three options
|
|||||||
::
|
::
|
||||||
import CHIP_IO.OverlayManager as OM
|
import CHIP_IO.OverlayManager as OM
|
||||||
# The toggle_debug() function turns on/off debug printing
|
# The toggle_debug() function turns on/off debug printing
|
||||||
#OM.toggle_debug()
|
OM.toggle_debug()
|
||||||
|
|
||||||
# To load an overlay, feed in the name to load()
|
# To load an overlay, feed in the name to load()
|
||||||
OM.load("PWM0")
|
OM.load("PWM0")
|
||||||
|
|
||||||
# To verify the overlay was properly loaded, the get_ functions return booleans
|
# To verify the overlay was properly loaded, the get_ functions return booleans
|
||||||
OM.get_pwm_loaded()
|
OM.get_pwm_loaded()
|
||||||
OM.get_spi_loaded()
|
OM.get_spi_loaded()
|
||||||
|
|
||||||
# To unload an overlay, feed in the name to unload()
|
# To unload an overlay, feed in the name to unload()
|
||||||
OM.unload("PWM0")
|
OM.unload("PWM0")
|
||||||
|
|
||||||
@ -392,8 +462,10 @@ There is no verification that the Custom Overlay is setup properly, it's fire an
|
|||||||
import CHIP_IO.OverlayManager as OM
|
import CHIP_IO.OverlayManager as OM
|
||||||
# The full path to the dtbo file needs to be specified
|
# The full path to the dtbo file needs to be specified
|
||||||
OM.load("CUST","/home/chip/projects/myfunproject/overlays/mycustomoverlay.dtbo")
|
OM.load("CUST","/home/chip/projects/myfunproject/overlays/mycustomoverlay.dtbo")
|
||||||
|
|
||||||
# You can check for loading like above, but it's really just there for sameness
|
# You can check for loading like above, but it's really just there for sameness
|
||||||
OM.get_custom_loaded()
|
OM.get_custom_loaded()
|
||||||
|
|
||||||
# To unload, just call unload()
|
# To unload, just call unload()
|
||||||
OM.unload("CUST")
|
OM.unload("CUST")
|
||||||
|
|
||||||
@ -408,20 +480,28 @@ To use the utilities, here is sample code::
|
|||||||
import CHIP_IO.Utilities as UT
|
import CHIP_IO.Utilities as UT
|
||||||
# Enable/Disable Debug
|
# Enable/Disable Debug
|
||||||
UT.toggle_debug()
|
UT.toggle_debug()
|
||||||
|
|
||||||
# Enable 1.8V Output
|
# Enable 1.8V Output
|
||||||
UT.enable_1v8_pin()
|
UT.enable_1v8_pin()
|
||||||
|
|
||||||
# Set 2.0V Output
|
# Set 2.0V Output
|
||||||
UT.set_1v8_pin_voltage(2.0)
|
UT.set_1v8_pin_voltage(2.0)
|
||||||
|
|
||||||
# Set 2.6V Output
|
# Set 2.6V Output
|
||||||
UT.set_1v8_pin_voltage(2.6)
|
UT.set_1v8_pin_voltage(2.6)
|
||||||
|
|
||||||
# Set 3.3V Output
|
# Set 3.3V Output
|
||||||
UT.set_1v8_pin_voltage(3.3)
|
UT.set_1v8_pin_voltage(3.3)
|
||||||
|
|
||||||
# Disable 1.8V Output
|
# Disable 1.8V Output
|
||||||
UT.disable_1v8_pin()
|
UT.disable_1v8_pin()
|
||||||
|
|
||||||
# Get currently-configured voltage (returns False if the pin is not enabled as output)
|
# Get currently-configured voltage (returns False if the pin is not enabled as output)
|
||||||
UT.get_1v8_pin_voltage()
|
UT.get_1v8_pin_voltage()
|
||||||
|
|
||||||
# Unexport Everything
|
# Unexport Everything
|
||||||
UT.unexport_all()
|
UT.unexport_all()
|
||||||
|
|
||||||
# Determine if you are running a CHIP/CHIP Pro
|
# Determine if you are running a CHIP/CHIP Pro
|
||||||
# This returns True if the computer is a CHIP Pro and False if it is a CHIP
|
# This returns True if the computer is a CHIP Pro and False if it is a CHIP
|
||||||
UT.is_chip_pro()
|
UT.is_chip_pro()
|
||||||
@ -438,11 +518,12 @@ Install py.test to run the tests. You'll also need the python compiler package f
|
|||||||
To run the tests, do the following.::
|
To run the tests, do the following.::
|
||||||
|
|
||||||
# If only one version of Python is installed
|
# If only one version of Python is installed
|
||||||
sudo py.test
|
# Python 2
|
||||||
# If more than one version of Python
|
sudo make pytest2
|
||||||
cd test
|
# Python 3
|
||||||
sudo python2 -m pytest
|
sudo make pytest3
|
||||||
sudo python3 -m pytest
|
# If more than one version of Python, run through both
|
||||||
|
sudo make test
|
||||||
|
|
||||||
**Credits**
|
**Credits**
|
||||||
|
|
||||||
|
87
debian/changelog
vendored
87
debian/changelog
vendored
@ -1,3 +1,90 @@
|
|||||||
|
chip-io (0.7.1-1) unstable; urgency=low
|
||||||
|
|
||||||
|
* Merged PR#79 and#80
|
||||||
|
* Added logging to tell user of the 1 second sleep before retry on setting gpio direction
|
||||||
|
|
||||||
|
-- Robert Wolterman <robert.wolterman@gmail.com> Sun, 12 Nov 2017 07:40:00 -0600
|
||||||
|
|
||||||
|
chip-io (0.7.0-1) unstable; urgency=low
|
||||||
|
|
||||||
|
* Added ability to specify GPIO only as a number, this doesn't work for PWM/SPWM/LRADC/SERVO
|
||||||
|
|
||||||
|
-- Robert Wolterman <robert.wolterman@gmail.com> Wed, 13 Sep 2017 09:51:00 -0600
|
||||||
|
|
||||||
|
chip-io (0.6.2-1) unstable; urgency=low
|
||||||
|
|
||||||
|
* Implementation for number 77 ability to push up binary pypi
|
||||||
|
* Implementation for number 75 wait for edge timeout
|
||||||
|
|
||||||
|
-- Robert Wolterman <robert.wolterman@gmail.com> Sun, 03 Sep 2017 21:34:00 -0600
|
||||||
|
|
||||||
|
chip-io (0.6.1-1) unstable; urgency=low
|
||||||
|
|
||||||
|
* Fixing implementation for #76
|
||||||
|
|
||||||
|
-- Robert Wolterman <robert.wolterman@gmail.com> Wed, 09 Aug 2017 23:09:00 -0600
|
||||||
|
|
||||||
|
chip-io (0.6.0-1) unstable; urgency=low
|
||||||
|
|
||||||
|
* Random comment cleanup
|
||||||
|
* Implement fix for #76
|
||||||
|
* API documentation added
|
||||||
|
* Closing #74
|
||||||
|
|
||||||
|
-- Robert Wolterman <robert.wolterman@gmail.com> Wed, 09 Aug 2017 22:50:00 -0600
|
||||||
|
|
||||||
|
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
|
chip-io (0.5.2-1) unstable; urgency=low
|
||||||
|
|
||||||
* Updating Utilities to determine CHIP Pro better
|
* Updating Utilities to determine CHIP Pro better
|
||||||
|
4
debian/files
vendored
4
debian/files
vendored
@ -1,2 +1,2 @@
|
|||||||
python-chip-io_0.4.0-1_armhf.deb python optional
|
python-chip-io_0.7.1-1_armhf.deb python optional
|
||||||
python3-chip-io_0.4.0-1_armhf.deb python optional
|
python3-chip-io_0.7.1-1_armhf.deb python optional
|
||||||
|
1
docs/_config.yml
Normal file
1
docs/_config.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
theme: jekyll-theme-minimal
|
354
docs/gpio.md
Normal file
354
docs/gpio.md
Normal file
@ -0,0 +1,354 @@
|
|||||||
|
## CHIP_IO.GPIO
|
||||||
|
Import the GPIO module as follows
|
||||||
|
|
||||||
|
```python
|
||||||
|
import CHIP_IO.GPIO as GPIO
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: As of version 0.7.0, all GPIO functions can use the SYSFS pin number for a GPIO for control, a la RPi.GPIO.
|
||||||
|
|
||||||
|
### toggle_debug()
|
||||||
|
Enable/Disable the Debug
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
GPIO.toggle_debug()
|
||||||
|
```
|
||||||
|
|
||||||
|
### is_chip_pro()
|
||||||
|
Function to report to the calling script if the SBC is a CHIP or a CHIP Pro
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
int - 1 for CHIP Pro, 0 for CHIP
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
is_chip_pro = GPIO.is_chip_pro()
|
||||||
|
```
|
||||||
|
|
||||||
|
### setmode(mode)
|
||||||
|
Dummy function to maintain backwards compatibility with Raspberry Pi scripts.
|
||||||
|
|
||||||
|
### setup(channel, direction, pull_up_down=PUD_OFF, initial=None)
|
||||||
|
Setup a GPIO pin. If pin is already configure, it will reconfigure.
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - GPIO pin
|
||||||
|
direction - INPUT or OUTPUT
|
||||||
|
pull_up_down - PUD_OFF, PUD_UP, PUD_DOWN (optional)
|
||||||
|
initial - Initial value for an OUTPUT pin (optional)
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
GPIO.setup("CSID0", GPIO.IN)
|
||||||
|
GPIO.setup(132, GPIO.IN)
|
||||||
|
GPIO.setup("CSID3", GPIO.OUT, initial=1)
|
||||||
|
GPIO.setup("CSID2", GPIO.IN, GPIO.PUD_UP)
|
||||||
|
```
|
||||||
|
|
||||||
|
### cleanup(channel)
|
||||||
|
Cleanup GPIO. If not channel input, all GPIO will be cleaned up
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - GPIO pin (optional)
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
GPIO.cleanup()
|
||||||
|
GPIO.cleanup("CSID3")
|
||||||
|
GPIO.cleanup(132)
|
||||||
|
```
|
||||||
|
|
||||||
|
### output(channel, value)
|
||||||
|
Write a value to a GPIO pin.
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - GPIO Pin
|
||||||
|
value - HIGH, LOW, 0, 1
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
GPIO.output("XIO-P7", GPIO.HIGH)
|
||||||
|
GPIO.output("XIO-P7", GPIO.LOW)
|
||||||
|
GPIO.output("CSID0", 1)
|
||||||
|
GPIO.output("CSID0", 0)
|
||||||
|
GPIO.output(132, 1)
|
||||||
|
```
|
||||||
|
|
||||||
|
### input(channel)
|
||||||
|
Read a GPIO pin once.
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - GPIO Pin
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
value - current value of the GPIO pin
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
value = GPIO.input("XIO-P7")
|
||||||
|
value = GPIO.input(1013)
|
||||||
|
```
|
||||||
|
|
||||||
|
### read_byte(channel)
|
||||||
|
Read a GPIO pin multiple times to fill up 8 bits.
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - GPIO Pin
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
int - 8 bit value of the GPIO pin
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
bits = GPIO.read_byte("XIO-P7")
|
||||||
|
bits = GPIO.read_byte(135)
|
||||||
|
```
|
||||||
|
|
||||||
|
### read_word(channel)
|
||||||
|
Read a GPIO pin multiple times to fill up 16 bits.
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - GPIO Pin
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
word - 16 bit value of the GPIO pin
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
bits = GPIO.read_word("XIO-P7")
|
||||||
|
bits = GPIO.read_word(134)
|
||||||
|
```
|
||||||
|
|
||||||
|
### add_event_detect(channel, edge, callback=None, bouncetime=0)
|
||||||
|
Add event detection to a pin. Refer to main table for which pins are able to use edge detection.
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - GPIO Pin
|
||||||
|
edge - edge: RISING_EDGE, FALLING_EDGE, BOTH_EDGE
|
||||||
|
callback - callback function to be run when edge is detected (optional)
|
||||||
|
bouncetime - level debounce time period in ms (optional)
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
GPIO.add_event_detect("XIO-P7", GPIO.RISING_EDGE)
|
||||||
|
GPIO.add_event_detect("AP-EINT3", GPIO.RISING_EDGE, mycallback)
|
||||||
|
GPIO.add_event_detect("XIO-P7", GPIO.FALLING_EDGE, bouncetime=30)
|
||||||
|
GPIO.add_event_detect("XIO-P7", GPIO.RISING_EDGE, mycallback, 45)
|
||||||
|
GPIO.add_event_detect(1013, GPIO.BOTH_EDGE)
|
||||||
|
```
|
||||||
|
|
||||||
|
### remove_event_detect(channel)
|
||||||
|
Remove a pins event detection. Refer to main table for which pins are able to use edge detection.
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - GPIO Pin
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
GPIO.remove_event_detect("XIO-P7")
|
||||||
|
GPIO.remove_event_detect(1013)
|
||||||
|
```
|
||||||
|
|
||||||
|
### event_detected(channel)
|
||||||
|
Function to determine if an event was detected on a pin. Pin must have an event detect added via add_event_detect() prior to calling this function. Refer to main table for which pins are able to use edge detection.
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - GPIO Pin
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
boolean - True if event was detected
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
have_event = GPIO.event_detected("XIO-P5")
|
||||||
|
have_event = GPIO.event_detected(1014)
|
||||||
|
```
|
||||||
|
|
||||||
|
### add_event_callback(channel, callback, bouncetime=0)
|
||||||
|
Add callback function to a pin that has been setup for edge detection. Refer to main table for which pins are able to use edge detection.
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - GPIO Pin
|
||||||
|
callback - callback function to be run when edge is detected
|
||||||
|
bouncetime - level debounce time period in ms (optional)
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
GPIO.add_event_callback("AP-EINT3", mycallback)
|
||||||
|
GPIO.add_event_callback("XIO-P7", mycallback, 45)
|
||||||
|
GPIO.add_event_callback(1013, mycallback)
|
||||||
|
```
|
||||||
|
|
||||||
|
### wait_for_edge(channel, edge, timeout=-1)
|
||||||
|
Wait for an edge to be detected. This is a blocking function. Refer to main table for which pins are able to use edge detection.
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - GPIO Pin
|
||||||
|
edge - edge: RISING_EDGE, FALLING_EDGE, BOTH_EDGE
|
||||||
|
timeout - timeout in milliseconds to wait before exiting function (optional)
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
GPIO.wait_for_edge("XIO-P3", GPIO.RISING_EDGE)
|
||||||
|
GPIO.wait_for_edge("AP-EINT3", GPIO.BOTH_EDGE)
|
||||||
|
GPIO.wait_for_edge("I2S-DI", GPIO.FALLING_EDGE)
|
||||||
|
GPIO.wait_for_edge("XIO-P3", GPIO.RISING_EDGE, 40)
|
||||||
|
GPIO.wait_for_edge(1013, GPIO.BOTH_EDGE, 35)
|
||||||
|
```
|
||||||
|
|
||||||
|
### gpio_function(channel)
|
||||||
|
Function to report get a GPIO Pins directioj
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - GPIO Pin
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
int - GPIO Pin direction
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
funct = GPIO.gpio_function("CSID0")
|
||||||
|
funct = GPIO.gpio_function(132)
|
||||||
|
```
|
||||||
|
|
||||||
|
### setwarnings(state)
|
||||||
|
Function to enable/disable warning print outs. This may or may not work properly. toggle_debug() is a better bet.
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
state - 1 for enable, 0 for disable
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
GPIO.set_warnings(1)
|
||||||
|
```
|
||||||
|
|
||||||
|
### get_gpio_base()
|
||||||
|
Function to get the SYSFS base value for the XIO pins on a CHIP
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
int - sysfs base of the XIO, returns -1 on a CHIP Pro
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
base = GPIO.get_gpio_base()
|
||||||
|
```
|
||||||
|
|
||||||
|
### selftest(value)
|
||||||
|
Function to perform a selftest on the GPIO module
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
value - a value
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
int - the input value
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
rtn = GPIO.selftest(0)
|
||||||
|
```
|
||||||
|
|
||||||
|
### direction(channel, direction)
|
||||||
|
Function to set the direction of an exported GPIO pin
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - GPIO Pin
|
||||||
|
direction - Direction Pin is to take
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
GPIO.set_direction("XIO-P0", GPIO.OUT)
|
||||||
|
GPIO.set_direction("XIO-P1", GPIO.IN)
|
||||||
|
GPIO.set_direction(1013, GPIO.OUT)
|
||||||
|
```
|
||||||
|
|
||||||
|
[home](./index.md)
|
75
docs/index.md
Normal file
75
docs/index.md
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
## CHIP_IO API Documentation
|
||||||
|
|
||||||
|
* [CHIP_IO.GPIO](./gpio.md)
|
||||||
|
* [CHIP_IO.PWM](./pwm.md)
|
||||||
|
* [CHIP_IO.SOFTPWM](./softpwm.md)
|
||||||
|
* [CHIP_IO.SERVO](./servo.md)
|
||||||
|
* [CHIP_IO.LRADC](./lradc.md)
|
||||||
|
* [CHIP_IO.Utilities](./utilities.md)
|
||||||
|
* [CHIP_IO.OverlayManager](./overlaymanager.md)
|
||||||
|
|
||||||
|
### Allowable Pin Names and Edge Detection Capability
|
||||||
|
|
||||||
|
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 (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 |
|
||||||
|
|
200
docs/lradc.md
Normal file
200
docs/lradc.md
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
## CHIP_IO.LRADC
|
||||||
|
The LRADC module handles interfacing with the onboard 6-Bit, 2V tolerant ADC in the R8/GR8.
|
||||||
|
|
||||||
|
Import the LRADC module as follows
|
||||||
|
|
||||||
|
```python
|
||||||
|
import CHIP_IO.LRADC as LRADC
|
||||||
|
```
|
||||||
|
|
||||||
|
### toggle_debug()
|
||||||
|
Enable/Disable the Debug
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
LRADC.toggle_debug()
|
||||||
|
```
|
||||||
|
|
||||||
|
### get_device_exist()
|
||||||
|
Check to see if the LRADC device exists
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
boolean - True if LRADC is enabled, False is LRADC is disabled
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
LRADC.get_device_exist()
|
||||||
|
```
|
||||||
|
|
||||||
|
### setup(rate=250)
|
||||||
|
Setup the LRADC, defaults to a sampling rate of 250.
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
rate (optional) - Sampling rate of the LRADC: 32.25, 62.5, 125, 250
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
boolean - True if LRADC is enabled, False is LRADC is disabled
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
LRADC.setup()
|
||||||
|
LRADC.setup(32.25)
|
||||||
|
```
|
||||||
|
|
||||||
|
### get_scale_factor()
|
||||||
|
Get the scaling factor applied to raw values from the LRADC
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
float - scale factor applied to the LRADC Raw data
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
factor = LRADC.get_scale_factor()
|
||||||
|
print(factor)
|
||||||
|
```
|
||||||
|
|
||||||
|
### get_allowable_sample_rates()
|
||||||
|
Get the allowable sample rates for the LRADC
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
tuple - sampling rates of the LRADC
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
rates = LRADC.get_allowable_sample_rates()
|
||||||
|
print(rates)
|
||||||
|
```
|
||||||
|
|
||||||
|
### set_sample_rate(rate)
|
||||||
|
Set the current sample rates for the LRADC
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
rate - Sample rate, only rates allowable by the LRADC
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
float - current sampling rate of the LRADC
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
curr_rate = LRADC.set_sample_rate(125.0)
|
||||||
|
```
|
||||||
|
|
||||||
|
### get_sample_rate()
|
||||||
|
Get the current sample rates for the LRADC
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
float - current sampling rate of the LRADC
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
curr_rate = LRADC.get_sample_rate()
|
||||||
|
```
|
||||||
|
|
||||||
|
### get_chan0_raw()
|
||||||
|
Get the raw value for LRADC Channel 0
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
float - current raw value of LRADC Channel 0
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
dat = LRADC.get_chan0_raw()
|
||||||
|
```
|
||||||
|
|
||||||
|
### get_chan1_raw()
|
||||||
|
Get the raw value for LRADC Channel 1
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
float - current raw value of LRADC Channel 1
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
dat = LRADC.get_chan1_raw()
|
||||||
|
```
|
||||||
|
|
||||||
|
### get_chan0()
|
||||||
|
Get the value for LRADC Channel 0
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
float - current value of LRADC Channel 0
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
dat = LRADC.get_chan0()
|
||||||
|
```
|
||||||
|
|
||||||
|
### get_chan1
|
||||||
|
Get the value for LRADC Channel 1
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
float - current value of LRADC Channel 1
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
dat = LRADC.get_chan1()
|
||||||
|
```
|
||||||
|
|
||||||
|
[home](./index.md)
|
117
docs/overlaymanager.md
Normal file
117
docs/overlaymanager.md
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
## CHIP_IO.OverlayManager
|
||||||
|
Import the OverlayManager module as follows
|
||||||
|
|
||||||
|
```python
|
||||||
|
import CHIP_IO.OverlayManager as OM
|
||||||
|
```
|
||||||
|
|
||||||
|
This module requires NTC's [CHIP-dt-overlays](https://github.com/NextThingCo/CHIP-dt-overlays) to be loaded.
|
||||||
|
|
||||||
|
### toggle_debug()
|
||||||
|
Enable/Disable the Debug
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
OM.toggle_debug()
|
||||||
|
```
|
||||||
|
|
||||||
|
### load(overlay, path="")
|
||||||
|
Loads the overlay specified. PWM0 is not available on the CHIP Pro due to the base DTS supporting both PWM0 and PWM1
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
overlay - Overlay to be loaded: SPI2, PWM0, CUST
|
||||||
|
path (optional) - Path to the custom compiled overlay
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
integer - 0: Success, 1: Fail, 2: Overlay already loaded
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
resp = OM.load("SPI2")
|
||||||
|
resp = OM.load("PWM0")
|
||||||
|
resp = OM.load("CUST","path/to/custom.dtbo")
|
||||||
|
```
|
||||||
|
|
||||||
|
### unload(overlay)
|
||||||
|
Unloads the overlay specified. PWM0 is not available on the CHIP Pro due to the base DTS supporting both PWM0 and PWM1
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
overlay - Overlay to be loaded: SPI2, PWM0, CUST
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
resp = OM.unload("SPI2")
|
||||||
|
resp = OM.unload("PWM0")
|
||||||
|
resp = OM.unload("CUST")
|
||||||
|
```
|
||||||
|
|
||||||
|
### get_spi_loaded()
|
||||||
|
Check to see if the SPI DTBO is loaded
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
boolean
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
is_spi_loaded = OM.get_spi_loaded()
|
||||||
|
```
|
||||||
|
|
||||||
|
### get_pwm_loaded()
|
||||||
|
Check to see if the PWM0 DTBO is loaded
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
boolean
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
is_pwm_loaded = OM.get_pwm_loaded()
|
||||||
|
```
|
||||||
|
|
||||||
|
### get_custom_loaded()
|
||||||
|
Check to see if the Custom DTBO is loaded
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
boolean
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
is_custom_loaded = OM.get_custom_loaded()
|
||||||
|
```
|
||||||
|
|
||||||
|
[home](./index.md)
|
172
docs/pwm.md
Normal file
172
docs/pwm.md
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
## CHIP_IO.PWM
|
||||||
|
Import the PWM module as follows
|
||||||
|
|
||||||
|
```python
|
||||||
|
import CHIP_IO.PWM as PWM
|
||||||
|
```
|
||||||
|
|
||||||
|
For the CHIP, this requires the PWM0 DTBO loaded via the OverlayManager or other means.
|
||||||
|
For the CHIP, PWM1 is unavaiable
|
||||||
|
For the CHIP Pro, PWM0 and PWM1 are setup in the base DTB by default
|
||||||
|
|
||||||
|
### toggle_debug()
|
||||||
|
Enable/Disable the Debug
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
PWM.toggle_debug()
|
||||||
|
```
|
||||||
|
|
||||||
|
### is_chip_pro()
|
||||||
|
Function to report to the calling script if the SBC is a CHIP or a CHIP Pro
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
int - 1 for CHIP Pro, 0 for CHIP
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
is_chip_pro = PWM.is_chip_pro()
|
||||||
|
```
|
||||||
|
|
||||||
|
### start(channel, duty_cycle=0.0, frequency=2000.0, polarity=0)
|
||||||
|
Start the Software PWM
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - pin for software PWM is configured
|
||||||
|
duty_cycle - initial duty cycle of the PWM (optional)
|
||||||
|
frequency - frequency of the PWM (optional)
|
||||||
|
polarity - signal polarity of the PWM (optional)
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
PWM.start("PWM0")
|
||||||
|
PWM.start("PWM0", 37.0)
|
||||||
|
PWM.start("PWM0", 10.0, 500.0)
|
||||||
|
PWM.start("PWM0", 50.0, 1000.0, 1)
|
||||||
|
```
|
||||||
|
|
||||||
|
### stop(channel)
|
||||||
|
Stop the PWM
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - pin PWM is configured
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
PWM.stop("PWM0")
|
||||||
|
```
|
||||||
|
|
||||||
|
### set_duty_cycle(channel, duty_cycle)
|
||||||
|
Set the duty cycle of the PWM
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - pin PWM is configured
|
||||||
|
duty_cycle - duty cycle of the PWM (0.0 to 100.0)
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
PWM.set_duty_cycle("PWM0", 25.0)
|
||||||
|
```
|
||||||
|
|
||||||
|
### set_pulse_width_ns(channel, pulse_width_ns)
|
||||||
|
Set the width of the PWM pulse in nano seconds
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - pin PWM is configured
|
||||||
|
pulse_width_ns - pulse width of the PWM in nanoseconds
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
PWM.set_pulse_width_ns("PWM0", 2500.0)
|
||||||
|
```
|
||||||
|
|
||||||
|
### set_frequency(channel, frequency)
|
||||||
|
Set the frequency of the PWM in Hertz
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - pin software PWM is configured
|
||||||
|
frequency - frequency of the PWM
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
PWM.set_frequency("PWM0", 450.0)
|
||||||
|
```
|
||||||
|
|
||||||
|
### set_period_ns(channel, pulse_width_ns)
|
||||||
|
Set the period of the PWM pulse in nano seconds
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - pin PWM is configured
|
||||||
|
period_ns - period of the PWM in nanoseconds
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
PWM.set_period_ns("PWM0", 130.0)
|
||||||
|
```
|
||||||
|
|
||||||
|
### cleanup(channel)
|
||||||
|
Cleanup PWM. If not channel input, all PWM will be cleaned up
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - pin PWM is configured (optional)
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
PWM.cleanup()
|
||||||
|
PWM.cleanup("PWM0")
|
||||||
|
```
|
||||||
|
|
||||||
|
[home](./index.md)
|
131
docs/servo.md
Normal file
131
docs/servo.md
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
## CHIP_IO.SERVO
|
||||||
|
Import the SERVO module as follows
|
||||||
|
|
||||||
|
```python
|
||||||
|
import CHIP_IO.SERVO as SERVO
|
||||||
|
```
|
||||||
|
|
||||||
|
### toggle_debug()
|
||||||
|
Enable/Disable the Debug
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
SERVO.toggle_debug()
|
||||||
|
```
|
||||||
|
|
||||||
|
### is_chip_pro()
|
||||||
|
Function to report to the calling script if the SBC is a CHIP or a CHIP Pro
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
int - 1 for CHIP Pro, 0 for CHIP
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
is_chip_pro = SERVO.is_chip_pro()
|
||||||
|
```
|
||||||
|
|
||||||
|
### start(channel, angle=0.0, range=180.0)
|
||||||
|
Start the Servo
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - Pin servo is attached to
|
||||||
|
angle - initial angle of the servo (optional)
|
||||||
|
range - total range of the servo in degrees (optional)
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
SERVO.start("CSID0")
|
||||||
|
SERVO.start("CSID0", 37.0)
|
||||||
|
SERVO.start("CSID0", -45.0, 180.0)
|
||||||
|
```
|
||||||
|
|
||||||
|
### stop(channel)
|
||||||
|
Stop the Servo
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - Pin servo is attached to
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
SERVO.stop("CSID0")
|
||||||
|
```
|
||||||
|
|
||||||
|
### set_range(channel, range)
|
||||||
|
Set the range of the Servo
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - Pin servo is attached to
|
||||||
|
range - total range of the servo in degrees
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
SERVO.set_range("CSID0", 180.0)
|
||||||
|
SERVO.set_range("CSID0", 360.0)
|
||||||
|
```
|
||||||
|
|
||||||
|
### set_angle(channel, angle)
|
||||||
|
Set the angle of the Servo
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - Pin servo is attached to
|
||||||
|
angle - angle to set the servo between +/- 1/2*Range
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
SERVO.set_angle("CSID0", -45.0)
|
||||||
|
SERVO.set_angle("CSID0", 36.0)
|
||||||
|
```
|
||||||
|
|
||||||
|
### cleanup()
|
||||||
|
Cleanup all setup Servos, this will blast away every sero currently in operation
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
SERVO.cleanup()
|
||||||
|
```
|
||||||
|
|
||||||
|
[home](./index.md)
|
132
docs/softpwm.md
Normal file
132
docs/softpwm.md
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
## CHIP_IO.SOFTPWM
|
||||||
|
Import the SOFTPWM module as follows
|
||||||
|
|
||||||
|
```python
|
||||||
|
import CHIP_IO.SOFTPWM as SPWM
|
||||||
|
```
|
||||||
|
|
||||||
|
### toggle_debug()
|
||||||
|
Enable/Disable the Debug
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
SPWM.toggle_debug()
|
||||||
|
```
|
||||||
|
|
||||||
|
### is_chip_pro()
|
||||||
|
Function to report to the calling script if the SBC is a CHIP or a CHIP Pro
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
int - 1 for CHIP Pro, 0 for CHIP
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
is_chip_pro = SPWM.is_chip_pro()
|
||||||
|
```
|
||||||
|
|
||||||
|
### start(channel, duty_cycle=0.0, frequency=2000.0, polarity=0)
|
||||||
|
Start the Software PWM
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - pin for software PWM is configured
|
||||||
|
duty_cycle - initial duty cycle of the PWM (optional)
|
||||||
|
frequency - frequency of the PWM (optional)
|
||||||
|
polarity - signal polarity of the PWM (optional)
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
SPWM.start("CSID0")
|
||||||
|
SPWM.start("CSID0", 37.0)
|
||||||
|
SPWM.start("CSID0", 10.0, 500.0)
|
||||||
|
SPWM.start("CSID0", 50.0, 1000.0, 1)
|
||||||
|
```
|
||||||
|
|
||||||
|
### stop(channel)
|
||||||
|
Stop the Software PWM
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - pin software PWM is configured
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
SPWM.stop("CSID0")
|
||||||
|
```
|
||||||
|
|
||||||
|
### set_duty_cycle(channel, duty_cycle)
|
||||||
|
Set the duty cycle of the Software PWM
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - pin software PWM is configured
|
||||||
|
duty_cycle - duty cycle of the PWM (0.0 to 100.0)
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
SPWM.set_duty_cycle("CSID0", 25.0)
|
||||||
|
```
|
||||||
|
|
||||||
|
### set_frequency(channel, frequency)
|
||||||
|
Set the frequency of the Software PWM in Hertz
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - pin PWM is configured
|
||||||
|
frequency - frequency of the PWM
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
SPWM.set_frequency("CSID0", 450.0)
|
||||||
|
```
|
||||||
|
|
||||||
|
### cleanup(channel)
|
||||||
|
Cleanup Software PWM. If not channel input, all Software PWM will be cleaned up
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
channel - pin Software PWM is configured (optional)
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
SPWM.cleanup()
|
||||||
|
SPWM.cleanup("CSID0")
|
||||||
|
```
|
||||||
|
|
||||||
|
[home](./index.md)
|
132
docs/utilities.md
Normal file
132
docs/utilities.md
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
## CHIP_IO.Utilities
|
||||||
|
Import the Utilities module as follows
|
||||||
|
|
||||||
|
```python
|
||||||
|
import CHIP_IO.Utilities as UT
|
||||||
|
```
|
||||||
|
|
||||||
|
### toggle_debug()
|
||||||
|
Enable/Disable the Debug
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
UT.toggle_debug()
|
||||||
|
```
|
||||||
|
|
||||||
|
### unexport_all()
|
||||||
|
Function to force clean up all exported GPIO on the system
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
UT.unexport_all()
|
||||||
|
```
|
||||||
|
|
||||||
|
### is_chip_pro()
|
||||||
|
Function to report to the calling script if the SBC is a CHIP or a CHIP Pro
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
boolean - True for CHIP Pro, False for CHIP
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
is_chip_pro = UT.is_chip_pro()
|
||||||
|
```
|
||||||
|
|
||||||
|
### enable_1v8_pin()
|
||||||
|
Enable the 1.8V pin on the CHIP as it is disabled by default. Also sets the output to 1.8V.
|
||||||
|
This only works on the CHIP.
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
UT.enable_1v8_pin()
|
||||||
|
```
|
||||||
|
|
||||||
|
### set_1v8_pin_voltage(voltage)
|
||||||
|
Change the voltage of the 1.8V Pin on the CHIP.
|
||||||
|
This only works on the CHIP.
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
voltage - 1.8, 2.0, 2.6, 3.3
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
boolean - False on error
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
UT.set_1v8_pin_voltage(2.0)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### get_1v8_pin_voltage()
|
||||||
|
Get the current voltage of the 1.8V Pin on the CHIP.
|
||||||
|
This only works on the CHIP.
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
float - current voltage of the 1.8V Pin
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
volts = UT.get_1v8_pin_voltage()
|
||||||
|
```
|
||||||
|
|
||||||
|
### disable_1v8_pin()
|
||||||
|
Disables the 1.8V pin on the CHIP.
|
||||||
|
This only works on the CHIP.
|
||||||
|
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Returns
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
* Examples
|
||||||
|
|
||||||
|
```python
|
||||||
|
UT.disable_1v8_pin()
|
||||||
|
```
|
||||||
|
|
||||||
|
[home](./index.md)
|
6
setup.cfg
Normal file
6
setup.cfg
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[bdist_wheel]
|
||||||
|
universal = 1
|
||||||
|
|
||||||
|
[metadata]
|
||||||
|
license_file = LICENSE
|
||||||
|
|
2
setup.py
2
setup.py
@ -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.2',
|
version = '0.7.1',
|
||||||
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',
|
||||||
|
@ -246,13 +246,14 @@ int pwm_set_polarity(const char *key, int polarity) {
|
|||||||
return rtnval;
|
return rtnval;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pwm->enable) {
|
// THIS ONLY WORKS WHEN PWM IS NOT ENABLED
|
||||||
|
if (pwm->enable == 0) {
|
||||||
if (polarity == 0) {
|
if (polarity == 0) {
|
||||||
len = snprintf(buffer, sizeof(buffer), "%s", "normal"); BUF2SMALL(buffer);
|
len = snprintf(buffer, sizeof(buffer), "%s", "normal"); BUF2SMALL(buffer);
|
||||||
}
|
}
|
||||||
else
|
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;
|
ssize_t s = write(pwm->polarity_fd, buffer, len); e_no = errno;
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@ -271,6 +272,7 @@ int pwm_set_polarity(const char *key, int polarity) {
|
|||||||
} else {
|
} else {
|
||||||
rtnval = 0;
|
rtnval = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rtnval;
|
return rtnval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,18 +529,19 @@ int pwm_start(const char *key, float duty, float freq, int polarity)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int rtnval = 0;
|
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
|
// Fix for issue #53
|
||||||
|
// Always set polarity first
|
||||||
|
rtnval = pwm_set_polarity(key, polarity);
|
||||||
if (rtnval != -1) {
|
if (rtnval != -1) {
|
||||||
rtnval = 0;
|
rtnval = 0;
|
||||||
rtnval = pwm_set_frequency(key, freq);
|
rtnval = pwm_set_enable(key, ENABLE);
|
||||||
if (rtnval != -1) {
|
if (rtnval != -1) {
|
||||||
rtnval = 0;
|
rtnval = 0;
|
||||||
rtnval = pwm_set_duty_cycle(key, duty);
|
rtnval = pwm_set_frequency(key, freq);
|
||||||
|
if (rtnval != -1) {
|
||||||
|
rtnval = 0;
|
||||||
|
rtnval = pwm_set_duty_cycle(key, duty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rtnval;
|
return rtnval;
|
||||||
@ -563,9 +566,7 @@ int pwm_disable(const char *key)
|
|||||||
pwm_set_frequency(key, 0);
|
pwm_set_frequency(key, 0);
|
||||||
pwm_set_duty_cycle(key, 0);
|
pwm_set_duty_cycle(key, 0);
|
||||||
pwm_set_enable(key, DISABLE);
|
pwm_set_enable(key, DISABLE);
|
||||||
if (pwm->iscpro == 1) {
|
pwm_set_polarity(key, 0);
|
||||||
pwm_set_polarity(key, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((fd = open("/sys/class/pwm/pwmchip0/unexport", O_WRONLY)) < 0)
|
if ((fd = open("/sys/class/pwm/pwmchip0/unexport", O_WRONLY)) < 0)
|
||||||
{
|
{
|
||||||
|
@ -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}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -263,7 +268,7 @@ int gpio_allowed(int gpio)
|
|||||||
// We have a CHIP and the pin is for CHIP/BOTH
|
// 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 (((p->sbc_type == CHIP) || (p->sbc_type == BOTH)) && (is_this_chippro() == 0)) {
|
||||||
if (DEBUG)
|
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;
|
rtnval = 1;
|
||||||
// We have a CHIP Pro and the pin is for CHIPPRO/BOTH
|
// 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)) {
|
} 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
|
// We have a CHIP and the pin is for CHIP/BOTH
|
||||||
if ((p->sbc_type == BOTH) && (is_this_chippro() == 0)) {
|
if ((p->sbc_type == BOTH) && (is_this_chippro() == 0)) {
|
||||||
if (DEBUG)
|
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;
|
rtnval = 1;
|
||||||
// We have a CHIP Pro and the pin is for CHIPPRO/BOTH
|
// 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)) {
|
} else if (((p->sbc_type == CHIPPRO) || (p->sbc_type == BOTH)) && (is_this_chippro() == 1)) {
|
||||||
@ -366,6 +371,28 @@ int gpio_pud_capable(pins_t *pin)
|
|||||||
return capable;
|
return capable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lookup_gpio_by_number(const char *num) {
|
||||||
|
// Convert the char to an int
|
||||||
|
char *ptr;
|
||||||
|
long ret;
|
||||||
|
int gpnum;
|
||||||
|
ret = strtol(num, &ptr, 10);
|
||||||
|
if (ret == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// If we make it here, lets look for the data
|
||||||
|
pins_t *p;
|
||||||
|
for (p = pins_info; p->key != NULL; ++p) {
|
||||||
|
gpnum = gpio_number(p);
|
||||||
|
// If the number of the gpio pin matches the input
|
||||||
|
// we are
|
||||||
|
if (gpnum == (int)ret) {
|
||||||
|
return gpnum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int lookup_gpio_by_key(const char *key)
|
int lookup_gpio_by_key(const char *key)
|
||||||
{
|
{
|
||||||
pins_t *p;
|
pins_t *p;
|
||||||
@ -536,10 +563,13 @@ int get_gpio_number(const char *key, int *gpio)
|
|||||||
if (*gpio <= 0) {
|
if (*gpio <= 0) {
|
||||||
*gpio = lookup_gpio_by_name(key);
|
*gpio = lookup_gpio_by_name(key);
|
||||||
if (*gpio <= 0) {
|
if (*gpio <= 0) {
|
||||||
*gpio = lookup_gpio_by_altname(key);
|
*gpio = lookup_gpio_by_altname(key);
|
||||||
if (*gpio <=0) {
|
if (*gpio <=0) {
|
||||||
status = -1; /* error */
|
*gpio = lookup_gpio_by_number(key);
|
||||||
}
|
if (*gpio <= 0) {
|
||||||
|
status = -1; /* error */
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
@ -554,7 +584,7 @@ int compute_port_pin(const char *key, int gpio, int *port, int *pin)
|
|||||||
if (capable < 0) {
|
if (capable < 0) {
|
||||||
capable = lookup_pud_capable_by_name(key);
|
capable = lookup_pud_capable_by_name(key);
|
||||||
if (capable < 0) {
|
if (capable < 0) {
|
||||||
capable = lookup_gpio_by_altname(key);
|
capable = lookup_pud_capable_by_altname(key);
|
||||||
if (capable < 0) {
|
if (capable < 0) {
|
||||||
capable = 0; // default to false
|
capable = 0; // default to false
|
||||||
}
|
}
|
||||||
|
@ -86,14 +86,15 @@ typedef struct dyn_int_array_s dyn_int_array_t;
|
|||||||
|
|
||||||
#define FILENAME_BUFFER_SIZE 128
|
#define FILENAME_BUFFER_SIZE 128
|
||||||
|
|
||||||
int setup_error;
|
extern int setup_error;
|
||||||
int module_setup;
|
extern int module_setup;
|
||||||
int DEBUG;
|
extern int DEBUG;
|
||||||
|
|
||||||
int get_xio_base(void);
|
int get_xio_base(void);
|
||||||
int is_this_chippro(void);
|
int is_this_chippro(void);
|
||||||
int gpio_number(pins_t *pin);
|
int gpio_number(pins_t *pin);
|
||||||
int gpio_pud_capable(pins_t *pin);
|
int gpio_pud_capable(pins_t *pin);
|
||||||
|
int lookup_gpio_by_number(const char *num);
|
||||||
int lookup_gpio_by_key(const char *key);
|
int lookup_gpio_by_key(const char *key);
|
||||||
int lookup_gpio_by_name(const char *name);
|
int lookup_gpio_by_name(const char *name);
|
||||||
int lookup_gpio_by_altname(const char *altname);
|
int lookup_gpio_by_altname(const char *altname);
|
||||||
|
@ -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.2");
|
version = Py_BuildValue("s", "0.7.1");
|
||||||
PyModule_AddObject(module, "VERSION", version);
|
PyModule_AddObject(module, "VERSION", version);
|
||||||
}
|
}
|
||||||
|
@ -171,13 +171,17 @@ int gpio_export(int gpio)
|
|||||||
|
|
||||||
len = snprintf(str_gpio, sizeof(str_gpio), "%d", gpio); BUF2SMALL(str_gpio);
|
len = snprintf(str_gpio, sizeof(str_gpio), "%d", gpio); BUF2SMALL(str_gpio);
|
||||||
ssize_t s = write(fd, str_gpio, len); e_no = errno;
|
ssize_t s = write(fd, str_gpio, len); e_no = errno;
|
||||||
|
if (DEBUG)
|
||||||
|
if (e_no)
|
||||||
|
printf("gpio_export: something went wrong: %s\n", strerror(e_no));
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
if (s != len)
|
if (s != len)
|
||||||
{
|
{
|
||||||
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
|
||||||
@ -379,11 +383,23 @@ int gpio_set_direction(int gpio, unsigned int in_flag)
|
|||||||
char filename[MAX_FILENAME]; filename[0] = '\0';
|
char filename[MAX_FILENAME]; filename[0] = '\0';
|
||||||
|
|
||||||
snprintf(filename, sizeof(filename), "/sys/class/gpio/gpio%d/direction", gpio); BUF2SMALL(filename);
|
snprintf(filename, sizeof(filename), "/sys/class/gpio/gpio%d/direction", gpio); BUF2SMALL(filename);
|
||||||
|
|
||||||
if ((fd = open(filename, O_WRONLY)) < 0) {
|
if ((fd = open(filename, O_WRONLY)) < 0) {
|
||||||
|
// NOTIFY THAT WE'RE GOING TO SLEEP AND RETRY
|
||||||
char err[256];
|
char err[256];
|
||||||
snprintf(err, sizeof(err), "gpio_set_direction: could not open '%s' (%s)", filename, strerror(errno));
|
snprintf(err, sizeof(err), "gpio_set_direction: could not open '%s', sleeping for 1 second and retrying", filename);
|
||||||
add_error_msg(err);
|
add_error_msg(err);
|
||||||
return -1;
|
// if called as non-root, udev may need time to adjust file
|
||||||
|
// permissions after setting up gpio
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
// TRY AGAIN AND IF THIS TIME FAILS, KICK OUT
|
||||||
|
if ((fd = open(filename, O_WRONLY)) < 0) {
|
||||||
|
char err[256];
|
||||||
|
snprintf(err, sizeof(err), "gpio_set_direction: could not open '%s' (%s)", filename, strerror(errno));
|
||||||
|
add_error_msg(err);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char direction[16];
|
char direction[16];
|
||||||
@ -1023,7 +1039,7 @@ void event_cleanup(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// blocking_wait_for_edge assumes the caller has ensured the GPIO is already exported.
|
// blocking_wait_for_edge assumes the caller has ensured the GPIO is already exported.
|
||||||
int blocking_wait_for_edge(int gpio, unsigned int edge)
|
int blocking_wait_for_edge(int gpio, unsigned int edge, int timeout)
|
||||||
// standalone from all the event functions above
|
// standalone from all the event functions above
|
||||||
{
|
{
|
||||||
int fd = fd_lookup(gpio);
|
int fd = fd_lookup(gpio);
|
||||||
@ -1078,7 +1094,7 @@ int blocking_wait_for_edge(int gpio, unsigned int edge)
|
|||||||
// epoll for event
|
// epoll for event
|
||||||
for (i = 0; i<2; i++) // first time triggers with current state, so ignore
|
for (i = 0; i<2; i++) // first time triggers with current state, so ignore
|
||||||
{
|
{
|
||||||
if ((n = epoll_wait(epfd, &events, 1, -1)) == -1)
|
if ((n = epoll_wait(epfd, &events, 1, timeout)) == -1)
|
||||||
{
|
{
|
||||||
gpio_event_remove(gpio);
|
gpio_event_remove(gpio);
|
||||||
return 5;
|
return 5;
|
||||||
|
@ -86,4 +86,4 @@ int gpio_event_remove(int gpio);
|
|||||||
int gpio_is_evented(int gpio);
|
int gpio_is_evented(int gpio);
|
||||||
int event_initialise(void);
|
int event_initialise(void);
|
||||||
void event_cleanup(void);
|
void event_cleanup(void);
|
||||||
int blocking_wait_for_edge(int gpio, unsigned int edge);
|
int blocking_wait_for_edge(int gpio, unsigned int edge, int timeout);
|
||||||
|
246
source/py_gpio.c
246
source/py_gpio.c
@ -36,6 +36,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
@ -129,13 +130,23 @@ static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs)
|
|||||||
{
|
{
|
||||||
int gpio;
|
int gpio;
|
||||||
char *channel;
|
char *channel;
|
||||||
|
int inchan;
|
||||||
static char *kwlist[] = {"channel", NULL};
|
static char *kwlist[] = {"channel", NULL};
|
||||||
|
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
// Channel is optional
|
// Channel is optional
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &channel)) {
|
// Try to parse the string
|
||||||
return NULL;
|
int rtn;
|
||||||
|
rtn = PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &channel);
|
||||||
|
if (!rtn) {
|
||||||
|
// Fall into here are try to parse an int
|
||||||
|
rtn = PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &inchan);
|
||||||
|
if (!rtn) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// We make it here, we can convert inchan to a string for us to ensure it's valid
|
||||||
|
asprintf(&channel, "%i", inchan);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The !channel fixes issues #50
|
// The !channel fixes issues #50
|
||||||
@ -157,6 +168,7 @@ static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwar
|
|||||||
int gpio;
|
int gpio;
|
||||||
int allowed = -1;
|
int allowed = -1;
|
||||||
char *channel;
|
char *channel;
|
||||||
|
int inchan;
|
||||||
int direction;
|
int direction;
|
||||||
int pud = PUD_OFF;
|
int pud = PUD_OFF;
|
||||||
int initial = 0;
|
int initial = 0;
|
||||||
@ -164,13 +176,30 @@ static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwar
|
|||||||
|
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "si|ii", kwlist, &channel, &direction, &pud, &initial))
|
// Try to parse the string
|
||||||
return NULL;
|
int rtn;
|
||||||
|
rtn = PyArg_ParseTupleAndKeywords(args, kwargs, "si|ii", kwlist, &channel, &direction, &pud, &initial);
|
||||||
|
if (!rtn) {
|
||||||
|
// Fall into here are try to parse an int
|
||||||
|
rtn = PyArg_ParseTupleAndKeywords(args, kwargs, "ii|ii", kwlist, &inchan, &direction, &pud, &initial);
|
||||||
|
if (!rtn) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// We make it here, we can convert inchan to a string for us to ensure it's valid
|
||||||
|
asprintf(&channel, "%i", inchan);
|
||||||
|
}
|
||||||
|
|
||||||
if (!module_setup) {
|
if (!module_setup) {
|
||||||
init_module();
|
init_module();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
if (direction != INPUT && direction != OUTPUT)
|
if (direction != INPUT && direction != OUTPUT)
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_ValueError, "An invalid direction was passed to setup()");
|
PyErr_SetString(PyExc_ValueError, "An invalid direction was passed to setup()");
|
||||||
@ -215,11 +244,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];
|
||||||
@ -254,23 +288,33 @@ static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwar
|
|||||||
}
|
}
|
||||||
|
|
||||||
remember_gpio_direction(gpio, direction);
|
remember_gpio_direction(gpio, direction);
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
} /* py_setup_channel */
|
} /* py_setup_channel */
|
||||||
|
|
||||||
|
|
||||||
// python function output(channel, value)
|
// python function output(channel, value)
|
||||||
static PyObject *py_output_gpio(PyObject *self, PyObject *args)
|
static PyObject *py_output_gpio(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
int gpio;
|
int gpio;
|
||||||
int value;
|
int value;
|
||||||
char *channel;
|
char *channel;
|
||||||
|
int inchan;
|
||||||
int allowed = -1;
|
int allowed = -1;
|
||||||
|
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "si", &channel, &value))
|
// Try to parse the string
|
||||||
return NULL;
|
int rtn;
|
||||||
|
rtn = PyArg_ParseTuple(args, "si", &channel, &value);
|
||||||
|
if (!rtn) {
|
||||||
|
// Fall into here are try to parse an int
|
||||||
|
rtn = PyArg_ParseTuple(args, "ii", &inchan, &value);
|
||||||
|
if (!rtn) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// We make it here, we can convert inchan to a string for us to ensure it's valid
|
||||||
|
asprintf(&channel, "%i", inchan);
|
||||||
|
}
|
||||||
|
|
||||||
if (get_gpio_number(channel, &gpio)) {
|
if (get_gpio_number(channel, &gpio)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Invalid channel");
|
PyErr_SetString(PyExc_ValueError, "Invalid channel");
|
||||||
@ -317,14 +361,25 @@ static PyObject *py_input_gpio(PyObject *self, PyObject *args)
|
|||||||
{
|
{
|
||||||
int gpio;
|
int gpio;
|
||||||
char *channel;
|
char *channel;
|
||||||
|
int inchan;
|
||||||
unsigned int value;
|
unsigned int value;
|
||||||
PyObject *py_value;
|
PyObject *py_value;
|
||||||
int allowed = -1;
|
int allowed = -1;
|
||||||
|
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &channel))
|
// Try to parse the string
|
||||||
return NULL;
|
int rtn;
|
||||||
|
rtn = PyArg_ParseTuple(args, "s", &channel);
|
||||||
|
if (!rtn) {
|
||||||
|
// Fall into here are try to parse an int
|
||||||
|
rtn = PyArg_ParseTuple(args, "i", &inchan);
|
||||||
|
if (!rtn) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// We make it here, we can convert inchan to a string for us to ensure it's valid
|
||||||
|
asprintf(&channel, "%i", inchan);
|
||||||
|
}
|
||||||
|
|
||||||
if (get_gpio_number(channel, &gpio)) {
|
if (get_gpio_number(channel, &gpio)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Invalid channel");
|
PyErr_SetString(PyExc_ValueError, "Invalid channel");
|
||||||
@ -371,14 +426,25 @@ static PyObject *py_read_byte_gpio(PyObject *self, PyObject *args)
|
|||||||
{
|
{
|
||||||
int gpio;
|
int gpio;
|
||||||
char *channel;
|
char *channel;
|
||||||
|
int inchan;
|
||||||
unsigned int value = 0;
|
unsigned int value = 0;
|
||||||
PyObject *py_value;
|
PyObject *py_value;
|
||||||
int allowed = -1;
|
int allowed = -1;
|
||||||
|
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &channel))
|
// Try to parse the string
|
||||||
return NULL;
|
int rtn;
|
||||||
|
rtn = PyArg_ParseTuple(args, "s", &channel);
|
||||||
|
if (!rtn) {
|
||||||
|
// Fall into here are try to parse an int
|
||||||
|
rtn = PyArg_ParseTuple(args, "i", &inchan);
|
||||||
|
if (!rtn) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// We make it here, we can convert inchan to a string for us to ensure it's valid
|
||||||
|
asprintf(&channel, "%i", inchan);
|
||||||
|
}
|
||||||
|
|
||||||
if (get_gpio_number(channel, &gpio)) {
|
if (get_gpio_number(channel, &gpio)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Invalid channel");
|
PyErr_SetString(PyExc_ValueError, "Invalid channel");
|
||||||
@ -425,14 +491,25 @@ static PyObject *py_read_word_gpio(PyObject *self, PyObject *args)
|
|||||||
{
|
{
|
||||||
int gpio;
|
int gpio;
|
||||||
char *channel;
|
char *channel;
|
||||||
|
int inchan;
|
||||||
unsigned int value = 0;
|
unsigned int value = 0;
|
||||||
PyObject *py_value;
|
PyObject *py_value;
|
||||||
int allowed = -1;
|
int allowed = -1;
|
||||||
|
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &channel))
|
// Try to parse the string
|
||||||
return NULL;
|
int rtn;
|
||||||
|
rtn = PyArg_ParseTuple(args, "s", &channel);
|
||||||
|
if (!rtn) {
|
||||||
|
// Fall into here are try to parse an int
|
||||||
|
rtn = PyArg_ParseTuple(args, "i", &inchan);
|
||||||
|
if (!rtn) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// We make it here, we can convert inchan to a string for us to ensure it's valid
|
||||||
|
asprintf(&channel, "%i", inchan);
|
||||||
|
}
|
||||||
|
|
||||||
if (get_gpio_number(channel, &gpio)) {
|
if (get_gpio_number(channel, &gpio)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Invalid channel");
|
PyErr_SetString(PyExc_ValueError, "Invalid channel");
|
||||||
@ -547,11 +624,12 @@ static int add_py_callback(char *channel, int gpio, int edge, unsigned int bounc
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// python function add_event_callback(gpio, callback, bouncetime=0)
|
// python function add_event_callback(channel, callback, bouncetime=0)
|
||||||
static PyObject *py_add_event_callback(PyObject *self, PyObject *args, PyObject *kwargs)
|
static PyObject *py_add_event_callback(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||||
{
|
{
|
||||||
int gpio;
|
int gpio;
|
||||||
char *channel;
|
char *channel;
|
||||||
|
int inchan;
|
||||||
int allowed = -1;
|
int allowed = -1;
|
||||||
unsigned int bouncetime = 0;
|
unsigned int bouncetime = 0;
|
||||||
PyObject *cb_func;
|
PyObject *cb_func;
|
||||||
@ -559,8 +637,18 @@ static PyObject *py_add_event_callback(PyObject *self, PyObject *args, PyObject
|
|||||||
|
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|i", kwlist, &channel, &cb_func, &bouncetime))
|
// Try to parse the string
|
||||||
return NULL;
|
int rtn;
|
||||||
|
rtn = PyArg_ParseTupleAndKeywords(args, kwargs, "sO|i", kwlist, &channel, &cb_func, &bouncetime);
|
||||||
|
if (!rtn) {
|
||||||
|
// Fall into here are try to parse an int
|
||||||
|
rtn = PyArg_ParseTupleAndKeywords(args, kwargs, "iO|i", kwlist, &inchan, &cb_func, &bouncetime);
|
||||||
|
if (!rtn) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// We make it here, we can convert inchan to a string for us to ensure it's valid
|
||||||
|
asprintf(&channel, "%i", inchan);
|
||||||
|
}
|
||||||
|
|
||||||
if (!PyCallable_Check(cb_func))
|
if (!PyCallable_Check(cb_func))
|
||||||
{
|
{
|
||||||
@ -591,6 +679,9 @@ static PyObject *py_add_event_callback(PyObject *self, PyObject *args, PyObject
|
|||||||
// check to ensure gpio is one of the allowed pins
|
// check to ensure gpio is one of the allowed pins
|
||||||
if (gpio != lookup_gpio_by_name("AP-EINT3")
|
if (gpio != lookup_gpio_by_name("AP-EINT3")
|
||||||
&& gpio != lookup_gpio_by_name("AP-EINT1")
|
&& 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"))) {
|
&& !(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");
|
PyErr_SetString(PyExc_ValueError, "Callbacks currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -615,11 +706,12 @@ static PyObject *py_add_event_callback(PyObject *self, PyObject *args, PyObject
|
|||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// python function add_event_detect(gpio, edge, callback=None, bouncetime=0
|
// python function add_event_detect(channel, edge, callback=None, bouncetime=0)
|
||||||
static PyObject *py_add_event_detect(PyObject *self, PyObject *args, PyObject *kwargs)
|
static PyObject *py_add_event_detect(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||||
{
|
{
|
||||||
int gpio;
|
int gpio;
|
||||||
char *channel;
|
char *channel;
|
||||||
|
int inchan;
|
||||||
int edge, result;
|
int edge, result;
|
||||||
unsigned int bouncetime = 0;
|
unsigned int bouncetime = 0;
|
||||||
int allowed = -1;
|
int allowed = -1;
|
||||||
@ -628,8 +720,18 @@ static PyObject *py_add_event_detect(PyObject *self, PyObject *args, PyObject *k
|
|||||||
|
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "si|Oi", kwlist, &channel, &edge, &cb_func, &bouncetime))
|
// Try to parse the string
|
||||||
return NULL;
|
int rtn;
|
||||||
|
rtn = PyArg_ParseTupleAndKeywords(args, kwargs, "si|Oi", kwlist, &channel, &edge, &cb_func, &bouncetime);
|
||||||
|
if (!rtn) {
|
||||||
|
// Fall into here are try to parse an int
|
||||||
|
rtn = PyArg_ParseTupleAndKeywords(args, kwargs, "ii|Oi", kwlist, &inchan, &edge, &cb_func, &bouncetime);
|
||||||
|
if (!rtn) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// We make it here, we can convert inchan to a string for us to ensure it's valid
|
||||||
|
asprintf(&channel, "%i", inchan);
|
||||||
|
}
|
||||||
|
|
||||||
if (cb_func != NULL && !PyCallable_Check(cb_func))
|
if (cb_func != NULL && !PyCallable_Check(cb_func))
|
||||||
{
|
{
|
||||||
@ -660,6 +762,9 @@ static PyObject *py_add_event_detect(PyObject *self, PyObject *args, PyObject *k
|
|||||||
// check to ensure gpio is one of the allowed pins
|
// check to ensure gpio is one of the allowed pins
|
||||||
if (gpio != lookup_gpio_by_name("AP-EINT3")
|
if (gpio != lookup_gpio_by_name("AP-EINT3")
|
||||||
&& gpio != lookup_gpio_by_name("AP-EINT1")
|
&& 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"))) {
|
&& !(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");
|
PyErr_SetString(PyExc_ValueError, "Edge Detection currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -698,11 +803,12 @@ static PyObject *py_add_event_detect(PyObject *self, PyObject *args, PyObject *k
|
|||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// python function remove_event_detect(gpio)
|
// python function remove_event_detect(channel)
|
||||||
static PyObject *py_remove_event_detect(PyObject *self, PyObject *args)
|
static PyObject *py_remove_event_detect(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
int gpio;
|
int gpio;
|
||||||
char *channel;
|
char *channel;
|
||||||
|
int inchan;
|
||||||
struct py_callback *cb = py_callbacks;
|
struct py_callback *cb = py_callbacks;
|
||||||
struct py_callback *temp;
|
struct py_callback *temp;
|
||||||
struct py_callback *prev = NULL;
|
struct py_callback *prev = NULL;
|
||||||
@ -710,8 +816,18 @@ static PyObject *py_remove_event_detect(PyObject *self, PyObject *args)
|
|||||||
|
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &channel))
|
// Try to parse the string
|
||||||
return NULL;
|
int rtn;
|
||||||
|
rtn = PyArg_ParseTuple(args, "s", &channel);
|
||||||
|
if (!rtn) {
|
||||||
|
// Fall into here are try to parse an int
|
||||||
|
rtn = PyArg_ParseTuple(args, "i", &inchan);
|
||||||
|
if (!rtn) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// We make it here, we can convert inchan to a string for us to ensure it's valid
|
||||||
|
asprintf(&channel, "%i", inchan);
|
||||||
|
}
|
||||||
|
|
||||||
if (get_gpio_number(channel, &gpio)) {
|
if (get_gpio_number(channel, &gpio)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Invalid channel");
|
PyErr_SetString(PyExc_ValueError, "Invalid channel");
|
||||||
@ -736,6 +852,9 @@ static PyObject *py_remove_event_detect(PyObject *self, PyObject *args)
|
|||||||
// check to ensure gpio is one of the allowed pins
|
// check to ensure gpio is one of the allowed pins
|
||||||
if (gpio != lookup_gpio_by_name("AP-EINT3")
|
if (gpio != lookup_gpio_by_name("AP-EINT3")
|
||||||
&& gpio != lookup_gpio_by_name("AP-EINT1")
|
&& 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"))) {
|
&& !(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");
|
PyErr_SetString(PyExc_ValueError, "Edge Detection currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -770,12 +889,23 @@ static PyObject *py_event_detected(PyObject *self, PyObject *args)
|
|||||||
{
|
{
|
||||||
int gpio;
|
int gpio;
|
||||||
char *channel;
|
char *channel;
|
||||||
|
int inchan;
|
||||||
int allowed = -1;
|
int allowed = -1;
|
||||||
|
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &channel))
|
// Try to parse the string
|
||||||
return NULL;
|
int rtn;
|
||||||
|
rtn = PyArg_ParseTuple(args, "s", &channel);
|
||||||
|
if (!rtn) {
|
||||||
|
// Fall into here are try to parse an int
|
||||||
|
rtn = PyArg_ParseTuple(args, "i", &inchan);
|
||||||
|
if (!rtn) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// We make it here, we can convert inchan to a string for us to ensure it's valid
|
||||||
|
asprintf(&channel, "%i", inchan);
|
||||||
|
}
|
||||||
|
|
||||||
if (get_gpio_number(channel, &gpio)) {
|
if (get_gpio_number(channel, &gpio)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Invalid channel");
|
PyErr_SetString(PyExc_ValueError, "Invalid channel");
|
||||||
@ -803,19 +933,32 @@ static PyObject *py_event_detected(PyObject *self, PyObject *args)
|
|||||||
Py_RETURN_FALSE;
|
Py_RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// python function py_wait_for_edge(gpio, edge)
|
// python function py_wait_for_edge(gpio, edge, timeout = -1)
|
||||||
static PyObject *py_wait_for_edge(PyObject *self, PyObject *args)
|
static PyObject *py_wait_for_edge(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
int gpio;
|
int gpio;
|
||||||
int edge, result;
|
int edge, result, timeout;
|
||||||
char *channel;
|
char *channel;
|
||||||
|
int inchan;
|
||||||
char error[81];
|
char error[81];
|
||||||
int allowed = -1;
|
int allowed = -1;
|
||||||
|
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "si", &channel, &edge))
|
timeout = -1;
|
||||||
return NULL;
|
|
||||||
|
// Try to parse the string
|
||||||
|
int rtn;
|
||||||
|
rtn = PyArg_ParseTuple(args, "si|i", &channel, &edge, &timeout);
|
||||||
|
if (!rtn) {
|
||||||
|
// Fall into here are try to parse an int
|
||||||
|
rtn = PyArg_ParseTuple(args, "ii|i", &inchan, &edge, &timeout);
|
||||||
|
if (!rtn) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// We make it here, we can convert inchan to a string for us to ensure it's valid
|
||||||
|
asprintf(&channel, "%i", inchan);
|
||||||
|
}
|
||||||
|
|
||||||
if (get_gpio_number(channel, &gpio)) {
|
if (get_gpio_number(channel, &gpio)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Invalid channel");
|
PyErr_SetString(PyExc_ValueError, "Invalid channel");
|
||||||
@ -840,6 +983,9 @@ static PyObject *py_wait_for_edge(PyObject *self, PyObject *args)
|
|||||||
// check to ensure gpio is one of the allowed pins
|
// check to ensure gpio is one of the allowed pins
|
||||||
if (gpio != lookup_gpio_by_name("AP-EINT3")
|
if (gpio != lookup_gpio_by_name("AP-EINT3")
|
||||||
&& gpio != lookup_gpio_by_name("AP-EINT1")
|
&& 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"))) {
|
&& !(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");
|
PyErr_SetString(PyExc_ValueError, "Edge Detection currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -860,7 +1006,7 @@ static PyObject *py_wait_for_edge(PyObject *self, PyObject *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS // disable GIL
|
Py_BEGIN_ALLOW_THREADS // disable GIL
|
||||||
result = blocking_wait_for_edge(gpio, edge);
|
result = blocking_wait_for_edge(gpio, edge, timeout);
|
||||||
Py_END_ALLOW_THREADS // enable GIL
|
Py_END_ALLOW_THREADS // enable GIL
|
||||||
|
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
@ -878,19 +1024,30 @@ static PyObject *py_wait_for_edge(PyObject *self, PyObject *args)
|
|||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// python function value = gpio_function(gpio)
|
// python function value = gpio_function(channel)
|
||||||
static PyObject *py_gpio_function(PyObject *self, PyObject *args)
|
static PyObject *py_gpio_function(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
int gpio;
|
int gpio;
|
||||||
unsigned int value;
|
unsigned int value;
|
||||||
PyObject *func;
|
PyObject *func;
|
||||||
char *channel;
|
char *channel;
|
||||||
|
int inchan;
|
||||||
int allowed = -1;
|
int allowed = -1;
|
||||||
|
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &channel))
|
// Try to parse the string
|
||||||
return NULL;
|
int rtn;
|
||||||
|
rtn = PyArg_ParseTuple(args, "s", &channel);
|
||||||
|
if (!rtn) {
|
||||||
|
// Fall into here are try to parse an int
|
||||||
|
rtn = PyArg_ParseTuple(args, "i", &inchan);
|
||||||
|
if (!rtn) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// We make it here, we can convert inchan to a string for us to ensure it's valid
|
||||||
|
asprintf(&channel, "%i", inchan);
|
||||||
|
}
|
||||||
|
|
||||||
if (get_gpio_number(channel, &gpio)) {
|
if (get_gpio_number(channel, &gpio)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Invalid channel");
|
PyErr_SetString(PyExc_ValueError, "Invalid channel");
|
||||||
@ -1093,19 +1250,30 @@ static const char moduledocstring[] = "GPIO functionality of a CHIP using Python
|
|||||||
/*
|
/*
|
||||||
mine for changing pin directipn
|
mine for changing pin directipn
|
||||||
*/
|
*/
|
||||||
|
// python function set_direction(channel, direction)
|
||||||
static PyObject *py_set_direction(PyObject *self, PyObject *args, PyObject *kwargs)
|
static PyObject *py_set_direction(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||||
{
|
{
|
||||||
int gpio;
|
int gpio;
|
||||||
char *channel;
|
char *channel;
|
||||||
|
int inchan;
|
||||||
int direction;
|
int direction;
|
||||||
int allowed = -1;
|
int allowed = -1;
|
||||||
static char *kwlist[] = { "channel", "direction", NULL };
|
static char *kwlist[] = { "channel", "direction", NULL };
|
||||||
|
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "si|ii", kwlist, &channel, &direction))
|
// Try to parse the string
|
||||||
return NULL;
|
int rtn;
|
||||||
|
rtn = PyArg_ParseTupleAndKeywords(args, kwargs, "si", kwlist, &channel, &direction);
|
||||||
|
if (!rtn) {
|
||||||
|
// Fall into here are try to parse an int
|
||||||
|
rtn = PyArg_ParseTupleAndKeywords(args, kwargs, "ii", kwlist, &inchan, &direction);
|
||||||
|
if (!rtn) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// We make it here, we can convert inchan to a string for us to ensure it's valid
|
||||||
|
asprintf(&channel, "%i", inchan);
|
||||||
|
}
|
||||||
|
|
||||||
if (!module_setup) {
|
if (!module_setup) {
|
||||||
init_module();
|
init_module();
|
||||||
@ -1162,7 +1330,7 @@ PyMethodDef gpio_methods[] = {
|
|||||||
{"remove_event_detect", py_remove_event_detect, METH_VARARGS, "Remove edge detection for a particular GPIO channel\ngpio - gpio channel"},
|
{"remove_event_detect", py_remove_event_detect, METH_VARARGS, "Remove edge detection for a particular GPIO channel\ngpio - gpio channel"},
|
||||||
{"event_detected", py_event_detected, METH_VARARGS, "Returns True if an edge has occured on a given GPIO. You need to enable edge detection using add_event_detect() first.\ngpio - gpio channel"},
|
{"event_detected", py_event_detected, METH_VARARGS, "Returns True if an edge has occured on a given GPIO. You need to enable edge detection using add_event_detect() first.\ngpio - gpio channel"},
|
||||||
{"add_event_callback", (PyCFunction)py_add_event_callback, METH_VARARGS | METH_KEYWORDS, "Add a callback for an event already defined using add_event_detect()\ngpio - gpio channel\ncallback - a callback function\n[bouncetime] - Switch bounce timeout in ms"},
|
{"add_event_callback", (PyCFunction)py_add_event_callback, METH_VARARGS | METH_KEYWORDS, "Add a callback for an event already defined using add_event_detect()\ngpio - gpio channel\ncallback - a callback function\n[bouncetime] - Switch bounce timeout in ms"},
|
||||||
{"wait_for_edge", py_wait_for_edge, METH_VARARGS, "Wait for an edge.\ngpio - gpio channel\nedge - RISING, FALLING or BOTH"},
|
{"wait_for_edge", py_wait_for_edge, METH_VARARGS, "Wait for an edge.\ngpio - gpio channel\nedge - RISING, FALLING or BOTH\ntimeout (optional) - time to wait in miliseconds. -1 will wait forever (default)"},
|
||||||
{"gpio_function", py_gpio_function, METH_VARARGS, "Return the current GPIO function (IN, OUT, ALT0)\ngpio - gpio channel"},
|
{"gpio_function", py_gpio_function, METH_VARARGS, "Return the current GPIO function (IN, OUT, ALT0)\ngpio - gpio channel"},
|
||||||
{"setwarnings", py_setwarnings, METH_VARARGS, "Enable or disable warning messages"},
|
{"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"},
|
{"get_gpio_base", py_gpio_base, METH_VARARGS, "Get the XIO base number for sysfs"},
|
||||||
|
@ -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}
|
||||||
|
@ -50,6 +50,8 @@ static PyObject *py_toggle_debug(PyObject *self, PyObject *args)
|
|||||||
// python function cleanup()
|
// python function cleanup()
|
||||||
static PyObject *py_cleanup(PyObject *self, PyObject *args)
|
static PyObject *py_cleanup(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
// TODO: PER PIN CLEANUP LIKE EVERYTHING ELSE
|
||||||
|
|
||||||
// unexport the Servo
|
// unexport the Servo
|
||||||
servo_cleanup();
|
servo_cleanup();
|
||||||
|
|
||||||
@ -68,7 +70,7 @@ static int init_module(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// python function value = is_chip_pro
|
// python function value = is_chip_pro()
|
||||||
static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
|
static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *py_value;
|
PyObject *py_value;
|
||||||
@ -185,7 +187,7 @@ static PyObject *py_stop_channel(PyObject *self, PyObject *args, PyObject *kwarg
|
|||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// python method SERVO.set_range(channel, duty_cycle)
|
// python method SERVO.set_range(channel, range)
|
||||||
static PyObject *py_set_range(PyObject *self, PyObject *args, PyObject *kwargs)
|
static PyObject *py_set_range(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||||
{
|
{
|
||||||
int gpio;
|
int gpio;
|
||||||
@ -241,7 +243,7 @@ static PyObject *py_set_range(PyObject *self, PyObject *args, PyObject *kwargs)
|
|||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// python method SERVO.set_angle(channel, duty_cycle)
|
// python method SERVO.set_angle(channel, angle)
|
||||||
static PyObject *py_set_angle(PyObject *self, PyObject *args, PyObject *kwargs)
|
static PyObject *py_set_angle(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||||
{
|
{
|
||||||
int gpio;
|
int gpio;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
@ -64,7 +82,7 @@ static int init_module(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// python function value = is_chip_pro
|
// python function value = is_chip_pro()
|
||||||
static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
|
static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *py_value;
|
PyObject *py_value;
|
||||||
@ -74,7 +92,7 @@ static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
|
|||||||
return py_value;
|
return py_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// python function start(channel, duty_cycle, freq)
|
// python function start(channel, duty_cycle, freq, polarity)
|
||||||
static PyObject *py_start_channel(PyObject *self, PyObject *args, PyObject *kwargs)
|
static PyObject *py_start_channel(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||||
{
|
{
|
||||||
char key[8];
|
char key[8];
|
||||||
@ -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}
|
||||||
|
45
test/integrations/spwmtest2.py
Normal file
45
test/integrations/spwmtest2.py
Normal 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
14
test/test_lradc.py
Normal 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
|
@ -4,29 +4,22 @@ import time
|
|||||||
|
|
||||||
import CHIP_IO.PWM as PWM
|
import CHIP_IO.PWM as PWM
|
||||||
import CHIP_IO.OverlayManager as OM
|
import CHIP_IO.OverlayManager as OM
|
||||||
|
import CHIP_IO.Utilities as UT
|
||||||
|
|
||||||
def setup_module(module):
|
def setup_module(module):
|
||||||
OM.load("PWM0")
|
if not UT.is_chip_pro():
|
||||||
|
OM.load("PWM0")
|
||||||
|
|
||||||
def teardown_module(module):
|
def teardown_module(module):
|
||||||
PWM.cleanup()
|
PWM.cleanup()
|
||||||
OM.unload("PWM0")
|
if not UT.is_chip_pro():
|
||||||
|
OM.unload("PWM0")
|
||||||
|
|
||||||
class TestPwmSetup:
|
class TestPwmSetup:
|
||||||
|
|
||||||
def setup_method(self, test_method):
|
def setup_method(self, test_method):
|
||||||
time.sleep(0.5)
|
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):
|
def test_start_pwm(self):
|
||||||
PWM.start("PWM0", 0)
|
PWM.start("PWM0", 0)
|
||||||
|
|
||||||
@ -38,27 +31,25 @@ class TestPwmSetup:
|
|||||||
assert int(duty) == 0
|
assert int(duty) == 0
|
||||||
assert int(period) == 500000
|
assert int(period) == 500000
|
||||||
|
|
||||||
@pytest.mark.xfail(reason="pwm cleanup is doing weirdness for this test")
|
|
||||||
def test_start_pwm_with_polarity_one(self):
|
def test_start_pwm_with_polarity_one(self):
|
||||||
|
PWM.cleanup()
|
||||||
PWM.start("PWM0", 0, 2000, 1)
|
PWM.start("PWM0", 0, 2000, 1)
|
||||||
|
|
||||||
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
|
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
|
||||||
|
|
||||||
#assert os.path.exists(pwm_test) == True
|
|
||||||
duty = open(pwm_test + 'duty_cycle').readline().strip()
|
duty = open(pwm_test + 'duty_cycle').readline().strip()
|
||||||
period = open(pwm_test + 'period').readline().strip()
|
period = open(pwm_test + 'period').readline().strip()
|
||||||
polarity = open(pwm_test + 'polarity').readline().strip()
|
polarity = open(pwm_test + 'polarity').readline().strip()
|
||||||
assert int(duty) == 0
|
assert int(duty) == 0
|
||||||
assert int(period) == 500000
|
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):
|
def test_start_pwm_with_polarity_default(self):
|
||||||
|
PWM.cleanup()
|
||||||
PWM.start("PWM0", 0, 2000, 0)
|
PWM.start("PWM0", 0, 2000, 0)
|
||||||
|
|
||||||
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
|
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
|
||||||
|
|
||||||
#assert os.path.exists(pwm_test) == True
|
|
||||||
duty = open(pwm_test + 'duty_cycle').readline().strip()
|
duty = open(pwm_test + 'duty_cycle').readline().strip()
|
||||||
period = open(pwm_test + 'period').readline().strip()
|
period = open(pwm_test + 'period').readline().strip()
|
||||||
polarity = open(pwm_test + 'polarity').readline().strip()
|
polarity = open(pwm_test + 'polarity').readline().strip()
|
||||||
@ -66,13 +57,12 @@ class TestPwmSetup:
|
|||||||
assert int(period) == 500000
|
assert int(period) == 500000
|
||||||
assert str(polarity) == "normal"
|
assert str(polarity) == "normal"
|
||||||
|
|
||||||
@pytest.mark.xfail(reason="pwm cleanup is doing weirdness for this test")
|
|
||||||
def test_start_pwm_with_polarity_zero(self):
|
def test_start_pwm_with_polarity_zero(self):
|
||||||
|
PWM.cleanup()
|
||||||
PWM.start("PWM0", 0, 2000, 0)
|
PWM.start("PWM0", 0, 2000, 0)
|
||||||
|
|
||||||
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
|
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
|
||||||
|
|
||||||
#assert os.path.exists(pwm_test) == True
|
|
||||||
duty = open(pwm_test + 'duty_cycle').readline().strip()
|
duty = open(pwm_test + 'duty_cycle').readline().strip()
|
||||||
period = open(pwm_test + 'period').readline().strip()
|
period = open(pwm_test + 'period').readline().strip()
|
||||||
polarity = open(pwm_test + 'polarity').readline().strip()
|
polarity = open(pwm_test + 'polarity').readline().strip()
|
||||||
@ -90,11 +80,14 @@ class TestPwmSetup:
|
|||||||
|
|
||||||
def test_pwm_start_valid_duty_cycle_min(self):
|
def test_pwm_start_valid_duty_cycle_min(self):
|
||||||
#testing an exception isn't thrown
|
#testing an exception isn't thrown
|
||||||
|
PWM.cleanup()
|
||||||
PWM.start("PWM0", 0)
|
PWM.start("PWM0", 0)
|
||||||
|
PWM.cleanup()
|
||||||
|
|
||||||
def test_pwm_start_valid_duty_cycle_max(self):
|
def test_pwm_start_valid_duty_cycle_max(self):
|
||||||
#testing an exception isn't thrown
|
#testing an exception isn't thrown
|
||||||
PWM.start("PWM0", 100)
|
PWM.start("PWM0", 100)
|
||||||
|
PWM.cleanup()
|
||||||
|
|
||||||
def test_pwm_start_invalid_duty_cycle_high(self):
|
def test_pwm_start_invalid_duty_cycle_high(self):
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
@ -143,7 +136,8 @@ class TestPwmSetup:
|
|||||||
assert int(period) == 500000
|
assert int(period) == 500000
|
||||||
|
|
||||||
def test_pwm_duty_cycle_non_setup_key(self):
|
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)
|
PWM.set_duty_cycle("PWM0", 100)
|
||||||
|
|
||||||
def test_pwm_duty_cycle_invalid_key(self):
|
def test_pwm_duty_cycle_invalid_key(self):
|
||||||
@ -154,26 +148,31 @@ class TestPwmSetup:
|
|||||||
PWM.start("PWM0", 0)
|
PWM.start("PWM0", 0)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
PWM.set_duty_cycle("PWM0", 101)
|
PWM.set_duty_cycle("PWM0", 101)
|
||||||
|
PWM.cleanup()
|
||||||
|
|
||||||
def test_pwm_duty_cycle_invalid_value_negative(self):
|
def test_pwm_duty_cycle_invalid_value_negative(self):
|
||||||
PWM.start("PWM0", 0)
|
PWM.start("PWM0", 0)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
PWM.set_duty_cycle("PWM0", -1)
|
PWM.set_duty_cycle("PWM0", -1)
|
||||||
|
PWM.cleanup()
|
||||||
|
|
||||||
def test_pwm_duty_cycle_invalid_value_string(self):
|
def test_pwm_duty_cycle_invalid_value_string(self):
|
||||||
PWM.start("PWM0", 0)
|
PWM.start("PWM0", 0)
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
PWM.set_duty_cycle("PWM0", "a")
|
PWM.set_duty_cycle("PWM0", "a")
|
||||||
|
PWM.cleanup()
|
||||||
|
|
||||||
def test_pwm_frequency_invalid_value_negative(self):
|
def test_pwm_frequency_invalid_value_negative(self):
|
||||||
PWM.start("PWM0", 0)
|
PWM.start("PWM0", 0)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
PWM.set_frequency("PWM0", -1)
|
PWM.set_frequency("PWM0", -1)
|
||||||
|
PWM.cleanup()
|
||||||
|
|
||||||
def test_pwm_frequency_invalid_value_string(self):
|
def test_pwm_frequency_invalid_value_string(self):
|
||||||
PWM.start("PWM0", 0)
|
PWM.start("PWM0", 0)
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
PWM.set_frequency("PWM0", "11")
|
PWM.set_frequency("PWM0", "11")
|
||||||
|
PWM.cleanup()
|
||||||
|
|
||||||
def test_pwm_freq_non_setup_key(self):
|
def test_pwm_freq_non_setup_key(self):
|
||||||
with pytest.raises(RuntimeError):
|
with pytest.raises(RuntimeError):
|
||||||
|
11
test/test_utilities.py
Normal file
11
test/test_utilities.py
Normal 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)
|
Reference in New Issue
Block a user