From 401bb3b0886ecf368c21215ec45e45ffe606c246 Mon Sep 17 00:00:00 2001 From: alloncm Date: Mon, 23 Sep 2024 23:12:26 +0300 Subject: [PATCH] Fix the ili9341 RGB mode Also fix some comments --- core/src/ppu/gfx_device.rs | 1 + rpi/src/drivers/ili9341_gfx_device.rs | 4 ++-- sdl/src/sdl_gfx_device.rs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/ppu/gfx_device.rs b/core/src/ppu/gfx_device.rs index a3d3ead1..787d0a43 100644 --- a/core/src/ppu/gfx_device.rs +++ b/core/src/ppu/gfx_device.rs @@ -1,5 +1,6 @@ use super::gb_ppu::{SCREEN_HEIGHT, SCREEN_WIDTH}; +/// Pixel is in the format of RGB555 as in the gbdev docs which is low bits (Red) -> high bits (Blue) pub type Pixel = u16; pub trait GfxDevice{ diff --git a/rpi/src/drivers/ili9341_gfx_device.rs b/rpi/src/drivers/ili9341_gfx_device.rs index e490ccac..975f3735 100644 --- a/rpi/src/drivers/ili9341_gfx_device.rs +++ b/rpi/src/drivers/ili9341_gfx_device.rs @@ -96,8 +96,8 @@ impl Ili9341Contoller{ controller.spi.write(Ili9341Command::VcomControl2 as u8, &[0x86]); // Configuring the screen - controller.spi.write(Ili9341Command::MemoryAccessControl as u8, &[0x28]); // This command tlit the screen 90 degree and set pixel to BGR order - controller.spi.write(Ili9341Command::PixelFormatSet as u8, &[0x55]); // set pixel format to 16 bit per pixel; + controller.spi.write(Ili9341Command::MemoryAccessControl as u8, &[0x20]); // This command tlit the screen 90 degree and set pixel to RGB order (low bits (Red) -> High bits (Blue)) + controller.spi.write(Ili9341Command::PixelFormatSet as u8, &[0x55]); // set pixel format to 16 bit per pixel; controller.spi.write(Ili9341Command::FrameRateControl as u8, &[0x0, 0x10 /*According to the docs this is 119 hrz, setting this option in order to avoid screen tearing on rpi zero2 */]); controller.spi.write(Ili9341Command::DisplayFunctionControl as u8, &[0x8, 0x82, 0x27]); diff --git a/sdl/src/sdl_gfx_device.rs b/sdl/src/sdl_gfx_device.rs index 8794f241..15b1ca2c 100644 --- a/sdl/src/sdl_gfx_device.rs +++ b/sdl/src/sdl_gfx_device.rs @@ -3,7 +3,7 @@ use sdl2::sys::*; use magenboy_core::{ppu::gb_ppu::{SCREEN_HEIGHT, SCREEN_WIDTH}, utils::vec2::Vec2, GfxDevice, Pixel}; use super::utils::get_sdl_error_message; -// The bit order is high -> low bit as opposed to RGB555 in the gbdev docs which is low -> high bit +// The bit order is high bits -> low bits as opposed to RGB555 in the gbdev docs which is low -> high const SDL_PIXEL_FORMAT:u32 = SDL_PixelFormatEnum::SDL_PIXELFORMAT_BGR555 as u32; struct SdlWindow{