speed up rendering by factor 1000
This commit is contained in:
+13
-18
@@ -15,6 +15,9 @@ use base64::{Engine as _, engine::general_purpose};
|
||||
use display_interface_spi::SPIInterface;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_time::Timer;
|
||||
use display_interface_spi::SPIInterface;
|
||||
use embedded_graphics::{Drawable, geometry::Size, primitives::Rectangle};
|
||||
use embedded_graphics::Pixel;
|
||||
use embedded_graphics::mono_font::MonoTextStyle;
|
||||
use embedded_graphics::mono_font::ascii::FONT_6X10;
|
||||
use embedded_graphics::pixelcolor::Rgb565;
|
||||
@@ -440,8 +443,7 @@ where
|
||||
// Bitwise operations are slightly faster than division/modulo
|
||||
let byte_index = pixel_index >> 1;
|
||||
let pixel_byte = sprite[byte_index];
|
||||
|
||||
let color_index = if pixel_index & 1 == 0 {
|
||||
let color_index = if pixel_index.is_multiple_of(2) {
|
||||
(pixel_byte >> 4) & 0x0F
|
||||
} else {
|
||||
pixel_byte & 0x0F
|
||||
@@ -449,24 +451,13 @@ where
|
||||
|
||||
let color = palette565[color_index as usize];
|
||||
|
||||
let start_x = (x * scale) as i32;
|
||||
let start_y = (y * scale) as i32;
|
||||
let end_x = core::cmp::min(start_x + scale as i32, target_width as i32);
|
||||
let end_y = core::cmp::min(start_y + scale as i32, target_width as i32);
|
||||
let width = u32::try_from(end_x - start_x).unwrap();
|
||||
let height = u32::try_from(end_y - start_y).unwrap();
|
||||
|
||||
let width = (end_x - start_x) as u32;
|
||||
let height = (end_y - start_y) as u32;
|
||||
let area = Rectangle::new(Point::new(start_x.try_into().unwrap(), start_y.try_into().unwrap()), Size::new(width, height));
|
||||
|
||||
if width == 0 || height == 0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
// OPTIMIZATION 2: Draw a rectangle block.
|
||||
// The display driver sets the SPI window ONCE per block.
|
||||
let rect = Rectangle::new(Point::new(start_x, start_y), Size::new(width, height));
|
||||
let style = PrimitiveStyle::with_fill(color);
|
||||
|
||||
let _ = rect.into_styled(style).draw(ili9341);
|
||||
let _ = ili9341.fill_solid(&area, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -630,10 +621,14 @@ async fn main(spawner: Spawner) {
|
||||
esp_hal::interrupt::software::SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
|
||||
esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0);
|
||||
|
||||
|
||||
let freq = Rate::from_khz(60_000);
|
||||
info!("Display freq: {freq}");
|
||||
|
||||
let spi_bus = Spi::new(
|
||||
peripherals.SPI2,
|
||||
Config::default()
|
||||
.with_frequency(Rate::from_mhz(40))
|
||||
.with_frequency(freq)
|
||||
.with_mode(Mode::_0),
|
||||
)
|
||||
.unwrap()
|
||||
|
||||
Reference in New Issue
Block a user