-
Notifications
You must be signed in to change notification settings - Fork 242
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
Implement send_break
support
#700
Conversation
1d80e9b
to
24ae844
Compare
While trying to write a good example for this function, I noticed a few things I don't like about this API:
This compiles without a warning, but wouldn't ever clear the break bit.
But the suggestion is misleading (
But as far as I understand, it's still not correct. The break bit is specified as:
All in all, this interface is easier to use incorrectly than correctly. While less flexible, wouldn't something like For now, we could add two low-level functions |
Realized that the API is too difficult to use correctly.
I know it makes it harder to handle but would changing the type of the uart be acceptable? (via a wrapping newtype or a generic). // with
fn break(self) -> Breaking<Self>;
let foo: Breaking<_> = serial.break();
// some wait logic
let serial = foo.unbreak(); |
I'm not a fan of the @ithinuel solution to the issue, because I store my UART in a struct, this would break things cuz now we got a consuming function. Im of the opinion that @jannic thoughts about the misusage in regards to bypassing the must_use via "_=" is unfounded because ppl who do this probably haven't really understood what a uart break actually is yet. A issue I do get is the TX buffer not being cleared, which can be confusing to beginners that don't understand a 100% how the rp2040 uart works yet. In my small world proper docs would suffice but I get that rust is all about enforcing the correctness via the compiler. I don't really have an issue with @jannic less flexible API, it doesn't effect my use case, but their might be some edge case out there where this doesn't suffice. Adding the low level functions (maybe as unsafe) might fix this as well. |
Rust is all about enforcing memory safety, sometimes via the compiler, sometimes via the standard library.
Putting low-level access behind "unsafe" is a terrible solution to this. This isn't a memory safety issue. If you really want low-level interfaces to be super obvious (and therefore, not what you choose when looking for a high-level API) we have better practices for logically separating functions that live at different levels of the API. serial.lowlevel_set_break(); |
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.
While I'm not convinced that the lowlevel_
-prefix is needed, it doesn't really hurt either. And instead of endlessly bikeshedding function naming, we should start providing a way to send a break using the HAL. → Approved.
No description provided.