Tweak the hell out of the code until it shows a small square in the center of the screen
This commit is contained in:
parent
fb0e914edf
commit
54dd004915
@ -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 ROWS: usize = 320;
|
||||
const COLUMNS: usize = 240;
|
||||
const COLUMNS: usize = 170;
|
||||
const FRAMEBUF: usize = ROWS * COLUMNS * 3;
|
||||
|
||||
struct Step {
|
||||
@ -65,7 +65,7 @@ const COLMOD: u8 = 0x3a;
|
||||
const MADCTL: Step = Step {
|
||||
param_cnt: 1,
|
||||
command: 0x36,
|
||||
params: [0x08, 0, 0, 0],
|
||||
params: [0x00, 0, 0, 0],
|
||||
delay: None,
|
||||
};
|
||||
const CASET: u8 = 0x2a;
|
||||
@ -111,7 +111,7 @@ const RAMWR: u8 = 0x2c;
|
||||
// DISPON, 10ms delay
|
||||
// turn the display on
|
||||
|
||||
const SETUP_PROGRAM: [Step; 9] = [
|
||||
const SETUP_PROGRAM: [Step; 8] = [
|
||||
SWRESET,
|
||||
SLPOUT,
|
||||
Step {
|
||||
@ -124,15 +124,17 @@ const SETUP_PROGRAM: [Step; 9] = [
|
||||
Step {
|
||||
param_cnt: 4,
|
||||
command: CASET,
|
||||
params: [0, 0, 0, 240],
|
||||
params: [0, 35, 0, 204],
|
||||
delay: None,
|
||||
},
|
||||
/*
|
||||
Step {
|
||||
param_cnt: 4,
|
||||
command: RASET,
|
||||
params: [0, 0, (320 >> 8) as u8, (320 & 0xff) as u8],
|
||||
delay: None,
|
||||
},
|
||||
*/
|
||||
INVON,
|
||||
NORON,
|
||||
DISPON,
|
||||
@ -177,6 +179,8 @@ unsafe fn main() -> ! {
|
||||
// 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 led = pins.gpio16.into_function();
|
||||
|
||||
// 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.
|
||||
let spi_clk = pins.gpio2.into_function();
|
||||
@ -216,22 +220,34 @@ unsafe fn main() -> ! {
|
||||
|
||||
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 {
|
||||
led.set_high();
|
||||
let _ = board_select.set_low();
|
||||
let _ = data_command.set_low();
|
||||
let _ = spi.write(&[RAMWR]);
|
||||
let _ = data_command.set_high();
|
||||
let _ = spi.write(&bitmap);
|
||||
let _ = spi.write(&framebuf);
|
||||
let _ = board_select.set_high();
|
||||
|
||||
let color = i << 2;
|
||||
bitmap = [color; FRAMEBUF];
|
||||
|
||||
i = if i >= 64 { 0 } else { i + 1 };
|
||||
for x in 80..90 {
|
||||
for y in 155..165 {
|
||||
write_pixel(&mut framebuf, x, y, (0, 0, 63));
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
[toolchain]
|
||||
channel = "1.81.0"
|
||||
channel = "1.85.0"
|
||||
targets = [ "wasm32-unknown-unknown", "thumbv6m-none-eabi" ]
|
||||
components = [ "rustfmt", "rust-analyzer", "clippy" ]
|
||||
|
Loading…
Reference in New Issue
Block a user