Skip to content

Commit 1b1997e

Browse files
author
steve
committed
Fix: flush() now calls libftdi(>= 1.5) tc[io]flush functions.
1 parent 9be4076 commit 1b1997e

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/pylibftdi/device.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,16 +493,18 @@ def flush(self, flush_what: int = FLUSH_BOTH) -> None:
493493
`FLUSH_INPUT` (just the rx buffer);
494494
`FLUSH_OUTPUT` (just the tx buffer)
495495
"""
496+
496497
if flush_what == FLUSH_BOTH:
497-
fn = self.fdll.ftdi_usb_purge_buffers
498+
fn = self.fdll.ftdi_tcioflush
498499
elif flush_what == FLUSH_INPUT:
499-
fn = self.fdll.ftdi_usb_purge_rx_buffer
500+
fn = self.fdll.ftdi_tciflush
500501
elif flush_what == FLUSH_OUTPUT:
501-
fn = self.fdll.ftdi_usb_purge_tx_buffer
502+
fn = self.fdll.ftdi_tcoflush
502503
else:
503504
raise ValueError(
504505
f"Invalid value passed to {self.__class__.__name__}.flush()"
505506
)
507+
506508
res = fn(byref(self.ctx))
507509
if res != 0:
508510
msg = "%s (%d)" % (self.get_error_string(), res)

tests/test_bitbang.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ def x():
121121
self.assertCallsExact(
122122
x,
123123
[
124-
"ftdi_usb_purge_tx_buffer",
124+
"ftdi_tcoflush",
125125
"ftdi_write_data",
126-
"ftdi_usb_purge_tx_buffer",
126+
"ftdi_tcoflush",
127127
"ftdi_write_data",
128-
"ftdi_usb_purge_tx_buffer",
128+
"ftdi_tcoflush",
129129
"ftdi_write_data",
130130
],
131131
)
@@ -155,10 +155,10 @@ def _2():
155155
dev.port |= 2
156156

157157
self.assertCallsExact(
158-
_1, ["ftdi_read_pins", "ftdi_usb_purge_tx_buffer", "ftdi_write_data"]
158+
_1, ["ftdi_read_pins", "ftdi_tcoflush", "ftdi_write_data"]
159159
)
160160
self.assertCallsExact(
161-
_2, ["ftdi_read_pins", "ftdi_usb_purge_tx_buffer", "ftdi_write_data"]
161+
_2, ["ftdi_read_pins", "ftdi_tcoflush", "ftdi_write_data"]
162162
)
163163

164164

tests/test_device.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ def testReadWrite(self):
6262

6363
def testFlush(self):
6464
with Device() as dev:
65-
self.assertCalls(dev.flush_input, "ftdi_usb_purge_rx_buffer")
66-
self.assertCalls(dev.flush_output, "ftdi_usb_purge_tx_buffer")
67-
self.assertCalls(dev.flush, "ftdi_usb_purge_buffers")
65+
self.assertCalls(dev.flush_input, "ftdi_tciflush")
66+
self.assertCalls(dev.flush_output, "ftdi_tcoflush")
67+
self.assertCalls(dev.flush, "ftdi_tcioflush")
6868

6969
def testClose(self):
7070
d = Device()

0 commit comments

Comments
 (0)