Skip to content

Support non-blocking serial/SPI/... communication #128

Open
@dflemstr

Description

@dflemstr

I'm working on embedded-platform and am targeting nrf52840 devices as the first use-case.

Currently, I'm using this code to support serial writes: https://github.com/dflemstr/embedded-platform/blob/f9ae5e7b686fdbf66ee3f172c755aea543d4c102/platforms/nrf52840/src/serial.rs#L19-L23

I haven't started on SPI/I²C/... mappings but I suspect there will be similar challenges in making the code non-blocking.

The execution model I have chosen is to have the main thread always run wfi when there is nothing happening, and rely on interrupts to wake it up, poll a main future, and do some work, before going back to wfi.

Ideally, the baseline behavior I would like to see is to break apart some of the blocking transactions into multiple steps. Let's look at this section for example:

https://github.com/nrf-rs/nrf52-hal/blob/90a8c3c7dbdb478b49580fd2bf2f89bdb9286cc2/nrf52-hal-common/src/uarte.rs#L145-L154

This could either be modeled as an explicit state machine (e.g. an enum) where during each state transition, there is some sort of polling method instead of a while loop. So imagine a SerialTransaction object with a poll() method that would eventually return a successful status.

If this approach sounds sane, I can make it into a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions