Skip to content

Instantly share code, notes, and snippets.

@almindor

almindor/lib.rs Secret

Last active November 9, 2024 22:08
Show Gist options
  • Save almindor/2a3c7243d4aa32e886895e145c7dc6d1 to your computer and use it in GitHub Desktop.
Save almindor/2a3c7243d4aa32e886895e145c7dc6d1 to your computer and use it in GitHub Desktop.
MIPIDSI direct render test (nostd)
// Add this to mipidsi/src/lib.rs
pub fn prep_pixels_from_buffer(
mut self,
sx: u16,
sy: u16,
ex: u16,
ey: u16,
) -> Result<Self, Error> {
self.set_address_window(sx, sy, ex, ey)?;
self.dcs.write_command(WriteMemoryStart)?;
Ok(self)
}
#![no_std]
#![no_main]
use display_interface_spi::SPIInterface as SpiInterface;
use embedded_graphics::{
draw_target::DrawTarget,
pixelcolor::Rgb565,
prelude::{Point, RgbColor, Size},
primitives::Rectangle,
};
use embedded_hal::spi::Operation;
use embedded_hal_bus::spi::ExclusiveDevice;
use esp_backtrace as _;
use esp_hal::{clock::Clocks, delay::Delay, gpio::*, prelude::*, spi::*, time};
use master::Spi;
use mipidsi::{models::ST7789, options::*, Builder};
#[entry]
fn main() -> ! {
#[allow(unused)]
let mut config = esp_hal::Config::default();
config.cpu_clock = CpuClock::Clock160MHz;
let peripherals = esp_hal::init(config);
let mut delay = Delay::new();
esp_println::logger::init_logger_from_env();
log::info!("running at {}", Clocks::get().cpu_clock);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let mosi = io.pins.gpio23;
let sclk = io.pins.gpio22;
let cs = Output::new(io.pins.gpio21, Level::High);
let dc = Output::new(io.pins.gpio20, Level::Low);
let rst = Output::new(io.pins.gpio19, Level::Low);
let spi =
Spi::new(peripherals.SPI2, 80.MHz(), SpiMode::Mode0).with_pins(sclk, mosi, NoPin, NoPin);
log::info!("Spi created");
let spi_device = ExclusiveDevice::new(spi, cs, delay).unwrap();
log::info!("SpiDevice created");
let di = SpiInterface::new(spi_device, dc);
log::info!("DI created");
let mut display = Builder::new(ST7789, di)
.reset_pin(rst)
.display_size(240, 320)
.orientation(Orientation::new().rotate(Rotation::Deg90))
.invert_colors(ColorInversion::Inverted)
.init(&mut delay)
.unwrap();
log::info!("Display created");
display.clear(Rgb565::BLUE).unwrap();
let fullscreen = Rectangle::new(Point::new(0, 0), Size::new(320, 240));
let raw_buf = [163u8; 320 * 240 * 2];
let start = time::now();
display.fill_solid(&fullscreen, Rgb565::RED).unwrap();
let total = time::now() - start;
log::info!("solid drawing time {}", total);
let start = time::now();
display
.set_pixels_from_buffer(0, 0, 239, 319, &raw_buf)
.unwrap();
let total = time::now() - start;
log::info!("from_buffer drawing time {}", total);
let (di, _model, _rst) = display
.prep_pixels_from_buffer(0, 0, 239, 319)
.unwrap()
.release();
let (mut spi, mut dc) = di.release();
let start = time::now();
dc.set_high();
use embedded_hal::spi::SpiDevice;
spi.transaction(&mut [Operation::Write(&raw_buf)]).unwrap();
let total = time::now() - start;
log::info!("direct drawing time {}", total);
loop {
delay.delay(500.millis());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment