mirror of
https://github.com/xtacocorex/CHIP_IO
synced 2025-07-20 04:43:21 +00:00
Compare commits
32 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 |
@ -1,3 +1,35 @@
|
|||||||
|
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
|
0.5.8
|
||||||
---
|
---
|
||||||
* Added 3 pins for the CHIP Pro as allowable for setting callbacks and edge detection to close out Issue #68
|
* Added 3 pins for the CHIP Pro as allowable for setting callbacks and edge detection to close out Issue #68
|
||||||
|
10
Makefile
10
Makefile
@ -1,10 +1,16 @@
|
|||||||
# PyPi Packaging
|
# PyPi Packaging
|
||||||
package: clean
|
package: clean
|
||||||
@echo " ** PACKAGING FOR PYPI **"
|
@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
|
# PyPi Publishing
|
||||||
publish: package
|
publish: package package3
|
||||||
@echo " ** UPLOADING TO PYPI **"
|
@echo " ** UPLOADING TO PYPI **"
|
||||||
twine upload dist/*
|
twine upload dist/*
|
||||||
|
|
||||||
|
290
README.rst
290
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,6 +244,7 @@ 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")
|
||||||
|
|
||||||
@ -230,7 +255,7 @@ You can quickly change a pins direction::
|
|||||||
GPIO.direction("XIO-P3", GPIO.OUT)
|
GPIO.direction("XIO-P3", GPIO.OUT)
|
||||||
GPIO.direction("XIO-P3", GPIO.IN)
|
GPIO.direction("XIO-P3", GPIO.IN)
|
||||||
|
|
||||||
You can also re-setup a pin in order to change direction, not that this is a slower operation::
|
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.OUT)
|
||||||
GPIO.setup("XIO-P3", GPIO.IN)
|
GPIO.setup("XIO-P3", GPIO.IN)
|
||||||
@ -246,6 +271,7 @@ 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!"
|
||||||
@ -256,17 +282,24 @@ CHIP_IO can also handle adding callback functions on any pin that supports edge
|
|||||||
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 Event Detect and Callback Separately for Falling Edge
|
# Add Event Detect and Callback Separately for Falling Edge
|
||||||
GPIO.add_event_detect("GPIO3", GPIO.FALLING)
|
GPIO.add_event_detect("GPIO3", GPIO.FALLING)
|
||||||
GPIO.add_event_callback("GPIO3", mycallback)
|
GPIO.add_event_callback("GPIO3", mycallback)
|
||||||
|
|
||||||
# Add Event Detect and Callback Separately for Rising Edge
|
# Add Event Detect and Callback Separately for Rising Edge
|
||||||
GPIO.add_event_detect("GPIO3", GPIO.RISING)
|
GPIO.add_event_detect("GPIO3", GPIO.RISING)
|
||||||
GPIO.add_event_callback("GPIO3", mycallback)
|
GPIO.add_event_callback("GPIO3", mycallback)
|
||||||
|
|
||||||
# Add Callback for Both Edges using the add_event_detect() method
|
# Add Callback for Both Edges using the add_event_detect() method
|
||||||
GPIO.add_event_detect("GPIO3", GPIO.BOTH, mycallback)
|
GPIO.add_event_detect("GPIO3", GPIO.BOTH, mycallback)
|
||||||
|
|
||||||
# Remove callback with the following
|
# 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**
|
||||||
|
|
||||||
@ -274,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")
|
||||||
|
|
||||||
@ -286,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)
|
||||||
|
|
||||||
@ -306,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)
|
||||||
|
|
||||||
@ -332,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()
|
||||||
|
|
||||||
@ -355,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()
|
||||||
@ -389,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")
|
||||||
|
|
||||||
@ -404,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")
|
||||||
|
|
||||||
@ -420,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()
|
||||||
|
43
debian/changelog
vendored
43
debian/changelog
vendored
@ -1,3 +1,46 @@
|
|||||||
|
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
|
chip-io (0.5.8-1) unstable; urgency=low
|
||||||
|
|
||||||
* Added 3 pins for the CHIP Pro as allowable for setting callbacks and edge
|
* Added 3 pins for the CHIP Pro as allowable for setting callbacks and edge
|
||||||
|
4
debian/files
vendored
4
debian/files
vendored
@ -1,2 +1,2 @@
|
|||||||
python-chip-io_0.5.7-1_armhf.deb python optional
|
python-chip-io_0.7.1-1_armhf.deb python optional
|
||||||
python3-chip-io_0.5.7-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.8',
|
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',
|
||||||
|
@ -371,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;
|
||||||
@ -542,11 +564,14 @@ int get_gpio_number(const char *key, int *gpio)
|
|||||||
*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) {
|
||||||
|
*gpio = lookup_gpio_by_number(key);
|
||||||
if (*gpio <= 0) {
|
if (*gpio <= 0) {
|
||||||
status = -1; /* error */
|
status = -1; /* error */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.8");
|
version = Py_BuildValue("s", "0.7.1");
|
||||||
PyModule_AddObject(module, "VERSION", version);
|
PyModule_AddObject(module, "VERSION", version);
|
||||||
}
|
}
|
||||||
|
@ -171,6 +171,10 @@ 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)
|
||||||
{
|
{
|
||||||
@ -379,12 +383,24 @@ 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) {
|
||||||
|
// NOTIFY THAT WE'RE GOING TO SLEEP AND RETRY
|
||||||
|
char err[256];
|
||||||
|
snprintf(err, sizeof(err), "gpio_set_direction: could not open '%s', sleeping for 1 second and retrying", filename);
|
||||||
|
add_error_msg(err);
|
||||||
|
// 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) {
|
if ((fd = open(filename, O_WRONLY)) < 0) {
|
||||||
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' (%s)", filename, strerror(errno));
|
||||||
add_error_msg(err);
|
add_error_msg(err);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char direction[16];
|
char direction[16];
|
||||||
if (in_flag) {
|
if (in_flag) {
|
||||||
@ -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);
|
||||||
|
197
source/py_gpio.c
197
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,14 +130,24 @@ 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
|
||||||
|
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;
|
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
|
||||||
if (channel == NULL || strcmp(channel, "\0") == 0) {
|
if (channel == NULL || strcmp(channel, "\0") == 0) {
|
||||||
@ -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
|
||||||
|
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;
|
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()");
|
||||||
@ -263,19 +292,29 @@ static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwar
|
|||||||
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
|
||||||
|
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;
|
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");
|
||||||
@ -322,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
|
||||||
|
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;
|
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");
|
||||||
@ -376,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
|
||||||
|
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;
|
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");
|
||||||
@ -430,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
|
||||||
|
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;
|
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");
|
||||||
@ -552,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;
|
||||||
@ -564,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
|
||||||
|
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;
|
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))
|
||||||
{
|
{
|
||||||
@ -623,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;
|
||||||
@ -636,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
|
||||||
|
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;
|
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))
|
||||||
{
|
{
|
||||||
@ -709,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;
|
||||||
@ -721,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
|
||||||
|
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;
|
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");
|
||||||
@ -784,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
|
||||||
|
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;
|
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");
|
||||||
@ -817,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;
|
||||||
|
|
||||||
|
// 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;
|
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");
|
||||||
@ -877,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) {
|
||||||
@ -895,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
|
||||||
|
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;
|
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");
|
||||||
@ -1110,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
|
||||||
|
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;
|
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();
|
||||||
@ -1179,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"},
|
||||||
|
@ -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;
|
||||||
|
@ -82,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;
|
||||||
@ -92,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];
|
||||||
|
Reference in New Issue
Block a user