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

37 Commits

Author SHA1 Message Date
84df4376f8 added logging to inform user of 1s retry if set_direction fails on the first try, updating to v0.7.1 2017-11-12 08:06:35 -06:00
906beb0257 Merge pull request #80 from MEitelwein/master
add 1s delay in set_direction to allow udev to set permissions
2017-11-12 07:31:02 -06:00
00cd5c09ad add 1s delay in set_direction to allow udev to set permissions 2017-11-11 19:08:02 +00:00
c87b0ca72a Merge pull request #79 from futuristicblanket/master
Fixed a small spelling error of the word 'note' in the readme
2017-10-22 11:44:53 -05:00
ff7bf2fa1c Fixed a small spelling error of the word 'note' 2017-10-14 10:44:27 +10:00
af9555fcdf updating the GPIO docs to reference ability to control pins via sysfs numbers 2017-09-13 11:45:20 -05:00
e7db735a2f GPIO able to be controlled by pin sysfs number like RPi.GPIO, close #65 2017-09-13 10:35:32 -05:00
e3a077bf82 implementation and close #75 - enabling a timeout for the wait_for_edge function 2017-09-03 21:43:59 -05:00
a0b2ac12a6 Adding the ability to generate wheel packages for uploading to pypi, thanks to help from pztrick. This will close #77 2017-09-02 21:04:24 -05:00
6af974c113 fixing implementation of #76 since i didn't actually test it 2017-08-09 23:18:16 -05:00
4670e44758 API documentation complete, closing #74 and closing #73 2017-08-09 22:54:20 -05:00
2247e9d234 fixing table formatting on the docs index page 2017-08-07 22:25:42 -05:00
ff91bcd0d1 cleanup of the readme and adding pin name table to doc index 2017-08-07 22:13:58 -05:00
35619e5baf adding code to close #76 2017-08-07 22:06:15 -05:00
1e3935c8ea finalizing servo, softpwm, and pwm api docs, cleanup of code comments for #73 2017-08-07 22:02:16 -05:00
e038fc9c89 actually finishing servo api docs 2017-08-07 21:24:15 -05:00
5b016887fe finishing servo api docs 2017-08-07 21:23:11 -05:00
aa76edb7b3 finished lradc api docs 2017-08-07 21:04:21 -05:00
d84c3c03d7 fixing a utilities function definition 2017-07-04 19:35:30 -05:00
c47fb197f5 utilities api documentaiton complete 2017-07-04 19:34:30 -05:00
a6111d8245 finished overlaymanager api docs 2017-07-04 17:03:44 -05:00
71923f5739 added overlaymanager.md 2017-07-04 15:10:35 -05:00
c9b0ae4229 moving the docs to separate files as it will be easier to maintain 2017-07-04 12:05:03 -05:00
5aef829dd1 another test commit of documentation formatting 2017-07-04 11:56:22 -05:00
3c3ec494dd test commit of documentation formatting 2017-07-04 11:52:56 -05:00
bb5f0083e8 start of api docs 2017-07-04 11:28:21 -05:00
408bf60ffa Set theme jekyll-theme-minimal 2017-07-04 11:18:06 -05:00
310c4a9ae4 adding docs folder 2017-07-04 11:16:38 -05:00
014dcb8a36 Updated README to close #71 2017-06-28 20:11:05 -05:00
6e93fad1de README updates following the merge of PR#70 into master 2017-06-08 20:06:52 -05:00
41d4b84c56 Merge pull request #70 from mzealey/master
Extern integer definitions in the header file
2017-06-08 19:19:17 -05:00
024e5d5797 Extern integer definitions in the header file
Integers are defined in both the .c and the common.h file leading to linking
issues with the library when used externally and potentially causing issues
within the code as well.
2017-06-08 15:23:32 +00:00
6ddd0e0b14 Closing out Issue #68 by adding 3 CHIP Pro pins able to be used as interrupts 2017-05-02 22:46:10 -05:00
d4b1d8a41c adding i2s pins as gpio capable for the chip pro, code to handle per pwm/softpwm cleanup to close #64 2017-05-01 22:50:17 -05:00
2b48571ee3 Updating setup to allow for repeated calls on a pin. Not totally sold on this, but it work and is what RPi.GPIO does. This will close #63 2017-03-20 23:06:09 -05:00
38a34e7edf Updating the README to clean up how to do callbacks for more clarification on #62 2017-03-07 07:22:09 -06:00
f32733bb07 Updating the Readme to add a note regarding one callback per pin 2017-03-06 17:53:34 -06:00
25 changed files with 1960 additions and 191 deletions

View File

@ -1,3 +1,49 @@
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

View File

@ -1,10 +1,16 @@
# PyPi Packaging
package: clean
@echo " ** PACKAGING FOR PYPI **"
python setup.py sdist
python setup.py sdist bdist_wheel
python3 setup.py bdist_wheel
# PyPi Packaging
package3: package
@echo " ** PACKAGING FOR PYPI **"
python3 setup.py bdist_wheel
# PyPi Publishing
publish: package
publish: package package3
@echo " ** UPLOADING TO PYPI **"
twine upload dist/*

View File

@ -2,6 +2,19 @@ CHIP_IO
============================
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::
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.
+------------------+--------------------------+-------------+-----------------+
| CHIP (Name) | PocketCHIP/CHIP Pro Name | CHIP Key | HW Support |
+------------------+--------------------------+-------------+-----------------+
| TWI1-SDA | KPD-I2C-SDA | U13_9 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| TWI1-SCK | KPD-I2C-SCL | U13_11 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| LCD-D2 | UART2-TX | U13_17 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| PWM0 | PWM0 | U13_18 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| PWM1 | PWM1 | EINT13 | CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| LCD-D4 | UART2-CTS | U13_19 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| LCD-D3 | UART2-RX | U13_20 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| LCD-D6 | LCD-D6 | U13_21 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D5 | UART2-RTS | U13_22 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| LCD-D10 | LCD-D10 | U13_23 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D7 | LCD-D7 | U13_24 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D12 | LCD-D12 | U13_25 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D11 | LCD-D11 | U13_26 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D14 | LCD-D14 | U13_27 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D13 | LCD-D13 | U13_28 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D18 | LCD-D18 | U13_29 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D15 | LCD-D15 | U13_30 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D20 | LCD-D20 | U13_31 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D19 | LCD-D19 | U13_32 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D22 | LCD-D22 | U13_33 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D21 | LCD-D21 | U13_34 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-CLK | LCD-CLK | U13_35 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-D23 | LCD-D23 | U13_36 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-VSYNC | LCD-VSYNC | U13_37 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-HSYNC | LCD-HSYNC | U13_38 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| LCD-DE | LCD-DE | U13_40 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| UART1-TX | UART-TX | U14_3 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| UART1-RX | UART-RX | U14_5 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| LRADC | ADC | U14_11 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| XIO-P0 | XIO-P0 | U14_13 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| XIO-P1 | XIO-P1 | U14_14 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| XIO-P2 | GPIO1 | U14_15 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| XIO-P3 | GPIO2 | U14_16 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| XIO-P4 | GPIO3 | U14_17 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| XIO-P5 | GPIO4 | U14_18 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| XIO-P6 | GPIO5 | U14_19 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| XIO-P7 | GPIO6 | U14_20 | CHIP |
+------------------+--------------------------+-------------+-----------------+
| AP-EINT1 | KPD-INT | U14_23 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| AP-EINT3 | AP-INT3 | U14_24 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| TWI2-SDA | I2C-SDA | U14_25 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| TWI2-SCK | I2C-SCL | U14_26 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSIPCK | SPI-SEL | U14_27 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSICK | SPI-CLK | U14_28 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSIHSYNC | SPI-MOSI | U14_29 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSIVSYNC | SPI-MISO | U14_30 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSID0 | D0 | U14_31 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSID1 | D1 | U14_32 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSID2 | D2 | U14_33 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSID3 | D3 | U14_34 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSID4 | D4 | U14_35 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSID5 | D5 | U14_36 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSID6 | D6 | U14_37 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
| CSID7 | D7 | U14_38 | CHIP/CHIP PRO |
+------------------+--------------------------+-------------+-----------------+
+------------------+--------------------------+----------------+-----------------+-----------------+
| CHIP (Main Name) | PocketCHIP/CHIP Pro Name | Key (Alt Name) | HW Support | Edge Detect |
+------------------+--------------------------+----------------+-----------------+-----------------+
| TWI1-SDA | KPD-I2C-SDA | U13_9 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| TWI1-SCK | KPD-I2C-SCL | U13_11 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D2 | UART2-TX | U13_17 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| PWM0 | PWM0 | U13_18 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| PWM1 | PWM1 | EINT13 | CHIP PRO | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D4 | UART2-CTS | U13_19 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D3 | UART2-RX | U13_20 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D6 | LCD-D6 | U13_21 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D5 | UART2-RTS | U13_22 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D10 | LCD-D10 | U13_23 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D7 | LCD-D7 | U13_24 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D12 | LCD-D12 | U13_25 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D11 | LCD-D11 | U13_26 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D14 | LCD-D14 | U13_27 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D13 | LCD-D13 | U13_28 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D18 | LCD-D18 | U13_29 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D15 | LCD-D15 | U13_30 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D20 | LCD-D20 | U13_31 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D19 | LCD-D19 | U13_32 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D22 | LCD-D22 | U13_33 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D21 | LCD-D21 | U13_34 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-CLK | LCD-CLK | U13_35 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-D23 | LCD-D23 | U13_36 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-VSYNC | LCD-VSYNC | U13_37 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-HSYNC | LCD-HSYNC | U13_38 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LCD-DE | LCD-DE | U13_40 | CHIP | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| UART1-TX | UART-TX | U14_3 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| UART1-RX | UART-RX | U14_5 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| LRADC | ADC | U14_11 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| XIO-P0 | XIO-P0 | U14_13 | CHIP | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| XIO-P1 | XIO-P1 | U14_14 | CHIP | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| XIO-P2 | GPIO1 | U14_15 | CHIP | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| XIO-P3 | GPIO2 | U14_16 | CHIP | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| XIO-P4 | GPIO3 | U14_17 | CHIP | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| XIO-P5 | GPIO4 | U14_18 | CHIP | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| XIO-P6 | GPIO5 | U14_19 | CHIP | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| XIO-P7 | GPIO6 | U14_20 | CHIP | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| AP-EINT1 | KPD-INT | U14_23 | CHIP/CHIP PRO | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| AP-EINT3 | AP-INT3 | U14_24 | CHIP/CHIP PRO | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| TWI2-SDA | I2C-SDA | U14_25 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| TWI2-SCK | I2C-SCL | U14_26 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSIPCK | SPI-SEL | U14_27 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSICK | SPI-CLK | U14_28 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSIHSYNC | SPI-MOSI | U14_29 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSIVSYNC | SPI-MISO | U14_30 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSID0 | D0 | U14_31 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSID1 | D1 | U14_32 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSID2 | D2 | U14_33 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSID3 | D3 | U14_34 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSID4 | D4 | U14_35 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSID5 | D5 | U14_36 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSID6 | D6 | U14_37 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| CSID7 | D7 | U14_38 | CHIP/CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| I2S-MCLK | EINT19 | 21 | CHIP PRO | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
| I2S-BCLK | I2S-BCLK | 22 | CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| I2S-LCLK | I2S-LCLK | 23 | CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| I2S-DO | EINT19 | 24 | CHIP PRO | NO |
+------------------+--------------------------+----------------+-----------------+-----------------+
| I2S-DI | EINT24 | 25 | CHIP PRO | YES |
+------------------+--------------------------+----------------+-----------------+-----------------+
**GPIO Setup**
@ -204,6 +227,7 @@ Other options when setting up pins::
# Specify pull up/pull down settings on a pin
GPIO.setup("CSID0", GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Specify initial value for an output
GPIO.setup("CSID0", GPIO.OUT, initial=1)
@ -220,11 +244,22 @@ Read lots of data::
# Get 8 bits of data in one shot
mybyte = GPIO.read_byte("LCD-D3")
# Get 16 bits of data in one shot
myword = GPIO.read_word("XIO-P4")
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.
Waiting for an edge (GPIO.RISING, GPIO.FALLING, or GPIO.BOTH::
@ -236,25 +271,35 @@ Detecting events::
GPIO.setup("XIO-P0", GPIO.IN)
GPIO.add_event_detect("XIO-P0", GPIO.FALLING)
#your amazing code here
#detect wherever:
if GPIO.event_detected("XIO-P0"):
print "event detected!"
CHIP_IO can also handle adding callback functions on any pin that supports edge detection.::
CHIP_IO can also handle adding callback functions on any pin that supports edge detection. Note that only one callback function can be specified per Pin, if you try to set more, an exception will be thrown.::
def mycallback(channel):
print("we hit the edge we want")
GPIO.setup("GPIO3", GPIO.IN)
# Add Callback: Falling Edge
GPIO.add_event_callback("GPIO3", GPIO.FALLING, mycallback)
# Add Callback: Rising Edge
GPIO.add_event_callback("GPIO3", GPIO.RISING, mycallback)
# Add Callback: Both Edges
GPIO.add_event_callback("GPIO3", GPIO.BOTH, mycallback)
# Remove callback
# Add Event Detect and Callback Separately for Falling Edge
GPIO.add_event_detect("GPIO3", GPIO.FALLING)
GPIO.add_event_callback("GPIO3", mycallback)
# Add Event Detect and Callback Separately for Rising Edge
GPIO.add_event_detect("GPIO3", GPIO.RISING)
GPIO.add_event_callback("GPIO3", mycallback)
# Add Callback for Both Edges using the add_event_detect() method
GPIO.add_event_detect("GPIO3", GPIO.BOTH, mycallback)
# Remove callback with the following
GPIO.remove_event_detect("GPIO3")
# 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**
@ -262,6 +307,7 @@ To clean up the GPIO when done, do the following::
# Clean up every exported GPIO Pin
GPIO.cleanup()
# Clean up a single pin (keeping everything else intact)
GPIO.cleanup("XIO-P0")
@ -274,16 +320,20 @@ Hardware PWM requires a DTB Overlay loaded on the CHIP to allow the kernel to kn
# 0 For CHIP
# 1 For CHIP Pro
PWM.is_chip_pro()
# Enable/Disable Debug
PWM.toggle_debug()
#PWM.start(channel, duty, freq=2000, polarity=0)
#duty values are valid 0 (off) to 100 (on)
PWM.start("PWM0", 50)
PWM.set_duty_cycle("PWM0", 25.5)
PWM.set_frequency("PWM0", 10)
# To stop PWM
PWM.stop("PWM0")
PWM.cleanup()
#For specific polarity: this example sets polarity to 1 on start:
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
# 1 For CHIP Pro
SPWM.is_chip_pro()
# Enable/Disable Debug
SPWM.toggle_debug()
#SPWM.start(channel, duty, freq=2000, polarity=0)
#duty values are valid 0 (off) to 100 (on)
#you can choose any pin
SPWM.start("XIO-P7", 50)
SPWM.set_duty_cycle("XIO-P7", 25.5)
SPWM.set_frequency("XIO-P7", 10)
# To Stop SPWM
SPWM.stop("XIO-P7")
# Cleanup
SPWM.cleanup()
#For specific polarity: this example sets polarity to 1 on start:
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
# 1 For CHIP Pro
SERVO.is_chip_pro()
# Enable/Disable Debug
SERVO.toggle_debug()
#SPWM.start(channel, angle=0, range=180)
#angle values are between +/- range/2)
#you can choose any pin except the XIO's
SERVO.start("CSID4", 50)
SERVO.set_angle("CSID4", 25.5)
SERVO.set_range("CSID4", 90)
# To Stop Servo
SERVO.stop("CSID4")
# Cleanup
SERVO.cleanup()
@ -343,23 +402,31 @@ Sample code below details how to talk to the LRADC.::
import CHIP_IO.LRADC as ADC
# Enable/Disable Debug
ADC.toggle_debug()
# Check to see if the LRADC Device exists
# Returns True/False
ADC.get_device_exists()
# Setup the LRADC
# Specify a sampling rate if needed
ADC.setup(rate)
# Get the Scale Factor
factor = ADC.get_scale_factor()
# Get the allowable Sampling Rates
sampleratestuple = ADC.get_allowable_sample_rates()
# Set the sampling rate
ADC.set_sample_rate(rate)
# Get the current sampling rate
currentrate = ADC.get_sample_rate()
# Get the Raw Channel 0 or 1 data
raw = ADC.get_chan0_raw()
raw = ADC.get_chan1_raw()
# Get the factored ADC Channel data
fulldata = ADC.get_chan0()
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
# 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()
OM.load("PWM0")
# To verify the overlay was properly loaded, the get_ functions return booleans
OM.get_pwm_loaded()
OM.get_spi_loaded()
# To unload an overlay, feed in the name to unload()
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
# The full path to the dtbo file needs to be specified
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
OM.get_custom_loaded()
# To unload, just call unload()
OM.unload("CUST")
@ -408,20 +480,28 @@ To use the utilities, here is sample code::
import CHIP_IO.Utilities as UT
# Enable/Disable Debug
UT.toggle_debug()
# Enable 1.8V Output
UT.enable_1v8_pin()
# Set 2.0V Output
UT.set_1v8_pin_voltage(2.0)
# Set 2.6V Output
UT.set_1v8_pin_voltage(2.6)
# Set 3.3V Output
UT.set_1v8_pin_voltage(3.3)
# Disable 1.8V Output
UT.disable_1v8_pin()
# Get currently-configured voltage (returns False if the pin is not enabled as output)
UT.get_1v8_pin_voltage()
# Unexport Everything
UT.unexport_all()
# 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
UT.is_chip_pro()

64
debian/changelog vendored
View File

@ -1,3 +1,67 @@
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

4
debian/files vendored
View File

@ -1,2 +1,2 @@
python-chip-io_0.5.4-1_armhf.deb python optional
python3-chip-io_0.5.4-1_armhf.deb python optional
python-chip-io_0.7.1-1_armhf.deb python optional
python3-chip-io_0.7.1-1_armhf.deb python optional

1
docs/_config.yml Normal file
View File

@ -0,0 +1 @@
theme: jekyll-theme-minimal

354
docs/gpio.md Normal file
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View File

@ -0,0 +1,6 @@
[bdist_wheel]
universal = 1
[metadata]
license_file = LICENSE

View File

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

View File

@ -138,6 +138,11 @@ pins_t pins_info[] = {
{ "CSID7", "D7", "U14_38", 139, BASE_METHOD_AS_IS, -1, -1, BOTH},
{ "GND", "GND", "U14_39", -1, BASE_METHOD_AS_IS, -1, -1, BOTH},
{ "GND", "GND", "U14_40", -1, BASE_METHOD_AS_IS, -1, -1, BOTH},
{ "I2S-MCLK", "EINT19", "21", 37, BASE_METHOD_AS_IS, -1, -1, CHIPPRO},
{ "I2S-BCLK", "I2S-BCLK", "22", 38, BASE_METHOD_AS_IS, -1, -1, CHIPPRO},
{ "I2S-LCLK", "I2S-LCLK", "23", 39, BASE_METHOD_AS_IS, -1, -1, CHIPPRO},
{ "I2S-DO", "I2S-DO", "24", 40, BASE_METHOD_AS_IS, -1, -1, CHIPPRO},
{ "I2S-DI", "EINT24", "25", 41, BASE_METHOD_AS_IS, -1, -1, CHIPPRO},
{ NULL, NULL, NULL, -1, 0, -1, -1, -1}
};
@ -366,6 +371,28 @@ int gpio_pud_capable(pins_t *pin)
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)
{
pins_t *p;
@ -536,10 +563,13 @@ int get_gpio_number(const char *key, int *gpio)
if (*gpio <= 0) {
*gpio = lookup_gpio_by_name(key);
if (*gpio <= 0) {
*gpio = lookup_gpio_by_altname(key);
if (*gpio <=0) {
status = -1; /* error */
}
*gpio = lookup_gpio_by_altname(key);
if (*gpio <=0) {
*gpio = lookup_gpio_by_number(key);
if (*gpio <= 0) {
status = -1; /* error */
}
}
}
}
return status;

View File

@ -86,14 +86,15 @@ typedef struct dyn_int_array_s dyn_int_array_t;
#define FILENAME_BUFFER_SIZE 128
int setup_error;
int module_setup;
int DEBUG;
extern int setup_error;
extern int module_setup;
extern int DEBUG;
int get_xio_base(void);
int is_this_chippro(void);
int gpio_number(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_name(const char *name);
int lookup_gpio_by_altname(const char *altname);

View File

@ -85,6 +85,6 @@ void define_constants(PyObject *module)
bcm = Py_BuildValue("i", BCM);
PyModule_AddObject(module, "BCM", bcm);
version = Py_BuildValue("s", "0.5.5");
version = Py_BuildValue("s", "0.7.1");
PyModule_AddObject(module, "VERSION", version);
}

View File

@ -171,13 +171,17 @@ int gpio_export(int gpio)
len = snprintf(str_gpio, sizeof(str_gpio), "%d", gpio); BUF2SMALL(str_gpio);
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);
if (s != len)
{
char err[256];
snprintf(err, sizeof(err), "gpio_export: could not write '%s' to %s (%s)", str_gpio, filename, strerror(e_no));
add_error_msg(err);
return -1;
return -2;
}
// add to list
@ -379,11 +383,23 @@ int gpio_set_direction(int gpio, unsigned int in_flag)
char filename[MAX_FILENAME]; filename[0] = '\0';
snprintf(filename, sizeof(filename), "/sys/class/gpio/gpio%d/direction", gpio); BUF2SMALL(filename);
if ((fd = open(filename, O_WRONLY)) < 0) {
// NOTIFY THAT WE'RE GOING TO SLEEP AND RETRY
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);
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];
@ -1023,7 +1039,7 @@ void event_cleanup(void)
}
// 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
{
int fd = fd_lookup(gpio);
@ -1078,7 +1094,7 @@ int blocking_wait_for_edge(int gpio, unsigned int edge)
// epoll for event
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);
return 5;

View File

@ -86,4 +86,4 @@ int gpio_event_remove(int gpio);
int gpio_is_evented(int gpio);
int event_initialise(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);

View File

@ -36,6 +36,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <stdio.h>
#include "stdlib.h"
#include "Python.h"
#include "constants.h"
@ -129,13 +130,23 @@ static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs)
{
int gpio;
char *channel;
int inchan;
static char *kwlist[] = {"channel", NULL};
clear_error_msg();
// Channel is optional
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &channel)) {
return NULL;
// Try to parse the string
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
@ -157,6 +168,7 @@ static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwar
int gpio;
int allowed = -1;
char *channel;
int inchan;
int direction;
int pud = PUD_OFF;
int initial = 0;
@ -164,13 +176,30 @@ static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwar
clear_error_msg();
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "si|ii", kwlist, &channel, &direction, &pud, &initial))
return NULL;
// Try to parse the string
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) {
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)
{
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();
}
if (gpio_export(gpio) < 0) {
int exprtn = gpio_export(gpio);
if (exprtn == -1) {
char err[2000];
snprintf(err, sizeof(err), "Error setting up channel %s, maybe already exported? (%s)", channel, get_error_msg());
PyErr_SetString(PyExc_RuntimeError, err);
return NULL;
} else if (exprtn == -2 && gpio_warnings) {
char warn[2000];
snprintf(warn, sizeof(warn), "Channel %s may already be exported, proceeding with rest of setup", channel);
PyErr_WarnEx(PyExc_Warning, warn, 1);
}
if (gpio_set_direction(gpio, direction) < 0) {
char err[2000];
@ -258,19 +292,29 @@ static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwar
Py_RETURN_NONE;
} /* py_setup_channel */
// python function output(channel, value)
static PyObject *py_output_gpio(PyObject *self, PyObject *args)
{
int gpio;
int value;
char *channel;
int inchan;
int allowed = -1;
clear_error_msg();
if (!PyArg_ParseTuple(args, "si", &channel, &value))
return NULL;
// Try to parse the string
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)) {
PyErr_SetString(PyExc_ValueError, "Invalid channel");
@ -317,14 +361,25 @@ static PyObject *py_input_gpio(PyObject *self, PyObject *args)
{
int gpio;
char *channel;
int inchan;
unsigned int value;
PyObject *py_value;
int allowed = -1;
clear_error_msg();
if (!PyArg_ParseTuple(args, "s", &channel))
return NULL;
// Try to parse the string
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)) {
PyErr_SetString(PyExc_ValueError, "Invalid channel");
@ -371,14 +426,25 @@ static PyObject *py_read_byte_gpio(PyObject *self, PyObject *args)
{
int gpio;
char *channel;
int inchan;
unsigned int value = 0;
PyObject *py_value;
int allowed = -1;
clear_error_msg();
if (!PyArg_ParseTuple(args, "s", &channel))
return NULL;
// Try to parse the string
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)) {
PyErr_SetString(PyExc_ValueError, "Invalid channel");
@ -425,14 +491,25 @@ static PyObject *py_read_word_gpio(PyObject *self, PyObject *args)
{
int gpio;
char *channel;
int inchan;
unsigned int value = 0;
PyObject *py_value;
int allowed = -1;
clear_error_msg();
if (!PyArg_ParseTuple(args, "s", &channel))
return NULL;
// Try to parse the string
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)) {
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;
}
// 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)
{
int gpio;
char *channel;
int inchan;
int allowed = -1;
unsigned int bouncetime = 0;
PyObject *cb_func;
@ -559,8 +637,18 @@ static PyObject *py_add_event_callback(PyObject *self, PyObject *args, PyObject
clear_error_msg();
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|i", kwlist, &channel, &cb_func, &bouncetime))
return NULL;
// Try to parse the string
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))
{
@ -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
if (gpio != lookup_gpio_by_name("AP-EINT3")
&& gpio != lookup_gpio_by_name("AP-EINT1")
&& gpio != lookup_gpio_by_name("I2S-MCLK") // CHIP PRO
&& gpio != lookup_gpio_by_name("I2S-DI") // CHIP PRO
&& gpio != lookup_gpio_by_name("PWM1") // CHIP PRO
&& !(gpio >= lookup_gpio_by_name("XIO-P0") && gpio <= lookup_gpio_by_name("XIO-P7"))) {
PyErr_SetString(PyExc_ValueError, "Callbacks currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only");
return NULL;
@ -615,11 +706,12 @@ static PyObject *py_add_event_callback(PyObject *self, PyObject *args, PyObject
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)
{
int gpio;
char *channel;
int inchan;
int edge, result;
unsigned int bouncetime = 0;
int allowed = -1;
@ -628,8 +720,18 @@ static PyObject *py_add_event_detect(PyObject *self, PyObject *args, PyObject *k
clear_error_msg();
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "si|Oi", kwlist, &channel, &edge, &cb_func, &bouncetime))
return NULL;
// Try to parse the string
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))
{
@ -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
if (gpio != lookup_gpio_by_name("AP-EINT3")
&& gpio != lookup_gpio_by_name("AP-EINT1")
&& gpio != lookup_gpio_by_name("I2S-MCLK") // CHIP PRO
&& gpio != lookup_gpio_by_name("I2S-DI") // CHIP PRO
&& gpio != lookup_gpio_by_name("PWM1") // CHIP PRO
&& !(gpio >= lookup_gpio_by_name("XIO-P0") && gpio <= lookup_gpio_by_name("XIO-P7"))) {
PyErr_SetString(PyExc_ValueError, "Edge Detection currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only");
return NULL;
@ -698,11 +803,12 @@ static PyObject *py_add_event_detect(PyObject *self, PyObject *args, PyObject *k
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)
{
int gpio;
char *channel;
int inchan;
struct py_callback *cb = py_callbacks;
struct py_callback *temp;
struct py_callback *prev = NULL;
@ -710,8 +816,18 @@ static PyObject *py_remove_event_detect(PyObject *self, PyObject *args)
clear_error_msg();
if (!PyArg_ParseTuple(args, "s", &channel))
return NULL;
// Try to parse the string
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)) {
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
if (gpio != lookup_gpio_by_name("AP-EINT3")
&& gpio != lookup_gpio_by_name("AP-EINT1")
&& gpio != lookup_gpio_by_name("I2S-MCLK") // CHIP PRO
&& gpio != lookup_gpio_by_name("I2S-DI") // CHIP PRO
&& gpio != lookup_gpio_by_name("PWM1") // CHIP PRO
&& !(gpio >= lookup_gpio_by_name("XIO-P0") && gpio <= lookup_gpio_by_name("XIO-P7"))) {
PyErr_SetString(PyExc_ValueError, "Edge Detection currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only");
return NULL;
@ -770,12 +889,23 @@ static PyObject *py_event_detected(PyObject *self, PyObject *args)
{
int gpio;
char *channel;
int inchan;
int allowed = -1;
clear_error_msg();
if (!PyArg_ParseTuple(args, "s", &channel))
return NULL;
// Try to parse the string
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)) {
PyErr_SetString(PyExc_ValueError, "Invalid channel");
@ -803,19 +933,32 @@ static PyObject *py_event_detected(PyObject *self, PyObject *args)
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)
{
int gpio;
int edge, result;
int edge, result, timeout;
char *channel;
int inchan;
char error[81];
int allowed = -1;
clear_error_msg();
if (!PyArg_ParseTuple(args, "si", &channel, &edge))
return NULL;
timeout = -1;
// 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)) {
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
if (gpio != lookup_gpio_by_name("AP-EINT3")
&& gpio != lookup_gpio_by_name("AP-EINT1")
&& gpio != lookup_gpio_by_name("I2S-MCLK") // CHIP PRO
&& gpio != lookup_gpio_by_name("I2S-DI") // CHIP PRO
&& gpio != lookup_gpio_by_name("PWM1") // CHIP PRO
&& !(gpio >= lookup_gpio_by_name("XIO-P0") && gpio <= lookup_gpio_by_name("XIO-P7"))) {
PyErr_SetString(PyExc_ValueError, "Edge Detection currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only");
return NULL;
@ -860,7 +1006,7 @@ static PyObject *py_wait_for_edge(PyObject *self, PyObject *args)
}
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
if (result == 0) {
@ -878,19 +1024,30 @@ static PyObject *py_wait_for_edge(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
// python function value = gpio_function(gpio)
// python function value = gpio_function(channel)
static PyObject *py_gpio_function(PyObject *self, PyObject *args)
{
int gpio;
unsigned int value;
PyObject *func;
char *channel;
int inchan;
int allowed = -1;
clear_error_msg();
if (!PyArg_ParseTuple(args, "s", &channel))
return NULL;
// Try to parse the string
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)) {
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
*/
// python function set_direction(channel, direction)
static PyObject *py_set_direction(PyObject *self, PyObject *args, PyObject *kwargs)
{
int gpio;
char *channel;
int inchan;
int direction;
int allowed = -1;
static char *kwlist[] = { "channel", "direction", NULL };
clear_error_msg();
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "si|ii", kwlist, &channel, &direction))
return NULL;
// Try to parse the string
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) {
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"},
{"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"},
{"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"},
{"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"},

View File

@ -34,11 +34,29 @@ SOFTWARE.
#include "common.h"
#include "c_pwm.h"
// python function cleanup()
static PyObject *py_cleanup(PyObject *self, PyObject *args)
// python function cleanup(channel)
static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs)
{
// unexport the PWM
pwm_cleanup();
char key[8];
char *channel;
static char *kwlist[] = {"channel", NULL};
clear_error_msg();
// Channel is optional
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &channel)) {
return NULL;
}
// The !channel fixes issues #50
if (channel == NULL || strcmp(channel, "\0") == 0) {
pwm_cleanup();
} else {
if (!get_pwm_key(channel, key)) {
pwm_cleanup();
}
pwm_disable(key);
}
Py_RETURN_NONE;
}
@ -395,7 +413,7 @@ PyMethodDef pwm_methods[] = {
{"set_frequency", (PyCFunction)py_set_frequency, METH_VARARGS, "Change the frequency\nfrequency - frequency in Hz (freq > 0.0)" },
{"set_period_ns", (PyCFunction)py_set_period_ns, METH_VARARGS, "Change the period\nperiod_ns - period in nanoseconds" },
{"set_pulse_width_ns", (PyCFunction)py_set_pulse_width_ns, METH_VARARGS, "Change the period\npulse_width_ns - pulse width in nanoseconds" },
{"cleanup", py_cleanup, METH_VARARGS, "Clean up by resetting all GPIO channels that have been used by this program to INPUT with no pullup/pulldown and no event detection"},
{"cleanup", (PyCFunction)py_cleanup, METH_VARARGS | METH_KEYWORDS, "Clean up by resetting PWM channel(s) that have been used by this program to be disabled"},
{"toggle_debug", py_toggle_debug, METH_VARARGS, "Toggles the enabling/disabling of Debug print output"},
{"is_chip_pro", py_is_chip_pro, METH_VARARGS, "Is hardware a CHIP Pro? Boolean False for normal CHIP/PocketCHIP (R8 SOC)"},
{NULL, NULL, 0, NULL}

View File

@ -50,6 +50,8 @@ static PyObject *py_toggle_debug(PyObject *self, PyObject *args)
// python function cleanup()
static PyObject *py_cleanup(PyObject *self, PyObject *args)
{
// TODO: PER PIN CLEANUP LIKE EVERYTHING ELSE
// unexport the Servo
servo_cleanup();
@ -68,7 +70,7 @@ static int init_module(void)
return 0;
}
// python function value = is_chip_pro
// python function value = is_chip_pro()
static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
{
PyObject *py_value;
@ -185,7 +187,7 @@ static PyObject *py_stop_channel(PyObject *self, PyObject *args, PyObject *kwarg
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)
{
int gpio;
@ -241,7 +243,7 @@ static PyObject *py_set_range(PyObject *self, PyObject *args, PyObject *kwargs)
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)
{
int gpio;

View File

@ -43,11 +43,29 @@ static PyObject *py_toggle_debug(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
// python function cleanup()
static PyObject *py_cleanup(PyObject *self, PyObject *args)
// python function cleanup(channel)
static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs)
{
// unexport the PWM
softpwm_cleanup();
char key[8];
char *channel;
static char *kwlist[] = {"channel", NULL};
clear_error_msg();
// Channel is optional
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &channel)) {
return NULL;
}
// The !channel fixes issues #50
if (channel == NULL || strcmp(channel, "\0") == 0) {
softpwm_cleanup();
} else {
if (!get_key(channel, key)) {
softpwm_cleanup();
}
softpwm_disable(key);
}
Py_RETURN_NONE;
}
@ -64,7 +82,7 @@ static int init_module(void)
return 0;
}
// python function value = is_chip_pro
// python function value = is_chip_pro()
static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
{
PyObject *py_value;
@ -74,7 +92,7 @@ static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
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)
{
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'"},
{"set_duty_cycle", (PyCFunction)py_set_duty_cycle, METH_VARARGS, "Change the duty cycle\ndutycycle - between 0.0 and 100.0" },
{"set_frequency", (PyCFunction)py_set_frequency, METH_VARARGS, "Change the frequency\nfrequency - frequency in Hz (freq > 0.0)" },
{"cleanup", (PyCFunction)py_cleanup, METH_VARARGS, "Clean up by resetting all GPIO channels that have been used by this program to INPUT with no pullup/pulldown and no event detection"},
{"cleanup", (PyCFunction)py_cleanup, METH_VARARGS | METH_KEYWORDS, "Clean up by resetting all GPIO channels that have been used by this program to INPUT with no pullup/pulldown and no event detection"},
{"toggle_debug", py_toggle_debug, METH_VARARGS, "Toggles the enabling/disabling of Debug print output"},
{"is_chip_pro", py_is_chip_pro, METH_VARARGS, "Is hardware a CHIP Pro? Boolean False for normal CHIP/PocketCHIP (R8 SOC)"},
{NULL, NULL, 0, NULL}