mirror of
https://github.com/xtacocorex/CHIP_IO
synced 2025-07-20 21:03:22 +00:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
84df4376f8 | |||
906beb0257 | |||
00cd5c09ad | |||
c87b0ca72a | |||
ff7bf2fa1c | |||
af9555fcdf |
@ -1,3 +1,9 @@
|
|||||||
|
0.7.1
|
||||||
|
---
|
||||||
|
* Merged in PR #79
|
||||||
|
* Merged in PR #80
|
||||||
|
* Added message notifying user of the gpio set direction retry
|
||||||
|
|
||||||
0.7.0
|
0.7.0
|
||||||
---
|
---
|
||||||
* Added ability to specify GPIO only as a number, this doesn't work for PWM/SPWM/LRADC/SERVO
|
* Added ability to specify GPIO only as a number, this doesn't work for PWM/SPWM/LRADC/SERVO
|
||||||
|
@ -255,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)
|
||||||
|
7
debian/changelog
vendored
7
debian/changelog
vendored
@ -1,3 +1,10 @@
|
|||||||
|
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
|
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
|
* Added ability to specify GPIO only as a number, this doesn't work for PWM/SPWM/LRADC/SERVO
|
||||||
|
4
debian/files
vendored
4
debian/files
vendored
@ -1,2 +1,2 @@
|
|||||||
python-chip-io_0.7.0-1_armhf.deb python optional
|
python-chip-io_0.7.1-1_armhf.deb python optional
|
||||||
python3-chip-io_0.7.0-1_armhf.deb python optional
|
python3-chip-io_0.7.1-1_armhf.deb python optional
|
||||||
|
15
docs/gpio.md
15
docs/gpio.md
@ -5,6 +5,8 @@ Import the GPIO module as follows
|
|||||||
import CHIP_IO.GPIO as GPIO
|
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()
|
### toggle_debug()
|
||||||
Enable/Disable the Debug
|
Enable/Disable the Debug
|
||||||
|
|
||||||
@ -56,6 +58,7 @@ Setup a GPIO pin. If pin is already configure, it will reconfigure.
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
GPIO.setup("CSID0", GPIO.IN)
|
GPIO.setup("CSID0", GPIO.IN)
|
||||||
|
GPIO.setup(132, GPIO.IN)
|
||||||
GPIO.setup("CSID3", GPIO.OUT, initial=1)
|
GPIO.setup("CSID3", GPIO.OUT, initial=1)
|
||||||
GPIO.setup("CSID2", GPIO.IN, GPIO.PUD_UP)
|
GPIO.setup("CSID2", GPIO.IN, GPIO.PUD_UP)
|
||||||
```
|
```
|
||||||
@ -76,6 +79,7 @@ Cleanup GPIO. If not channel input, all GPIO will be cleaned up
|
|||||||
```python
|
```python
|
||||||
GPIO.cleanup()
|
GPIO.cleanup()
|
||||||
GPIO.cleanup("CSID3")
|
GPIO.cleanup("CSID3")
|
||||||
|
GPIO.cleanup(132)
|
||||||
```
|
```
|
||||||
|
|
||||||
### output(channel, value)
|
### output(channel, value)
|
||||||
@ -97,6 +101,7 @@ Write a value to a GPIO pin.
|
|||||||
GPIO.output("XIO-P7", GPIO.LOW)
|
GPIO.output("XIO-P7", GPIO.LOW)
|
||||||
GPIO.output("CSID0", 1)
|
GPIO.output("CSID0", 1)
|
||||||
GPIO.output("CSID0", 0)
|
GPIO.output("CSID0", 0)
|
||||||
|
GPIO.output(132, 1)
|
||||||
```
|
```
|
||||||
|
|
||||||
### input(channel)
|
### input(channel)
|
||||||
@ -114,6 +119,7 @@ Read a GPIO pin once.
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
value = GPIO.input("XIO-P7")
|
value = GPIO.input("XIO-P7")
|
||||||
|
value = GPIO.input(1013)
|
||||||
```
|
```
|
||||||
|
|
||||||
### read_byte(channel)
|
### read_byte(channel)
|
||||||
@ -131,6 +137,7 @@ Read a GPIO pin multiple times to fill up 8 bits.
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
bits = GPIO.read_byte("XIO-P7")
|
bits = GPIO.read_byte("XIO-P7")
|
||||||
|
bits = GPIO.read_byte(135)
|
||||||
```
|
```
|
||||||
|
|
||||||
### read_word(channel)
|
### read_word(channel)
|
||||||
@ -148,6 +155,7 @@ Read a GPIO pin multiple times to fill up 16 bits.
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
bits = GPIO.read_word("XIO-P7")
|
bits = GPIO.read_word("XIO-P7")
|
||||||
|
bits = GPIO.read_word(134)
|
||||||
```
|
```
|
||||||
|
|
||||||
### add_event_detect(channel, edge, callback=None, bouncetime=0)
|
### add_event_detect(channel, edge, callback=None, bouncetime=0)
|
||||||
@ -171,6 +179,7 @@ Add event detection to a pin. Refer to main table for which pins are able to use
|
|||||||
GPIO.add_event_detect("AP-EINT3", GPIO.RISING_EDGE, mycallback)
|
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.FALLING_EDGE, bouncetime=30)
|
||||||
GPIO.add_event_detect("XIO-P7", GPIO.RISING_EDGE, mycallback, 45)
|
GPIO.add_event_detect("XIO-P7", GPIO.RISING_EDGE, mycallback, 45)
|
||||||
|
GPIO.add_event_detect(1013, GPIO.BOTH_EDGE)
|
||||||
```
|
```
|
||||||
|
|
||||||
### remove_event_detect(channel)
|
### remove_event_detect(channel)
|
||||||
@ -188,6 +197,7 @@ Remove a pins event detection. Refer to main table for which pins are able to us
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
GPIO.remove_event_detect("XIO-P7")
|
GPIO.remove_event_detect("XIO-P7")
|
||||||
|
GPIO.remove_event_detect(1013)
|
||||||
```
|
```
|
||||||
|
|
||||||
### event_detected(channel)
|
### event_detected(channel)
|
||||||
@ -205,6 +215,7 @@ Function to determine if an event was detected on a pin. Pin must have an event
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
have_event = GPIO.event_detected("XIO-P5")
|
have_event = GPIO.event_detected("XIO-P5")
|
||||||
|
have_event = GPIO.event_detected(1014)
|
||||||
```
|
```
|
||||||
|
|
||||||
### add_event_callback(channel, callback, bouncetime=0)
|
### add_event_callback(channel, callback, bouncetime=0)
|
||||||
@ -225,6 +236,7 @@ Add callback function to a pin that has been setup for edge detection. Refer to
|
|||||||
```python
|
```python
|
||||||
GPIO.add_event_callback("AP-EINT3", mycallback)
|
GPIO.add_event_callback("AP-EINT3", mycallback)
|
||||||
GPIO.add_event_callback("XIO-P7", mycallback, 45)
|
GPIO.add_event_callback("XIO-P7", mycallback, 45)
|
||||||
|
GPIO.add_event_callback(1013, mycallback)
|
||||||
```
|
```
|
||||||
|
|
||||||
### wait_for_edge(channel, edge, timeout=-1)
|
### wait_for_edge(channel, edge, timeout=-1)
|
||||||
@ -247,6 +259,7 @@ Wait for an edge to be detected. This is a blocking function. Refer to main tab
|
|||||||
GPIO.wait_for_edge("AP-EINT3", GPIO.BOTH_EDGE)
|
GPIO.wait_for_edge("AP-EINT3", GPIO.BOTH_EDGE)
|
||||||
GPIO.wait_for_edge("I2S-DI", GPIO.FALLING_EDGE)
|
GPIO.wait_for_edge("I2S-DI", GPIO.FALLING_EDGE)
|
||||||
GPIO.wait_for_edge("XIO-P3", GPIO.RISING_EDGE, 40)
|
GPIO.wait_for_edge("XIO-P3", GPIO.RISING_EDGE, 40)
|
||||||
|
GPIO.wait_for_edge(1013, GPIO.BOTH_EDGE, 35)
|
||||||
```
|
```
|
||||||
|
|
||||||
### gpio_function(channel)
|
### gpio_function(channel)
|
||||||
@ -264,6 +277,7 @@ Function to report get a GPIO Pins directioj
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
funct = GPIO.gpio_function("CSID0")
|
funct = GPIO.gpio_function("CSID0")
|
||||||
|
funct = GPIO.gpio_function(132)
|
||||||
```
|
```
|
||||||
|
|
||||||
### setwarnings(state)
|
### setwarnings(state)
|
||||||
@ -334,6 +348,7 @@ Function to set the direction of an exported GPIO pin
|
|||||||
```python
|
```python
|
||||||
GPIO.set_direction("XIO-P0", GPIO.OUT)
|
GPIO.set_direction("XIO-P0", GPIO.OUT)
|
||||||
GPIO.set_direction("XIO-P1", GPIO.IN)
|
GPIO.set_direction("XIO-P1", GPIO.IN)
|
||||||
|
GPIO.set_direction(1013, GPIO.OUT)
|
||||||
```
|
```
|
||||||
|
|
||||||
[home](./index.md)
|
[home](./index.md)
|
||||||
|
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.7.0',
|
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',
|
||||||
|
@ -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.7");
|
version = Py_BuildValue("s", "0.7.1");
|
||||||
PyModule_AddObject(module, "VERSION", version);
|
PyModule_AddObject(module, "VERSION", version);
|
||||||
}
|
}
|
||||||
|
@ -383,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) {
|
||||||
|
Reference in New Issue
Block a user