|
34 | 34 |
|
35 | 35 | try:
|
36 | 36 | from os import PathLike
|
37 |
| - from typing import Any, Dict, Optional, Tuple, TypeAlias |
| 37 | + from typing import Any, Dict, List, Optional, Tuple, TypeAlias, Union |
38 | 38 |
|
39 | 39 | # Technically this type should come from: from _typeshed import FileDescriptorOrPath
|
40 | 40 | # Unfortunately _typeshed is only in the standard library in newer releases of Python, e.g. 3.11
|
|
49 | 49 |
|
50 | 50 | from math import floor
|
51 | 51 |
|
52 |
| -from busio import SPI |
| 52 | +from busio import I2C, SPI |
53 | 53 | from digitalio import DigitalInOut, Direction
|
54 | 54 |
|
55 | 55 | _SLOW_CLOCK: int = 100000
|
@@ -107,7 +107,7 @@ class Boards:
|
107 | 107 | _spi: SPI = None
|
108 | 108 | _rst: DigitalInOut = None
|
109 | 109 |
|
110 |
| - def init(self, spi_bus: SPI, rst_pin) -> None: |
| 110 | + def init(self, spi_bus: SPI, rst_pin: Union[SPI, I2C]) -> None: |
111 | 111 | """
|
112 | 112 | Initialize the programmer with an SPI port that will be used to
|
113 | 113 | communicate with the chip. Make sure your SPI supports 'write_readinto'
|
@@ -206,8 +206,11 @@ def program_file(
|
206 | 206 | return True
|
207 | 207 |
|
208 | 208 | def verify_file(
|
209 |
| - self, chip: Dict[str, Any], file_name: FileDescriptorOrPath, verbose=False |
210 |
| - ): |
| 209 | + self, |
| 210 | + chip: Dict[str, Any], |
| 211 | + file_name: FileDescriptorOrPath, |
| 212 | + verbose: bool = False, |
| 213 | + ) -> bool: |
211 | 214 | """
|
212 | 215 | Perform a chip full-flash verification from a file that
|
213 | 216 | contains Intel HEX data. Returns True/False on success/fail.
|
@@ -252,12 +255,12 @@ def verify_file(
|
252 | 255 | self.end()
|
253 | 256 | return True
|
254 | 257 |
|
255 |
| - def read_fuses(self, chip: Dict[str, Any]) -> tuple: |
| 258 | + def read_fuses(self, chip: Dict[str, Any]) -> Tuple[int, int, int, int]: |
256 | 259 | """
|
257 | 260 | Read the 4 fuses and return them in a tuple (low, high, ext, lock)
|
258 | 261 | Each fuse is bitwise-&'s with the chip's fuse mask for simplicity
|
259 | 262 | """
|
260 |
| - mask = chip["fuse_mask"] |
| 263 | + mask: Tuple[int, int, int, int] = chip["fuse_mask"] |
261 | 264 | self.begin(clock=_SLOW_CLOCK)
|
262 | 265 | low = self._transaction((0x50, 0, 0, 0))[2] & mask[0]
|
263 | 266 | high = self._transaction((0x58, 0x08, 0, 0))[2] & mask[1]
|
@@ -311,7 +314,7 @@ def verify_fuses(
|
311 | 314 | return False
|
312 | 315 | return True
|
313 | 316 |
|
314 |
| - def erase_chip(self): |
| 317 | + def erase_chip(self) -> None: |
315 | 318 | """
|
316 | 319 | Fully erases the chip.
|
317 | 320 | """
|
@@ -340,7 +343,7 @@ def end(self) -> None:
|
340 | 343 | self._spi.unlock()
|
341 | 344 | self._rst.value = True
|
342 | 345 |
|
343 |
| - def read_signature(self) -> list: |
| 346 | + def read_signature(self) -> List[int]: |
344 | 347 | """
|
345 | 348 | Read and return the signature of the chip as two bytes in an array.
|
346 | 349 | Requires calling begin() beforehand to put in programming mode.
|
@@ -395,7 +398,7 @@ def _flash_page(
|
395 | 398 | raise RuntimeError("Failed to commit page to flash")
|
396 | 399 | self._busy_wait()
|
397 | 400 |
|
398 |
| - def _transaction(self, command: Tuple[int, int, int, int]) -> bytes: |
| 401 | + def _transaction(self, command: Tuple[int, int, int, int]) -> bytearray: |
399 | 402 | reply = bytearray(4)
|
400 | 403 | command_bytes = bytearray([i & 0xFF for i in command])
|
401 | 404 |
|
|
0 commit comments