Remove progmem

This commit is contained in:
Sofia 2025-09-13 13:08:32 +03:00
parent 606d7d43ce
commit ed3265f156
4 changed files with 38 additions and 43 deletions

23
Cargo.lock generated
View File

@ -50,17 +50,6 @@ dependencies = [
"unwrap-infallible",
]
[[package]]
name = "avr-progmem"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e93a9dd7da8f4eb57c912367e337687e06a8db6452d8c89eeb9eff1e0d2ba2d"
dependencies = [
"cfg-if",
"derivative",
"ufmt",
]
[[package]]
name = "az"
version = "1.2.1"
@ -91,17 +80,6 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
[[package]]
name = "derivative"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "embedded-graphics-core"
version = "0.4.0"
@ -206,7 +184,6 @@ version = "0.1.0"
dependencies = [
"atmega-hal",
"avr-device",
"avr-progmem",
"embedded-graphics-core",
"embedded-hal 1.0.0",
"panic-halt",

View File

@ -11,7 +11,6 @@ atmega-hal = { git = "https://github.com/Rahix/avr-hal?tab=readme-ov-file", rev=
ufmt = "0.2.0"
embedded-graphics-core = "0.4.0"
avr-progmem = "0.4.0"
# nb = "1.1.0"
# pwm-pca9685 = "1.0.0"
# infrared = "0.14.1"

View File

@ -6,7 +6,7 @@
#![feature(iter_array_chunks)]
#![feature(const_slice_make_iter)]
#![feature(slice_as_chunks)]
#![feature(generic_const_exprs)]
#![feature(asm_experimental_arch)]
use atmega_hal::{
Adc, Eeprom, Usart,

View File

@ -1,5 +1,7 @@
use core::{
arch::asm,
hint::black_box,
ptr::addr_of,
slice::{Chunks, Iter},
};
@ -8,7 +10,6 @@ use atmega_hal::{
pac::USART0,
port::{PB3, PB5, PD0, PD1, Pin, PinOps, mode},
};
use avr_progmem::{progmem, wrapper::ProgMem};
use embedded_hal::delay::DelayNs;
use ufmt::derive::uDebug;
@ -18,31 +19,51 @@ use crate::{
qoi,
};
progmem! {
/// Static byte stored in progmem!
static progmem P_BYTE: u8 = 42;
static progmem VERY_LARGE: [u8; 23731] = *include_bytes!("../images/cat.qoi");
}
// progmem! {
// /// Static byte stored in progmem!
// static progmem P_BYTE: u8 = 42;
// static progmem VERY_LARGE: [u8; 23731] = *include_bytes!("../images/cat.qoi");
// }
// https://qoiformat.org/qoi-specification.pdf
pub static MARIO: [u8; 161] = *include_bytes!("../images/mario.qoi");
pub static PRESS_BTN: [u8; 174] = *include_bytes!("../images/press_btn.qoi");
pub struct LargeIterator<const LENGTH: usize> {
buffer: ProgMem<[u8; LENGTH]>,
#[unsafe(link_section = ".progmem.data")]
static LARGE_CAT: [u8; 23731] = *include_bytes!("../images/cat.qoi");
pub struct LargeIterator {
ptr: *const u8,
length: usize,
index: usize,
}
impl<const LENGTH: usize> Iterator for LargeIterator<LENGTH> {
impl LargeIterator {
pub fn from<const N: usize>(addr: *const [u8; N]) -> LargeIterator {
LargeIterator {
ptr: addr.cast(),
length: N,
index: 0,
}
}
}
impl Iterator for LargeIterator {
type Item = u8;
fn next(&mut self) -> Option<Self::Item> {
if self.index >= LENGTH {
if self.index >= self.length {
return None;
}
let item = self.buffer.load_at(self.index);
let elem_ptr = self.ptr.wrapping_add(self.index);
let res: u8;
unsafe {
asm!(
"lpm {}, Z",
out(reg) res,
in("Z") elem_ptr,
)
}
self.index += 1;
Some(item)
Some(res)
}
}
@ -60,10 +81,8 @@ pub fn draw_image<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
) -> Result<(), QoiErr> {
// let mut iter = buffer.iter().map(|b| *b);
let mut iter = LargeIterator {
buffer: VERY_LARGE,
index: 0,
};
let addr = addr_of!(LARGE_CAT);
let mut iter = LargeIterator::from(addr);
if let (Some(113), Some(111), Some(105), Some(102)) =
(iter.next(), iter.next(), iter.next(), iter.next())