mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-15 10:10:57 +00:00
esp32-s3-lcd-ev-board clean up implementation
This commit is contained in:
parent
7ff648c41e
commit
bb23ed15e3
1 changed files with 10 additions and 53 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
||||||
// SPDX-License-Identifier: MIT
|
// 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;
|
extern crate alloc;
|
||||||
|
|
||||||
|
|
@ -41,10 +41,6 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
use alloc::boxed::Box;
|
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::dma::{DmaDescriptor, DmaTxBuf, CHUNK_SIZE};
|
||||||
use esp_hal::i2c;
|
use esp_hal::i2c;
|
||||||
use esp_hal::peripherals::Peripherals;
|
use esp_hal::peripherals::Peripherals;
|
||||||
|
|
@ -91,44 +87,6 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A wrapper around a boxed array that implements FrameBufferBackend.
|
|
||||||
pub struct HeapBuffer<C: PixelColor, const N: usize>(Box<[C; N]>);
|
|
||||||
|
|
||||||
impl<C: PixelColor, const N: usize> HeapBuffer<C, N> {
|
|
||||||
pub fn new(data: Box<[C; N]>) -> Self {
|
|
||||||
Self(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_slice(&self) -> &[C] {
|
|
||||||
self.0.as_ref()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<C: PixelColor, const N: usize> core::ops::Deref for HeapBuffer<C, N> {
|
|
||||||
type Target = [C; N];
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&*self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<C: PixelColor, const N: usize> core::ops::DerefMut for HeapBuffer<C, N> {
|
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
||||||
&mut *self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<C: PixelColor, const N: usize> FrameBufferBackend for HeapBuffer<C, N> {
|
|
||||||
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 {
|
struct EspBackend {
|
||||||
window: RefCell<Option<Rc<slint::platform::software_renderer::MinimalSoftwareWindow>>>,
|
window: RefCell<Option<Rc<slint::platform::software_renderer::MinimalSoftwareWindow>>>,
|
||||||
|
|
@ -315,16 +273,15 @@ impl slint::platform::Platform for EspBackend {
|
||||||
let mut pixel_box: Box<[Rgb565Pixel; FRAME_PIXELS]> =
|
let mut pixel_box: Box<[Rgb565Pixel; FRAME_PIXELS]> =
|
||||||
Box::new([Rgb565Pixel(0); FRAME_PIXELS]);
|
Box::new([Rgb565Pixel(0); FRAME_PIXELS]);
|
||||||
let pixel_buf: &mut [Rgb565Pixel] = &mut *pixel_box;
|
let pixel_buf: &mut [Rgb565Pixel] = &mut *pixel_box;
|
||||||
// Clear screen to blue for sanity check
|
// 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();
|
let dst = dma_tx.as_mut_slice();
|
||||||
let [blue_lo, blue_hi] = Rgb565::BLUE.into_storage().to_le_bytes();
|
for (i, px) in pixel_buf.iter().enumerate() {
|
||||||
for pixel in 0..FRAME_PIXELS {
|
let [lo, hi] = px.0.to_le_bytes();
|
||||||
dst[2 * pixel] = blue_lo;
|
dst[2 * i] = lo;
|
||||||
dst[2 * pixel + 1] = blue_hi;
|
dst[2 * i + 1] = hi;
|
||||||
}
|
}
|
||||||
}
|
// Initial flush of the screen buffer
|
||||||
// Initial flush of the blue screen
|
|
||||||
match dpi.send(false, dma_tx) {
|
match dpi.send(false, dma_tx) {
|
||||||
Ok(xfer) => {
|
Ok(xfer) => {
|
||||||
let (_res, dpi2, tx2) = xfer.wait();
|
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)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
enum InitCmd {
|
enum InitCmd {
|
||||||
Cmd(u8, &'static [u8]),
|
Cmd(u8, &'static [u8]),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue