Tweak the hell out of the code until it shows a small square in the center of the screen

This commit is contained in:
Savanni D'Gerinel 2025-02-26 23:59:10 -05:00
parent fb0e914edf
commit 54dd004915
2 changed files with 28 additions and 12 deletions

View File

@ -18,7 +18,7 @@ use rp_pico::{
const XOSC_CRYSTAL_FREQ: u32 = 12_000_000; // MHz, https://forums.raspberrypi.com/viewtopic.php?t=356764 const XOSC_CRYSTAL_FREQ: u32 = 12_000_000; // MHz, https://forums.raspberrypi.com/viewtopic.php?t=356764
const ROWS: usize = 320; const ROWS: usize = 320;
const COLUMNS: usize = 240; const COLUMNS: usize = 170;
const FRAMEBUF: usize = ROWS * COLUMNS * 3; const FRAMEBUF: usize = ROWS * COLUMNS * 3;
struct Step { struct Step {
@ -65,7 +65,7 @@ const COLMOD: u8 = 0x3a;
const MADCTL: Step = Step { const MADCTL: Step = Step {
param_cnt: 1, param_cnt: 1,
command: 0x36, command: 0x36,
params: [0x08, 0, 0, 0], params: [0x00, 0, 0, 0],
delay: None, delay: None,
}; };
const CASET: u8 = 0x2a; const CASET: u8 = 0x2a;
@ -111,7 +111,7 @@ const RAMWR: u8 = 0x2c;
// DISPON, 10ms delay // DISPON, 10ms delay
// turn the display on // turn the display on
const SETUP_PROGRAM: [Step; 9] = [ const SETUP_PROGRAM: [Step; 8] = [
SWRESET, SWRESET,
SLPOUT, SLPOUT,
Step { Step {
@ -124,15 +124,17 @@ const SETUP_PROGRAM: [Step; 9] = [
Step { Step {
param_cnt: 4, param_cnt: 4,
command: CASET, command: CASET,
params: [0, 0, 0, 240], params: [0, 35, 0, 204],
delay: None, delay: None,
}, },
/*
Step { Step {
param_cnt: 4, param_cnt: 4,
command: RASET, command: RASET,
params: [0, 0, (320 >> 8) as u8, (320 & 0xff) as u8], params: [0, 0, (320 >> 8) as u8, (320 & 0xff) as u8],
delay: None, delay: None,
}, },
*/
INVON, INVON,
NORON, NORON,
DISPON, DISPON,
@ -177,6 +179,8 @@ unsafe fn main() -> ! {
// An abstraction for a timer which we can use to delay the code. // An abstraction for a timer which we can use to delay the code.
let mut timer = Timer::new(peripherals.TIMER, &mut peripherals.RESETS, &clocks); let mut timer = Timer::new(peripherals.TIMER, &mut peripherals.RESETS, &clocks);
let mut led = pins.gpio16.into_function();
// Grab the clock and data pins for SPI1. For Clock pins and for Data pins, there are only two // Grab the clock and data pins for SPI1. For Clock pins and for Data pins, there are only two
// pins each on the Pico which can function for SPI1. // pins each on the Pico which can function for SPI1.
let spi_clk = pins.gpio2.into_function(); let spi_clk = pins.gpio2.into_function();
@ -216,22 +220,34 @@ unsafe fn main() -> ! {
timer.delay_ms(1000); timer.delay_ms(1000);
let mut bitmap: [u8; FRAMEBUF] = [0; FRAMEBUF]; let mut framebuf: [u8; FRAMEBUF] = [0; FRAMEBUF];
let mut i = 0; let mut strength = 0;
loop { loop {
led.set_high();
let _ = board_select.set_low(); let _ = board_select.set_low();
let _ = data_command.set_low(); let _ = data_command.set_low();
let _ = spi.write(&[RAMWR]); let _ = spi.write(&[RAMWR]);
let _ = data_command.set_high(); let _ = data_command.set_high();
let _ = spi.write(&bitmap); let _ = spi.write(&framebuf);
let _ = board_select.set_high(); let _ = board_select.set_high();
let color = i << 2; for x in 80..90 {
bitmap = [color; FRAMEBUF]; for y in 155..165 {
write_pixel(&mut framebuf, x, y, (0, 0, 63));
i = if i >= 64 { 0 } else { i + 1 }; }
}
timer.delay_ms(10); timer.delay_ms(10);
led.set_low();
timer.delay_ms(1000);
} }
} }
fn write_pixel(framebuf: &mut[u8], x: usize, y: usize, color: (u8, u8, u8)) {
framebuf[(y * COLUMNS + x) * 3 + 0] = color.0 << 2;
framebuf[(y * COLUMNS + x) * 3 + 1] = color.1 << 2;
framebuf[(y * COLUMNS + x) * 3 + 2] = color.2 << 2;
}

View File

@ -1,4 +1,4 @@
[toolchain] [toolchain]
channel = "1.81.0" channel = "1.85.0"
targets = [ "wasm32-unknown-unknown", "thumbv6m-none-eabi" ] targets = [ "wasm32-unknown-unknown", "thumbv6m-none-eabi" ]
components = [ "rustfmt", "rust-analyzer", "clippy" ] components = [ "rustfmt", "rust-analyzer", "clippy" ]