Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
V
vSPI
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rasky
vSPI
Commits
7d13bfe3
Commit
7d13bfe3
authored
Feb 28, 2012
by
Michael Lyons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moving SPI calls into spilib module
parent
585b81c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
58 deletions
+60
-58
spilib.py
scripts/master/spilib.py
+57
-0
spitest.py
scripts/master/spitest.py
+3
-58
No files found.
scripts/master/spilib.py
0 → 100644
View file @
7d13bfe3
from
cheetah_py
import
*
class
SpiComm
:
"""Controls a Cheetah USB/SPI adapter to talk over SPI to the spiifc
module"""
_port
=
0
# Change if using multiple Cheetahs
_mode
=
3
# spiifc SPI mode
_bitrate
=
30000
# bytes
handle
=
None
# handle to Cheetah SPI
class
SpiCommError
(
Exception
):
"""There was some error interacting with the Cheetah SPI adapter"""
def
__init__
(
self
,
msg
):
self
.
msg
=
msg
def
__init__
(
self
):
self
.
handle
=
ch_open
(
self
.
_port
)
if
(
self
.
handle
<=
0
):
raise
SpiCommError
(
"Unable to open Cheetah device on port
%
d.
\n
Error code =
%
d (
%
s)"
%
(
self
.
_port
,
self
.
handle
,
ch_status_string
(
self
.
handle
)))
ch_host_ifce_speed
(
self
.
handle
)
ch_spi_configure
(
self
.
handle
,
(
self
.
_mode
>>
1
),
self
.
_mode
&
1
,
CH_SPI_BITORDER_MSB
,
0x0
)
ch_spi_bitrate
(
self
.
handle
,
self
.
_bitrate
)
def
__del__
(
self
):
ch_close
(
self
.
handle
)
def
SendToSlave
(
self
,
byteArray
):
byteCount
=
len
(
byteArray
)
+
1
data_in
=
array
(
'B'
,
[
0
for
i
in
range
(
byteCount
)])
actualByteCount
=
0
ch_spi_queue_clear
(
self
.
handle
)
ch_spi_queue_oe
(
self
.
handle
,
1
)
ch_spi_queue_ss
(
self
.
handle
,
0x1
)
ch_spi_queue_byte
(
self
.
handle
,
1
,
1
)
# Sending data to slave
for
byte
in
byteArray
:
ch_spi_queue_byte
(
self
.
handle
,
1
,
byte
)
ch_spi_queue_ss
(
self
.
handle
,
0
)
(
actualByteCount
,
data_in
)
=
ch_spi_batch_shift
(
self
.
handle
,
byteCount
)
def
RecvFromSlave
(
self
,
byteCount
):
totalByteCount
=
byteCount
+
1
# Extra byte for cmd
data_in
=
array
(
'B'
,
[
0
for
i
in
range
(
totalByteCount
)])
actualByteCount
=
0
ch_spi_queue_clear
(
self
.
handle
)
ch_spi_queue_oe
(
self
.
handle
,
1
)
ch_spi_queue_ss
(
self
.
handle
,
0x1
)
ch_spi_queue_byte
(
self
.
handle
,
1
,
3
)
# Receive data from slave
for
byteIndex
in
range
(
byteCount
):
ch_spi_queue_byte
(
self
.
handle
,
1
,
0
)
ch_spi_queue_ss
(
self
.
handle
,
0
)
(
actualByteCount
,
data_in
)
=
ch_spi_batch_shift
(
self
.
handle
,
totalByteCount
)
return
data_in
scripts/master/spitest.py
View file @
7d13bfe3
from
cheetah_py
import
*
import
sys
from
time
import
*
import
spilib
class
SpiComm
:
"""Controls a Cheetah USB/SPI adapter to talk over SPI to the spiifc
module"""
_port
=
0
# Change if using multiple Cheetahs
_mode
=
3
# spiifc SPI mode
_bitrate
=
30000
# bytes
handle
=
None
# handle to Cheetah SPI
class
SpiCommError
(
Exception
):
"""There was some error interacting with the Cheetah SPI adapter"""
def
__init__
(
self
,
msg
):
self
.
msg
=
msg
def
__init__
(
self
):
self
.
handle
=
ch_open
(
self
.
_port
)
if
(
self
.
handle
<=
0
):
raise
SpiCommError
(
"Unable to open Cheetah device on port
%
d.
\n
Error code =
%
d (
%
s)"
%
(
self
.
_port
,
self
.
handle
,
ch_status_string
(
self
.
handle
)))
ch_host_ifce_speed
(
self
.
handle
)
ch_spi_configure
(
self
.
handle
,
(
self
.
_mode
>>
1
),
self
.
_mode
&
1
,
CH_SPI_BITORDER_MSB
,
0x0
)
ch_spi_bitrate
(
self
.
handle
,
self
.
_bitrate
)
def
__del__
(
self
):
ch_close
(
self
.
handle
)
def
SendToSlave
(
self
,
byteArray
):
byteCount
=
len
(
byteArray
)
+
1
data_in
=
array
(
'B'
,
[
0
for
i
in
range
(
byteCount
)])
actualByteCount
=
0
ch_spi_queue_clear
(
self
.
handle
)
ch_spi_queue_oe
(
self
.
handle
,
1
)
ch_spi_queue_ss
(
self
.
handle
,
0x1
)
ch_spi_queue_byte
(
self
.
handle
,
1
,
1
)
# Sending data to slave
for
byte
in
byteArray
:
ch_spi_queue_byte
(
self
.
handle
,
1
,
byte
)
ch_spi_queue_ss
(
self
.
handle
,
0
)
(
actualByteCount
,
data_in
)
=
ch_spi_batch_shift
(
self
.
handle
,
byteCount
)
def
RecvFromSlave
(
self
,
byteCount
):
totalByteCount
=
byteCount
+
1
# Extra byte for cmd
data_in
=
array
(
'B'
,
[
0
for
i
in
range
(
totalByteCount
)])
actualByteCount
=
0
ch_spi_queue_clear
(
self
.
handle
)
ch_spi_queue_oe
(
self
.
handle
,
1
)
ch_spi_queue_ss
(
self
.
handle
,
0x1
)
ch_spi_queue_byte
(
self
.
handle
,
1
,
3
)
# Receive data from slave
for
byteIndex
in
range
(
byteCount
):
ch_spi_queue_byte
(
self
.
handle
,
1
,
0
)
ch_spi_queue_ss
(
self
.
handle
,
0
)
(
actualByteCount
,
data_in
)
=
ch_spi_batch_shift
(
self
.
handle
,
totalByteCount
)
return
data_in
# Initialize Cheetah SPI/USB adapter
# Initialize Cheetah SPI/USB adapter
spi
=
SpiComm
()
spi
=
spilib
.
SpiComm
()
# Send some data to the slave
# Send some data to the slave
sys
.
stdout
.
write
(
"Sending data to slave..."
);
sys
.
stdout
.
write
(
"Sending data to slave..."
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment