From 599e18a3e4d14dd5a5f14c6bbbacc63afbbfdac9 Mon Sep 17 00:00:00 2001 From: mndza Date: Tue, 14 Nov 2023 16:01:44 +0100 Subject: [PATCH] gateware.usb2: add port-specific hook support in USBDevice --- luna/gateware/usb/usb2/device.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/luna/gateware/usb/usb2/device.py b/luna/gateware/usb/usb2/device.py index e73b0f522..d0301a5e9 100644 --- a/luna/gateware/usb/usb2/device.py +++ b/luna/gateware/usb/usb2/device.py @@ -150,6 +150,7 @@ def __init__(self, *, bus, handle_clocking=True): # Internals. # self._endpoints = [] + self._bus_name = bus.name def add_endpoint(self, endpoint): @@ -202,6 +203,12 @@ def add_standard_control_endpoint(self, descriptors: DeviceDescriptorCollection, def elaborate(self, platform): m = Module() + # Call any hooks registered for the bus in the platform definition. + if hasattr(platform, "usb_device_hooks"): + hook = platform.usb_device_hooks.get(self._bus_name) + if hook is not None: + hook(self, m) + # If we have a bus translator, include it in our submodules. if self.translator: m.submodules.translator = self.translator