This commit is contained in:
Your Name
2024-04-27 03:19:19 -05:00
parent df418b503f
commit 03af7b6107
306 changed files with 108529 additions and 119 deletions

View File

@@ -2,7 +2,6 @@ import os
import usb1
import struct
import binascii
from typing import List, Optional
from .base import BaseSTBootloaderHandle
from .spi import STBootloaderSPIHandle, PandaSpiException
@@ -11,9 +10,9 @@ from .constants import FW_PATH, McuType
class PandaDFU:
def __init__(self, dfu_serial: Optional[str]):
def __init__(self, dfu_serial: str | None):
# try USB, then SPI
handle: Optional[BaseSTBootloaderHandle]
handle: BaseSTBootloaderHandle | None
self._context, handle = PandaDFU.usb_connect(dfu_serial)
if handle is None:
self._context, handle = PandaDFU.spi_connect(dfu_serial)
@@ -38,7 +37,7 @@ class PandaDFU:
self._context.close()
@staticmethod
def usb_connect(dfu_serial: Optional[str]):
def usb_connect(dfu_serial: str | None):
handle = None
context = usb1.USBContext()
context.open()
@@ -56,7 +55,7 @@ class PandaDFU:
return context, handle
@staticmethod
def spi_connect(dfu_serial: Optional[str]):
def spi_connect(dfu_serial: str | None):
handle = None
this_dfu_serial = None
@@ -72,13 +71,7 @@ class PandaDFU:
return None, handle
@staticmethod
def list() -> List[str]:
ret = PandaDFU.usb_list()
ret += PandaDFU.spi_list()
return list(set(ret))
@staticmethod
def usb_list() -> List[str]:
def usb_list() -> list[str]:
dfu_serials = []
try:
with usb1.USBContext() as context:
@@ -93,7 +86,7 @@ class PandaDFU:
return dfu_serials
@staticmethod
def spi_list() -> List[str]:
def spi_list() -> list[str]:
try:
_, h = PandaDFU.spi_connect(None)
if h is not None:
@@ -134,3 +127,9 @@ class PandaDFU:
code = f.read()
self.program_bootstub(code)
self.reset()
@staticmethod
def list() -> list[str]:
ret = PandaDFU.usb_list()
ret += PandaDFU.spi_list()
return list(set(ret))