mayio
mayio is a small no_std Rust crate that provides typed GPIO abstractions.
The crate offers a type-safe API for working with GPIO pins using compile-time
direction markers (Input / Output) and a bank/register abstraction.
Goals
- Small, zero-std dependency surface for embedded contexts.
- Type-level safety to prevent writing to input pins and similar mistakes.
- Minimal runtime overhead.
Mock GPIO example
The following example shows a minimal, host-friendly mock implementation of
the register block, a GpioRegisters implementation, and a Bank type. It
is illustrative — adapt it to your hardware.
use mayio:;
// A tiny mock of the register block. On real hardware this would be the
// svd2rust-generated struct with volatile register accessors.
unsafe
// Provide a `Bank` implementation that returns a (mock) base address.
;
// Once Bank and GpioRegisters are implemented, a type alias is to be used
// as it is more ergonomic
type Pin<const N: u32, D> = ;
// Usage
// At init, output should not be set
let mut out = init;
assert_eq!;
// Activate
out.activate;
assert_eq!;
// Assert that the output register bit for pin 3 was unset by the driver.
// We read the mock register directly via the bank address returned by
// `MyBank::addr()`; this mirrors what real hardware would contain.
out.deactivate;
assert_eq!;
// Prepare the input register for pin 4 and verify the typed API reads it.
unsafe
// Usage
let input = init;
let level = input.read;
// Final check: ensure the typed API reports the pin as `High`.
// If this assertion fails, the example/driver did not set the mock input
// register as expected.
assert!;
Building
This crate is intended for no_std embedded targets. To run cargo build, use
an appropriate target and the platform's toolchain.
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)