simplified find_udc()

This commit is contained in:
Maxim Devaev
2022-03-31 03:37:04 +03:00
parent ed93f1f4d3
commit 94dca7d7c6
3 changed files with 5 additions and 8 deletions

View File

@@ -22,15 +22,13 @@
import os
from typing import Tuple
from .logging import get_logger
from . import env
# =====
def find_udc(udc: str) -> Tuple[str, str]:
def find_udc(udc: str) -> str:
path = f"{env.SYSFS_PREFIX}/sys/class/udc"
candidates = sorted(os.listdir(path))
if not udc:
@@ -39,8 +37,7 @@ def find_udc(udc: str) -> Tuple[str, str]:
udc = candidates[0]
elif udc not in candidates:
raise RuntimeError(f"Can't find selected UDC: {udc}")
driver = os.path.basename(os.readlink(os.path.join(path, udc, "device/driver")))
return (udc, driver) # (fe980000.usb, dwc2)
return udc # fe980000.usb
class UsbDeviceController:
@@ -49,7 +46,7 @@ class UsbDeviceController:
self.__state_path = ""
def find(self) -> None:
udc = find_udc(self.__udc)[0]
udc = find_udc(self.__udc)
self.__state_path = os.path.join(f"{env.SYSFS_PREFIX}/sys/class/udc", udc, "state")
get_logger().info("Using UDC %s", udc)