Configure ravedude
This commit is contained in:
parent
91d04ff3cc
commit
f2fda32009
@ -1,6 +1,6 @@
|
|||||||
[build]
|
[build]
|
||||||
target = "avr-none"
|
target = "avr-none"
|
||||||
rustflags = ["-C", "target-cpu=atmega328p"]
|
rustflags = ["-C", "target-cpu=atmega328p", "--emit=llvm-ir"]
|
||||||
|
|
||||||
[target.'cfg(target_arch = "avr")']
|
[target.'cfg(target_arch = "avr")']
|
||||||
runner = "ravedude"
|
runner = "ravedude"
|
||||||
|
@ -24,6 +24,9 @@ panic = "abort"
|
|||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
|
opt-level = "s" # Size is more important than performance on MSP430.
|
||||||
|
codegen-units = 1 # Better size optimization.
|
||||||
|
lto = "fat" # _Much_ better size optimization.
|
||||||
|
|
||||||
[build]
|
[build]
|
||||||
rustflags = ["-C", "link-args=-lc"]
|
rustflags = ["-C", "link-args=-lc", "--emit=llvm-ir"]
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
[general]
|
[general]
|
||||||
board = "uno"
|
port = "/dev/ttyUSB0"
|
||||||
serial-baudrate = 57600
|
serial-baudrate = 57600
|
||||||
open-console = true
|
open-console = true
|
||||||
|
|
||||||
|
[board.avrdude]
|
||||||
|
# avrdude configuration
|
||||||
|
programmer = "arduino"
|
||||||
|
partno = "m328p"
|
||||||
|
baudrate = 57600
|
||||||
|
do-chip-erase = true
|
||||||
|
|
||||||
# For documentation about this file, check here:
|
# For documentation about this file, check here:
|
||||||
# https://github.com/Rahix/avr-hal/blob/main/ravedude/README.md#ravedudetoml-format
|
# https://github.com/Rahix/avr-hal/blob/main/ravedude/README.md#ravedudetoml-format
|
||||||
|
BIN
images/large.qoi
BIN
images/large.qoi
Binary file not shown.
BIN
images/sheep.xcf
BIN
images/sheep.xcf
Binary file not shown.
59
src/qoi.rs
59
src/qoi.rs
@ -14,7 +14,8 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
// https://qoiformat.org/qoi-specification.pdf
|
// https://qoiformat.org/qoi-specification.pdf
|
||||||
const image: &[u8; 1253] = include_bytes!("../images/hi.qoi");
|
const LARGE: &[u8; 1966] = include_bytes!("../images/large.qoi");
|
||||||
|
const SHEEP: &[u8; 852] = include_bytes!("../images/sheep.qoi");
|
||||||
|
|
||||||
#[derive(Debug, uDebug)]
|
#[derive(Debug, uDebug)]
|
||||||
pub enum QoiErr {
|
pub enum QoiErr {
|
||||||
@ -22,34 +23,52 @@ pub enum QoiErr {
|
|||||||
UnexpectedEOF,
|
UnexpectedEOF,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
struct LargeIter<const N: usize> {
|
||||||
|
index: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const N: usize> Iterator for LargeIter<N> {
|
||||||
|
type Item = u8;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
if self.index >= N {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let old_idx = self.index;
|
||||||
|
self.index += 1;
|
||||||
|
Some(SHEEP[old_idx])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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>,
|
||||||
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 = LargeIter::<852>::default();
|
||||||
|
|
||||||
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())
|
||||||
{
|
{
|
||||||
fn next<'a>(iter: &mut Iter<'a, u8>) -> Result<&'a u8, QoiErr> {
|
fn next<const N: usize>(iter: &mut LargeIter<N>) -> Result<u8, QoiErr> {
|
||||||
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(&mut iter)?,
|
next(&mut iter)?,
|
||||||
*next(&mut iter)?,
|
next(&mut iter)?,
|
||||||
*next(&mut iter)?,
|
next(&mut iter)?,
|
||||||
*next(&mut iter)?,
|
next(&mut iter)?,
|
||||||
]) as u16;
|
]) as u16;
|
||||||
let height = u32::from_be_bytes([
|
let height = u32::from_be_bytes([
|
||||||
*next(&mut iter)?,
|
next(&mut iter)?,
|
||||||
*next(&mut iter)?,
|
next(&mut iter)?,
|
||||||
*next(&mut iter)?,
|
next(&mut iter)?,
|
||||||
*next(&mut iter)?,
|
next(&mut iter)?,
|
||||||
]) as u16;
|
]) as u16;
|
||||||
let channels = *next(&mut iter)?;
|
let channels = next(&mut iter)?;
|
||||||
let colorspace = *next(&mut iter)?;
|
let colorspace = next(&mut iter)?;
|
||||||
|
|
||||||
ufmt::uwriteln!(serial, "Successfully read QOI header").unwrap();
|
ufmt::uwriteln!(serial, "Successfully read QOI header").unwrap();
|
||||||
|
|
||||||
@ -61,7 +80,7 @@ pub fn draw_image<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let qoi_iter = QoiIterator::from(iter, serial, width * height);
|
let qoi_iter = QoiIterator::from(&mut iter, serial, width * height);
|
||||||
|
|
||||||
// let mut chunks = qoi_iter.array_chunks::<BUFFER_SIZE>();
|
// let mut chunks = qoi_iter.array_chunks::<BUFFER_SIZE>();
|
||||||
// while let Some(array) = chunks.next() {
|
// while let Some(array) = chunks.next() {
|
||||||
@ -96,7 +115,7 @@ pub fn draw_image<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct QoiIterator<'a> {
|
struct QoiIterator<'a> {
|
||||||
inner: Iter<'a, u8>,
|
inner: &'a mut dyn Iterator<Item = u8>,
|
||||||
serial: &'a mut Usart<USART0, Pin<mode::Input, PD0>, Pin<mode::Output, PD1>, CoreClock>,
|
serial: &'a mut Usart<USART0, Pin<mode::Input, PD0>, Pin<mode::Output, PD1>, CoreClock>,
|
||||||
prev_pixels: [Rgb565; 64],
|
prev_pixels: [Rgb565; 64],
|
||||||
last_pixel: Rgb565,
|
last_pixel: Rgb565,
|
||||||
@ -107,7 +126,7 @@ struct QoiIterator<'a> {
|
|||||||
|
|
||||||
impl<'a> QoiIterator<'a> {
|
impl<'a> QoiIterator<'a> {
|
||||||
fn from(
|
fn from(
|
||||||
bytes: Iter<'a, u8>,
|
bytes: &'a mut dyn Iterator<Item = u8>,
|
||||||
serial: &'a mut Usart<USART0, Pin<mode::Input, PD0>, Pin<mode::Output, PD1>, CoreClock>,
|
serial: &'a mut Usart<USART0, Pin<mode::Input, PD0>, Pin<mode::Output, PD1>, CoreClock>,
|
||||||
expected: u16,
|
expected: u16,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@ -138,19 +157,19 @@ impl<'a> Iterator for QoiIterator<'a> {
|
|||||||
return Some(self.last_pixel);
|
return Some(self.last_pixel);
|
||||||
}
|
}
|
||||||
if let Some(byte) = self.inner.next() {
|
if let Some(byte) = self.inner.next() {
|
||||||
let color = if *byte == 0xff {
|
let color = if byte == 0xff {
|
||||||
let red = self.inner.next().unwrap();
|
let red = self.inner.next().unwrap();
|
||||||
let green = self.inner.next().unwrap();
|
let green = self.inner.next().unwrap();
|
||||||
let blue = self.inner.next().unwrap();
|
let blue = self.inner.next().unwrap();
|
||||||
let _alpha = self.inner.next().unwrap();
|
let _alpha = self.inner.next().unwrap();
|
||||||
// ufmt::uwriteln!(self.serial, "RGBA: {} {} {} {}", red, green, blue, alpha).unwrap();
|
// ufmt::uwriteln!(self.serial, "RGBA: {} {} {} {}", red, green, blue, alpha).unwrap();
|
||||||
Rgb565(*red, *green, *blue)
|
Rgb565(red, green, blue)
|
||||||
} else if *byte == 0b11111110 {
|
} else if byte == 0b11111110 {
|
||||||
let red = self.inner.next().unwrap();
|
let red = self.inner.next().unwrap();
|
||||||
let green = self.inner.next().unwrap();
|
let green = self.inner.next().unwrap();
|
||||||
let blue = self.inner.next().unwrap();
|
let blue = self.inner.next().unwrap();
|
||||||
// ufmt::uwriteln!(self.serial, "RGB: {} {} {}", red, green, blue).unwrap();
|
// ufmt::uwriteln!(self.serial, "RGB: {} {} {}", red, green, blue).unwrap();
|
||||||
Rgb565(*red, *green, *blue)
|
Rgb565(red, green, blue)
|
||||||
} else {
|
} else {
|
||||||
let tag = (0b11000000 & byte) >> 6;
|
let tag = (0b11000000 & byte) >> 6;
|
||||||
let data = 0b00111111 & byte;
|
let data = 0b00111111 & byte;
|
||||||
|
Loading…
Reference in New Issue
Block a user