Skip to content

Commit 0b49916

Browse files
committed
Sync from upstream master
2 parents a86300f + b1557e2 commit 0b49916

File tree

4 files changed

+13
-125
lines changed

4 files changed

+13
-125
lines changed

Adafruit_BBIO/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ To add user `userName` to the `eqep` group (run this command as root):
9494
usermod -a -G eqep userName
9595
```
9696

97+
Note: you will need to log out and log back in for the group membership change to take effect.
98+
9799
### Capes
98100

99101
In order to use all eQEP pins the BeagleBone must boot with the [cape-universal](https://github.com/beagleboard/bb.org-overlays/tree/master/tools/beaglebone-universal-io) enabled, and load the `cape-universal` overlay.

Adafruit_I2C.py

Lines changed: 5 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,13 @@
11
#!/usr/bin/python
22

3-
import smbus
4-
5-
# ===========================================================================
6-
# Adafruit_I2C Class
7-
# Adafruit_I2C.py is essentially a fork of the Adafruit Raspberry Pi I2C module.
8-
# Any pull requests for this module should be directed to the following, and I
9-
# can pull them. I'd rather not deviate from the original:
10-
# https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code/tree/master/Adafruit_I2C
11-
# ===========================================================================
3+
# WARNING: THIS MODULE IS DEPRECATED!
4+
# use Adafruit_GPIO.I2C instead:
5+
# https://github.com/adafruit/Adafruit_Python_GPIO/blob/master/Adafruit_GPIO/I2C.py
126

137
class Adafruit_I2C :
148

159
def __init__(self, address, busnum=-1, debug=False):
16-
self.address = address
17-
self.bus = smbus.SMBus(busnum if busnum >= 0 else 1)
18-
self.debug = debug
19-
20-
def reverseByteOrder(self, data):
21-
"Reverses the byte order of an int (16-bit) or long (32-bit) value"
22-
# Courtesy Vishal Sapre
23-
byteCount = len(hex(data)[2:].replace('L','')[::2])
24-
val = 0
25-
for i in range(byteCount):
26-
val = (val << 8) | (data & 0xff)
27-
data >>= 8
28-
return val
29-
30-
def errMsg(self):
31-
print("Error accessing 0x%02X: Check your I2C address" % self.address)
32-
return -1
33-
34-
def write8(self, reg, value):
35-
"Writes an 8-bit value to the specified register/address"
36-
try:
37-
self.bus.write_byte_data(self.address, reg, value)
38-
if self.debug:
39-
print("I2C: Wrote 0x%02X to register 0x%02X" % (value, reg))
40-
except IOError as err:
41-
return self.errMsg()
42-
43-
def write16(self, reg, value):
44-
"Writes a 16-bit value to the specified register/address pair"
45-
try:
46-
self.bus.write_word_data(self.address, reg, value)
47-
if self.debug:
48-
print("I2C: Wrote 0x%02X to register pair 0x%02X,0x%02X" %
49-
(value, reg, reg+1))
50-
except IOError as err:
51-
return self.errMsg()
52-
53-
def writeList(self, reg, list):
54-
"Writes an array of bytes using I2C format"
55-
try:
56-
if self.debug:
57-
print("I2C: Writing list to register 0x%02X:" % reg)
58-
print(list)
59-
self.bus.write_i2c_block_data(self.address, reg, list)
60-
except IOError as err:
61-
return self.errMsg()
62-
63-
def readList(self, reg, length):
64-
"Read a list of bytes from the I2C device"
65-
try:
66-
results = self.bus.read_i2c_block_data(self.address, reg, length)
67-
if self.debug:
68-
print("I2C: Device 0x%02X returned the following from reg 0x%02X" %
69-
(self.address, reg))
70-
print(results)
71-
return results
72-
except IOError as err:
73-
return self.errMsg()
74-
75-
def readU8(self, reg):
76-
"Read an unsigned byte from the I2C device"
77-
try:
78-
result = self.bus.read_byte_data(self.address, reg)
79-
if self.debug:
80-
print("I2C: Device 0x%02X returned 0x%02X from reg 0x%02X" %
81-
(self.address, result & 0xFF, reg))
82-
return result
83-
except IOError as err:
84-
return self.errMsg()
85-
86-
def readS8(self, reg):
87-
"Reads a signed byte from the I2C device"
88-
try:
89-
result = self.bus.read_byte_data(self.address, reg)
90-
if result > 127: result -= 256
91-
if self.debug:
92-
print("I2C: Device 0x%02X returned 0x%02X from reg 0x%02X" %
93-
(self.address, result & 0xFF, reg))
94-
return result
95-
except IOError as err:
96-
return self.errMsg()
97-
98-
def readU16(self, reg):
99-
"Reads an unsigned 16-bit value from the I2C device"
100-
try:
101-
result = self.bus.read_word_data(self.address,reg)
102-
if (self.debug):
103-
print("I2C: Device 0x%02X returned 0x%04X from reg 0x%02X" % (self.address, result & 0xFFFF, reg))
104-
return result
105-
except IOError as err:
106-
return self.errMsg()
107-
108-
def readS16(self, reg):
109-
"Reads a signed 16-bit value from the I2C device"
110-
try:
111-
result = self.bus.read_word_data(self.address,reg)
112-
if (self.debug):
113-
print("I2C: Device 0x%02X returned 0x%04X from reg 0x%02X" % (self.address, result & 0xFFFF, reg))
114-
return result
115-
except IOError as err:
116-
return self.errMsg()
10+
print("WARNING: THIS MODULE IS DEPRECATED. Use Adafruit_GPIO.I2C instead.\n");
11711

11812
if __name__ == '__main__':
119-
try:
120-
bus = Adafruit_I2C(address=0)
121-
print("Default I2C bus is accessible")
122-
except:
123-
print("Error accessing default I2C bus")
13+
print("WARNING: THIS MODULE IS DEPRECATED. Use Adafruit_GPIO.I2C instead.\n");

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![PyPI version](https://badge.fury.io/py/Adafruit_BBIO.svg)](https://badge.fury.io/py/Adafruit_BBIO)
55
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/Adafruit_BBIO.svg)](https://pypi.python.org/pypi/Adafruit_BBIO/)
66

7-
Adafruit BBIO is an API to enable [GPIO](README.md#gpio-setup), [PWM](README.md#pwm), [ADC](README.md#adc), [UART](README.md#uart), SPI and eQEP hardware access from Python applications running on the Beaglebone.
7+
Adafruit BBIO is an API to enable [GPIO](README.md#gpio-setup), [PWM](README.md#pwm), [ADC](README.md#adc), [UART](README.md#uart), [SPI](README.md#spi) and [eQEP](README.md#eqep) (Quadrature Encoder) hardware access from Python applications running on the Beaglebone.
88

99
* It is recommended to use an [official BeagleBoard.org Debian image](https://beagleboard.org/latest-images)
1010
* **Currently recommended image: [Debian 9.2 "Stretch" iot (2017-10-29)](https://elinux.org/Beagleboard:BeagleBoneBlack_Debian#microSD.2FStandalone:_.28stretch-iot.29_.28All_BeagleBone_Variants_.26_PocketBeagle.29)**
@@ -250,6 +250,10 @@ print(spi.xfer2([32, 11, 110, 22, 220]))
250250
spi.close()
251251
```
252252

253+
### eQEP
254+
255+
To use the enhanced Quadrature Encoder Pulse (eQEP) module, please refer to the [`Encoder` module's documentation](https://github.com/adafruit/adafruit-beaglebone-io-python/tree/master/Adafruit_BBIO#usage).
256+
253257
## Running tests
254258

255259
Install py.test to run the tests. You'll also need the python compiler package for pytest:

source/spimodule.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,6 @@ static PyObject *
703703
SPI_open(SPI *self, PyObject *args, PyObject *kwds)
704704
{
705705
int bus, device;
706-
int bus_path;
707706
int max_dt_length = 15;
708707
char device_tree_name[max_dt_length];
709708
char path[MAXPATH];
@@ -722,14 +721,7 @@ SPI_open(SPI *self, PyObject *args, PyObject *kwds)
722721
return NULL;
723722
}
724723

725-
bus_path = get_spi_bus_path_number(bus);
726-
if (bus_path == -1) {
727-
PyErr_SetString(PyExc_OverflowError,
728-
"Unable to find loaded spi bus path.");
729-
return NULL;
730-
}
731-
732-
if (snprintf(path, MAXPATH, "/dev/spidev%d.%d", bus_path, device) >= MAXPATH) {
724+
if (snprintf(path, MAXPATH, "/dev/spidev%d.%d", bus, device) >= MAXPATH) {
733725
PyErr_SetString(PyExc_OverflowError,
734726
"Bus and/or device number is invalid.");
735727
return NULL;

0 commit comments

Comments
 (0)