@@ -62,7 +62,6 @@ class I2CDevice:
62
62
def __init__ (self , i2c , device_address , probe = True ):
63
63
64
64
self .i2c = i2c
65
- self ._has_write_read = hasattr (self .i2c , "writeto_then_readfrom" )
66
65
self .device_address = device_address
67
66
68
67
if probe :
@@ -85,10 +84,10 @@ def readinto(self, buf, *, start=0, end=None):
85
84
end = len (buf )
86
85
self .i2c .readfrom_into (self .device_address , buf , start = start , end = end )
87
86
88
- def write (self , buf , * , start = 0 , end = None , stop = True ):
87
+ def write (self , buf , * , start = 0 , end = None ):
89
88
"""
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 .
92
91
93
92
If ``start`` or ``end`` is provided, then the buffer will be sliced
94
93
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):
97
96
:param bytearray buffer: buffer containing the bytes to write
98
97
:param int start: Index to start writing from
99
98
: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
101
99
"""
102
100
if end is None :
103
101
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 )
105
103
106
104
# pylint: disable-msg=too-many-arguments
107
105
def write_then_readinto (
@@ -113,7 +111,6 @@ def write_then_readinto(
113
111
out_end = None ,
114
112
in_start = 0 ,
115
113
in_end = None ,
116
- stop = False
117
114
):
118
115
"""
119
116
Write the bytes from ``out_buffer`` to the device, then immediately
@@ -136,30 +133,21 @@ def write_then_readinto(
136
133
:param int out_end: Index to read up to but not include; if None, use ``len(out_buffer)``
137
134
:param int in_start: Index to start writing at
138
135
:param int in_end: Index to write up to but not include; if None, use ``len(in_buffer)``
139
- :param bool stop: Deprecated
140
136
"""
141
137
if out_end is None :
142
138
out_end = len (out_buffer )
143
139
if in_end is None :
144
140
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
+ )
163
151
164
152
# pylint: enable-msg=too-many-arguments
165
153
0 commit comments