Skip to content

feat: implement embedded-io traits#42

Open
mkroening wants to merge 8 commits intorust-osdev:masterfrom
mkroening:embedded-io
Open

feat: implement embedded-io traits#42
mkroening wants to merge 8 commits intorust-osdev:masterfrom
mkroening:embedded-io

Conversation

@mkroening
Copy link
Member

This PR implements embedded-io's traits.

This makes the serial port usable via std-like Read and Write traits.

This PR depends on #41.

phip1611 and others added 8 commits January 17, 2026 18:22
## TL;DR

As discussed [0], this is my 100% rewrite of the crate. It is 100% spec
compliant, highly configurable (usable in kernel drivers) while still
preserving a very simple entry-level abstraction that "just works".

**It also runs on real hardware now!** The original code wasn't mature
enough for all the caveats. Further, we have one common abstraction for
x86 port I/O and MMIO.

## Background

As part of a learning project, I conducted an in-depth exploration of
UART 16550 devices and driver development. During this process, I
identified a key limitation in the current crate: the inability to
configure the baud rate. This functionality is essential for real
hardware usage, and addressing it was my primary motivation.

As I continued, I recognized additional areas for improvement.
Incremental changes quickly proved insufficient to meet the standards
of code quality, completeness, and maintainability I aimed for.
Consequently, I undertook a full rewrite, resulting in a driver that
is fully spec-compliant while maintaining seamless and idiomatic Rust
integration.

While I could release this as a separate crate, I prefer not to fragment
the ecosystem - especially given that rust-osdev already maintains a
crate in this space. **I fully acknowledge that this presents a "take it
or leave it" ("friss oder stirb") scenario** 😞 . That said, I am eager to
collaborate toward a solution that serves the community effectively,
and I am confident this rewrite provides a strong, forward-looking
foundation.

## Notes about Real Hardware Tests

To properly operate with real hardware, I had to specifically
investigate the behavior and especially adapt try_send_bytes()
and test_loopback().

Further, the source and the destination must agree on the baud
rate. Tests in VMs would behave differently (have fewer caveats),
especially as the baud rate is mostly irrelevant there.

## About API and Implementation

Please look into `lib.rs`, I suggest using `cargo doc`. A small except from README is also here:

[0] https://rust-osdev.zulipchat.com/#narrow/channel/426430-general/topic/uart.2016550.20.2F.20serial/near/566528969
This is a basic integration test that runs the code in a VM machine
that uses a x86 port I/O backed UART16550.
This enables to compile the crate normally even on non-x86. We could work
around using combinations of #[cfg] and #[doc], but this would be very
ugly.
This is best practice in Rust. It is a private API helper anyway that just must be public to a certain degree.
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