Skip to content

Commit

Permalink
LTDC Layer 1 pixel format changed as RGB565
Browse files Browse the repository at this point in the history
  • Loading branch information
ierturk committed Nov 23, 2023
1 parent 34edc32 commit e37a7f7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
11 changes: 4 additions & 7 deletions src/drivers/display.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use embedded_graphics_core::{pixelcolor::Rgb565, prelude::*, primitives::Rectangle};

pub struct LtdcDisplay {
fb_ptr: *mut u8,
fb_ptr: *mut u16,
len: usize,
}

impl LtdcDisplay {
pub fn new(fb_ptr: *mut u8, len: usize) -> LtdcDisplay {
pub fn new(fb_ptr: *mut u16, len: usize) -> LtdcDisplay {
return LtdcDisplay { fb_ptr, len };
}
}
Expand All @@ -32,11 +32,8 @@ impl DrawTarget for LtdcDisplay {
let x = point.x as usize;
let y = point.y as usize;

let addr: usize = 3 * x + 3 * 240 * y;

fb[addr] = color.g();
fb[addr + 1] = color.b();
fb[addr + 2] = color.r();
let addr: usize = x + 240 * y;
fb[addr] = color.into_storage();
}
}
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/fmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ macro_rules! fmc_pins {

pub struct Sdram {}
impl Sdram {
pub fn new<D>(delay: &mut D) -> *mut u8
pub fn new<D>(delay: &mut D) -> *mut u16
where
D: DelayUs<u16>,
{
Expand Down Expand Up @@ -279,7 +279,7 @@ impl Sdram {
// Wait for SDRAM module is ready
while dp.FMC.sdsr.read().busy().bit_is_set() {}

return 0xd000_0000 as *mut u8;
return 0xd000_0000 as *mut u16;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/drivers/ltdc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ impl Ltdc {
.modify(|_, w| w.wvsppos().bits(0x0143).wvstpos().bits(0x04));

// Pixel format
ltd_dev.layer1.pfcr.modify(|_, w| w.pf().bits(0x01));
ltd_dev.layer1.pfcr.modify(|_, w| w.pf().bits(0x02));

// Default colours
ltd_dev.layer1.dccr.modify(|_, w| {
Expand Down Expand Up @@ -719,7 +719,7 @@ impl Ltdc {
ltd_dev
.layer1
.cfblnr
.modify(|_, w| w.cfblnbr().bits(3 * 0x0140));
.modify(|_, w| w.cfblnbr().bits(0x0140));

// Enable LTDC_Layer by setting LEN bit
ltd_dev.layer1.cr.modify(|_, w| w.len().enabled());
Expand Down
27 changes: 12 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use drivers::ltdc::Ltdc;
use embedded_graphics::primitives::Primitive;
use embedded_graphics::{
mono_font::{ascii::FONT_9X18, MonoTextStyle},
prelude::*,
text::Text,
};
use embedded_graphics::{
Expand Down Expand Up @@ -73,7 +72,9 @@ fn main() -> ! {
// Init and test FMC/SDRAM that start at 0xD000_0000
let sdram_ptr = Sdram::new(&mut delay);
let sdram_size = 8 * 1024 * 1024; // 8MiB
let sdram = unsafe { core::slice::from_raw_parts_mut(sdram_ptr, sdram_size) };
let sdram = unsafe {
core::slice::from_raw_parts_mut(sdram_ptr, sdram_size / core::mem::size_of::<u16>())
};
/*
for n in 0..ram_slice.len() {
ram_slice[n] = n as u16;
Expand All @@ -87,18 +88,14 @@ fn main() -> ! {
sdram.fill(0x00);

for n in 0..240 {
sdram[3 * n + 1] = 0xff;
}

for n in 0..240 {
sdram[3 * n + 10 * (3 * 240)] = 0xff;
sdram[3 * n + 20 * (3 * 240)] = 0xff;
sdram[3 * n + 1 + 30 * (3 * 240)] = 0xff;
sdram[n] = 0x1f;
sdram[n + 10 * 240] = 0x1f;
sdram[n + 20 * 240] = 0x3f << 5;
sdram[n + 30 * 240] = 0x1f << 11;
}

for n in 0..320 {
sdram[n * (3 * 240) + 120] = 0xff;
sdram[n * (3 * 240) + 121] = 0xff;
sdram[n * 240 + 120] = 0x1f | (0x3f << 5);
}

// Init LCD/LTDC Display
Expand All @@ -107,12 +104,12 @@ fn main() -> ! {

let mut display = LtdcDisplay::new(sdram_ptr, sdram_size);

let _ = Circle::new(Point::new(100, 240), 20)
.into_styled(PrimitiveStyle::with_stroke(Rgb565::WHITE, 2))
let _ = Circle::new(Point::new(100, 100), 40)
.into_styled(PrimitiveStyle::with_stroke(Rgb565::WHITE, 1))
.draw(&mut display);

let style = MonoTextStyle::new(&FONT_9X18, Rgb565::WHITE);
let _ = Text::new("Hello Rust!", Point::new(100, 200), style).draw(&mut display);
let style = MonoTextStyle::new(&FONT_9X18, Rgb565::RED);
let _ = Text::new("Hello Rust!", Point::new(100, 300), style).draw(&mut display);

// Idle async app for heartbeat
dp.GPIOG
Expand Down

0 comments on commit e37a7f7

Please sign in to comment.