Code Monkey home page Code Monkey logo

Comments (2)

japaric avatar japaric commented on June 9, 2024

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 nb crate and the block!, try_nb! macros.

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 default impl doesn't work today because of limitations of the feature (it doesn't work when associated types are involved) which throws a wrench into my plans. However, I think I have come up with a reasonable workaround. I'll test it and send a PR to show the approach.

from embedded-hal.

japaric avatar japaric commented on June 9, 2024

Closing as this now exists in the form of the linux-embedded-hal crate.

from embedded-hal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.