A fork of pulp-os for the xteink4 adding custom apps
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

add: helper for bitwise display inversions, rotation opts

hansmrtn 3b0fae9e 0cf807e5

+51 -23
+35 -10
kernel/src/drivers/ssd1677.rs
··· 147 147 } 148 148 } 149 149 150 + /// write BW RAM with content, RED RAM with inverted content 150 151 #[allow(clippy::too_many_arguments)] 151 152 fn write_region_strips_bw_inv_red<F>( 152 153 &mut self, ··· 182 183 self.send_command(cmd::WRITE_RAM_BW); 183 184 self.send_data(strip.data()); 184 185 185 - for byte in strip.data_mut().iter_mut() { 186 - *byte = !*byte; 187 - } 188 - if needs_mask && row_bytes > 0 { 189 - for row in strip.data_mut().chunks_mut(row_bytes) { 190 - row[0] |= left_mask; 191 - row[row.len() - 1] |= right_mask; 192 - } 193 - } 194 186 self.set_partial_ram_area(px, y, pw, rows); 195 187 self.send_command(cmd::WRITE_RAM_RED); 196 - self.send_data(strip.data()); 188 + self.send_data_inverted(strip.data(), left_mask, right_mask, row_bytes); 197 189 198 190 y += rows; 199 191 } ··· 361 353 fn send_data(&mut self, data: &[u8]) { 362 354 let _ = self.dc.set_high(); 363 355 let _ = self.spi.write(data); 356 + } 357 + 358 + /// Send data with each byte inverted, re-applying edge masks. 359 + /// Uses a small batch buffer to amortize SPI call overhead. 360 + fn send_data_inverted(&mut self, data: &[u8], left_mask: u8, right_mask: u8, row_bytes: usize) { 361 + const BATCH_SIZE: usize = 64; 362 + let mut batch = [0u8; BATCH_SIZE]; 363 + 364 + let _ = self.dc.set_high(); 365 + 366 + let mut offset = 0; 367 + while offset < data.len() { 368 + let chunk_len = (data.len() - offset).min(BATCH_SIZE); 369 + for i in 0..chunk_len { 370 + let byte_in_row = if row_bytes > 0 { 371 + (offset + i) % row_bytes 372 + } else { 373 + 0 374 + }; 375 + let mut inverted = !data[offset + i]; 376 + 377 + // Re-apply edge masks (inversion flipped them) 378 + if byte_in_row == 0 { 379 + inverted |= left_mask; 380 + } 381 + if row_bytes > 0 && byte_in_row == row_bytes - 1 { 382 + inverted |= right_mask; 383 + } 384 + batch[i] = inverted; 385 + } 386 + let _ = self.spi.write(&batch[..chunk_len]); 387 + offset += chunk_len; 388 + } 364 389 } 365 390 366 391 #[allow(clippy::too_many_arguments)]
+16 -13
kernel/src/drivers/strip.rs
··· 3 3 // widgets draw to logical coords, clipped here 4 4 5 5 use embedded_graphics_core::{ 6 - Pixel, 7 6 draw_target::DrawTarget, 8 7 geometry::{OriginDimensions, Size}, 9 8 pixelcolor::BinaryColor, 10 9 primitives::Rectangle, 10 + Pixel, 11 11 }; 12 12 13 - use super::ssd1677::{HEIGHT, Rotation, WIDTH}; 13 + use super::ssd1677::{Rotation, HEIGHT, WIDTH}; 14 14 use crate::ui::Region; 15 15 16 16 pub const STRIP_ROWS: u16 = 40; ··· 376 376 let black = color == BinaryColor::On; 377 377 378 378 match self.rotation { 379 - Rotation::Deg270 => { 380 - // logical (lx,ly) -> physical (ly, HEIGHT-1-lx) 381 - self.fill_physical_rect(ly0, HEIGHT - lx1, ly1, HEIGHT - lx0, black); 382 - } 383 379 Rotation::Deg0 => { 384 380 self.fill_physical_rect(lx0, ly0, lx1, ly1, black); 385 381 } 386 - _ => { 387 - for ly in ly0..ly1 { 388 - for lx in lx0..lx1 { 389 - let (px, py) = self.to_physical(lx, ly); 390 - self.set_pixel_physical(px, py, black); 391 - } 392 - } 382 + Rotation::Deg90 => { 383 + self.fill_physical_rect(WIDTH - ly1, lx0, WIDTH - ly0, lx1, black); 384 + } 385 + Rotation::Deg180 => { 386 + self.fill_physical_rect( 387 + WIDTH - lx1, 388 + HEIGHT - ly1, 389 + WIDTH - lx0, 390 + HEIGHT - ly0, 391 + black, 392 + ); 393 + } 394 + Rotation::Deg270 => { 395 + self.fill_physical_rect(ly0, HEIGHT - lx1, ly1, HEIGHT - lx0, black); 393 396 } 394 397 } 395 398 Ok(())