fix bug in abi_sys causing display driver crashes

This commit is contained in:
2025-10-06 00:18:44 -06:00
parent ddcdd5942a
commit 28417cce69
3 changed files with 21 additions and 33 deletions

View File

@@ -5,6 +5,8 @@ use abi_sys::{RngRequest, keyboard::KeyEvent};
use rand_core::RngCore;
use talc::*;
extern crate alloc;
static mut ARENA: [u8; 10000] = [0; 10000];
#[global_allocator]
@@ -29,8 +31,8 @@ pub mod display {
use embedded_graphics::{
Pixel,
geometry::{Dimensions, Point},
pixelcolor::{Rgb565, RgbColor},
prelude::{DrawTarget, IntoStorage, Size},
pixelcolor::Rgb565,
prelude::{DrawTarget, Size},
primitives::Rectangle,
};
@@ -45,27 +47,6 @@ pub mod display {
const BUF_SIZE: usize = 1024; // tune this for performance
fn draw_iter(pixels: &[Pixel<Rgb565>]) {
let mut cpixels: [CPixel; BUF_SIZE] = [const {
CPixel {
x: 0,
y: 0,
color: 0,
}
}; BUF_SIZE];
for (px, cpx) in pixels.iter().zip(cpixels.iter_mut()) {
let Pixel(pos, color) = px;
let color: u16 = color.into_storage(); // convert Rgb565 -> u16
*cpx = CPixel {
x: pos.x,
y: pos.y,
color,
};
}
abi_sys::draw_iter(cpixels.as_ptr(), cpixels.len())
}
pub struct Display;
impl Dimensions for Display {
@@ -88,21 +69,21 @@ pub mod display {
where
I: IntoIterator<Item = Pixel<Self::Color>>,
{
let mut buf: [Pixel565; BUF_SIZE] = [Pixel(Point::new(0, 0), Rgb565::BLACK); BUF_SIZE];
let mut buf: [CPixel; BUF_SIZE] = [CPixel::new(); BUF_SIZE];
let mut count = 0;
for p in pixels {
buf[count] = p;
buf[count] = p.into();
count += 1;
if count == BUF_SIZE {
draw_iter(&buf[..count]);
abi_sys::draw_iter(buf.as_ptr(), count);
count = 0;
}
}
if count > 0 {
draw_iter(&buf[..count]);
abi_sys::draw_iter(buf.as_ptr(), count);
}
Ok(())

View File

@@ -2,7 +2,7 @@
use embedded_graphics::{
Pixel,
pixelcolor::Rgb565,
pixelcolor::{Rgb565, raw::RawU16},
prelude::{IntoStorage, Point},
};
use embedded_sdmmc::DirEntry;
@@ -65,6 +65,16 @@ pub struct CPixel {
pub color: u16,
}
impl CPixel {
pub fn new() -> Self {
Self {
x: 0,
y: 0,
color: 0,
}
}
}
impl Into<CPixel> for Pixel<Rgb565> {
fn into(self) -> CPixel {
CPixel {
@@ -77,10 +87,7 @@ impl Into<CPixel> for Pixel<Rgb565> {
impl Into<Pixel<Rgb565>> for CPixel {
fn into(self) -> Pixel<Rgb565> {
let r5 = ((self.color >> 11) & 0x1F) as u8;
let g6 = ((self.color >> 5) & 0x3F) as u8;
let b5 = (self.color & 0x1F) as u8;
Pixel(Point::new(self.x, self.y), Rgb565::new(r5, g6, b5))
Pixel(Point::new(self.x, self.y), RawU16::new(self.color).into())
}
}

View File

@@ -5,7 +5,7 @@ use abi_sys::{
use alloc::{string::ToString, vec::Vec};
use core::sync::atomic::Ordering;
use embassy_rp::clocks::{RoscRng, clk_sys_freq};
use embedded_graphics::{Pixel, draw_target::DrawTarget, pixelcolor::Rgb565};
use embedded_graphics::draw_target::DrawTarget;
use embedded_sdmmc::{DirEntry, LfnBuffer};
use heapless::spsc::Queue;