Skip to content

Commit 4417378

Browse files
committed
Start SPI support
1 parent 904fa76 commit 4417378

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

pytronics.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,19 @@ def toggle(pin):
132132
def spiRead():
133133
pass
134134

135-
def spiWrite(val):
136-
pass
135+
def spiWrite(val, cs='0'):
136+
with open('/dev/spidev1.' + str(cs), 'w') as f:
137+
f.write(val)
138+
f.close()
139+
140+
def spiGetSpeed(channel='0'):
141+
import array, fcntl
142+
with open('/dev/spidev1.' + str(channel), 'w') as f:
143+
speed = array.array('i', [0])
144+
fcntl.ioctl(f, 0x80046B04, speed)
145+
return speed[0]
146+
147+
def spiSetSpeed(speed, channel='0'):
148+
import array, fcntl
149+
with open('/dev/spidev1.' + str(channel), 'w') as f:
150+
return fcntl.ioctl(f, 0x40046B04, array.array('i', [int(speed)]))

0 commit comments

Comments
 (0)