feat: implement embedded-io traits#42
Conversation
|
Please rebase. |
Done. 👍 |
|
|
||
| [dependencies] | ||
| bitflags = { version = "2.11", default-features = false, features = [] } | ||
| embedded-io = { version = "0.7", optional = true } |
There was a problem hiding this comment.
This is missing
[features]
default = ["embedded-io"]
embedded-io = ["dep:embedded-io"]
There was a problem hiding this comment.
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. 👍
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
Can you please add a test case for this similar to the mmio_dummy() test? It can be minimal.
There was a problem hiding this comment.
What should this test, though? 🤔
All register accesses have been extracted.
There was a problem hiding this comment.
You are right! Sorry, my head is already in weekend-mode!
phip1611
left a comment
There was a problem hiding this comment.
Thanks for the contribution, this is a great addition! Left some small remarks
src/embedded_io.rs
Outdated
| return Ok(false); | ||
| } | ||
|
|
||
| if !mcr.contains(MCR::LOOP_BACK) && !msr.contains(MSR::CTS) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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!
|
thanks, that's a nice contribution! |
This PR implements
embedded-io's traits.This makes the serial port usable via
std-likeReadandWritetraits.This PR depends on #41.