//! Blinks an LED
//!
//! This assumes that a LED is connected to GPIO4.
//! Depending on your target and the board you are using you should change the pin.
//! If your board doesn't have on-board LEDs don't forget to add an appropriate resistor.
//!
use esp_idf_hal::delay::FreeRtos;
use esp_idf_hal::gpio::*;
use esp_idf_hal::peripherals::Peripherals;
use esp_idf_sys as _; // If usisng the `binstart` feature of `esp-idf-sys`, always keep this module imported
use std::thread;
use std::time::Duration;
use embedded_hal::spi::MODE_3;
use esp_idf_hal::delay::Ets;
use esp_idf_hal::spi::*;
use esp_idf_hal::units::FromValueType;
use display_interface_spi::SPIInterfaceNoCS;
use mipidsi::{Builder, Orientation};
use embedded_graphics::image::*;
use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::prelude::*;
use embedded_graphics::mono_font::MonoTextStyle;
use embedded_graphics::pixelcolor::*;
use embedded_graphics::prelude::*;
use embedded_graphics::primitives::*;
use embedded_graphics::text::*;
use embedded_graphics::image::Image;
use embedded_graphics::geometry::*;
use embedded_graphics::draw_target::DrawTarget;
use profont::{PROFONT_24_POINT, PROFONT_18_POINT};
fn main() -> anyhow::Result<()> {
esp_idf_sys::link_patches();
let peripherals = Peripherals::take().unwrap();
let spi = peripherals.spi2;
let rst = PinDriver::output(peripherals.pins.gpio3)?;
let dc = PinDriver::output(peripherals.pins.gpio4)?;
let mut backlight = PinDriver::output(peripherals.pins.gpio5)?;
let sclk = peripherals.pins.gpio6;
let sda = peripherals.pins.gpio7;
let sdi = peripherals.pins.gpio8;
let cs = peripherals.pins.gpio10;
let mut delay = Ets;
// configuring the spi interface, note that in order for the ST7789 to work, the data_mode needs to be set to MODE_3
let config = config::Config::new()
.baudrate(26.MHz().into())
.data_mode(MODE_3);
let device =
SpiDeviceDriver::new_single(spi, sclk, sda, Some(sdi), Dma::Disabled, Some(cs), &config)?;
// display interface abstraction from SPI and DC
let di = SPIInterfaceNoCS::new(device, dc);
// create driver
let mut display = Builder::st7789(di)
.with_display_size(240, 240)
// set default orientation
.with_orientation(Orientation::Portrait(false))
// initialize
.init(&mut delay, Some(rst))
.unwrap();
// turn on the backlight
backlight.set_high()?;
// draw image on black background
display.clear(Rgb565::BLACK).unwrap();
Text::new("Display initializedz",
display.bounding_box().center() - Size::new(display.bounding_box().size.width/2 - 10, 0),
MonoTextStyle::new(&PROFONT_24_POINT, Rgb565::BLACK))
.draw(&mut display)
.unwrap();
println!("Image printed!");
loop {
thread::sleep(Duration::from_millis(1000));
}
}Loading
esp32-c3-devkitm-1
esp32-c3-devkitm-1