Add some testings from Rust-discord #dark-arts

This commit is contained in:
Sofia 2025-09-12 19:05:32 +03:00
parent f2fda32009
commit fbca758e1b
4 changed files with 138 additions and 21 deletions

57
Cargo.lock generated
View File

@ -68,6 +68,16 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "cc"
version = "1.2.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65193589c6404eb80b450d618eaf9a2cafaaafd57ecce47370519ef674a7bd44"
dependencies = [
"find-msvc-tools",
"shlex",
]
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.3" version = "1.0.3"
@ -122,6 +132,12 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "723dce4e9f25b6e6c5f35628e144794e5b459216ed7da97b7c4b66cdb3fa82ca" checksum = "723dce4e9f25b6e6c5f35628e144794e5b459216ed7da97b7c4b66cdb3fa82ca"
[[package]]
name = "find-msvc-tools"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fd99930f64d146689264c637b5af2f0233a933bef0d8570e2526bf9e083192d"
[[package]] [[package]]
name = "hash32" name = "hash32"
version = "0.3.1" version = "0.3.1"
@ -198,12 +214,52 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver",
]
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]] [[package]]
name = "stable_deref_trait" name = "stable_deref_trait"
version = "1.2.0" 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 = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "stackalloc"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b5b7088084b7f78305a42468c9a3693918620f0b8ec86260f1132dc0521e78"
dependencies = [
"cc",
"rustc_version",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.109" version = "1.0.109"
@ -225,6 +281,7 @@ dependencies = [
"embedded-hal 1.0.0", "embedded-hal 1.0.0",
"mipidsi", "mipidsi",
"panic-halt", "panic-halt",
"stackalloc",
"ufmt", "ufmt",
] ]

View File

@ -12,6 +12,7 @@ atmega-hal = { git = "https://github.com/Rahix/avr-hal?tab=readme-ov-file", rev=
ufmt = "0.2.0" ufmt = "0.2.0"
mipidsi = "0.9.0" mipidsi = "0.9.0"
embedded-graphics-core = "0.4.0" embedded-graphics-core = "0.4.0"
stackalloc = { version = "1.2.1", features = ["no_std"] }
# 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"

View File

@ -4,9 +4,11 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
#![feature(iter_array_chunks)] #![feature(iter_array_chunks)]
#![feature(const_slice_make_iter)]
#![feature(slice_as_chunks)]
use atmega_hal::{ use atmega_hal::{
Adc, Usart, Adc, Eeprom, Usart,
port::{Pin, mode}, port::{Pin, mode},
spi::{self, Settings}, spi::{self, Settings},
usart::Baudrate, usart::Baudrate,
@ -42,6 +44,9 @@ fn main() -> ! {
Baudrate::<CoreClock>::new(57600), Baudrate::<CoreClock>::new(57600),
); );
// let eeprom = Eeprom::new(dp.EEPROM);
// ufmt::uwriteln!(serial, "Eeprom capacity: {}", eeprom.capacity()).unwrap();
let cs = pins.pb2.into_output(); let cs = pins.pb2.into_output();
let (mut spi, mut cs) = spi::Spi::new( let (mut spi, mut cs) = spi::Spi::new(
dp.SPI, dp.SPI,

View File

@ -1,4 +1,7 @@
use core::slice::Iter; use core::{
hint::black_box,
slice::{Chunks, Iter},
};
use atmega_hal::{ use atmega_hal::{
Atmega, Usart, Atmega, Usart,
@ -13,9 +16,57 @@ use crate::{
display::{Color, Display, Position, Rgb565, Writeable}, display::{Color, Display, Position, Rgb565, Writeable},
}; };
#[repr(u8)]
enum NonBssByte {
V = 1,
}
pub struct NonBss<Buf> {
_hack: NonBssByte,
pub buf: Buf,
}
impl<const N: usize> NonBss<[u8; N]> {
pub const fn new(buf: [u8; N]) -> Self {
Self {
_hack: NonBssByte::V,
buf,
}
}
}
macro_rules! non_bss_statics {(
$(
$(#$attr:tt)*
$pub:vis
static ref $NAME:ident : [$u8:ty] = *include_bytes!($($args:tt)*);
)*
) => (
$(
$(#$attr)*
$pub
const $NAME: &[u8] = {
static $NAME: NonBss<[$u8; ::core::include_bytes!($($args)*).len()]> =
NonBss::new(*::core::include_bytes!($($args)*));
&$NAME.buf
};
)*
)}
// https://qoiformat.org/qoi-specification.pdf // https://qoiformat.org/qoi-specification.pdf
const LARGE: &[u8; 1966] = include_bytes!("../images/large.qoi"); // static LARGE: [u8; 1966] = *include_bytes!("../images/large.qoi");
const SHEEP: &[u8; 852] = include_bytes!("../images/sheep.qoi"); // static SHEEP: [u8; 852] = *include_bytes!("../images/sheep.qoi");
non_bss_statics! {
static ref SHEEP: [u8] = *include_bytes!("../images/sheep.qoi");
static ref LARGE: [u8] = *include_bytes!("../images/large.qoi");
}
// const LARGE_C1: [u8; 512] = LARGE.as_chunks().0[0];
// const LARGE_C2: [u8; 512] = LARGE.as_chunks().0[1];
// const LARGE_C3: [u8; 512] = LARGE.as_chunks().0[2];
// const LARGE_C4: &[u8] = LARGE.as_chunks::<512>().1;
#[derive(Debug, uDebug)] #[derive(Debug, uDebug)]
pub enum QoiErr { pub enum QoiErr {
@ -23,35 +74,38 @@ pub enum QoiErr {
UnexpectedEOF, UnexpectedEOF,
} }
#[derive(Default)] // #[derive(Default)]
struct LargeIter<const N: usize> { // struct LargeIter<const N: usize> {
index: usize, // index: usize,
} // }
impl<const N: usize> Iterator for LargeIter<N> { // impl<const N: usize> Iterator for LargeIter<N> {
type Item = u8; // type Item = u8;
fn next(&mut self) -> Option<Self::Item> { // fn next(&mut self) -> Option<Self::Item> {
if self.index >= N { // if self.index >= N {
return None; // return None;
} // }
let old_idx = self.index; // let old_idx = self.index;
self.index += 1; // self.index += 1;
Some(SHEEP[old_idx]) // 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 = LargeIter::<852>::default(); let a = LARGE[black_box(50)];
ufmt::uwriteln!(serial, "Successfully read QOI header {}", a).unwrap();
let mut iter = SHEEP.iter().map(|v| *v);
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<const N: usize>(iter: &mut LargeIter<N>) -> Result<u8, QoiErr> { fn next(iter: &mut dyn Iterator<Item = u8>) -> Result<u8, QoiErr> {
iter.next().ok_or(QoiErr::UnexpectedEOF) iter.next().ok_or(QoiErr::UnexpectedEOF)
} }