use std::{error::Error, thread::sleep, time::Duration}; use embedded_graphics::{image::Image, pixelcolor::Rgb565, prelude::*}; use esp_idf_hal::{ gpio::{Gpio16, Gpio17, Gpio18, Gpio23, Gpio5, Output}, prelude::{Hertz, Peripherals}, spi::{self, Pins, SPI3}, }; use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported use ssd1331::{DisplayRotation::Rotate0, Ssd1331}; use tinybmp::Bmp; fn secondary() -> Result<(), Box> { // Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once, // or else some patches to the runtime implemented by esp-idf-sys might not link properly. esp_idf_sys::link_patches(); // Bind the log crate to the ESP Logging facilities esp_idf_svc::log::EspLogger::initialize_default(); let peripherals = Peripherals::take().unwrap(); let spi3 = peripherals.spi3; let pins = peripherals.pins; let cs: Gpio17 = pins.gpio17.into_output()?; let dc: Gpio16 = pins.gpio16.into_output()?; let mosi: Gpio23 = pins.gpio23.into_output()?; let sclk: Gpio18 = pins.gpio18.into_output()?; let reset: Gpio5 = pins.gpio5.into_output()?; // // Set up SPI interface and digital pin. These are stub implementations used in examples. let spiman = spi::Master::, Gpio23, Gpio5, Gpio17>::new( spi3, Pins { sclk: sclk, sdo: mosi, sdi: Some(reset), cs: Some(cs), }, spi::config::Config { baudrate: Hertz(24000000), data_mode: embedded_hal::spi::MODE_0, write_only: false, dma: spi::Dma::Disabled, }, )?; let mut display = Ssd1331::new(spiman, dc, Rotate0); display.init().unwrap(); display.flush().unwrap(); let (w, h) = display.dimensions(); println!("got resolution {} x {}", w.clone(), h.clone()); let bmp = Bmp::from_slice(include_bytes!("./eye.bmp")).expect("Failed to load BMP image"); let im: Image> = Image::new(&bmp, Point::zero()); // Position image in the center of the display let moved = im.translate(Point::new( (w as u32 - bmp.size().width) as i32 / 2, (h as u32 - bmp.size().height) as i32 / 2, )); moved.draw(&mut display).unwrap(); display.flush().unwrap(); Ok(()) } fn main() -> Result<(), Box> { sleep(Duration::from_secs(1)); Ok(secondary().unwrap()) }