]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/spi/pd.py
sdcard_spi: Fix handling of some warning annotations.
[libsigrokdecode.git] / decoders / spi / pd.py
index 2d971d31c4fb8657765489f4a6393eb5046f05f9..3bebc7d6efa70e822069eeb5002a47ddc1e31748 100644 (file)
@@ -150,9 +150,11 @@ class Decoder(srd.Decoder):
 
         # Dataword annotations.
         if self.have_miso:
-            self.putw([0, ['%02X' % self.misodata]])
+            ss, es = self.misobits[0][1], self.misobits[-1][2]
+            self.put(ss, es, self.out_ann, [0, ['%02X' % self.misodata]])
         if self.have_mosi:
-            self.putw([1, ['%02X' % self.mosidata]])
+            ss, es = self.mosibits[0][1], self.mosibits[-1][2]
+            self.put(ss, es, self.out_ann, [1, ['%02X' % self.mosidata]])
 
     def reset_decoder_state(self):
         self.misodata = 0 if self.have_miso else None
@@ -187,7 +189,7 @@ class Decoder(srd.Decoder):
             else:
                 self.mosidata |= mosi << self.bitcount
 
-        # Guesstimate the endsample for this bit (can be overridden later).
+        # Guesstimate the endsample for this bit (can be overridden below).
         es = self.samplenum
         if self.bitcount > 0:
             es += self.samplenum - self.misobits[self.bitcount - 1][1]
@@ -264,6 +266,10 @@ class Decoder(srd.Decoder):
             self.have_mosi = (mosi in (0, 1))
             self.have_cs = (cs in (0, 1))
 
+            # Either MISO or MOSI (but not both) can be omitted.
+            if not (self.have_miso or self.have_mosi):
+                raise Exception('Either MISO or MOSI (or both) pins required.')
+
             # State machine.
             if self.state == 'IDLE':
                 self.find_clk_edge(miso, mosi, clk, cs)