Skip to content

Commit

Permalink
support/usb: check for udc instance
Browse files Browse the repository at this point in the history
Check if the system has any udc instances to avoid a nasty
exception.

Closes: #367
Signed-off-by: Cedric Hombourger <[email protected]>
  • Loading branch information
chombourger committed Feb 15, 2024
1 parent 6b4c1a2 commit 9ce53ad
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions mtda/support/usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,20 @@ def _configure(what, conf):
return result

def _enable():
usbdrv = os.listdir("/sys/class/udc")[0]
udc = os.path.join(Composite.path, "UDC")
result = write(udc, usbdrv)
return result > 0
Composite.debug(3, "composite._enable()")

instances = os.listdir("/sys/class/udc")
result = False
if instances:
usbdrv = instances[0]
udc = os.path.join(Composite.path, "UDC")
result = write(udc, usbdrv) > 0
else:
Composite.debug(1, "composite._enable(): "
"platform does not support udc")

Composite.debug(3, f"composite._enable(): {result}")
return result

def _disable():
udc = os.path.join(Composite.path, "UDC")
Expand Down

0 comments on commit 9ce53ad

Please sign in to comment.