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

Nonblocking implementation #146

Open
ost-ing opened this issue Jan 19, 2021 · 3 comments
Open

Nonblocking implementation #146

ost-ing opened this issue Jan 19, 2021 · 3 comments

Comments

@ost-ing
Copy link

ost-ing commented Jan 19, 2021

  • MCU/other hardware in use: STM32h7
  • Display resolution and interface: I2C, [128x64]

Nonblocking I2C support

Hello, I'm attempting to build an application that utilizes this library in conjunction with doing real-time DAC/ADC functions. I have noticed that my DAC output, which is executed from a Timer producing a simple sine-wave is blocked by the I2C communication that this library executes, which distorts the output of the DAC.

I know that the embedded-hal doesn't support non-blocking for various reasons. What I would like to do is write my own interface adapter and implement I2C interrupt handling within my app to unblock the communication to the display.

Looking at the test_helpers.rs, I see this:

#[allow(dead_code)]
#[derive(Debug, Clone, Copy)]
pub struct StubInterface;

impl WriteOnlyDataCommand for StubInterface {
    fn send_commands(
        &mut self,
        _cmd: display_interface::DataFormat<'_>,
    ) -> Result<(), DisplayError> {
        Ok(())
    }
    fn send_data(&mut self, _buf: display_interface::DataFormat<'_>) -> Result<(), DisplayError> {
        Ok(())
    }
}

I assume that I could use the WriteOnlyDataCommand trait to achieve this?

Kind regards
Oliver

@jamwaffles
Copy link
Collaborator

Sorry for the delay! @therealprof maintains the crate that WriteOnlyDataCommand so might be able to offer more insight, but yes I think it's enough to add a custom impl of WriteOnlyDataCommand and pass that into Builder::new().connect(interface).into() instead of the provided blocking implementations.

@quentinmit
Copy link

quentinmit commented Jul 10, 2022

There's an embedded-hal-async now that provides async/await-compatible bus interfaces. See rust-embedded-community/ssd1331#13 for a PR adding support to the ssd1311 crate and follow embedded-graphics/embedded-graphics#622 for an upstream embedded-graphics trait.

It looks like someone already has an async fork: https://github.com/simmsb/ssd1306

@bugadani
Copy link
Contributor

cc #178

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

No branches or pull requests

4 participants