1 Commits

Author SHA1 Message Date
d7fb4b4058 fuck 2025-10-28 17:08:50 -06:00
10 changed files with 192 additions and 87 deletions

83
Cargo.lock generated
View File

@@ -124,7 +124,7 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3"
dependencies = [ dependencies = [
"rustc_version", "rustc_version 0.2.3",
] ]
[[package]] [[package]]
@@ -225,7 +225,7 @@ dependencies = [
"embedded-io", "embedded-io",
"embedded-io-async", "embedded-io-async",
"futures-intrusive", "futures-intrusive",
"heapless", "heapless 0.8.0",
"uuid", "uuid",
] ]
@@ -409,7 +409,7 @@ dependencies = [
"embedded-hal 1.0.0", "embedded-hal 1.0.0",
"embedded-io-async", "embedded-io-async",
"futures", "futures",
"heapless", "heapless 0.8.0",
"num_enum 0.5.11", "num_enum 0.5.11",
] ]
@@ -788,7 +788,7 @@ dependencies = [
"embedded-io-async", "embedded-io-async",
"futures-sink", "futures-sink",
"futures-util", "futures-util",
"heapless", "heapless 0.8.0",
] ]
[[package]] [[package]]
@@ -803,7 +803,7 @@ dependencies = [
"embedded-io-async", "embedded-io-async",
"futures-core", "futures-core",
"futures-sink", "futures-sink",
"heapless", "heapless 0.8.0",
] ]
[[package]] [[package]]
@@ -856,7 +856,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80e2ee86063bd028a420a5fb5898c18c87a8898026da1d4c852af2c443d0a454" checksum = "80e2ee86063bd028a420a5fb5898c18c87a8898026da1d4c852af2c443d0a454"
dependencies = [ dependencies = [
"embassy-executor-timer-queue", "embassy-executor-timer-queue",
"heapless", "heapless 0.8.0",
] ]
[[package]] [[package]]
@@ -870,7 +870,7 @@ dependencies = [
"embassy-sync 0.7.2", "embassy-sync 0.7.2",
"embassy-usb-driver 0.2.0", "embassy-usb-driver 0.2.0",
"embedded-io-async", "embedded-io-async",
"heapless", "heapless 0.8.0",
"ssmarshal", "ssmarshal",
"usbd-hid", "usbd-hid",
] ]
@@ -1032,7 +1032,7 @@ dependencies = [
"defmt 0.3.100", "defmt 0.3.100",
"embedded-hal 1.0.0", "embedded-hal 1.0.0",
"embedded-io", "embedded-io",
"heapless", "heapless 0.8.0",
] ]
[[package]] [[package]]
@@ -1312,6 +1312,15 @@ dependencies = [
"crunchy", "crunchy",
] ]
[[package]]
name = "hash32"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67"
dependencies = [
"byteorder",
]
[[package]] [[package]]
name = "hash32" name = "hash32"
version = "0.3.1" version = "0.3.1"
@@ -1342,13 +1351,26 @@ version = "0.15.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5"
[[package]]
name = "heapless"
version = "0.7.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f"
dependencies = [
"atomic-polyfill",
"hash32 0.2.1",
"rustc_version 0.4.1",
"spin 0.9.8",
"stable_deref_trait",
]
[[package]] [[package]]
name = "heapless" name = "heapless"
version = "0.8.0" version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad"
dependencies = [ dependencies = [
"hash32", "hash32 0.3.1",
"serde", "serde",
"stable_deref_trait", "stable_deref_trait",
] ]
@@ -1502,14 +1524,14 @@ dependencies = [
"embedded-sdmmc", "embedded-sdmmc",
"embedded-text", "embedded-text",
"goblin", "goblin",
"heapless", "heapless 0.8.0",
"kolibri-embedded-gui", "kolibri-embedded-gui",
"num_enum 0.7.4", "num_enum 0.7.4",
"once_cell", "once_cell",
"panic-probe", "panic-probe",
"portable-atomic", "portable-atomic",
"rand", "rand",
"spin", "spin 0.10.0",
"st7365p-lcd", "st7365p-lcd",
"static_cell", "static_cell",
"strum", "strum",
@@ -1526,7 +1548,7 @@ dependencies = [
"embedded-graphics", "embedded-graphics",
"embedded-iconoir", "embedded-iconoir",
"foldhash", "foldhash",
"heapless", "heapless 0.8.0",
] ]
[[package]] [[package]]
@@ -2142,7 +2164,16 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [ dependencies = [
"semver", "semver 0.9.0",
]
[[package]]
name = "rustc_version"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92"
dependencies = [
"semver 1.0.27",
] ]
[[package]] [[package]]
@@ -2200,6 +2231,12 @@ dependencies = [
"semver-parser", "semver-parser",
] ]
[[package]]
name = "semver"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
[[package]] [[package]]
name = "semver-parser" name = "semver-parser"
version = "0.7.0" version = "0.7.0"
@@ -2305,6 +2342,15 @@ dependencies = [
"rand", "rand",
] ]
[[package]]
name = "spin"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
dependencies = [
"lock_api",
]
[[package]] [[package]]
name = "spin" name = "spin"
version = "0.10.0" version = "0.10.0"
@@ -2333,7 +2379,7 @@ dependencies = [
"embedded-graphics-core", "embedded-graphics-core",
"embedded-hal 1.0.0", "embedded-hal 1.0.0",
"embedded-hal-async", "embedded-hal-async",
"heapless", "heapless 0.8.0",
"nb 1.1.0", "nb 1.1.0",
] ]
@@ -2563,10 +2609,11 @@ dependencies = [
[[package]] [[package]]
name = "tinygif" name = "tinygif"
version = "0.0.4" version = "0.0.4"
source = "git+https://github.com/LegitCamper/tinygif#083c0efbdbeb21835de30425e234247340f6e370" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09f1406b710986188de8d393c810213d4bbf940e327d90d52cff9930d007a248"
dependencies = [ dependencies = [
"embedded-graphics", "embedded-graphics",
"heapless", "heapless 0.7.17",
] ]
[[package]] [[package]]
@@ -2590,7 +2637,7 @@ dependencies = [
"embassy-time 0.4.0", "embassy-time 0.4.0",
"embedded-io", "embedded-io",
"futures", "futures",
"heapless", "heapless 0.8.0",
"rand_core 0.6.4", "rand_core 0.6.4",
"static_cell", "static_cell",
"trouble-host-macros", "trouble-host-macros",
@@ -2641,7 +2688,7 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98816b1accafbb09085168b90f27e93d790b4bfa19d883466b5e53315b5f06a6" checksum = "98816b1accafbb09085168b90f27e93d790b4bfa19d883466b5e53315b5f06a6"
dependencies = [ dependencies = [
"heapless", "heapless 0.8.0",
"portable-atomic", "portable-atomic",
] ]

View File

@@ -46,7 +46,7 @@ pub fn get_key() -> KeyEvent {
pub mod display { pub mod display {
use abi_sys::CPixel; use abi_sys::CPixel;
use alloc::{vec, vec::Vec}; // use alloc::{vec, vec::Vec};
use embedded_graphics::{ use embedded_graphics::{
Pixel, Pixel,
geometry::{Dimensions, Point}, geometry::{Dimensions, Point},
@@ -54,7 +54,7 @@ pub mod display {
prelude::{DrawTarget, Size}, prelude::{DrawTarget, Size},
primitives::Rectangle, primitives::Rectangle,
}; };
use once_cell::unsync::Lazy; // use once_cell::unsync::Lazy;
pub const SCREEN_WIDTH: usize = 320; pub const SCREEN_WIDTH: usize = 320;
pub const SCREEN_HEIGHT: usize = 320; pub const SCREEN_HEIGHT: usize = 320;

View File

@@ -46,7 +46,7 @@ pub struct CLayout {
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
impl Into<Layout> for CLayout { impl Into<Layout> for CLayout {
fn into(self) -> Layout { fn into(self) -> Layout {
unsafe { Layout::from_size_align_unchecked(self.size, self.alignment) } Layout::from_size_align(self.size, self.alignment).unwrap()
} }
} }

View File

@@ -3,7 +3,7 @@ use abi_sys::{
PrintAbi, ReadFile, RngRequest, SleepMsAbi, keyboard::*, PrintAbi, ReadFile, RngRequest, SleepMsAbi, keyboard::*,
}; };
use alloc::{string::ToString, vec::Vec}; use alloc::{string::ToString, vec::Vec};
use core::{alloc::GlobalAlloc, sync::atomic::Ordering}; use core::{alloc::GlobalAlloc, ops::DerefMut, sync::atomic::Ordering};
use embassy_rp::clocks::{RoscRng, clk_sys_freq}; use embassy_rp::clocks::{RoscRng, clk_sys_freq};
use embassy_time::Instant; use embassy_time::Instant;
use embedded_graphics::draw_target::DrawTarget; use embedded_graphics::draw_target::DrawTarget;
@@ -11,8 +11,7 @@ use embedded_sdmmc::{DirEntry, LfnBuffer};
use heapless::spsc::Queue; use heapless::spsc::Queue;
use crate::{ use crate::{
display::FRAMEBUFFER, display::{FRAMEBUFFER, FRAMEBUFFER2, WRITE_FRAMEBUFFER2},
framebuffer::FB_PAUSED,
storage::{Dir, File, SDCARD}, storage::{Dir, File, SDCARD},
}; };
@@ -80,9 +79,19 @@ pub extern "C" fn draw_iter(cpixels: *const CPixel, len: usize) {
let iter = cpixels.iter().copied().map(|c: CPixel| c.into()); let iter = cpixels.iter().copied().map(|c: CPixel| c.into());
FB_PAUSED.store(true, Ordering::Release); let fb = if cfg!(feature = "pimoroni2w") {
unsafe { FRAMEBUFFER.draw_iter(iter).unwrap() } if WRITE_FRAMEBUFFER2.load(Ordering::Acquire) {
FB_PAUSED.store(false, Ordering::Release); unsafe { FRAMEBUFFER2.deref_mut() }
} else {
unsafe { &mut FRAMEBUFFER }
}
} else {
unsafe { &mut FRAMEBUFFER }
};
fb.draw_iter(iter).unwrap();
WRITE_FRAMEBUFFER2.fetch_not(Ordering::AcqRel);
} }
pub static mut KEY_CACHE: Queue<KeyEvent, 32> = Queue::new(); pub static mut KEY_CACHE: Queue<KeyEvent, 32> = Queue::new();

View File

@@ -1,6 +1,10 @@
use crate::framebuffer::{self, AtomicFrameBuffer, FB_PAUSED}; use crate::framebuffer::{self, AtomicFrameBuffer};
use alloc::vec; use alloc::vec;
use core::sync::atomic::{AtomicBool, Ordering}; use core::alloc::GlobalAlloc;
use core::alloc::Layout;
#[cfg(feature = "pimoroni2w")]
use core::sync::atomic::AtomicBool;
use core::sync::atomic::Ordering;
use embassy_rp::{ use embassy_rp::{
Peri, Peri,
gpio::{Level, Output}, gpio::{Level, Output},
@@ -22,11 +26,34 @@ type DISPLAY = ST7365P<
pub const SCREEN_WIDTH: usize = 320; pub const SCREEN_WIDTH: usize = 320;
pub const SCREEN_HEIGHT: usize = 320; pub const SCREEN_HEIGHT: usize = 320;
// used to switch which fb is being used for read/write
#[cfg(feature = "pimoroni2w")]
pub static WRITE_FRAMEBUFFER2: AtomicBool = AtomicBool::new(false);
// the default screen buffer - the only one on boards without extra ram or psram
pub static mut FRAMEBUFFER: Lazy<AtomicFrameBuffer> = Lazy::new(|| { pub static mut FRAMEBUFFER: Lazy<AtomicFrameBuffer> = Lazy::new(|| {
static mut BUF: [u16; framebuffer::SIZE] = [0; framebuffer::SIZE]; static mut BUF: [u16; framebuffer::SIZE] = [0; framebuffer::SIZE];
AtomicFrameBuffer::new(unsafe { &mut BUF }) AtomicFrameBuffer::new(unsafe { &mut BUF })
}); });
#[cfg(feature = "pimoroni2w")]
pub static mut FRAMEBUFFER2: Lazy<AtomicFrameBuffer> = Lazy::new(|| {
use embedded_graphics::{
pixelcolor::Rgb565,
prelude::{DrawTarget, RgbColor},
};
let buf = unsafe {
let slab =
crate::heap::HEAP.alloc(Layout::array::<u16>(framebuffer::SIZE).unwrap()) as *mut u16;
core::slice::from_raw_parts_mut(slab, framebuffer::SIZE)
};
let mut fb = AtomicFrameBuffer::new(buf);
fb.set_all_tiles(false);
fb.clear(Rgb565::BLACK).unwrap();
fb
});
pub async fn init_display( pub async fn init_display(
spi: Spi<'static, SPI1, Async>, spi: Spi<'static, SPI1, Async>,
cs: Peri<'static, PIN_13>, cs: Peri<'static, PIN_13>,
@@ -53,11 +80,18 @@ pub async fn init_display(
#[embassy_executor::task] #[embassy_executor::task]
pub async fn display_handler(mut display: DISPLAY) { pub async fn display_handler(mut display: DISPLAY) {
loop { loop {
if !FB_PAUSED.load(Ordering::Acquire) { let fb = if cfg!(feature = "pimoroni2w") {
unsafe { FRAMEBUFFER.safe_draw(&mut display).await.unwrap() }; if WRITE_FRAMEBUFFER2.load(Ordering::Acquire) {
} unsafe { &mut FRAMEBUFFER }
} else {
unsafe { &mut FRAMEBUFFER2 }
}
} else {
unsafe { &mut FRAMEBUFFER }
};
fb.safe_draw(&mut display).await.unwrap();
// small yield to allow other tasks to run // small yield to allow other tasks to run
Timer::after_nanos(500).await; Timer::after_nanos(100).await;
} }
} }

View File

@@ -23,23 +23,29 @@ type MetaTileVec = heapless::Vec<Rectangle, { TILE_COUNT / MAX_META_TILES }>;
pub const SIZE: usize = SCREEN_HEIGHT * SCREEN_WIDTH; pub const SIZE: usize = SCREEN_HEIGHT * SCREEN_WIDTH;
pub static FB_PAUSED: AtomicBool = AtomicBool::new(false);
static mut DIRTY_TILES: LazyLock<heapless::Vec<AtomicBool, TILE_COUNT>> = LazyLock::new(|| {
let mut tiles = heapless::Vec::new();
for _ in 0..TILE_COUNT {
tiles.push(AtomicBool::new(true)).unwrap();
}
tiles
});
#[allow(dead_code)] #[allow(dead_code)]
pub struct AtomicFrameBuffer<'a>(&'a mut [u16]); pub struct AtomicFrameBuffer<'a> {
fb: &'a mut [u16],
dirty_tiles: heapless::Vec<AtomicBool, TILE_COUNT>,
}
impl<'a> AtomicFrameBuffer<'a> { impl<'a> AtomicFrameBuffer<'a> {
pub fn new(buffer: &'a mut [u16]) -> Self { pub fn new(buffer: &'a mut [u16]) -> Self {
assert!(buffer.len() == SIZE); assert!(buffer.len() == SIZE);
Self(buffer) let mut dirty_tiles = heapless::Vec::new();
for _ in 0..TILE_COUNT {
dirty_tiles.push(AtomicBool::new(true)).unwrap()
}
Self {
fb: buffer,
dirty_tiles,
}
}
pub fn set_all_tiles(&mut self, set: bool) {
for t in self.dirty_tiles.iter_mut() {
t.store(set, Ordering::Release);
}
} }
fn mark_tiles_dirty(&mut self, rect: Rectangle) { fn mark_tiles_dirty(&mut self, rect: Rectangle) {
@@ -52,7 +58,7 @@ impl<'a> AtomicFrameBuffer<'a> {
for ty in start_ty..=end_ty { for ty in start_ty..=end_ty {
for tx in start_tx..=end_tx { for tx in start_tx..=end_tx {
let tile_idx = ty * tiles_x + tx; let tile_idx = ty * tiles_x + tx;
unsafe { DIRTY_TILES.get_mut()[tile_idx].store(true, Ordering::Release) }; self.dirty_tiles[tile_idx].store(true, Ordering::Release);
} }
} }
} }
@@ -78,7 +84,7 @@ impl<'a> AtomicFrameBuffer<'a> {
for y in sy..=ey { for y in sy..=ey {
for x in sx..=ex { for x in sx..=ex {
if let Some(color) = color_iter.next() { if let Some(color) = color_iter.next() {
self.0[(y as usize * SCREEN_WIDTH) + x as usize] = color; self.fb[(y as usize * SCREEN_WIDTH) + x as usize] = color;
} else { } else {
return Err(()); // Not enough data return Err(()); // Not enough data
} }
@@ -101,7 +107,7 @@ impl<'a> AtomicFrameBuffer<'a> {
let mut tx = 0; let mut tx = 0;
while tx < tiles_x { while tx < tiles_x {
let idx = ty * tiles_x + tx; let idx = ty * tiles_x + tx;
if !unsafe { DIRTY_TILES.get()[idx].load(Ordering::Acquire) } { if !self.dirty_tiles[idx].load(Ordering::Acquire) {
tx += 1; tx += 1;
continue; continue;
} }
@@ -113,7 +119,7 @@ impl<'a> AtomicFrameBuffer<'a> {
// Grow horizontally, but keep under MAX_TILES_PER_METATILE // Grow horizontally, but keep under MAX_TILES_PER_METATILE
while tx + width_tiles < tiles_x while tx + width_tiles < tiles_x
&& unsafe { && unsafe {
DIRTY_TILES.get()[ty * tiles_x + tx + width_tiles].load(Ordering::Acquire) self.dirty_tiles[ty * tiles_x + tx + width_tiles].load(Ordering::Acquire)
} }
&& (width_tiles + height_tiles) <= MAX_META_TILES && (width_tiles + height_tiles) <= MAX_META_TILES
{ {
@@ -124,8 +130,7 @@ impl<'a> AtomicFrameBuffer<'a> {
for x_off in 0..width_tiles { for x_off in 0..width_tiles {
unsafe { unsafe {
DIRTY_TILES.get()[ty * tiles_x + tx + x_off] self.dirty_tiles[ty * tiles_x + tx + x_off].store(false, Ordering::Release);
.store(false, Ordering::Release);
}; };
} }
@@ -165,12 +170,12 @@ impl<'a> AtomicFrameBuffer<'a> {
0, 0,
self.size().width as u16 - 1, self.size().width as u16 - 1,
self.size().height as u16 - 1, self.size().height as u16 - 1,
&self.0[..], &self.fb[..],
) )
.await?; .await?;
unsafe { unsafe {
for tile in DIRTY_TILES.get_mut().iter() { for tile in self.dirty_tiles.iter() {
tile.store(false, Ordering::Release); tile.store(false, Ordering::Release);
} }
}; };
@@ -191,11 +196,10 @@ impl<'a> AtomicFrameBuffer<'a> {
let tiles_x = SCREEN_WIDTH / TILE_SIZE; let tiles_x = SCREEN_WIDTH / TILE_SIZE;
let _tiles_y = SCREEN_HEIGHT / TILE_SIZE; let _tiles_y = SCREEN_HEIGHT / TILE_SIZE;
let tiles = unsafe { DIRTY_TILES.get_mut() };
let mut pixel_buffer: heapless::Vec<u16, { TILE_SIZE * TILE_SIZE }> = heapless::Vec::new(); let mut pixel_buffer: heapless::Vec<u16, { TILE_SIZE * TILE_SIZE }> = heapless::Vec::new();
for tile_idx in 0..TILE_COUNT { for tile_idx in 0..TILE_COUNT {
if tiles[tile_idx].swap(false, Ordering::AcqRel) { if self.dirty_tiles[tile_idx].swap(false, Ordering::AcqRel) {
let tx = tile_idx % tiles_x; let tx = tile_idx % tiles_x;
let ty = tile_idx / tiles_x; let ty = tile_idx / tiles_x;
@@ -210,7 +214,9 @@ impl<'a> AtomicFrameBuffer<'a> {
for y in y_start..y_end { for y in y_start..y_end {
let start = y * SCREEN_WIDTH + x_start; let start = y * SCREEN_WIDTH + x_start;
let end = y * SCREEN_WIDTH + x_end; let end = y * SCREEN_WIDTH + x_end;
pixel_buffer.extend_from_slice(&self.0[start..end]).unwrap(); pixel_buffer
.extend_from_slice(&self.fb[start..end])
.unwrap();
} }
display display
@@ -240,7 +246,7 @@ impl<'a> AtomicFrameBuffer<'a> {
RST: OutputPin, RST: OutputPin,
DELAY: DelayNs, DELAY: DelayNs,
{ {
if unsafe { DIRTY_TILES.get().iter().any(|p| p.load(Ordering::Acquire)) } { if unsafe { self.dirty_tiles.iter().any(|p| p.load(Ordering::Acquire)) } {
let tiles_x = (SCREEN_WIDTH + TILE_SIZE - 1) / TILE_SIZE; let tiles_x = (SCREEN_WIDTH + TILE_SIZE - 1) / TILE_SIZE;
let tiles_y = (SCREEN_HEIGHT + TILE_SIZE - 1) / TILE_SIZE; let tiles_y = (SCREEN_HEIGHT + TILE_SIZE - 1) / TILE_SIZE;
@@ -264,7 +270,9 @@ impl<'a> AtomicFrameBuffer<'a> {
let end = start + rect_width; let end = start + rect_width;
// Safe: we guarantee buffer will not exceed MAX_META_TILE_PIXELS // Safe: we guarantee buffer will not exceed MAX_META_TILE_PIXELS
pixel_buffer.extend_from_slice(&self.0[start..end]).unwrap(); pixel_buffer
.extend_from_slice(&self.fb[start..end])
.unwrap();
} }
display display
@@ -286,7 +294,7 @@ impl<'a> AtomicFrameBuffer<'a> {
for ty in start_ty..=end_ty { for ty in start_ty..=end_ty {
for tx in start_tx..=end_tx { for tx in start_tx..=end_tx {
let tile_idx = ty * tiles_x + tx; let tile_idx = ty * tiles_x + tx;
unsafe { DIRTY_TILES.get_mut()[tile_idx].store(false, Ordering::Release) }; self.dirty_tiles[tile_idx].store(false, Ordering::Release);
} }
} }
} }
@@ -315,8 +323,8 @@ impl<'a> DrawTarget for AtomicFrameBuffer<'a> {
if (x as usize) < SCREEN_WIDTH && (y as usize) < SCREEN_HEIGHT { if (x as usize) < SCREEN_WIDTH && (y as usize) < SCREEN_HEIGHT {
let idx = (y as usize) * SCREEN_WIDTH + (x as usize); let idx = (y as usize) * SCREEN_WIDTH + (x as usize);
let raw_color = RawU16::from(color).into_inner(); let raw_color = RawU16::from(color).into_inner();
if self.0[idx] != raw_color { if self.fb[idx] != raw_color {
self.0[idx] = raw_color; self.fb[idx] = raw_color;
changed = true; changed = true;
} }
@@ -365,8 +373,8 @@ impl<'a> DrawTarget for AtomicFrameBuffer<'a> {
if let Some(color) = colors.next() { if let Some(color) = colors.next() {
let idx = (p.y as usize * SCREEN_WIDTH) + (p.x as usize); let idx = (p.y as usize * SCREEN_WIDTH) + (p.x as usize);
let raw_color = RawU16::from(color).into_inner(); let raw_color = RawU16::from(color).into_inner();
if self.0[idx] != raw_color { if self.fb[idx] != raw_color {
self.0[idx] = raw_color; self.fb[idx] = raw_color;
changed = true; changed = true;
} }
} else { } else {
@@ -404,7 +412,7 @@ impl<'a> DrawTarget for AtomicFrameBuffer<'a> {
.take((self.size().width * self.size().height) as usize), .take((self.size().width * self.size().height) as usize),
)?; )?;
for tile in unsafe { DIRTY_TILES.get_mut() }.iter() { for tile in self.dirty_tiles.iter() {
tile.store(true, Ordering::Release); tile.store(true, Ordering::Release);
} }

View File

@@ -246,7 +246,7 @@ async fn setup_mcu(mcu: Mcu) {
async fn setup_display(display: Display, spawner: Spawner) { async fn setup_display(display: Display, spawner: Spawner) {
let mut config = spi::Config::default(); let mut config = spi::Config::default();
config.frequency = 64_000_000; config.frequency = 16_000_000;
let spi = Spi::new( let spi = Spi::new(
display.spi, display.spi,
display.clk, display.clk,
@@ -323,6 +323,11 @@ async fn kernel_task(
spawner spawner
.spawn(watchdog_task(Watchdog::new(watchdog))) .spawn(watchdog_task(Watchdog::new(watchdog)))
.unwrap(); .unwrap();
// setup_psram(psram).await;
#[cfg(feature = "pimoroni2w")]
setup_qmi_psram().await;
setup_mcu(mcu).await; setup_mcu(mcu).await;
setup_display(display, spawner).await; setup_display(display, spawner).await;
setup_sd(sd).await; setup_sd(sd).await;
@@ -330,10 +335,6 @@ async fn kernel_task(
let _usb = embassy_rp_usb::Driver::new(usb, Irqs); let _usb = embassy_rp_usb::Driver::new(usb, Irqs);
// spawner.spawn(usb_handler(usb)).unwrap(); // spawner.spawn(usb_handler(usb)).unwrap();
// setup_psram(psram).await;
#[cfg(feature = "pimoroni2w")]
setup_qmi_psram().await;
loop { loop {
let ui_enabled = ENABLE_UI.load(Ordering::Relaxed); let ui_enabled = ENABLE_UI.load(Ordering::Relaxed);
if ui_enabled { if ui_enabled {

View File

@@ -1,10 +1,13 @@
use crate::{ use crate::{
BINARY_CH, display::FRAMEBUFFER, elf::load_binary, framebuffer::FB_PAUSED, BINARY_CH,
peripherals::keyboard, storage::FileName, display::{FRAMEBUFFER, FRAMEBUFFER2, WRITE_FRAMEBUFFER2},
elf::load_binary,
peripherals::keyboard,
storage::FileName,
}; };
use abi_sys::keyboard::{KeyCode, KeyState}; use abi_sys::keyboard::{KeyCode, KeyState};
use alloc::{str::FromStr, string::String, vec::Vec}; use alloc::{str::FromStr, string::String, vec::Vec};
use core::sync::atomic::Ordering; use core::{ops::DerefMut, sync::atomic::Ordering};
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, mutex::Mutex}; use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, mutex::Mutex};
use embedded_graphics::{ use embedded_graphics::{
Drawable, Drawable,
@@ -83,7 +86,15 @@ async fn draw_selection() {
const NO_BINS: &str = "No Programs found on SD Card. Ensure programs end with '.bin', and are located in the root directory"; const NO_BINS: &str = "No Programs found on SD Card. Ensure programs end with '.bin', and are located in the root directory";
let no_bins = String::from_str(NO_BINS).unwrap(); let no_bins = String::from_str(NO_BINS).unwrap();
FB_PAUSED.store(true, Ordering::Release); // ensure all elements show up at once let mut fb = if cfg!(feature = "pimoroni2w") {
if WRITE_FRAMEBUFFER2.load(Ordering::Acquire) {
unsafe { FRAMEBUFFER2.deref_mut() }
} else {
unsafe { &mut FRAMEBUFFER }
}
} else {
unsafe { &mut FRAMEBUFFER }
};
if file_names.is_empty() { if file_names.is_empty() {
TextBox::new( TextBox::new(
@@ -94,7 +105,7 @@ async fn draw_selection() {
), ),
text_style, text_style,
) )
.draw(unsafe { &mut *FRAMEBUFFER }) .draw(fb.deref_mut())
.unwrap(); .unwrap();
} else { } else {
let mut views: alloc::vec::Vec<Text<MonoTextStyle<Rgb565>>> = Vec::new(); let mut views: alloc::vec::Vec<Text<MonoTextStyle<Rgb565>>> = Vec::new();
@@ -119,16 +130,17 @@ async fn draw_selection() {
.bounding_box(); .bounding_box();
Rectangle::new(selected_bounds.top_left, selected_bounds.size) Rectangle::new(selected_bounds.top_left, selected_bounds.size)
.into_styled(PrimitiveStyle::with_stroke(Rgb565::WHITE, 1)) .into_styled(PrimitiveStyle::with_stroke(Rgb565::WHITE, 1))
.draw(unsafe { &mut *FRAMEBUFFER }) .draw(fb.deref_mut())
.unwrap(); .unwrap();
guard.last_bounds = Some(layout.bounds()); guard.last_bounds = Some(layout.bounds());
layout.draw(unsafe { &mut *FRAMEBUFFER }).unwrap(); layout.draw(fb.deref_mut()).unwrap();
} }
guard.changed = false; guard.changed = false;
FB_PAUSED.store(false, Ordering::Release); // ensure all elements show up at once
WRITE_FRAMEBUFFER2.fetch_not(Ordering::AcqRel);
} }
#[derive(Clone)] #[derive(Clone)]

View File

@@ -6,4 +6,4 @@ edition = "2024"
[dependencies] [dependencies]
abi = { path = "../../abi" } abi = { path = "../../abi" }
embedded-graphics = "0.8.1" embedded-graphics = "0.8.1"
tinygif = { git = "https://github.com/LegitCamper/tinygif" } tinygif = "0.0.4"

View File

@@ -11,9 +11,7 @@ use abi::{
}; };
use alloc::vec; use alloc::vec;
use core::panic::PanicInfo; use core::panic::PanicInfo;
use embedded_graphics::{ use embedded_graphics::{image::ImageDrawable, pixelcolor::Rgb565};
image::ImageDrawable, pixelcolor::Rgb565, prelude::Point, transform::Transform,
};
use tinygif::Gif; use tinygif::Gif;
#[panic_handler] #[panic_handler]
@@ -38,17 +36,13 @@ pub fn main() {
assert!(read == size); assert!(read == size);
let gif = Gif::<Rgb565>::from_slice(&buf).unwrap(); let gif = Gif::<Rgb565>::from_slice(&buf).unwrap();
let height = gif.height();
let mut frame_num = 0; let mut frame_num = 0;
loop { loop {
for mut frame in gif.frames() { for frame in gif.frames() {
let start = get_ms(); let start = get_ms();
frame frame.draw(&mut display).unwrap();
.translate_mut(Point::new(0, (320 - height as i32) / 2))
.draw(&mut display)
.unwrap();
frame_num += 1; frame_num += 1;
if frame_num % 100 == 0 { if frame_num % 100 == 0 {