-
Notifications
You must be signed in to change notification settings - Fork 232
Bikeshed: Should (Embedded) Linux Be Able to Implement These Traits? #17
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
Comments
The short answer is: yes. The long answer is: but probably not the lowest level traits because they are tailored for MCUs where non-blocking operations are retry-able without having to track state in the program (the state is in the registers). That form of non-blocking operation is covered by the More concretely apart from the low level traits which are already in tree we want to add traits tailored for blocking operation and another set of traits for interoperation with futures. Where possible we want those traits to built on top of the existing low level traits to avoid rewriting register manipulation code in the implementation of the higher level traits. I was originally envisioning something like this: // write half the Serial trait we already have
trait Write<Word> {
type Error;
fn write(&self, word: Word) -> nb::Result<(), Self::Error>;
}
// Blocking write operations
trait BWrite {
type Error;
fn bwrite_all(&self, buffer: &[u8]) -> Result<(), Self::Error>;
// ..
}
// overridable blanket implementation
default impl<S> BWrite for S where S: Write<u8> {
type Error = S::Error;
fn write_all(&self, buffer: &[u8]) -> Result<(), S::Error> {
for byte in buffer {
block!(self.write(*byte))?;
}
Ok(())
}
} However the |
Closing as this now exists in the form of the |
17: Remove #[deny(warnings)] r=therealprof a=dbrgn The library currently does not currently build anymore, because upstream libraries have added new deprecation warnings. A deprecation warning should not break compilation though. There was a post on Reddit about this about a year ago, but I can't find it anymore. I think adding a CI check step would be fine, but `#[deny(warnings)]` is a bit too much. These are the warnings: ``` warning: use of deprecated item 'hal::digital::OutputPin': Deprecated because the methods cannot return errors. Users should use the traits in digital::v2. --> src/lib.rs:111:6 | 111 | impl hal::digital::OutputPin for Pin { | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: #[warn(deprecated)] on by default warning: use of deprecated item 'hal::digital::InputPin': Deprecated because the methods cannot return errors. Users should use the traits in digital::v2. --> src/lib.rs:121:6 | 121 | impl hal::digital::InputPin for Pin { | ^^^^^^^^^^^^^^^^^^^^^^ warning: use of deprecated item 'hal::digital::InputPin::is_high': Deprecated because the methods cannot return errors. Users should use the traits in digital::v2. --> src/lib.rs:131:15 | 131 | !self.is_high() | ^^^^^^^ ``` Co-authored-by: Danilo Bargen <[email protected]>
18: Move to digital v2 traits r=nastevens a=dbrgn The v1 traits are deprecated because they don't have a way to report errors. Gets rid of the deprecation warnings (which are hard errors until rust-embedded#17 is merged). Co-authored-by: Danilo Bargen <[email protected]>
In looking to address comments like some of those raised on the i2cdev crate (rust-embedded/rust-i2cdev#27 / rust-embedded/rust-i2cdev#28) I went around to the embedded RFCs and found time to review some of this for the first time.
The basic question here is whether it should be a goal or whether (and how) a concerted effort should be made to support the
embedded-hal
traits under Linux for usage/testing from a Linux userspace system such as a raspberry pi.Benefits of Supporting Linux:
Challenges to Supporting LInux:
Life without Linux Support:
The dream is to be able to write a piece of higher-level code using a set of base APIs/Traits to access hardware and be able to have this code work in a variety of platforms, including Linux. If we end up needing a separate set of traits for systems like MCUs and systems like Linux then driver work for a particular sensor cannot be easily shared (there may still be opportunity for reuse in a crate but it would be additional work for the author).
I have not dug deeply into what it would look like to attempt to implement any of the existing or proposed traits for Linux but it would be an interesting thing to explore as the support would, in my opinion, be extremely nice.
All of this being said, I wholeheartedly believe that what is proposed here is the right approach when working with the actual hardware in a least-common-denominator system like an MCU.
The text was updated successfully, but these errors were encountered: