flipperzero-rs / flipperzero

Rust on the Flipper Zero
MIT License
499 stars 32 forks source link

Add embedded-hal I2C traits implementations #117

Closed agarof closed 11 months ago

agarof commented 11 months ago

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 commented 11 months ago

@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 commented 11 months ago

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

str4d commented 11 months ago

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.