diff options
| author | Zixun LI <[email protected]> | 2026-03-22 22:54:34 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-03-22 22:54:34 +0100 |
| commit | 434947495ca2ff418aa2ad2db889fb34294defb2 (patch) | |
| tree | 284bb84927538039b9321c74f912b3ba4f4a10ca | |
| parent | 8a9f44bdd267d05640d1028c07269d044291243b (diff) | |
| parent | f0d7db1788bc526d75c400f3362e4ee7540363a6 (diff) | |
Merge pull request #3565 from Precidata/driver-init
Make driver init() function optional
| -rw-r--r-- | docs/reference/architecture.rst | 2 | ||||
| -rw-r--r-- | src/device/usbd.c | 7 | ||||
| -rw-r--r-- | src/host/usbh.c | 2 |
3 files changed, 6 insertions, 5 deletions
diff --git a/docs/reference/architecture.rst b/docs/reference/architecture.rst index 70ea17ed4..523e1d615 100644 --- a/docs/reference/architecture.rst +++ b/docs/reference/architecture.rst @@ -189,13 +189,13 @@ Class Driver Interface See ``usbd.c``. **Required Functions**: -- ``init()``: Initialize class driver - ``reset()``: Reset class state - ``open()``: Configure class endpoints - ``control_xfer_cb()``: Handle control requests - ``xfer_cb()``: Handle data transfer completion **Optional Functions**: +- ``init()``: Initialize class driver - ``close()``: Clean up class resources - ``deinit()``: Deinitialize class driver - ``sof()``: Start-of-frame processing diff --git a/src/device/usbd.c b/src/device/usbd.c index 42903576c..c7f511eac 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -572,9 +572,10 @@ bool tud_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { // Init class drivers for (uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++) { usbd_class_driver_t const* driver = get_driver(i); - TU_ASSERT(driver && driver->init); - TU_LOG_USBD("%s init\r\n", driver->name); - driver->init(); + if (driver && driver->init) { + TU_LOG_USBD("%s init\r\n", driver->name); + driver->init(); + } } _usbd_rhport = rhport; diff --git a/src/host/usbh.c b/src/host/usbh.c index 75df6bf60..f65a3a427 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -544,7 +544,7 @@ bool tuh_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { // Class drivers for (uint8_t drv_id = 0; drv_id < TOTAL_DRIVER_COUNT; drv_id++) { usbh_class_driver_t const* driver = get_driver(drv_id); - if (driver != NULL) { + if (driver && driver->init) { TU_LOG_USBH("%s init\r\n", driver->name); driver->init(); } |
