From bb23ed15e3531f4c407f74fdd989b9d9efef3d58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Mich=C3=A1lek?= Date: Mon, 14 Jul 2025 10:28:34 +0200 Subject: [PATCH] esp32-s3-lcd-ev-board clean up implementation --- .../esp32_s3_lcd_ev_board.rs | 63 +++---------------- 1 file changed, 10 insertions(+), 53 deletions(-) diff --git a/examples/mcu-board-support/esp32_s3_lcd_ev_board.rs b/examples/mcu-board-support/esp32_s3_lcd_ev_board.rs index 69794a105..41317d66e 100644 --- a/examples/mcu-board-support/esp32_s3_lcd_ev_board.rs +++ b/examples/mcu-board-support/esp32_s3_lcd_ev_board.rs @@ -1,6 +1,6 @@ // Copyright © SixtyFPS GmbH // SPDX-License-Identifier: MIT -//! Board support for ESP32-S3-LCD-EV-Board using the same init sequence as Conway's Game of Life example. +//! Board support for ESP32-S3-LCD-EV-Board with display and touch controller support. extern crate alloc; @@ -41,10 +41,6 @@ where } use alloc::boxed::Box; -use embedded_graphics_core::pixelcolor::Rgb565; -use embedded_graphics_core::pixelcolor::{IntoStorage, RgbColor}; -use embedded_graphics_core::prelude::PixelColor; -use embedded_graphics_framebuf::backends::FrameBufferBackend; use esp_hal::dma::{DmaDescriptor, DmaTxBuf, CHUNK_SIZE}; use esp_hal::i2c; use esp_hal::peripherals::Peripherals; @@ -91,44 +87,6 @@ fn panic(_info: &core::panic::PanicInfo) -> ! { loop {} } -/// A wrapper around a boxed array that implements FrameBufferBackend. -pub struct HeapBuffer(Box<[C; N]>); - -impl HeapBuffer { - pub fn new(data: Box<[C; N]>) -> Self { - Self(data) - } - - pub fn as_slice(&self) -> &[C] { - self.0.as_ref() - } -} - -impl core::ops::Deref for HeapBuffer { - type Target = [C; N]; - fn deref(&self) -> &Self::Target { - &*self.0 - } -} - -impl core::ops::DerefMut for HeapBuffer { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut *self.0 - } -} - -impl FrameBufferBackend for HeapBuffer { - type Color = C; - fn set(&mut self, index: usize, color: Self::Color) { - self.0[index] = color; - } - fn get(&self, index: usize) -> Self::Color { - self.0[index] - } - fn nr_elements(&self) -> usize { - N - } -} struct EspBackend { window: RefCell>>, @@ -315,16 +273,15 @@ impl slint::platform::Platform for EspBackend { let mut pixel_box: Box<[Rgb565Pixel; FRAME_PIXELS]> = Box::new([Rgb565Pixel(0); FRAME_PIXELS]); let pixel_buf: &mut [Rgb565Pixel] = &mut *pixel_box; - // Clear screen to blue for sanity check - { - let dst = dma_tx.as_mut_slice(); - let [blue_lo, blue_hi] = Rgb565::BLUE.into_storage().to_le_bytes(); - for pixel in 0..FRAME_PIXELS { - dst[2 * pixel] = blue_lo; - dst[2 * pixel + 1] = blue_hi; - } + // Initialize pixel buffer and DMA buffer + // The pixel buffer will be filled by Slint's renderer in the main loop + let dst = dma_tx.as_mut_slice(); + for (i, px) in pixel_buf.iter().enumerate() { + let [lo, hi] = px.0.to_le_bytes(); + dst[2 * i] = lo; + dst[2 * i + 1] = hi; } - // Initial flush of the blue screen + // Initial flush of the screen buffer match dpi.send(false, dma_tx) { Ok(xfer) => { let (_res, dpi2, tx2) = xfer.wait(); @@ -443,7 +400,7 @@ impl Tca9554 { } } -// Initialization commands matching the Conway example +// Display initialization commands for the ESP32-S3-LCD-EV-Board #[derive(Copy, Clone, Debug)] enum InitCmd { Cmd(u8, &'static [u8]),