sham, mask = self.cs['_mask']
mode, pins = self.cs[device]
- p = self._pinstate & ~mask
- p += pins & mask
+ # set SK before asserting CS to not violate timing
+ if True:
+ # first, ensure SK starts in the correct state
+ p = self._pinstate
+ if mode in (0, 1):
+ p |= 0x01
+ elif mode in (2, 3):
+ p &= 0xfe
+ cmd = chr(self.ftdi.SET_BITS_LOW) + chr(p) + chr(self._pindir)
+
+ p &= ~mask
+ p += pins & mask
+ self._pinstate = p
+ cmd += chr(self.ftdi.SET_BITS_LOW) + chr(p) + chr(self._pindir)
+ # old behavior: set CS and SK in same command
+ else:
+ p = self._pinstate & ~mask
+ p += pins & mask
- # ensure SK starts in the correct state
- if mode in (0, 1):
- p |= 0x01
- elif mode in (2, 3):
- p &= 0xfe
+ # ensure SK starts in the correct state
+ if mode in (0, 1):
+ p |= 0x01
+ elif mode in (2, 3):
+ p &= 0xfe
+
+ self._pinstate = p
+ cmd = chr(self.ftdi.SET_BITS_LOW) + chr(p) + chr(self._pindir)
- self._pinstate = p
- cmd = chr(self.ftdi.SET_BITS_LOW) + chr(p) + chr(self._pindir)
return cmd
def _mk_cs_cmd_cache(self):