-
Notifications
You must be signed in to change notification settings - Fork 368
Async serial uart read #615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
MabezDev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this! This is a good first iteration but I have a few comments I think we should address :).
MabezDev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, nearly there, just a few more little bits to address :)
esp-hal-common/src/uart.rs
Outdated
| .await; | ||
|
|
||
| while self.uart.get_rx_fifo_count() > 0 && read_bytes < buf.len() { | ||
| buf[read_bytes] = unsafe { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we just use read() here? We could do while let Ok(byte) = self.read() instead of duplicating some code.
esp-hal-common/src/uart.rs
Outdated
| where | ||
| T: Instance, | ||
| { | ||
| pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's document that read might not fill buf completely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will also insert an error case Error::ReadBufferFull when provided buffer size is not enough.
|
Did you mean to close this @alexiionescu? |
|
No, I messed up my pull request branch by merging the latest from upstream in order to run the examples. Also someone has rewrite the examples to use the same type on all examples and I have already merged that changed interrupt::enable(Interrupt::UART0, interrupt::Priority::Priority1).unwrap();I can keep the merging, although I guess the CI will fail. |
|
I have pushed the commit before the force-push closed. I don't think I can re-open it myself. |
|
I have also pushed my latest changes based on your review. Please let me know If I need to make a new PR or you can re-open this. |
serial uart
readforembassyasyncAlso fix an issue with async write on large buffers, was panicking with Err Would Block. Discovered when testing reading and echoing back a large reader buffer.
Tested on ESP32C3 (WROOM) only using a separate project. Examples do not work on riscv at the moment (see issue #604)
I will use this on a separate larger project that requires a serial bridge between PC and a network of ESP32C3 (WROOM) communicating via ESP-NOW. I might revisit it and fix some issues if I find any.
NOTE:
embassy_hal_asyncdoes not have aReadtrait forserial,onlyWritetraits, so I could not follow the same implementation pattern as in the write case. The new function is calledread, not sure if it is Ok, there was not a read function for nb implementation. If you think is to generic, I can change it toread_asyncMust
errorsorwarnings.cargo fmtwas run.CHANGELOG.mdin the proper section.Nice to have