Skip to content

✨ (minor) Usb enumeration#92

Merged
kammce merged 24 commits intolibhal:mainfrom
PhazonicRidley:usb-enumeration
Apr 20, 2026
Merged

✨ (minor) Usb enumeration#92
kammce merged 24 commits intolibhal:mainfrom
PhazonicRidley:usb-enumeration

Conversation

@PhazonicRidley
Copy link
Copy Markdown

@PhazonicRidley PhazonicRidley commented Jan 30, 2026

Implemented a USB enumerator that can be used in various projects. This is meant as a default and reference implementation of an enumerator using the libhal USB system.

@PhazonicRidley PhazonicRidley changed the title ✨ Usb enumeration ✨ (minor) Usb enumeration Jan 30, 2026
@PhazonicRidley PhazonicRidley marked this pull request as draft February 1, 2026 05:19
@PhazonicRidley PhazonicRidley force-pushed the usb-enumeration branch 2 times, most recently from 780ef28 to f41be54 Compare February 5, 2026 20:57
@kammce kammce self-requested a review February 7, 2026 22:59
Copy link
Copy Markdown
Member

@kammce kammce left a comment

Choose a reason for hiding this comment

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

Please rebase your project and fix your merge conflicts. Also, we moved the libhal-util code into v5 in preperation for v6 which will use libhal-v5. So we can remove the include files within the include directory and only keep the ones within v5/*

Comment thread .github/workflows/ci.yml Outdated
Comment thread include/libhal-util/usb/descriptors.hpp Outdated
Comment thread include/libhal-util/usb/endpoints.hpp Outdated
@PhazonicRidley PhazonicRidley force-pushed the usb-enumeration branch 3 times, most recently from 6b474f8 to c9c62f1 Compare February 9, 2026 19:10
@PhazonicRidley PhazonicRidley marked this pull request as ready for review February 10, 2026 00:26
PhazonicRidley and others added 17 commits February 9, 2026 16:28
For devices that use the libhal usb interface high level class.
Handles configuration at the device and usb configuration level
Handles multiple configurations and multiple interfaces.
Simulated host by sending enumerator requests and having it respond.
Correct payloads were verified
Changed usb.hpp to be a shorthand for including all usb utils
For devices that use the libhal usb interface high level class.
Handles configuration at the device and usb configuration level
Handles multiple configurations and multiple interfaces.
Simulated host by sending enumerator requests and having it respond.
Correct payloads were verified
Changed usb.hpp to be a shorthand for including all usb utils
Copy link
Copy Markdown
Member

@kammce kammce left a comment

Choose a reason for hiding this comment

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

I haven't reviewed everything. I'm posting what I have now because I'm not sure if github will lose my info.

Comment thread .claude/settings.local.json Outdated
Comment thread v5/include/libhal-util/mock/usb.hpp Outdated
Comment thread v5/include/libhal-util/mock/usb.hpp Outdated
Comment thread v5/include/libhal-util/mock/usb.hpp Outdated
Comment thread v5/include/libhal-util/mock/usb.hpp Outdated
Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Comment thread v5/include/libhal-util/usb/descriptors.hpp Outdated
Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Added required copyright notices
Changed over from span_eq to ranges::equal and removed function
Renamed truncated constant names to their full names
Changed mock interface's packed array to use a predefined constant instead of a magic number
Changed headers in the same library to be relative paths
Factored out ctor arguments for device, config, and enumeration
Enforced endianess with device descriptor
Changed ref getters to return by value and add setters where needed
Documented make_sub_scatter_array and changed return type to a struct for clarity
Hardcoded string indexes for device descriptors, removed the ablity to set a start for string descriptors
Copy link
Copy Markdown
Member

@kammce kammce left a comment

Choose a reason for hiding this comment

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

This is a partial review of the changes you've made. Things are looking really good. I plan to dig into the details of the enumerator next. Thank you for your effort on this!

Comment thread v5/include/libhal-util/usb/descriptors.hpp Outdated
Comment thread v5/include/libhal-util/usb/descriptors.hpp Outdated
Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Comment thread v5/tests/usb.test.cpp
Copy link
Copy Markdown
Member

@kammce kammce left a comment

Choose a reason for hiding this comment

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

alright, this is the review of the enumerator it self. There is a lot of extra code hanging around that needs some cleanup. And I think we should think very critically about errors and how we expect developers to handle them. No error should come without a means to handle it. And I think in most cases, the exceptions can be eliminated entirely.

Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Comment thread v5/include/libhal-util/usb/enumerator.hpp
Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Comment thread v5/include/libhal-util/usb/enumerator.hpp
Comment thread v5/include/libhal-util/usb/enumerator.hpp
Comment thread v5/include/libhal-util/usb/descriptors.hpp Outdated
Comment thread v5/include/libhal-util/usb/enumerator.hpp
Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Made system non-blocking
Errors do not propagate unless they have to or are insighted by user
System will STALL on invalid requests from the host automatically
System will have user defined number of retries before giving up
@PhazonicRidley
Copy link
Copy Markdown
Author

On testing on hardware, I am getting timed_out exception. Not to be merged yet until this is resolved.

Copy link
Copy Markdown
Member

@kammce kammce left a comment

Choose a reason for hiding this comment

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

So I'm noticing a lot of extra commented out code in this last commit? Can you review your PR yourself then @ me in a message when this is ready.

Comment thread v5/include/libhal-util/usb/enumerator.hpp
Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Copy link
Copy Markdown
Member

@kammce kammce left a comment

Choose a reason for hiding this comment

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

Everything that I prefixed with NIT is something you can simply mark as resolved. These will be things that I may pick up later in order to clean up some of the code here. Otherwise, most of this looks good. I also added a number of TODO issues to go along with your TODOs. Any FIXMEs should be replaced with TODOs although I gave one a pass until later.

Also, please make sure to review your PR yourself and remove any commented sections of code.

Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Comment thread v5/include/libhal-util/usb/enumerator.hpp
Comment thread v5/include/libhal-util/usb/descriptors.hpp
Comment thread v5/include/libhal-util/usb/descriptors.hpp Outdated
Comment thread v5/include/libhal-util/usb/enumerator.hpp Outdated
Comment thread v5/tests/usb.test.cpp
Comment thread v5/tests/usb.test.cpp Outdated
Comment thread v5/include/libhal-util/mock/usb.hpp Outdated
Comment thread v5/include/libhal-util/mock/usb.hpp Outdated
Copy link
Copy Markdown
Member

@kammce kammce left a comment

Choose a reason for hiding this comment

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

LGTM.

@kammce kammce merged commit 0721621 into libhal:main Apr 20, 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.

2 participants