Skip to content

feat: implement embedded-io traits#42

Merged
phip1611 merged 3 commits intorust-osdev:masterfrom
mkroening:embedded-io
Mar 20, 2026
Merged

feat: implement embedded-io traits#42
phip1611 merged 3 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
Copy link
Member

Please rebase.

@phip1611 phip1611 self-requested a review March 20, 2026 14:37
@mkroening
Copy link
Member Author

Please rebase.

Done. 👍


[dependencies]
bitflags = { version = "2.11", default-features = false, features = [] }
embedded-io = { version = "0.7", optional = true }
Copy link
Member

Choose a reason for hiding this comment

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

This is missing

[features]
default = ["embedded-io"]
embedded-io = ["dep:embedded-io"]

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I was not expecting you to want this to be a default feature.

The corresponding feature is already defined implicitly, but I am happy to make it explicit. 👍

Copy link
Member

@phip1611 phip1611 Mar 20, 2026

Choose a reason for hiding this comment

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

The corresponding feature is already defined implicitly, but I am happy to make it explicit. 👍

I didn't know there is an implicit feature detection. I'd prefer an explicit feature list however

Ah, I was not expecting you to want this to be a default feature.

No strong opinion. Up to you!

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd prefer an explicit feature list however

Done.

No strong opinion. Up to you!

Difficult question. I have leaned towards making this a non-default feature. Just a gut feeling, though.

}
}

impl<B: Backend> ReadReady for Uart16550<B> {
Copy link
Member

@phip1611 phip1611 Mar 20, 2026

Choose a reason for hiding this comment

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

Can you please add a test case for this similar to the mmio_dummy() test? It can be minimal.

Copy link
Member Author

Choose a reason for hiding this comment

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

What should this test, though? 🤔

All register accesses have been extracted.

Copy link
Member

Choose a reason for hiding this comment

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

You are right! Sorry, my head is already in weekend-mode!

Copy link
Member

@phip1611 phip1611 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, this is a great addition! Left some small remarks

return Ok(false);
}

if !mcr.contains(MCR::LOOP_BACK) && !msr.contains(MSR::CTS) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be worth it to add a private ready_to_send(&self) helper in the base type. THen we can use the same logic in try_send_bytes() and here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. I have done the same for receiving (two separate commits).

fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
loop {
let n = self.try_receive_bytes(buf);
if n > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Note to self: https://docs.rs/embedded-io/latest/embedded_io/trait.Read.html

The method blocks until at least one byte becomes available;

make sense. thanks!

@phip1611 phip1611 merged commit f9e5bf6 into rust-osdev:master Mar 20, 2026
14 checks passed
@phip1611
Copy link
Member

thanks, that's a nice contribution!

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