Skip to content
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

UART: Add wrapper around RIOT's UART-interface #39

Open
wants to merge 43 commits into
base: main
Choose a base branch
from

Conversation

kbarning
Copy link

@kbarning kbarning commented Feb 9, 2023

Here is my attempt to create a wrapper for RIOT's UART-interface :)

@chrysn
Copy link
Member

chrysn commented Feb 11, 2023

Thanks for the PR. I've cleared it for a first CI run, but haven't yet had time to look at it. Given this needs a uart_t at construction, it might be good to look at #37 in parallel.

Copy link
Member

@chrysn chrysn 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 adding this. It looks good over-all, and very comprehensive. I have several details and questions annotated across the source. Quite a few of them might easily be explained by inspiration from existing code; I'd still hope to not continue on the bad examples I've set in the past.

src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
@kbarning
Copy link
Author

Thanks for adding this. It looks good over-all, and very comprehensive. I have several details and questions annotated across the source. Quite a few of them might easily be explained by inspiration from existing code; I'd still hope to not continue on the bad examples I've set in the past.

First of all, thank you for this comprehensive review. I will try to resolve your issues in the next few days :)

src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
@chrysn
Copy link
Member

chrysn commented Feb 19, 2023

CI tests are failing because RIOT's version of the riot-sys crate wasn't updated to the latest nightly yet -- but that's on the RIOT repository side of things.

@chrysn
Copy link
Member

chrysn commented Mar 4, 2023

When all open issues are addressed (I think it's only the matter of safety and scoping), as with the DAC PR, I'll want to have a test around to ensure that the code is actually built during CI. Let me know whether you want to give that a try in the style of c9cf3f2, otherwise I'll do it as part of the final review.

Copy link
Member

@chrysn chrysn left a comment

Choose a reason for hiding this comment

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

I think this is approaching completion.

Given the many fixes and merges, please rebase onto current master and squash into one or some logically structured commits.

Would you add some small runnable test?

src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
@Teufelchen1
Copy link
Contributor

@kbarning hey! I accidentally started a competing PR, I overlooked your work. Do you intend of picking this PR up again?

@kbarning
Copy link
Author

@kbarning hey! I accidentally started a competing PR, I overlooked your work. Do you intend of picking this PR up again?

Hey, I'm still waiting for an answer from @chrysn. I've implemented everything that he suggested to me so far, but I'm still waiting for approval.

@chrysn
Copy link
Member

chrysn commented Nov 20, 2024

Sorry for having let this sit unduly long, especially after you've brought it all this way – and not having remembered that this is sitting when Teufelchen started up his PR didn't help make the situation better, yet here we are.

Before I start looking through both PRs to see whether there's one that clearly outperforms (on usability, safe usability, features or clarity), would the two of you like to have a look over each other's PRs and/or a short exchange on whether there is one you both prefer or aspects missing from both?

@Teufelchen1
Copy link
Contributor

Okay, I gave it a thought and I believe this PR is better, in the sense that it is much more mature (documentation, api completeness, etc.).

What is missing compared to my draft is the implementation of embedded_io::Write / embedded_io::ErrorKind that chrysn wished for - But that can be retro fitted easily. I recommend doing that in a follow up PR (maybe I can do that), so this work here can finally get merged.

This PR needs a rebase. I did a shitty one locally to test this PR, it was annoying but not too bad. The code still works as intended.

@kbarning I can imagine you want this done sooner than later, please rebase and squash. I'll poke @chrysn to review it in a timely manner :)

(I can also offer to rebase & squash for you, if you like)

Copy link
Member

@chrysn chrysn left a comment

Choose a reason for hiding this comment

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

Final round of comments while going through this again after the duplicate PR situation is being resolved.

Most of them should be easy to apply. The soundness one will need another round of review, but given that there was a lifetime in the type in earlier iterations, it should be managable.

tests/uart/Cargo.toml Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
src/uart.rs Show resolved Hide resolved
src/uart.rs Outdated
/// static mut CB: fn(u8) = |new_data| {
/// //do something here with the received data
/// };
/// let mut uart = UartDevice::new_with_static_cb(0, 115200, unsafe { &mut CB })
Copy link
Member

Choose a reason for hiding this comment

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

The better example would be to use static_cell or maybe crate::mutex::Mutex, or even println!("Received {:02x}", new_data);, but unless you feel super motivate to update this, we can leave that as is for now.

Copy link
Author

Choose a reason for hiding this comment

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

I have added the println! in the examples :)

Copy link
Member

Choose a reason for hiding this comment

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

Then could almost just be fn cb(new_data: &[u8) { println!(...) }, no need for a mut static that'll need unsafe and makes the linter scream.

Almost, because we don't get a &mut cb, which hints at that user_callback should be F and not &'scope mut F … which again we can't do because we don't have a size limit.

We may need to iterate over that later on, but that'll work better when we see actual use cases. So let's have this in for now. I've just updated the example to not use static muts any more.

src/uart.rs Show resolved Hide resolved
src/uart.rs Outdated Show resolved Hide resolved
tests/uart/Cargo.toml Outdated Show resolved Hide resolved
@kbarning
Copy link
Author

Final round of comments while going through this again after the duplicate PR situation is being resolved.

Most of them should be easy to apply. The soundness one will need another round of review, but given that there was a lifetime in the type in earlier iterations, it should be managable.

I will have a look in the following days :)

kbarning and others added 19 commits December 7, 2024 04:17
Co-authored-by: chrysn <chrysn@fsfe.org>
Co-authored-by: chrysn <chrysn@fsfe.org>
Co-authored-by: chrysn <chrysn@fsfe.org>
Co-authored-by: chrysn <chrysn@fsfe.org>
Co-authored-by: chrysn <chrysn@fsfe.org>
Co-authored-by: chrysn <chrysn@fsfe.org>
Co-authored-by: chrysn <chrysn@fsfe.org>
Co-authored-by: chrysn <chrysn@fsfe.org>
Co-authored-by: chrysn <chrysn@fsfe.org>
@kbarning
Copy link
Author

kbarning commented Dec 7, 2024

Okay, I gave it a thought and I believe this PR is better, in the sense that it is much more mature (documentation, api completeness, etc.).

What is missing compared to my draft is the implementation of embedded_io::Write / embedded_io::ErrorKind that chrysn wished for - But that can be retro fitted easily. I recommend doing that in a follow up PR (maybe I can do that), so this work here can finally get merged.

This PR needs a rebase. I did a shitty one locally to test this PR, it was annoying but not too bad. The code still works as intended.

@kbarning I can imagine you want this done sooner than later, please rebase and squash. I'll poke @chrysn to review it in a timely manner :)

(I can also offer to rebase & squash for you, if you like)

I have rebased my branch. The squashing is done directly via this PR right? (at least I think so, if not I think @chrysn can enable it). It would be great if you can add the embedded_io stuff @Teufelchen1 because I hardly have any time at the moment 😞.

@Teufelchen1
Copy link
Contributor

Yes, squashing can be done via GitHub UI by chrysn (I do not have permissions).
Yes, I will add the embedded_io stuff in a followup PR, once this is merged :)

@chrysn
Copy link
Member

chrysn commented Dec 9, 2024

I wouldn't insist on squashing in general; if you prefer things squashed to a single commit, that can be done at merge time. (My general approach is that I like to have history visible in the tree, and merges from master into the feature branches, because people can always get a view as-if-squashed from git using --first-parent. For many of the items in here such as the fixes, it makes sense to apply them, and if doing that is excessive, let's rather squash it all -- also because due to the rebasing, it'll be nontrivial to understand where the added pub mod dac comes from before this is squashed.)

The latest version you pushed was not tested locally, was it? I've found a few compile errors, but am fixing them locally and pushing to the branch as part of a final checking round.

@chrysn
Copy link
Member

chrysn commented Dec 9, 2024

I've added a few fixes to the branch chrysn-impl_uart_wrapper (couldn't push to the PR's branch); am not through with them, but you may want to have a look at them.

@kbarning
Copy link
Author

I've added a few fixes to the branch chrysn-impl_uart_wrapper (couldn't push to the PR's branch); am not through with them, but you may want to have a look at them.

When you're done with the fixes, should I rebase this branch from yours?

@chrysn
Copy link
Member

chrysn commented Jan 6, 2025

I think I'm happy with the branch containing your work and my fixes now; I've created #143 as to run CI on it.

Can either of you run a check on that one, and look into whether anything is amiss?

I'll go through the open comments, and mark as resolved what has been addressed.

@@ -0,0 +1,331 @@
//! Access to [RIOT's UART](https://doc.riot-os.org/group__drivers__periph__uart.html)
//!
//! Author: Kilian Barning <barning@uni-bremen.de>
Copy link
Member

Choose a reason for hiding this comment

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

We don't have a consistent policy in Rust code for RIOT as to how to annotate authorship per module. I'd leave this in for now, especially until we do have something more generic, but as this is not a copyright note, it may be removed in a later version – realistically, I expect it to be moved into more meta data at some point.

@chrysn
Copy link
Member

chrysn commented Jan 7, 2025

With the review on #143, I've squashed things there; I'll merge that soon.

@kbarning, you might take interest in the notes of squashing there in #143 (comment)

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.

3 participants