- # If this is first bit, save timestamp
- if self.rxcount == 0:
- self.time = timeoffset # FIXME
- # Receive bit into our shift register
- if sdata:
- self.rxdata |= 1 << (7 - self.rxcount)
- self.rxcount += 1
- # Continue to receive if not a byte yet
- if self.rxcount != 8:
+ # Sample data on rising/falling clock edge (depends on mode).
+ mode = spi_mode[self.cpol, self.cpha]
+ if mode == 0 and sck == 0: # Sample on rising clock edge
+ continue
+ elif mode == 1 and sck == 1: # Sample on falling clock edge
+ continue
+ elif mode == 2 and sck == 1: # Sample on falling clock edge
+ continue
+ elif mode == 3 and sck == 0: # Sample on rising clock edge
+ continue
+
+ # If this is the first bit, save its sample number.
+ if self.bitcount == 0:
+ self.start_sample = samplenum
+ deasserted = cs if (self.cs_polarity == ACTIVE_LOW) else not c
+ if deasserted:
+ self.cs_was_deasserted_during_data_word = 1
+
+ # Receive MOSI bit into our shift register.
+ if self.bitorder == MSB_FIRST:
+ self.mosidata |= mosi << (self.wordsize - 1 - self.bitcount)
+ else:
+ self.mosidata |= mosi << self.bitcount
+
+ # Receive MISO bit into our shift register.
+ if self.bitorder == MSB_FIRST:
+ self.misodata |= miso << (self.wordsize - 1 - self.bitcount)
+ else:
+ self.misodata |= miso << self.bitcount
+
+ self.bitcount += 1
+
+ # Continue to receive if not a byte yet.
+ if self.bitcount != self.wordsize: