+ # Receive MOSI bit into our shift register.
+ if self.have_mosi:
+ if bo == 'msb-first':
+ self.mosidata |= mosi << (ws - 1 - self.bitcount)
+ else:
+ self.mosidata |= mosi << self.bitcount
+
+ # Guesstimate the endsample for this bit (can be overridden below).
+ es = self.samplenum
+ if self.bitcount > 0:
+ if self.have_miso:
+ es += self.samplenum - self.misobits[0][1]
+ elif self.have_mosi:
+ es += self.samplenum - self.mosibits[0][1]
+
+ if self.have_miso:
+ self.misobits.insert(0, [miso, self.samplenum, es])
+ if self.have_mosi:
+ self.mosibits.insert(0, [mosi, self.samplenum, es])
+
+ if self.bitcount > 0 and self.have_miso:
+ self.misobits[1][2] = self.samplenum
+ if self.bitcount > 0 and self.have_mosi:
+ self.mosibits[1][2] = self.samplenum
+
+ self.bitcount += 1
+
+ # Continue to receive if not enough bits were received, yet.
+ if self.bitcount != ws:
+ return
+
+ self.putdata()
+
+ # Meta bitrate.
+ if self.samplerate:
+ elapsed = 1 / float(self.samplerate)
+ elapsed *= (self.samplenum - self.ss_block + 1)
+ 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.putw([4, ['CS# was deasserted during this data word!']])
+
+ self.reset_decoder_state()
+
+ def find_clk_edge(self, miso, mosi, clk, cs, first):
+ if self.have_cs and (first or self.matched[self.have_cs]):
+ # Send all CS# pin value changes.
+ oldcs = None if first else 1 - cs
+ self.put(self.samplenum, self.samplenum, self.out_python,
+ ['CS-CHANGE', oldcs, cs])
+
+ if self.cs_asserted(cs):
+ self.ss_transfer = self.samplenum
+ self.misobytes = []
+ self.mosibytes = []
+ elif self.ss_transfer != -1:
+ if self.have_miso:
+ self.put(self.ss_transfer, self.samplenum, self.out_ann,
+ [5, [' '.join(format(x.val, '02X') for x in self.misobytes)]])
+ if self.have_mosi:
+ self.put(self.ss_transfer, self.samplenum, self.out_ann,
+ [6, [' '.join(format(x.val, '02X') for x in self.mosibytes)]])
+ self.put(self.ss_transfer, self.samplenum, self.out_python,
+ ['TRANSFER', self.mosibytes, self.misobytes])
+
+ # Reset decoder state when CS# changes (and the CS# pin is used).
+ self.reset_decoder_state()
+
+ # We only care about samples if CS# is asserted.
+ if self.have_cs and not self.cs_asserted(cs):
+ return
+
+ # Ignore sample if the clock pin hasn't changed.
+ if first or not self.matched[0]:
+ return