Skip to content

Commit b5b4d6d

Browse files
committed
show usb3
1 parent 14feaf2 commit b5b4d6d

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

openpilot/cereal/log.capnp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,13 @@ struct UsbState {
704704
manufacturer @6 :Text;
705705
product @5 :Text;
706706
linkErrorCount @7 :UInt16;
707+
usb3Lane @8 :Usb3Lane;
708+
709+
enum Usb3Lane {
710+
unknown @0;
711+
a @1;
712+
b @2;
713+
}
707714
}
708715
}
709716

openpilot/common/hardware/usb.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
CHESTNUT_USB_IDS = ((0xADD1, 0x0001), (0x3801, 0x0001))
66
CHESTNUT_ROM_USB_IDS = ((0x174C, 0x2464), (0x174C, 0x2463))
77
USB_DEVICES_PATH = Path("/sys/bus/usb/devices")
8+
TYPEC_CC_ORIENTATION_PATH = Path("/sys/class/power_supply/usb/typec_cc_orientation")
9+
PRIMARY_USB_CONTROLLER = "a600000.ssusb"
810

911

1012
def get_usb_topology() -> set[str]:
@@ -45,6 +47,7 @@ def controller(device: Path) -> Path | None:
4547

4648
def get_usb_state() -> list[dict]:
4749
devices = []
50+
typec_orientation = read_int(TYPEC_CC_ORIENTATION_PATH)
4851
for device in usb_devices():
4952
vendor_id = read_int(device / "idVendor", 16)
5053
product_id = read_int(device / "idProduct", 16)
@@ -58,6 +61,7 @@ def get_usb_state() -> list[dict]:
5861
"manufacturer": read(device / "manufacturer") or "",
5962
"product": read(device / "product") or "",
6063
"linkErrorCount": read_int(ctrl / "portli", 0) & 0xFFFF if ctrl is not None else 0,
64+
"usb3Lane": {1: "a", 2: "b"}.get(typec_orientation, "unknown") if ctrl is not None and ctrl.name == PRIMARY_USB_CONTROLLER else "unknown",
6165
})
6266
return devices
6367

@@ -75,6 +79,7 @@ def set_usb_state(device_state, devices: list[dict]) -> None:
7579
entry.manufacturer = device["manufacturer"]
7680
entry.product = device["product"]
7781
entry.linkErrorCount = device["linkErrorCount"]
82+
entry.usb3Lane = device.get("usb3Lane", "unknown")
7883

7984
if (entry.vendorId, entry.productId) in CHESTNUT_USB_IDS:
8085
chestnut_present = True

openpilot/selfdrive/ui/mici/onroad/augmented_road_view.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from openpilot.system.ui.widgets.label import UnifiedLabel
1616
from openpilot.system.ui.widgets import Widget
1717
from openpilot.common.filter_simple import BounceFilter
18+
from openpilot.common.hardware.usb import CHESTNUT_ROM_USB_IDS, CHESTNUT_USB_IDS
1819
from openpilot.common.transformations.camera import DEVICE_CAMERAS, DeviceCameraConfig, view_frame_from_device_frame
1920
from openpilot.common.transformations.orientation import rot_from_euler
2021
from enum import IntEnum
@@ -245,10 +246,17 @@ def _render(self, _):
245246
self._bookmark_icon.render(self.rect)
246247

247248
gps = ui_state.sm["gpsLocationExternal"]
249+
chestnut = next((device for device in ui_state.sm["deviceState"].usbState.devices
250+
if (device.vendorId, device.productId) in CHESTNUT_USB_IDS + CHESTNUT_ROM_USB_IDS), None)
251+
usb3_debug_text = "NO USB3"
252+
if chestnut is not None and chestnut.speedMbps >= 5000:
253+
usb3_debug_text = f"USB3 lane: {str(chestnut.usb3Lane).upper()}"
254+
248255
gps_debug_text = (
249256
f"GPS sats: {gps.satelliteCount}",
250257
f"GPS fix: {gps.hasFix}",
251258
f"GPS hacc: {gps.horizontalAccuracy:.1f} m",
259+
usb3_debug_text,
252260
)
253261
font_size = 36
254262
for i, text in enumerate(gps_debug_text):

0 commit comments

Comments
 (0)