PandaDFU: abstract out USB comms (#1274)

* wip

* revert that

* split list + connect

* some more

* mypy fix

* add clear status back

* rename

* cleanup

* cleaner mypy fix

---------

Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
Adeeb Shihadeh
2023-03-06 09:24:00 -08:00
committed by GitHub
parent 946f952aa7
commit 18230831f3
4 changed files with 143 additions and 68 deletions

View File

@@ -1,9 +1,12 @@
from abc import ABC, abstractmethod
from typing import List
from typing import List, Optional
# This mimics the handle given by libusb1 for easy interoperability
class BaseHandle(ABC):
"""
A handle to talk to a panda.
Borrows heavily from the libusb1 handle API.
"""
@abstractmethod
def close(self) -> None:
...
@@ -23,3 +26,30 @@ class BaseHandle(ABC):
@abstractmethod
def bulkRead(self, endpoint: int, length: int, timeout: int = 0) -> bytes:
...
class BaseSTBootloaderHandle(ABC):
"""
A handle to talk to a panda while it's in the STM32 bootloader.
"""
@abstractmethod
def close(self) -> None:
...
@abstractmethod
def clear_status(self) -> None:
...
@abstractmethod
def program(self, address: int, dat: bytes, block_size: Optional[int] = None) -> None:
...
@abstractmethod
def erase(self, address: int) -> None:
...
@abstractmethod
def jump(self, address: int) -> None:
...