-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi2c_stream.py
55 lines (39 loc) · 1.07 KB
/
i2c_stream.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python
import sys
class BP_I2C:
def __init__(self):
from pyBusPirate.BinaryMode.I2C import *
self.i2c = I2C('/dev/ttyUSB0', 115200)
if not self.i2c.BBmode():
print 'Failed to enter BitBang mode'
sys.exit()
if not self.i2c.enter_I2C():
print 'Failed to enter I2C mode'
sys.exit()
if not self.i2c.set_speed(I2CSpeed._400KHZ):
print 'Failed to set I2C speed'
sys.exit()
self.i2c.timeout(0.2)
def close(self):
if not self.i2c.resetBP():
print 'Failed to reset BP to user terminal'
def start(self):
self.i2c.send_start_bit()
def stop(self):
self.i2c.send_stop_bit()
def write(self, data):
self.i2c.bulk_trans(len(data), data)
class XB_I2C:
def __init__(self):
self.w = open('/dev/xillybus_write_8','w')
def close(self):
self.w.close()
def start(self):
self.w.write('\xff\x02\x01')
self.w.flush()
def stop(self):
self.w.write('\xff\x02\x02')
self.w.flush()
def write(self, data):
self.w.write(''.join(map(chr,data)))
self.w.flush()