1919
2020try :
2121 from typing import Optional , List , Tuple
22+ from circuitpython_typing import ReadableBuffer , WriteableBuffer
2223 from microcontroller import Pin
2324except ImportError :
2425 pass
@@ -97,7 +98,7 @@ def reset(self, required: bool = False) -> bool:
9798 return not reset
9899
99100 def readinto (
100- self , buf : bytearray , * , start : int = 0 , end : Optional [int ] = None
101+ self , buf : WriteableBuffer , * , start : int = 0 , end : Optional [int ] = None
101102 ) -> None :
102103 """
103104 Read into ``buf`` from the device. The number of bytes read will be the
@@ -107,7 +108,7 @@ def readinto(
107108 as if ``buf[start:end]``. This will not cause an allocation like
108109 ``buf[start:end]`` will so it saves memory.
109110
110- :param bytearray buf: buffer to write into
111+ :param ~WriteableBuffer buf: Buffer to write into
111112 :param int start: Index to start writing at
112113 :param int end: Index to write up to but not include
113114 """
@@ -117,7 +118,7 @@ def readinto(
117118 buf [i ] = self ._readbyte ()
118119
119120 def write (
120- self , buf : bytearray , * , start : int = 0 , end : Optional [int ] = None
121+ self , buf : ReadableBuffer , * , start : int = 0 , end : Optional [int ] = None
121122 ) -> None :
122123 """
123124 Write the bytes from ``buf`` to the device.
@@ -126,7 +127,7 @@ def write(
126127 as if ``buffer[start:end]``. This will not cause an allocation like
127128 ``buffer[start:end]`` will so it saves memory.
128129
129- :param bytearray buf: buffer containing the bytes to write
130+ :param ReadableBuffer buf: Buffer containing the bytes to write
130131 :param int start: Index to start writing from
131132 :param int end: Index to read up to but not include
132133 """
@@ -168,7 +169,7 @@ def _writebyte(self, value: int) -> None:
168169 self ._ow .write_bit (bit )
169170
170171 def _search_rom (
171- self , l_rom : Optional [bytearray ], diff : int
172+ self , l_rom : Optional [ReadableBuffer ], diff : int
172173 ) -> Tuple [bytearray , int ]:
173174 if not self .reset ():
174175 return None , 0
@@ -197,11 +198,11 @@ def _search_rom(
197198 return rom , next_diff
198199
199200 @staticmethod
200- def crc8 (data : bytearray ) -> int :
201+ def crc8 (data : ReadableBuffer ) -> int :
201202 """
202203 Perform the 1-Wire CRC check on the provided data.
203204
204- :param bytearray data: 8 byte array representing 64 bit ROM code
205+ :param ReadableBuffer data: 8 byte array representing 64 bit ROM code
205206 """
206207 crc = 0
207208
0 commit comments