]> sigrok.org Git - libsigrokdecode.git/commitdiff
spi: Simplify some code chunks.
authorUwe Hermann <redacted>
Thu, 15 Jun 2017 21:34:56 +0000 (23:34 +0200)
committerUwe Hermann <redacted>
Fri, 16 Jun 2017 10:48:39 +0000 (12:48 +0200)
decoders/spi/pd.py

index b08b8a8d93ee0a208160fac6b7805b1573d17159..7b979f0762bf3e50e555627344f26f916ec9c272 100644 (file)
@@ -207,17 +207,18 @@ class Decoder(srd.Decoder):
                 not self.cs_asserted(cs) if self.have_cs else False
 
         ws = self.options['wordsize']
                 not self.cs_asserted(cs) if self.have_cs else False
 
         ws = self.options['wordsize']
+        bo = self.options['bitorder']
 
         # Receive MISO bit into our shift register.
         if self.have_miso:
 
         # Receive MISO bit into our shift register.
         if self.have_miso:
-            if self.options['bitorder'] == 'msb-first':
+            if bo == 'msb-first':
                 self.misodata |= miso << (ws - 1 - self.bitcount)
             else:
                 self.misodata |= miso << self.bitcount
 
         # Receive MOSI bit into our shift register.
         if self.have_mosi:
                 self.misodata |= miso << (ws - 1 - self.bitcount)
             else:
                 self.misodata |= miso << self.bitcount
 
         # Receive MOSI bit into our shift register.
         if self.have_mosi:
-            if self.options['bitorder'] == 'msb-first':
+            if bo == 'msb-first':
                 self.mosidata |= mosi << (ws - 1 - self.bitcount)
             else:
                 self.mosidata |= mosi << self.bitcount
                 self.mosidata |= mosi << (ws - 1 - self.bitcount)
             else:
                 self.mosidata |= mosi << self.bitcount
@@ -252,7 +253,7 @@ class Decoder(srd.Decoder):
         if self.samplerate is not None:
             elapsed = 1 / float(self.samplerate)
             elapsed *= (self.samplenum - self.ss_block + 1)
         if self.samplerate is not None:
             elapsed = 1 / float(self.samplerate)
             elapsed *= (self.samplenum - self.ss_block + 1)
-            bitrate = int(1 / elapsed * self.options['wordsize'])
+            bitrate = int(1 / elapsed * ws)
             self.put(self.ss_block, self.samplenum, self.out_bitrate, bitrate)
 
         if self.have_cs and self.cs_was_deasserted:
             self.put(self.ss_block, self.samplenum, self.out_bitrate, bitrate)
 
         if self.have_cs and self.cs_was_deasserted:
@@ -326,12 +327,9 @@ class Decoder(srd.Decoder):
         # process the very first sample before checking for edges. The
         # previous implementation did this by seeding old values with
         # None, which led to an immediate "change" in comparison.
         # process the very first sample before checking for edges. The
         # previous implementation did this by seeding old values with
         # None, which led to an immediate "change" in comparison.
-        pins = self.wait({})
-        (clk, miso, mosi, cs) = pins
+        (clk, miso, mosi, cs) = self.wait({})
         self.find_clk_edge(miso, mosi, clk, cs, True)
 
         while True:
         self.find_clk_edge(miso, mosi, clk, cs, True)
 
         while True:
-            # Ignore identical samples early on (for performance reasons).
-            pins = self.wait(wait_cond)
-            (clk, miso, mosi, cs) = pins
+            (clk, miso, mosi, cs) = self.wait(wait_cond)
             self.find_clk_edge(miso, mosi, clk, cs, False)
             self.find_clk_edge(miso, mosi, clk, cs, False)