Skip to content

Commit 856b91f

Browse files
authored
Merge pull request #55 from jepler/remove-stop-kwarg2
i2c_device: remove write(stop=), write_then_readinto(stop=)
2 parents 2fd13d2 + 789ea19 commit 856b91f

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

adafruit_bus_device/i2c_device.py

+14-26
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class I2CDevice:
6262
def __init__(self, i2c, device_address, probe=True):
6363

6464
self.i2c = i2c
65-
self._has_write_read = hasattr(self.i2c, "writeto_then_readfrom")
6665
self.device_address = device_address
6766

6867
if probe:
@@ -85,10 +84,10 @@ def readinto(self, buf, *, start=0, end=None):
8584
end = len(buf)
8685
self.i2c.readfrom_into(self.device_address, buf, start=start, end=end)
8786

88-
def write(self, buf, *, start=0, end=None, stop=True):
87+
def write(self, buf, *, start=0, end=None):
8988
"""
90-
Write the bytes from ``buffer`` to the device. Transmits a stop bit if
91-
``stop`` is set.
89+
Write the bytes from ``buffer`` to the device, then transmit a stop
90+
bit.
9291
9392
If ``start`` or ``end`` is provided, then the buffer will be sliced
9493
as if ``buffer[start:end]``. This will not cause an allocation like
@@ -97,11 +96,10 @@ def write(self, buf, *, start=0, end=None, stop=True):
9796
:param bytearray buffer: buffer containing the bytes to write
9897
:param int start: Index to start writing from
9998
:param int end: Index to read up to but not include; if None, use ``len(buf)``
100-
:param bool stop: If true, output an I2C stop condition after the buffer is written
10199
"""
102100
if end is None:
103101
end = len(buf)
104-
self.i2c.writeto(self.device_address, buf, start=start, end=end, stop=stop)
102+
self.i2c.writeto(self.device_address, buf, start=start, end=end)
105103

106104
# pylint: disable-msg=too-many-arguments
107105
def write_then_readinto(
@@ -113,7 +111,6 @@ def write_then_readinto(
113111
out_end=None,
114112
in_start=0,
115113
in_end=None,
116-
stop=False
117114
):
118115
"""
119116
Write the bytes from ``out_buffer`` to the device, then immediately
@@ -136,30 +133,21 @@ def write_then_readinto(
136133
:param int out_end: Index to read up to but not include; if None, use ``len(out_buffer)``
137134
:param int in_start: Index to start writing at
138135
:param int in_end: Index to write up to but not include; if None, use ``len(in_buffer)``
139-
:param bool stop: Deprecated
140136
"""
141137
if out_end is None:
142138
out_end = len(out_buffer)
143139
if in_end is None:
144140
in_end = len(in_buffer)
145-
if stop:
146-
raise ValueError("Stop must be False. Use writeto instead.")
147-
if self._has_write_read:
148-
# In linux, at least, this is a special kernel function call
149-
self.i2c.writeto_then_readfrom(
150-
self.device_address,
151-
out_buffer,
152-
in_buffer,
153-
out_start=out_start,
154-
out_end=out_end,
155-
in_start=in_start,
156-
in_end=in_end,
157-
)
158-
159-
else:
160-
# If we don't have a special implementation, we can fake it with two calls
161-
self.write(out_buffer, start=out_start, end=out_end, stop=False)
162-
self.readinto(in_buffer, start=in_start, end=in_end)
141+
142+
self.i2c.writeto_then_readfrom(
143+
self.device_address,
144+
out_buffer,
145+
in_buffer,
146+
out_start=out_start,
147+
out_end=out_end,
148+
in_start=in_start,
149+
in_end=in_end,
150+
)
163151

164152
# pylint: enable-msg=too-many-arguments
165153

0 commit comments

Comments
 (0)