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

Add embedded-hal I2C traits implementations #117

Merged
merged 4 commits into from
Oct 30, 2023

Conversation

agarof
Copy link
Contributor

@agarof agarof commented Oct 26, 2023

Implements the I2C traits from embedded-hal, both the 0.2 and 1.0 rc1 versions.

Both implementations are optional features to avoid forcing the dependencies onto users.

Tested quickly using a logic analyzer and the ssd1306 crate with the following code:

use core::fmt::Write;
use ssd1306::prelude::*;

let bus = flipperzero::gpio::i2c::EmbeddedHalBus::new(
    flipperzero::gpio::i2c::Bus::EXTERNAL,
    flipperzero::furi::time::Duration::from_millis(100),
);

let interface = ssd1306::I2CDisplayInterface::new(bus);
let mut display = ssd1306::Ssd1306::new(interface, DisplaySize128x32, DisplayRotation::Rotate0)
    .into_terminal_mode();

display.init().unwrap();
display.clear().unwrap();

display.write_str("Hello from the\nFlipper Zero\n").unwrap();

image

@dcoles dcoles self-requested a review October 28, 2023 23:23
Copy link
Collaborator

@dcoles dcoles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @agarof. Thanks for the pull request! It looks great and would be happy to accept it. I've wanted to implement parts of embedded-hal for a while, but just haven't had the time. Opens up a lot more libraries in the ecosystem.

Only feedback on the review is some stale comments and some optional derives that could be implemented.

crates/flipperzero/src/gpio/i2c.rs Outdated Show resolved Hide resolved
crates/flipperzero/src/gpio/i2c.rs Show resolved Hide resolved
crates/flipperzero/src/gpio/i2c.rs Show resolved Hide resolved
@dcoles dcoles merged commit e0b6e90 into flipperzero-rs:main Oct 30, 2023
@dcoles
Copy link
Collaborator

dcoles commented Oct 30, 2023

@agarof Thanks for the pull request. Let me know if you're planning any other related PRs that should be in the next release, so I hold off on making it until then.

@agarof agarof deleted the embedded-hal branch October 30, 2023 22:45
@agarof
Copy link
Contributor Author

agarof commented Oct 30, 2023

@dcoles I should have time to implement embedded-hal's digital traits for the GPIOs during the week.

@str4d
Copy link
Contributor

str4d commented Oct 31, 2023

I'm glad you're going to work on this, because I'd just started a few weeks ago integrating embedded-hal myself (as part of writing SPI bindings, to write an example testing them), and was running into issues with the digital IO traits.

That is to say, I'll have #113 ready to review once there are GPIO bindings for embedded-hal.

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

Successfully merging this pull request may close these issues.

3 participants