Skip to content

Commit bda8d8a

Browse files
committed
Annotation and hinting for BitbangIO
1 parent 74c265d commit bda8d8a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

adafruit_bitbangio.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def writeto(
130130
buffer: ReadableBuffer,
131131
*,
132132
start: int = 0,
133-
end: Optional[int] = None
133+
end: Optional[int] = None,
134134
) -> None:
135135
"""Write data from the buffer to an address"""
136136
if end is None:
@@ -144,7 +144,7 @@ def readfrom_into(
144144
buffer: WriteableBuffer,
145145
*,
146146
start: int = 0,
147-
end: Optional[int] = None
147+
end: Optional[int] = None,
148148
) -> None:
149149
"""Read data from an address and into the buffer"""
150150
if end is None:
@@ -164,7 +164,7 @@ def writeto_then_readfrom(
164164
out_start: int = 0,
165165
out_end: Optional[int] = None,
166166
in_start: int = 0,
167-
in_end: Optional[int] = None
167+
in_end: Optional[int] = None,
168168
) -> None:
169169
"""Write data from buffer_out to an address and then
170170
read data from an address and into buffer_in
@@ -279,7 +279,8 @@ def _probe(self, address: int) -> bool:
279279
def _write(self, address: int, buffer: ReadableBuffer, transmit_stop: bool) -> None:
280280
self._start()
281281
if not self._write_byte(address << 1):
282-
raise RuntimeError("Device not responding at 0x{:02X}".format(address))
282+
# raise RuntimeError("Device not responding at 0x{:02X}".format(address))
283+
raise RuntimeError(f"Device not responding at 0x{address:02X}")
283284
for byte in buffer:
284285
self._write_byte(byte)
285286
if transmit_stop:
@@ -288,7 +289,8 @@ def _write(self, address: int, buffer: ReadableBuffer, transmit_stop: bool) -> N
288289
def _read(self, address: int, length: int) -> bytearray:
289290
self._start()
290291
if not self._write_byte(address << 1 | 1):
291-
raise RuntimeError("Device not responding at 0x{:02X}".format(address))
292+
# raise RuntimeError("Device not responding at 0x{:02X}".format(address))
293+
raise RuntimeError(f"Device not responding at 0x{address:02X}")
292294
buffer = bytearray(length)
293295
for byte_position in range(length):
294296
buffer[byte_position] = self._read_byte(ack=(byte_position != length - 1))
@@ -344,7 +346,7 @@ def configure(
344346
baudrate: int = 100000,
345347
polarity: Literal[0, 1] = 0,
346348
phase: Literal[0, 1] = 0,
347-
bits: int = 8
349+
bits: int = 8,
348350
) -> None:
349351
"""Configures the SPI bus. Only valid when locked."""
350352
if self._check_lock():
@@ -464,7 +466,7 @@ def write_readinto(
464466
out_start: int = 0,
465467
out_end: Optional[int] = None,
466468
in_start: int = 0,
467-
in_end: Optional[int] = None
469+
in_end: Optional[int] = None,
468470
) -> None:
469471
"""Write out the data in buffer_out while simultaneously reading data into buffer_in.
470472
The lengths of the slices defined by buffer_out[out_start:out_end] and

0 commit comments

Comments
 (0)