summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
Diffstat (limited to 'decoders')
-rw-r--r--decoders/mx25lxx05d/mx25lxx05d.py2
-rw-r--r--decoders/spi/__init__.py18
-rw-r--r--decoders/spi/spi.py11
3 files changed, 29 insertions, 2 deletions
diff --git a/decoders/mx25lxx05d/mx25lxx05d.py b/decoders/mx25lxx05d/mx25lxx05d.py
index f7c8476..eb0e798 100644
--- a/decoders/mx25lxx05d/mx25lxx05d.py
+++ b/decoders/mx25lxx05d/mx25lxx05d.py
@@ -232,7 +232,7 @@ class Decoder(srd.Decoder):
ptype, mosi, miso = data
- if ptype != 'data':
+ if ptype != 'DATA':
return
cmd = mosi
diff --git a/decoders/spi/__init__.py b/decoders/spi/__init__.py
index c1b5889..8734acf 100644
--- a/decoders/spi/__init__.py
+++ b/decoders/spi/__init__.py
@@ -23,6 +23,24 @@ Serial Peripheral Interface protocol decoder.
Details:
TODO
+
+Protocol output format:
+
+SPI packet:
+[<cmd>, <data1>, <data2>]
+
+Commands:
+ - 'DATA': <data1> contains the MISO data, <data2> contains the MOSI data.
+ The data is _usually_ 8 bits (but can also be fewer or more bits).
+ Both data items are Python numbers, not strings.
+ - 'CS CHANGE': <data1> is the old CS# pin value, <data2> is the new value.
+ Both data items are Python numbers (0/1), not strings.
+
+Example:
+ ['CS-CHANGE', 1, 0]
+ ['DATA', 0xff, 0x3a]
+ ['DATA', 0x65, 0x00]
+ ['CS-CHANGE', 0, 1]
'''
from .spi import *
diff --git a/decoders/spi/spi.py b/decoders/spi/spi.py
index 72a3dfb..2f10ef4 100644
--- a/decoders/spi/spi.py
+++ b/decoders/spi/spi.py
@@ -73,6 +73,7 @@ class Decoder(srd.Decoder):
self.bytesreceived = 0
self.samplenum = -1
self.cs_was_deasserted_during_data_word = 0
+ self.oldcs = -1
def start(self, metadata):
self.out_proto = self.add(srd.OUTPUT_PROTO, 'spi')
@@ -85,6 +86,14 @@ class Decoder(srd.Decoder):
# TODO: Either MISO or MOSI could be optional. CS# is optional.
for (self.samplenum, (miso, mosi, sck, cs)) in data:
+ if self.oldcs != cs:
+ # Send all CS# pin value changes.
+ self.put(self.samplenum, self.samplenum, self.out_proto,
+ ['CS-CHANGE', self.oldcs, cs])
+ self.put(self.samplenum, self.samplenum, self.out_ann,
+ [0, ['CS-CHANGE: %d->%d' % (self.oldcs, cs)]])
+ self.oldcs = cs
+
# Ignore sample if the clock pin hasn't changed.
if sck == self.oldsck:
continue
@@ -131,7 +140,7 @@ class Decoder(srd.Decoder):
continue
self.put(self.start_sample, self.samplenum, self.out_proto,
- ['data', self.mosidata, self.misodata])
+ ['DATA', self.mosidata, self.misodata])
self.put(self.start_sample, self.samplenum, self.out_ann,
[ANN_HEX, ['MOSI: 0x%02x, MISO: 0x%02x' % (self.mosidata,
self.misodata)]])