Hw alloc - #387
Draft
JesseMelon wants to merge 8 commits into
Draft
Conversation
JesseMelon
force-pushed
the
hw-alloc
branch
4 times, most recently
from
August 4, 2026 15:01
2c9f65a to
774ca8e
Compare
JesseMelon
force-pushed
the
hw-alloc
branch
2 times, most recently
from
August 18, 2026 14:15
47593fd to
1e8ff88
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pin ownership: compile-time hardware allocation
This is meant to reduce the number of unsafe keywords by implementing a zero overhead linear chain of authority from the one physical unsafe boundary - hardware.
By collecting hardware facts into data tables, we can assume the correctness of these tables to make functions safe. This also reduces implementation effort for new targets who can reuse more behavior.
This PR converts gpio and i2c to use the safer hardware allocation model, mirroring the abstraction boundaries from zephyr whenever possible.
Writing a test against this
There are two sides. Whoever holds the SCU grant muxes the pin; everyone else binds an
already-muxed pin. In practice: the kernel/board side routes, userspace apps bind.
Kernel / board side — mint, route, use
Userspace app — mint, bind, use
The kernel already routed the pin at the SCU; userspace has no SCU grant, so it binds instead of
routing (writes no SCU register):
I2C server app
The four rules (read before you copy-paste)
create_pins()runs exactly once per binary. It'sunsafefor that reason. Each app and thekernel each call it once at boot; it hands you every pin token.
into_gpio()/bind_gpio()/i2c_bus()isyour proof of exclusive ownership. Using a pin twice — or minting two handles for one pin — does
not compile.
into_gpio()thenscu::route(...).Userspace:
bind_gpio()(binds an already-routed pin).scu::route()once, passing every handle as a single tuple:route(&(&a, &b, &c)). Allmux writes coalesce at compile time. A lone handle is fine too:
route(&h).Adding a new pin or capability
Add a row to the
pins!table intarget/ast10x0/peripherals/scu/pins.rs. Each row is one physicalpad plus one entry per capability it supports —
capability: &[route writes] => datum:gpio/map.rs; theGpiodatum pointsthe pin at its group (
&EFGH) and bit.runtime panic.
Layout
Eight logical commits, bottom-up: HAL core (
resource+field_mux) → HAL GPIO → HAL I2C → SCU pinuniverse → GPIO port → I2C port → board wiring → test migration.