Skip to content

Refactor: Introduce Queue-Based Transfer API and Unified Endpoint Model#71

Merged
ZR233 merged 3 commits intomainfrom
dev-api
Apr 30, 2026
Merged

Refactor: Introduce Queue-Based Transfer API and Unified Endpoint Model#71
ZR233 merged 3 commits intomainfrom
dev-api

Conversation

@ZR233
Copy link
Copy Markdown
Member

@ZR233 ZR233 commented Apr 30, 2026

Summary

  • Introduce EndpointQueue trait (usb-if/src/endpoint.rs): New unified transfer API with submit/reclaim/poll_request pattern, replacing per-transfer-type endpoint traits (EndpointBulkIn, EndpointBulkOut, etc.)
  • Refactor endpoint abstraction (usb-host/src/backend/ty/ep/): Consolidate bulk/interrupt/isochronous endpoint implementations into a single Endpoint struct backed by EndpointOp trait, removing ~370 lines of duplicated code
  • Unify backend implementations: Update both kmod (xHCI) and umod (libusb) backends to implement the new EndpointOp trait, aligning control transfer handling across backends
  • Update device/drivers: Adapt UsbDevice, UVC stream, HID keyboard, and test crates to use the new queue-based API

Key Changes

Area Before After
Transfer API Per-type traits (EndpointBulkIn, etc.) Unified EndpointQueue with submit/reclaim
Endpoint types Separate structs per transfer kind Single Endpoint + EndpointInfo
Control transfers Inline in device layer Dedicated EndpointOp implementation
New file usb-if/src/endpoint.rs (329 lines)
Removed files bulk.rs, int.rs, iso.rs from ty/ep/

Test plan

  • cargo check -p crab-usb --test test --target aarch64-unknown-none-softfloat passes
  • cargo fmt --all applied
  • libusb backend test with real UVC device
  • Hub enumeration test on RK3588 hardware

🤖 Generated with Claude Code

ZR233 and others added 3 commits April 29, 2026 17:48
- Added a new queue-based transfer management system to handle USB endpoint transfers.
- Removed bulk, interrupt, and isochronous endpoint implementations in favor of a unified queue approach.
- Introduced `TransferRequest` and `TransferCompletion` types to encapsulate transfer details and results.
- Updated `EndpointBase` to support queue configurations and operations.
- Modified `Device` and `DeviceOp` to utilize the new queue-based endpoint retrieval.
- Enhanced error handling with new error types for queue management.
- Updated documentation to reflect changes in transfer handling and endpoint management.
- Updated UVC device to use synchronous endpoint retrieval instead of asynchronous.
- Changed `EndpointQueue` to `Endpoint` in video streaming and transfer handling.
- Refactored HubDevice to utilize `ctrl_ep_mut()` for control endpoint operations.
- Modified transfer handling in the Kmod backend to support cancellation of requests.
- Introduced a new `Endpoint` struct to encapsulate endpoint operations and information.
- Updated the USB interface to include a new `endpoint` module for better organization.
- Adjusted various backend implementations to align with the new endpoint structure.
- Enhanced error handling and request validation in transfer operations.
libusb1-sys v0.7.0 moved LIBUSB_SUCCESS behind the `constants` module,
making the direct path private.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@ZR233 ZR233 merged commit 2ab8b55 into main Apr 30, 2026
2 checks passed
@ZR233 ZR233 deleted the dev-api branch April 30, 2026 04:14
@ZR233 ZR233 mentioned this pull request Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant