rust-embedded-community / ssd1306

SSD1306 OLED driver
Apache License 2.0
314 stars 70 forks source link

use embedded_hal_async::i2c::I2c in I2CDisplayInterface if feature 'a… #216

Closed mwesterm closed 1 month ago

mwesterm commented 1 month ago

use embedded_hal_async::i2c::I2c in I2CDisplayInterface if feature 'async' is enabled to enable embassy_embedded_hal::shared_bus::asynch::i2c

With embassy_embedded_hal::shared_bus::asynch::i2c you can share the same i2c for multiple devices. I.e.

use embassy_embedded_hal::shared_bus::asynch::i2c::I2cDevice; use embassy_sync::mutex::Mutex; use embassy_sync::blocking_mutex::raw::NoopRawMutex;

static I2C_BUS: StaticCell<Mutex<NoopRawMutex, Twim>> = StaticCell::new(); let config = twim::Config::default(); let i2c = Twim::new(p.TWISPI0, Irqs, p.P0_03, p.P0_04, config); let i2c_bus = Mutex::new(i2c); let i2c_bus = I2C_BUS.init(i2c_bus); // first device on the bus let interface = I2CDisplayInterface::new(I2cDevice::new(i2c_bus)); let mut display = Ssd1306Async::new(interface, DisplaySize128x32, DisplayRotation::Rotate0).into_terminal_mode(); //second device on the bus let mut ms5611 = Ms5611::new(I2cDevice::new(i2c_bus), None).await.unwrap();

mwesterm commented 1 month ago

Sorry, have found a problem with it.