diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2012-05-16 22:48:47 +0200 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2012-05-17 00:07:27 +0200 |
commit | 3e3c03309ee21d839f85e981d361ca77b08d5ba0 (patch) | |
tree | 63dbbb3ac20d9e120a9b4dec1c03aa3e9f14bf29 /decoders/spi/spi.py | |
parent | bdd820e3c0c2681b171fc7cc0198244f40a64b34 (diff) | |
download | libsigrokdecode-3e3c03309ee21d839f85e981d361ca77b08d5ba0.tar.gz libsigrokdecode-3e3c03309ee21d839f85e981d361ca77b08d5ba0.zip |
srd: spi: Document output protocol, send CS# changes.
As per guidelines in HACKING, the protocol "commands"/items should be ALLCAPS,
thus change 'data' to 'DATA'. Also, fix MX25Lxx05D protocol decoder
accordingly, currently the only one we have which stacks on top of SPI.
Add a new 'CS-CHANGE' output protocol item, which is sent upon every
change of the CS# pin value (either 0->1, or vice versa). This is needed
by various higher-level PDs.
Diffstat (limited to 'decoders/spi/spi.py')
-rw-r--r-- | decoders/spi/spi.py | 11 |
1 files changed, 10 insertions, 1 deletions
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)]]) |