Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions pyftdi/spi.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,6 @@ def _exchange_half_duplex(self, frequency: float,
raise SpiIOError("FTDI controller not initialized")
if len(out) > SpiController.PAYLOAD_MAX_LENGTH:
raise SpiIOError("Output payload is too large")
if readlen > SpiController.PAYLOAD_MAX_LENGTH:
raise SpiIOError("Input payload is too large")
if cpha:
# to enable CPHA, we need to use a workaround with FTDI device,
# that is enable 3-phase clocking (which is usually dedicated to
Expand Down Expand Up @@ -830,17 +828,31 @@ def _exchange_half_duplex(self, frequency: float,
cmd.extend(write_cmd)
if readlen:
if not droptail:
n = readlen // SpiController.PAYLOAD_MAX_LENGTH
r = readlen % SpiController.PAYLOAD_MAX_LENGTH

rcmd = (Ftdi.READ_BYTES_NVE_MSB if not cpol else
Ftdi.READ_BYTES_PVE_MSB)
read_cmd = spack('<BH', rcmd, readlen-1)
cmd.extend(read_cmd)
for i in range(n):
read_cmd = spack('<BH', rcmd, SpiController.PAYLOAD_MAX_LENGTH-1)
cmd.extend(read_cmd)
if r:
read_cmd = spack('<BH', rcmd, r-1)
cmd.extend(read_cmd)
else:
bytelen = readlen-1
if bytelen:
n = bytelen // SpiController.PAYLOAD_MAX_LENGTH
r = bytelen % SpiController.PAYLOAD_MAX_LENGTH

rcmd = (Ftdi.READ_BYTES_NVE_MSB if not cpol else
Ftdi.READ_BYTES_PVE_MSB)
read_cmd = spack('<BH', rcmd, bytelen-1)
cmd.extend(read_cmd)
for i in range(n):
read_cmd = spack('<BH', rcmd, SpiController.PAYLOAD_MAX_LENGTH-1)
cmd.extend(read_cmd)
if r:
read_cmd = spack('<BH', rcmd, r-1)
cmd.extend(read_cmd)
rcmd = (Ftdi.READ_BITS_NVE_MSB if not cpol else
Ftdi.READ_BITS_PVE_MSB)
read_cmd = spack('<BB', rcmd, 7-droptail)
Expand Down