Compare commits
No commits in common. "309ca727fc4cde74ebf8b8930307bee043018556" and "606d7d43ce7f352b6d95327e8e168df65c008ad5" have entirely different histories.
309ca727fc
...
606d7d43ce
23
Cargo.lock
generated
23
Cargo.lock
generated
@ -50,6 +50,17 @@ dependencies = [
|
|||||||
"unwrap-infallible",
|
"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]]
|
[[package]]
|
||||||
name = "az"
|
name = "az"
|
||||||
version = "1.2.1"
|
version = "1.2.1"
|
||||||
@ -80,6 +91,17 @@ version = "1.2.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
|
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]]
|
[[package]]
|
||||||
name = "embedded-graphics-core"
|
name = "embedded-graphics-core"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
@ -184,6 +206,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"atmega-hal",
|
"atmega-hal",
|
||||||
"avr-device",
|
"avr-device",
|
||||||
|
"avr-progmem",
|
||||||
"embedded-graphics-core",
|
"embedded-graphics-core",
|
||||||
"embedded-hal 1.0.0",
|
"embedded-hal 1.0.0",
|
||||||
"panic-halt",
|
"panic-halt",
|
||||||
|
@ -11,6 +11,7 @@ atmega-hal = { git = "https://github.com/Rahix/avr-hal?tab=readme-ov-file", rev=
|
|||||||
|
|
||||||
ufmt = "0.2.0"
|
ufmt = "0.2.0"
|
||||||
embedded-graphics-core = "0.4.0"
|
embedded-graphics-core = "0.4.0"
|
||||||
|
avr-progmem = "0.4.0"
|
||||||
# nb = "1.1.0"
|
# nb = "1.1.0"
|
||||||
# pwm-pca9685 = "1.0.0"
|
# pwm-pca9685 = "1.0.0"
|
||||||
# infrared = "0.14.1"
|
# infrared = "0.14.1"
|
||||||
|
BIN
images/cat.qoi
BIN
images/cat.qoi
Binary file not shown.
BIN
images/mario.qoi
Normal file
BIN
images/mario.qoi
Normal file
Binary file not shown.
BIN
images/pikachu.qoi
Normal file
BIN
images/pikachu.qoi
Normal file
Binary file not shown.
Binary file not shown.
BIN
images/rick.qoi
BIN
images/rick.qoi
Binary file not shown.
BIN
images/steve.qoi
Normal file
BIN
images/steve.qoi
Normal file
Binary file not shown.
Binary file not shown.
26
src/main.rs
26
src/main.rs
@ -6,21 +6,21 @@
|
|||||||
#![feature(iter_array_chunks)]
|
#![feature(iter_array_chunks)]
|
||||||
#![feature(const_slice_make_iter)]
|
#![feature(const_slice_make_iter)]
|
||||||
#![feature(slice_as_chunks)]
|
#![feature(slice_as_chunks)]
|
||||||
#![feature(asm_experimental_arch)]
|
#![feature(generic_const_exprs)]
|
||||||
|
|
||||||
use core::ptr::addr_of;
|
|
||||||
|
|
||||||
use atmega_hal::{
|
use atmega_hal::{
|
||||||
Usart,
|
Adc, Eeprom, Usart,
|
||||||
|
port::{Pin, mode},
|
||||||
spi::{self, Settings},
|
spi::{self, Settings},
|
||||||
usart::Baudrate,
|
usart::Baudrate,
|
||||||
};
|
};
|
||||||
|
use embedded_hal::delay::DelayNs;
|
||||||
use panic_halt as _;
|
use panic_halt as _;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
display::{Display, Position},
|
display::{Display, Position, Rgb565},
|
||||||
peripherals::Button,
|
peripherals::{Button, Knob},
|
||||||
qoi::{Image, LARGE_CAT_UNSAFE, PRESS_BTN_UNSAFE, RICK_UNSAFE, XP_DESKTOP_UNSAFE, draw_image},
|
qoi::{MARIO, PRESS_BTN, 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 = [&MARIO.as_slice()];
|
||||||
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)),
|
&MARIO.as_slice(),
|
||||||
&mut display,
|
&mut display,
|
||||||
Position { x: 0, y: 0 },
|
Position { x: 0, y: 0 },
|
||||||
) {
|
) {
|
||||||
@ -97,6 +93,8 @@ fn main() -> ! {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
if button.poll() {
|
if button.poll() {
|
||||||
|
idx = (idx + 1) % len;
|
||||||
|
|
||||||
match draw_image(
|
match draw_image(
|
||||||
&mut serial,
|
&mut serial,
|
||||||
&images[idx],
|
&images[idx],
|
||||||
@ -106,8 +104,6 @@ fn main() -> ! {
|
|||||||
Ok(_) => ufmt::uwriteln!(serial, "Successfully read QOI").unwrap(),
|
Ok(_) => ufmt::uwriteln!(serial, "Successfully read QOI").unwrap(),
|
||||||
Err(e) => ufmt::uwriteln!(serial, "Error: {:?}", e).unwrap(),
|
Err(e) => ufmt::uwriteln!(serial, "Error: {:?}", e).unwrap(),
|
||||||
}
|
}
|
||||||
|
|
||||||
idx = (idx + 1) % len;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
83
src/qoi.rs
83
src/qoi.rs
@ -1,75 +1,48 @@
|
|||||||
use core::{arch::asm, ptr::addr_of};
|
use core::{
|
||||||
|
hint::black_box,
|
||||||
|
slice::{Chunks, Iter},
|
||||||
|
};
|
||||||
|
|
||||||
use atmega_hal::{
|
use atmega_hal::{
|
||||||
Usart,
|
Atmega, Usart,
|
||||||
pac::USART0,
|
pac::USART0,
|
||||||
port::{PD0, PD1, Pin, PinOps, mode},
|
port::{PB3, PB5, PD0, PD1, Pin, PinOps, mode},
|
||||||
};
|
};
|
||||||
|
use avr_progmem::{progmem, wrapper::ProgMem};
|
||||||
use embedded_hal::delay::DelayNs;
|
use embedded_hal::delay::DelayNs;
|
||||||
use ufmt::derive::uDebug;
|
use ufmt::derive::uDebug;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
CoreClock,
|
CoreClock,
|
||||||
display::{Display, Position, Rgb565, Writeable},
|
display::{Color, Display, Position, Rgb565, Writeable},
|
||||||
|
qoi,
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://qoiformat.org/qoi-specification.pdf
|
progmem! {
|
||||||
|
/// Static byte stored in progmem!
|
||||||
#[unsafe(link_section = ".progmem.data")]
|
static progmem P_BYTE: u8 = 42;
|
||||||
pub static LARGE_CAT_UNSAFE: [u8; 8765] = *include_bytes!("../images/cat.qoi");
|
static progmem VERY_LARGE: [u8; 23731] = *include_bytes!("../images/cat.qoi");
|
||||||
#[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 struct Image {
|
|
||||||
ptr: *const u8,
|
|
||||||
length: usize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ImageIterator {
|
// https://qoiformat.org/qoi-specification.pdf
|
||||||
ptr: *const u8,
|
pub static MARIO: [u8; 161] = *include_bytes!("../images/mario.qoi");
|
||||||
length: usize,
|
pub static PRESS_BTN: [u8; 174] = *include_bytes!("../images/press_btn.qoi");
|
||||||
|
|
||||||
|
pub struct LargeIterator<const LENGTH: usize> {
|
||||||
|
buffer: ProgMem<[u8; LENGTH]>,
|
||||||
index: usize,
|
index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Image {
|
impl<const LENGTH: usize> Iterator for LargeIterator<LENGTH> {
|
||||||
pub const fn from<const N: usize>(addr: *const [u8; N]) -> Image {
|
|
||||||
Image {
|
|
||||||
ptr: addr.cast(),
|
|
||||||
length: N,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn iter(&self) -> ImageIterator {
|
|
||||||
ImageIterator {
|
|
||||||
ptr: self.ptr,
|
|
||||||
length: self.length,
|
|
||||||
index: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Iterator for ImageIterator {
|
|
||||||
type Item = u8;
|
type Item = u8;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
if self.index >= self.length {
|
if self.index >= LENGTH {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let elem_ptr = self.ptr.wrapping_add(self.index);
|
let item = self.buffer.load_at(self.index);
|
||||||
let res: u8;
|
|
||||||
unsafe {
|
|
||||||
asm!(
|
|
||||||
"lpm {}, Z",
|
|
||||||
out(reg) res,
|
|
||||||
in("Z") elem_ptr,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
self.index += 1;
|
self.index += 1;
|
||||||
Some(res)
|
Some(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,11 +54,17 @@ 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,
|
buffer: &[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();
|
// let mut iter = buffer.iter().map(|b| *b);
|
||||||
|
|
||||||
|
let mut iter = LargeIterator {
|
||||||
|
buffer: VERY_LARGE,
|
||||||
|
index: 0,
|
||||||
|
};
|
||||||
|
|
||||||
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())
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user