Tweak api a little bit

This commit is contained in:
Sofia 2025-09-13 14:05:08 +03:00
parent 6a999e3db8
commit 0ad742df48
2 changed files with 11 additions and 29 deletions

View File

@ -20,7 +20,7 @@ use panic_halt as _;
use crate::{ use crate::{
display::{Display, Position}, display::{Display, Position},
peripherals::Button, peripherals::Button,
qoi::{Image, LARGE_CAT_UNSAFE, PRESS_BTN_UNSAFE, RICK_UNSAFE, XP_DESKTOP_UNSAFE, draw_image}, qoi::{Image, LARGE_CAT_UNSAFE, PRESS_BTN_UNSAFE, draw_image},
}; };
mod display; mod display;
@ -78,16 +78,12 @@ fn main() -> ! {
let mut button = Button::from(pins.pd5.into_pull_up_input()); let mut button = Button::from(pins.pd5.into_pull_up_input());
let mut idx = 0; let mut idx = 0;
let images = [ let images = [Image::from(addr_of!(LARGE_CAT_UNSAFE))];
Image::from(addr_of!(LARGE_CAT_UNSAFE)),
Image::from(addr_of!(XP_DESKTOP_UNSAFE)),
Image::from(addr_of!(RICK_UNSAFE)),
];
let len = images.len(); let len = images.len();
match draw_image( match draw_image(
&mut serial, &mut serial,
&Image::from(addr_of!(PRESS_BTN_UNSAFE)), &mut Image::from(addr_of!(PRESS_BTN_UNSAFE)).iter(),
&mut display, &mut display,
Position { x: 0, y: 0 }, Position { x: 0, y: 0 },
) { ) {
@ -99,7 +95,7 @@ fn main() -> ! {
if button.poll() { if button.poll() {
match draw_image( match draw_image(
&mut serial, &mut serial,
&images[idx], &mut images[idx].iter(),
&mut display, &mut display,
Position { x: 0, y: 0 }, Position { x: 0, y: 0 },
) { ) {

View File

@ -18,10 +18,6 @@ use crate::{
#[unsafe(link_section = ".progmem.data")] #[unsafe(link_section = ".progmem.data")]
pub static LARGE_CAT_UNSAFE: [u8; 8765] = *include_bytes!("../images/cat.qoi"); pub static LARGE_CAT_UNSAFE: [u8; 8765] = *include_bytes!("../images/cat.qoi");
#[unsafe(link_section = ".progmem.data")] #[unsafe(link_section = ".progmem.data")]
pub static XP_DESKTOP_UNSAFE: [u8; 7360] = *include_bytes!("../images/xp_desktop.qoi");
#[unsafe(link_section = ".progmem.data")]
pub static RICK_UNSAFE: [u8; 2391] = *include_bytes!("../images/rick.qoi");
#[unsafe(link_section = ".progmem.data")]
pub static PRESS_BTN_UNSAFE: [u8; 1225] = *include_bytes!("../images/press_btn.qoi"); pub static PRESS_BTN_UNSAFE: [u8; 1225] = *include_bytes!("../images/press_btn.qoi");
pub struct Image { pub struct Image {
@ -81,11 +77,10 @@ pub enum QoiErr {
pub fn draw_image<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>( pub fn draw_image<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
serial: &mut Usart<USART0, Pin<mode::Input, PD0>, Pin<mode::Output, PD1>, CoreClock>, serial: &mut Usart<USART0, Pin<mode::Input, PD0>, Pin<mode::Output, PD1>, CoreClock>,
image: &Image, iter: &mut dyn Iterator<Item = u8>,
display: &mut Display<T, DCPin, RSTPin>, display: &mut Display<T, DCPin, RSTPin>,
position: Position, position: Position,
) -> Result<(), QoiErr> { ) -> Result<(), QoiErr> {
let mut iter = image.iter();
if let (Some(113), Some(111), Some(105), Some(102)) = if let (Some(113), Some(111), Some(105), Some(102)) =
(iter.next(), iter.next(), iter.next(), iter.next()) (iter.next(), iter.next(), iter.next(), iter.next())
{ {
@ -93,20 +88,11 @@ pub fn draw_image<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
iter.next().ok_or(QoiErr::UnexpectedEOF) iter.next().ok_or(QoiErr::UnexpectedEOF)
} }
let width = u32::from_be_bytes([ let width = u32::from_be_bytes([next(iter)?, next(iter)?, next(iter)?, next(iter)?]) as u16;
next(&mut iter)?, let height =
next(&mut iter)?, u32::from_be_bytes([next(iter)?, next(iter)?, next(iter)?, next(iter)?]) as u16;
next(&mut iter)?, let _channels = next(iter)?;
next(&mut iter)?, let _colorspace = next(iter)?;
]) as u16;
let height = u32::from_be_bytes([
next(&mut iter)?,
next(&mut iter)?,
next(&mut iter)?,
next(&mut iter)?,
]) as u16;
let _channels = next(&mut iter)?;
let _colorspace = next(&mut iter)?;
ufmt::uwriteln!(serial, "Successfully read QOI header").unwrap(); ufmt::uwriteln!(serial, "Successfully read QOI header").unwrap();
@ -120,7 +106,7 @@ pub fn draw_image<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
}, },
); );
let qoi_iter = QoiIterator::from(&mut iter, width * height); let qoi_iter = QoiIterator::from(iter, width * height);
let scale_iter = ScaleIterator { let scale_iter = ScaleIterator {
qoi: qoi_iter, qoi: qoi_iter,
last_row: [Rgb565::yellow(); 120], last_row: [Rgb565::yellow(); 120],