diff --git a/examples/common/429disco/board-lcd-controller.adb b/examples/common/429disco/board-lcd-controller.adb index 8cd65df..7cbd853 100644 --- a/examples/common/429disco/board-lcd-controller.adb +++ b/examples/common/429disco/board-lcd-controller.adb @@ -10,7 +10,7 @@ package body Board.LCD.Controller is -- PA3 B5 -- PA4 VSYNC - GPIOA.AFR (3 .. 4) := (others => Alternate_Functions.LTDC); + GPIOA.AFR (3 .. 4) := (others => Alternate_Functions.LTDC_B); GPIOA.MODER (3 .. 4) := (others => Alternate_Mode); GPIOA.OTYPER (3 .. 4) := (others => Push_Pull_Type); GPIOA.OSPEEDR (3 .. 4) := (others => Very_High_Speed); @@ -18,7 +18,7 @@ package body Board.LCD.Controller is -- PA6 G2 - GPIOA.AFR (6) := Alternate_Functions.LTDC; + GPIOA.AFR (6) := Alternate_Functions.LTDC_B; GPIOA.MODER (6) := Alternate_Mode; GPIOA.OTYPER (6) := Push_Pull_Type; GPIOA.OSPEEDR (6) := Very_High_Speed; @@ -27,7 +27,7 @@ package body Board.LCD.Controller is -- PA11 R4 -- PA12 R5 - GPIOA.AFR (11 .. 12) := (others => Alternate_Functions.LTDC); + GPIOA.AFR (11 .. 12) := (others => Alternate_Functions.LTDC_B); GPIOA.MODER (11 .. 12) := (others => Alternate_Mode); GPIOA.OTYPER (11 .. 12) := (others => Push_Pull_Type); GPIOA.OSPEEDR (11 .. 12) := (others => Very_High_Speed); @@ -36,7 +36,7 @@ package body Board.LCD.Controller is -- PB0 R3 -- PB1 R6 - GPIOB.AFR (0 .. 1) := (others => Alternate_Functions.LTDC); + GPIOB.AFR (0 .. 1) := (others => Alternate_Functions.LTDC_A); GPIOB.MODER (0 .. 1) := (others => Alternate_Mode); GPIOB.OTYPER (0 .. 1) := (others => Push_Pull_Type); GPIOB.OSPEEDR (0 .. 1) := (others => Very_High_Speed); @@ -47,7 +47,7 @@ package body Board.LCD.Controller is -- PB10 G4 -- PB11 G5 - GPIOB.AFR (8 .. 11) := (others => Alternate_Functions.LTDC); + GPIOB.AFR (8 .. 11) := (others => Alternate_Functions.LTDC_B); GPIOB.MODER (8 .. 11) := (others => Alternate_Mode); GPIOB.OTYPER (8 .. 11) := (others => Push_Pull_Type); GPIOB.OSPEEDR (8 .. 11) := (others => Very_High_Speed); @@ -56,7 +56,7 @@ package body Board.LCD.Controller is -- PC6 HSYNC -- PC7 G6 - GPIOC.AFR (6 .. 7) := (others => Alternate_Functions.LTDC); + GPIOC.AFR (6 .. 7) := (others => Alternate_Functions.LTDC_B); GPIOC.MODER (6 .. 7) := (others => Alternate_Mode); GPIOC.OTYPER (6 .. 7) := (others => Push_Pull_Type); GPIOC.OSPEEDR (6 .. 7) := (others => Very_High_Speed); @@ -64,7 +64,7 @@ package body Board.LCD.Controller is -- PC10 R2 - GPIOC.AFR (10) := Alternate_Functions.LTDC; + GPIOC.AFR (10) := Alternate_Functions.LTDC_B; GPIOC.MODER (10) := Alternate_Mode; GPIOC.OTYPER (10) := Push_Pull_Type; GPIOC.OSPEEDR (10) := Very_High_Speed; @@ -72,7 +72,7 @@ package body Board.LCD.Controller is -- PD3 G7 - GPIOD.AFR (3) := Alternate_Functions.LTDC; + GPIOD.AFR (3) := Alternate_Functions.LTDC_B; GPIOD.MODER (3) := Alternate_Mode; GPIOD.OTYPER (3) := Push_Pull_Type; GPIOD.OSPEEDR (3) := Very_High_Speed; @@ -80,7 +80,7 @@ package body Board.LCD.Controller is -- PD6 B2 - GPIOD.AFR (6) := Alternate_Functions.LTDC; + GPIOD.AFR (6) := Alternate_Functions.LTDC_B; GPIOD.MODER (6) := Alternate_Mode; GPIOD.OTYPER (6) := Push_Pull_Type; GPIOD.OSPEEDR (6) := Very_High_Speed; @@ -88,7 +88,7 @@ package body Board.LCD.Controller is -- PF10 DE - GPIOF.AFR (10) := Alternate_Functions.LTDC; + GPIOF.AFR (10) := Alternate_Functions.LTDC_B; GPIOF.MODER (10) := Alternate_Mode; GPIOF.OTYPER (10) := Push_Pull_Type; GPIOF.OSPEEDR (10) := Very_High_Speed; @@ -97,7 +97,7 @@ package body Board.LCD.Controller is -- PG6 R7 -- PG7 CLK - GPIOG.AFR (6 .. 7) := (others => Alternate_Functions.LTDC); + GPIOG.AFR (6 .. 7) := (others => Alternate_Functions.LTDC_B); GPIOG.MODER (6 .. 7) := (others => Alternate_Mode); GPIOG.OTYPER (6 .. 7) := (others => Push_Pull_Type); GPIOG.OSPEEDR (6 .. 7) := (others => Very_High_Speed); @@ -107,7 +107,9 @@ package body Board.LCD.Controller is -- PG11 B3 -- PG12 B4 - GPIOG.AFR (10 .. 12) := (others => Alternate_Functions.LTDC); + GPIOG.AFR (10) := Alternate_Functions.LTDC_A; + GPIOG.AFR (11) := Alternate_Functions.LTDC_B; + GPIOG.AFR (12) := Alternate_Functions.LTDC_A; GPIOG.MODER (10 .. 12) := (others => Alternate_Mode); GPIOG.OTYPER (10 .. 12) := (others => Push_Pull_Type); GPIOG.OSPEEDR (10 .. 12) := (others => Very_High_Speed); diff --git a/examples/common/429disco/board-lcd-generic_io.adb b/examples/common/429disco/board-lcd-generic_io.adb index 8f50e45..129e191 100644 --- a/examples/common/429disco/board-lcd-generic_io.adb +++ b/examples/common/429disco/board-lcd-generic_io.adb @@ -70,6 +70,7 @@ package body Board.LCD.Generic_IO is 16#08#, 16#4E#, 16#F1#, 16#37#, 16#07#, 16#10#, 16#03#, 16#0E#, 16#09#, 16#00#)); Write_Command (ILI9341.NGAMCTRL, (16#00#, 16#0E#, 16#14#, 16#03#, 16#11#, 16#07#, 16#31#, 16#C1#, 16#48#, 16#08#, 16#0F#, 16#0C#, 16#31#, 16#36#, 16#0F#)); + -- 16 bit? Now := Clock + Milliseconds (120); delay until Now; Write_Command (ILI9341.SLPOUT); @@ -82,6 +83,7 @@ package body Board.LCD.Generic_IO is -- EPL = true, DPL = Falling, HSPL = low, VSPL = low, RCM = 10, bypass = memory Write_Command (ILI9341.IFCTL, (16#01#, 16#00#, 16#06#)); -- WEMODE = 1, BGR_EOR = 0, MV_EOR = 0, MX_EOR = 0, MY_EOR = 0, MDT = 0, EPF = MSB, RIM = 18/16, RM = RGB, DM = RGB, ENDIAN = MSB first + Write_Command (ILI9341.PIXSET, (16#66#)); end Initialize_RGB_Interface; procedure Plot_24 (X, Y, R, G, B: Integer) is diff --git a/examples/sdram_pool/simple_pools.adb b/examples/common/simple_pools.adb similarity index 100% rename from examples/sdram_pool/simple_pools.adb rename to examples/common/simple_pools.adb diff --git a/examples/sdram_pool/simple_pools.ads b/examples/common/simple_pools.ads similarity index 100% rename from examples/sdram_pool/simple_pools.ads rename to examples/common/simple_pools.ads diff --git a/examples/lcd_demo/lcd_demo.adb b/examples/lcd_demo/lcd_demo.adb index c7a4fa4..925f396 100644 --- a/examples/lcd_demo/lcd_demo.adb +++ b/examples/lcd_demo/lcd_demo.adb @@ -1,13 +1,40 @@ +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 Ada.Real_Time; -use Ada.Real_Time; +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); @@ -27,6 +54,101 @@ begin --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 diff --git a/source/f4/stm32-gpio.ads b/source/f4/stm32-gpio.ads index 5f1f1be..630e490 100644 --- a/source/f4/stm32-gpio.ads +++ b/source/f4/stm32-gpio.ads @@ -151,6 +151,7 @@ package STM32.GPIO is TIM12 : constant Alternate_Function := 9; TIM13 : constant Alternate_Function := 9; TIM14 : constant Alternate_Function := 9; + LTDC_A : constant Alternate_Function := 9; OTG_FS : constant Alternate_Function := 10; OTG_HS : constant Alternate_Function := 10; @@ -164,7 +165,7 @@ package STM32.GPIO is DCMI : constant Alternate_Function := 13; - LTDC : constant Alternate_Function := 14; + LTDC_B : constant Alternate_Function := 14; EVENTOUT : constant Alternate_Function := 15;