Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference/architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines 196 to +198
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section still references device-side behavior ("See usbd.c"), where init() is required (the stack asserts driver->init). Moving init() to Optional Functions here makes the documentation inaccurate unless the device-side requirement is also relaxed, or the doc is clarified/split for host vs device class driver interfaces.

Suggested change
**Optional Functions**:
- ``init()``: Initialize class driver
- ``init()``: Initialize class driver
**Optional Functions**:

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot make device side init() optional

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see if I'm a good copilot...

- ``close()``: Clean up class resources
- ``deinit()``: Deinitialize class driver
- ``sof()``: Start-of-frame processing
Expand Down
2 changes: 1 addition & 1 deletion src/host/usbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 != NULL && driver->init) {
TU_LOG_USBH("%s init\r\n", driver->name);
driver->init();
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

driver->init() returns bool (see usbh_class_driver_t), but its return value is ignored. Several built-in class init functions can return false on internal TU_ASSERT failures, so tuh_rhport_init() may still succeed even though a class driver failed to initialize. Consider asserting/propagating the init result (e.g., fail tuh_rhport_init() if any present init() returns false).

Suggested change
driver->init();
bool inited = driver->init();
TU_ASSERT(inited);
if (!inited) {
return false;
}

Copilot uses AI. Check for mistakes.
}
Expand Down
Loading