19
19
20
20
try :
21
21
from typing import Optional , List , Tuple
22
+ from circuitpython_typing import ReadableBuffer , WriteableBuffer
22
23
from microcontroller import Pin
23
24
except ImportError :
24
25
pass
@@ -97,7 +98,7 @@ def reset(self, required: bool = False) -> bool:
97
98
return not reset
98
99
99
100
def readinto (
100
- self , buf : bytearray , * , start : int = 0 , end : Optional [int ] = None
101
+ self , buf : WriteableBuffer , * , start : int = 0 , end : Optional [int ] = None
101
102
) -> None :
102
103
"""
103
104
Read into ``buf`` from the device. The number of bytes read will be the
@@ -107,7 +108,7 @@ def readinto(
107
108
as if ``buf[start:end]``. This will not cause an allocation like
108
109
``buf[start:end]`` will so it saves memory.
109
110
110
- :param bytearray buf: buffer to write into
111
+ :param ~WriteableBuffer buf: Buffer to write into
111
112
:param int start: Index to start writing at
112
113
:param int end: Index to write up to but not include
113
114
"""
@@ -117,7 +118,7 @@ def readinto(
117
118
buf [i ] = self ._readbyte ()
118
119
119
120
def write (
120
- self , buf : bytearray , * , start : int = 0 , end : Optional [int ] = None
121
+ self , buf : ReadableBuffer , * , start : int = 0 , end : Optional [int ] = None
121
122
) -> None :
122
123
"""
123
124
Write the bytes from ``buf`` to the device.
@@ -126,7 +127,7 @@ def write(
126
127
as if ``buffer[start:end]``. This will not cause an allocation like
127
128
``buffer[start:end]`` will so it saves memory.
128
129
129
- :param bytearray buf: buffer containing the bytes to write
130
+ :param ReadableBuffer buf: Buffer containing the bytes to write
130
131
:param int start: Index to start writing from
131
132
:param int end: Index to read up to but not include
132
133
"""
@@ -168,7 +169,7 @@ def _writebyte(self, value: int) -> None:
168
169
self ._ow .write_bit (bit )
169
170
170
171
def _search_rom (
171
- self , l_rom : Optional [bytearray ], diff : int
172
+ self , l_rom : Optional [ReadableBuffer ], diff : int
172
173
) -> Tuple [bytearray , int ]:
173
174
if not self .reset ():
174
175
return None , 0
@@ -197,11 +198,11 @@ def _search_rom(
197
198
return rom , next_diff
198
199
199
200
@staticmethod
200
- def crc8 (data : bytearray ) -> int :
201
+ def crc8 (data : ReadableBuffer ) -> int :
201
202
"""
202
203
Perform the 1-Wire CRC check on the provided data.
203
204
204
- :param bytearray data: 8 byte array representing 64 bit ROM code
205
+ :param ReadableBuffer data: 8 byte array representing 64 bit ROM code
205
206
"""
206
207
crc = 0
207
208
0 commit comments