mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-05 16:26:06 +08:00
support current eGPU USB ID
This commit is contained in:
@@ -2,7 +2,7 @@ import time
|
||||
from pathlib import Path
|
||||
|
||||
from openpilot.common.swaglog import cloudlog
|
||||
from openpilot.system.hardware.usb import CHESTNUT_PRODUCT_ID, CHESTNUT_VENDOR_ID, controller, read_int, usb_devices
|
||||
from openpilot.system.hardware.usb import CHESTNUT_PRODUCT_ID, CHESTNUT_VENDOR_IDS, controller, read_int, usb_devices
|
||||
|
||||
STABLE_SECONDS = 2.0
|
||||
STABLE_THRESHOLD = 5.0
|
||||
@@ -10,7 +10,7 @@ STABLE_THRESHOLD = 5.0
|
||||
|
||||
def _chestnut_portli() -> Path | None:
|
||||
for device in usb_devices():
|
||||
if read_int(device / "idVendor", 16) != CHESTNUT_VENDOR_ID or \
|
||||
if read_int(device / "idVendor", 16) not in CHESTNUT_VENDOR_IDS or \
|
||||
read_int(device / "idProduct", 16) != CHESTNUT_PRODUCT_ID:
|
||||
continue
|
||||
usb_controller = controller(device)
|
||||
|
||||
@@ -11,6 +11,18 @@ def test_chestnut_present(tmp_path, monkeypatch):
|
||||
assert usb.chestnut_present()
|
||||
|
||||
|
||||
def test_chestnut_present_with_comma_vendor_id(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(usb, "USB_DEVICES_PATH", tmp_path)
|
||||
device = tmp_path / "1-1"
|
||||
device.mkdir()
|
||||
(device / "idVendor").write_text("3801\n")
|
||||
(device / "idProduct").write_text("0001\n")
|
||||
|
||||
assert usb.read_int(device / "idVendor", 16) in usb.CHESTNUT_VENDOR_IDS
|
||||
assert usb.usb_devices() == [device]
|
||||
assert usb.chestnut_present()
|
||||
|
||||
|
||||
def test_chestnut_absent_for_other_usb_device(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(usb, "USB_DEVICES_PATH", tmp_path)
|
||||
device = tmp_path / "1-1"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from pathlib import Path
|
||||
|
||||
CHESTNUT_VENDOR_ID = 0xADD1
|
||||
CHESTNUT_VENDOR_IDS = (CHESTNUT_VENDOR_ID, 0x3801)
|
||||
CHESTNUT_PRODUCT_ID = 0x0001
|
||||
USB_DEVICES_PATH = Path("/sys/bus/usb/devices")
|
||||
|
||||
@@ -22,7 +23,7 @@ def usb_devices() -> list[Path]:
|
||||
|
||||
def chestnut_present() -> bool:
|
||||
return any(
|
||||
read_int(device / "idVendor", 16) == CHESTNUT_VENDOR_ID and
|
||||
read_int(device / "idVendor", 16) in CHESTNUT_VENDOR_IDS and
|
||||
read_int(device / "idProduct", 16) == CHESTNUT_PRODUCT_ID
|
||||
for device in usb_devices()
|
||||
)
|
||||
|
||||
@@ -914,7 +914,7 @@ class USBIface(PCIIface):
|
||||
def __init__(self, dev, dev_id): # pylint: disable=super-init-not-called
|
||||
deadline, visible = time.monotonic() + 5.0, []
|
||||
while dev_id >= len(visible) and time.monotonic() < deadline:
|
||||
visible = hcq_filter_visible_devices(USB3.list_devices(0xADD1, 0x0001), "AMD")
|
||||
visible = hcq_filter_visible_devices(USB3.list_devices(0xADD1, 0x0001) + USB3.list_devices(0x3801, 0x0001), "AMD")
|
||||
if dev_id >= len(visible): time.sleep(0.1)
|
||||
if dev_id >= len(visible):
|
||||
raise RuntimeError(f"AMD:{dev_id} does not exist ({pluralize('device', len(visible))} available)")
|
||||
|
||||
@@ -212,7 +212,7 @@ class ScsiWriteOp: data:bytes; lba:int=0 # noqa: E702
|
||||
class CustomASM24Controller:
|
||||
def __init__(self, usb:USB3|None=None):
|
||||
if not usb:
|
||||
devs = USB3.list_devices(0xADD1, 0x0001)
|
||||
devs = USB3.list_devices(0xADD1, 0x0001) + USB3.list_devices(0x3801, 0x0001)
|
||||
assert len(devs), "no ASM24 controller found"
|
||||
self.usb = USB3(devs[0][0], 0x81, 0x83, 0x02, 0x04, use_bot=True)
|
||||
else: self.usb = usb
|
||||
@@ -333,7 +333,7 @@ class CustomASM24Controller:
|
||||
class ASM24Controller:
|
||||
def __init__(self, usb:USB3|None=None):
|
||||
if not usb:
|
||||
devs = USB3.list_devices(0xADD1, 0x0001)
|
||||
devs = USB3.list_devices(0xADD1, 0x0001) + USB3.list_devices(0x3801, 0x0001)
|
||||
assert len(devs), "no ASM24 controller found"
|
||||
self.usb = USB3(devs[0][0], 0x81, 0x83, 0x02, 0x04, use_bot=bool(getenv("USE_BOT", 0)))
|
||||
else: self.usb = usb
|
||||
|
||||
Reference in New Issue
Block a user