stm32-ada/examples/lcd_demo/lcd_demo.adb

160 lines
5.3 KiB
Ada

with Ada.Real_Time;
use Ada.Real_Time;
with Board.LCD.SPI_IO;
with Board.LCD.Controller;
with Board.UART.IO;
with Board.Frequencies;
use Board.Frequencies;
with Board.Memory;
with Chip;
with Chip.Units;
with Simple_Pools;
with STM32.Graphics;
with STM32.LTDC;
use STM32.LTDC;
with System.Storage_Elements;
use type System.Storage_Elements.Storage_Offset;
with System.Address_To_Access_Conversions;
procedure LCD_Demo is
Now : Time := Clock;
C : Integer := 0;
SDRAM_Pool : Simple_Pools.Simple_Pool := Simple_Pools.Make_Simple_Pool (
System.Storage_Elements.To_Address (Board.Memory.Memory_Base),
Board.Memory.Memory_Size / System.Storage_Unit);
type Pixel_Array is array (Integer range <>, Integer range <>) of aliased STM32.Graphics.RGB888_Pixel with Component_Size => 24;
type Pixel_Array_Access is access Pixel_Array
with Storage_Pool => SDRAM_Pool;
package A is new System.Address_To_Access_Conversions (STM32.Graphics.RGB888_Pixel);
Frame : Pixel_Array_Access := new Pixel_Array (0 .. 319, 0 .. 239);
begin
Board.UART.IO.Transmit ("Frequencies" & ASCII.CR & ASCII.LF);
Board.UART.IO.Transmit ("VCO In " & Integer'Image (VCO_Input_Frequency) & ASCII.CR & ASCII.LF);
Board.UART.IO.Transmit ("PLLCLK " & Integer'Image (PLLCLK_Frequency) & ASCII.CR & ASCII.LF);
Board.UART.IO.Transmit ("HCLK " & Integer'Image (HCLK_Frequency) & ASCII.CR & ASCII.LF);
Board.UART.IO.Transmit ("USBCLK " & Integer'Image (USB_Frequency) & ASCII.CR & ASCII.LF);
Board.UART.IO.Transmit ("PCLK1 " & Integer'Image (PCLK1_Frequency) & ASCII.CR & ASCII.LF);
Board.UART.IO.Transmit ("PCLK2 " & Integer'Image (PCLK2_Frequency) & ASCII.CR & ASCII.LF);
Board.UART.IO.Transmit ("PTIM1 " & Integer'Image (APB1_Timer_Clock_Frequency) & ASCII.CR & ASCII.LF);
Board.UART.IO.Transmit ("PTIM2 " & Integer'Image (APB2_Timer_Clock_Frequency) & ASCII.CR & ASCII.LF);
Board.UART.IO.Transmit ("PTIM2 " & Integer'Image (APB2_Timer_Clock_Frequency) & ASCII.CR & ASCII.LF);
Board.UART.IO.Transmit ("I2S " & Integer'Image (I2S_Clock_Frequency) & ASCII.CR & ASCII.LF);
Board.UART.IO.Transmit ("SAI1A " & Integer'Image (SAI1A_Clock_Frequency) & ASCII.CR & ASCII.LF);
Board.UART.IO.Transmit ("SAI1B " & Integer'Image (SAI1B_Clock_Frequency) & ASCII.CR & ASCII.LF);
Board.UART.IO.Transmit ("LCD " & Integer'Image (LCD_Clock_Frequency) & ASCII.CR & ASCII.LF);
--Board.LCD.Controller.Initialize;
Board.LCD.SPI_IO.Initialize_RGB_Interface;
-- Setting up a layer
declare
R : Layer_Horizontal_Position_Register := Chip.Units.LTDC.L (1).WHPCR;
Offset : constant Integer := Chip.Units.LTDC.BPCR.HW + 1;
begin
R.WHSTPOS := 0 + Offset;
R.WHSPPOS := 240 + Offset;
Chip.Units.LTDC.L (1).WHPCR := R;
end;
declare
R : Layer_Vertical_Position_Register := Chip.Units.LTDC.L (1).WVPCR;
Offset : constant Integer := Chip.Units.LTDC.BPCR.VH + 1;
begin
R.WVSTPOS := 0 + Offset;
R.WVSPPOS := 320 + Offset;
Chip.Units.LTDC.L (1).WVPCR := R;
end;
declare
R : Pixel_Format_Configuration_Register := Chip.Units.LTDC.L (1).PFCR;
begin
R.PF := STM32.Graphics.RGB888;
Chip.Units.LTDC.L (1).PFCR := R;
end;
declare
C : Color_Register := Chip.Units.LTDC.L (1).DCCR;
begin
C.R := 128;
C.G := 0;
C.B := 128;
Chip.Units.LTDC.L (1).DCCR := C;
end;
Chip.Units.LTDC.L (1).CACR := 255;
declare
R : Layer_Blending_Factors_Config_Register := Chip.Units.LTDC.L (1).BFCR;
begin
R.BF1 := Constant_Alpha;
R.BF2 := One_Minus_Constant_Alpha;
Chip.Units.LTDC.L (1).BFCR := R;
end;
Chip.Units.LTDC.L (1).CFBAR := Frame (0, 0)'Address;
declare
R : Layer_Buffer_Length_Register := Chip.Units.LTDC.L (1).CFBLR;
begin
R.CFBP := Integer (Frame (1, 0)'Address - Frame (0, 0)'Address);
R.CFBLL := 240 * 3 + 4;
Chip.Units.LTDC.L (1).CFBLR := R;
end;
Chip.Units.LTDC.L (1).CFBLNR := 320;
declare
R : Layer_Control_Register := Chip.Units.LTDC.L (1).CR;
begin
R.LEN := True;
Chip.Units.LTDC.L (1).CR := R;
end;
Board.UART.IO.Transmit ("Pitch = " & System.Storage_Elements.Storage_Offset'Image (Frame (1, 0)'Address - Frame (0, 0)'Address) & ASCII.CR & ASCII.LF);
Board.UART.IO.Transmit ("Frame (0,0)'Address = " & System.Storage_Elements.Integer_Address'Image (System.Storage_Elements.To_Integer (Frame (0, 0)'Address)) & ASCII.CR & ASCII.LF);
Board.UART.IO.Transmit ("Filling frame" & ASCII.CR & ASCII.LF);
for X in 0 .. 239 loop
for Y in 0 .. 319 loop
--Board.UART.IO.Transmit ("@ (" & Integer'Image (X) & " " & Integer'Image (Y) & ")" & ASCII.CR & ASCII.LF);
--Frame (Y, X) := (R => 0, G => 255, B => 0);
if (X + Y) mod 50 = 0 or (X - Y) mod 50 = 0 then
Frame (Y, X) := (R => X * 31 / 239 * 8, G => Y * 255 / 319, B => 0);
else
Frame (Y, X) := (others => 0);
end if;
end loop;
end loop;
for Bit in 0 .. 7 loop
for Y in 1 .. 25 loop
for X in Bit * 30 + 1 .. Bit * 30 + 25 loop
Frame (Y, X) := (R => 2**Bit, others => 0);
Frame (Y + 30, X) := (G => 2**Bit, others => 0);
Frame (Y + 60, X) := (B => 2**Bit, others => 0);
end loop;
end loop;
end loop;
--Frame (0, 0) := (R => 255, others => 0);
--Frame (0, 8) := (G => 255, others => 0);
--Frame (0, 16) := (B => 255, others => 0);
Board.UART.IO.Transmit ("Frame filled" & ASCII.CR & ASCII.LF);
Now := Clock;
loop
Board.LCD.Controller.Set_Background(C, 255 - C, 255 - C);
C := (C + 1) mod 256;
Now := Now + Milliseconds (5);
delay until Now;
end loop;
end LCD_Demo;