use core::cell::RefCell; use display_interface_spi::SPIInterface; use embedded_graphics::pixelcolor::BinaryColor; use embedded_graphics::prelude::*; use embedded_hal::digital::OutputPin as EhOutputPin; use embedded_hal_bus::spi::RefCellDevice; use esp_hal::delay::Delay; use esp_hal::gpio::{Level, Output, OutputConfig, OutputPin}; use ssd1306::mode::BufferedGraphicsMode; use ssd1306::prelude::*; use ssd1306::Ssd1306; pub type SecondaryOledDisplay<'a, BUS, DC> = Ssd1306< SPIInterface< RefCellDevice<'a, BUS, Output<'a>, Delay>, DC, >, DisplaySize128x64, BufferedGraphicsMode, >; pub fn init_secondary_oled_on_bus<'a, BUS, CS, RES, DC>( spi_bus: &'a RefCell, cs: CS, mut res: RES, dc: DC, delay: &mut Delay, ) -> SecondaryOledDisplay<'a, BUS, DC> where BUS: embedded_hal::spi::SpiBus, CS: OutputPin + 'static, RES: EhOutputPin, DC: EhOutputPin, { let cs_pin = Output::new(cs, Level::High, OutputConfig::default()); let spi_dev = RefCellDevice::new(spi_bus, cs_pin, *delay).unwrap(); let interface = SPIInterface::new(spi_dev, dc); let mut display = Ssd1306::new( interface, DisplaySize128x64, DisplayRotation::Rotate0, ) .into_buffered_graphics_mode(); display.reset(&mut res, delay).unwrap(); display.init().unwrap(); display.clear(BinaryColor::Off).unwrap(); display.flush().unwrap(); display }