From 753e98c6918a6514dd48468ac6161733330e4bfc Mon Sep 17 00:00:00 2001 From: Vovanium Date: Wed, 29 Sep 2021 18:05:32 +0300 Subject: [PATCH] Examples / LCD_Demo now flashing screen through LTDC. --- .../common/429disco/board-lcd-controller.adb | 23 +++++++++++++++---- .../common/429disco/board-lcd-controller.ads | 1 + .../common/429disco/board-lcd-generic_io.adb | 11 ++++++++- .../common/429disco/board-lcd-generic_io.ads | 1 + examples/common/429disco/board-lcd-spi_io.adb | 1 + examples/common/429disco/board-lcd-spi_io.ads | 1 + examples/lcd_demo/lcd_demo.adb | 14 +++++++++-- source/f4/stm32-rcc-frequencies.adb | 5 ++-- 8 files changed, 48 insertions(+), 9 deletions(-) diff --git a/examples/common/429disco/board-lcd-controller.adb b/examples/common/429disco/board-lcd-controller.adb index 480d5dc..8cd65df 100644 --- a/examples/common/429disco/board-lcd-controller.adb +++ b/examples/common/429disco/board-lcd-controller.adb @@ -184,19 +184,21 @@ package body Board.LCD.Controller is RCC.APB2ENR (Index.LTDC) := True; RCC.APB2RSTR (Index.LTDC) := True; RCC.APB2RSTR (Index.LTDC) := False; - + -- Configure Pixel clock Initialize_Pixel_Clock; + -- Configure synchronous timings -- Configure synchronous signals in the LTDC_GCR Initialize_Timings; + -- Configure the background color declare R : Color_Register := LTDC.BCCR; begin - R.R := 200; - R.G := 56; - R.B := 255; + R.R := 16#AA#; + R.G := 16#AA#; + R.B := 16#55#; LTDC.BCCR := R; end; -- Configure the needed interrupts @@ -214,6 +216,19 @@ package body Board.LCD.Controller is end; -- All layer parameters may be modified... end Initialize; + + procedure Set_Background (R, G, B : Integer) is + begin + declare + C : Color_Register := LTDC.BCCR; + begin + C.R := R; + C.G := G; + C.B := B; + LTDC.BCCR := C; + end; + LTDC.SRCR := (IMR => True, others => <>); + end; begin Initialize; end Board.LCD.Controller; diff --git a/examples/common/429disco/board-lcd-controller.ads b/examples/common/429disco/board-lcd-controller.ads index ed5fb88..0e4c78d 100644 --- a/examples/common/429disco/board-lcd-controller.ads +++ b/examples/common/429disco/board-lcd-controller.ads @@ -1,3 +1,4 @@ package Board.LCD.Controller is procedure Initialize; + procedure Set_Background (R, G, B : Integer); end Board.LCD.Controller; diff --git a/examples/common/429disco/board-lcd-generic_io.adb b/examples/common/429disco/board-lcd-generic_io.adb index 05ff654..8f50e45 100644 --- a/examples/common/429disco/board-lcd-generic_io.adb +++ b/examples/common/429disco/board-lcd-generic_io.adb @@ -29,11 +29,12 @@ package body Board.LCD.Generic_IO is Now := Clock + Milliseconds (5); delay until Now; + --Write_Command (ILI9341.Undocumented_CA, (16#C3#, 16#08#, 16#50#)); Write_Command (ILI9341.Power_Control_A, (16#39#, 16#2C#, 16#00#, 16#34#, 16#02#)); -- Vcore = 1.6, DDVDH = 5.6 (default) Write_Command (ILI9341.Power_Control_B, (16#00#, 16#C1#, 16#30#)); -- PCEQ = 1, DRV_ena = 0, Power_Control = 0, DRV_vml = 0, DRV_vmh = 0, DC_ena = 1 - --Command (ILI9341.Undocumented_EF, 16#03#, 16#80#, 16#02#); + --Write_Command (ILI9341.Undocumented_EF, (16#03#, 16#80#, 16#02#)); Write_Command (ILI9341.Driver_Timing_Control_A, (16#85#, 16#00#, 16#78#)); -- NOW = 1, EQ = 0, CR = 0, precharge = 2unit Write_Command (ILI9341.Driver_Timing_Control_B, (16#00#, 16#00#)); @@ -75,6 +76,14 @@ package body Board.LCD.Generic_IO is Write_Command (ILI9341.DISPON); end Initialize_Controller; + procedure Initialize_RGB_Interface is + begin + Write_Command (ILI9341.IFMODE, (16#C2#)); + -- 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 + end Initialize_RGB_Interface; + procedure Plot_24 (X, Y, R, G, B: Integer) is -- Draw a pixel; begin diff --git a/examples/common/429disco/board-lcd-generic_io.ads b/examples/common/429disco/board-lcd-generic_io.ads index 031719d..295fe07 100644 --- a/examples/common/429disco/board-lcd-generic_io.ads +++ b/examples/common/429disco/board-lcd-generic_io.ads @@ -6,5 +6,6 @@ generic with procedure Write_Data (Data : Interfaces.Unsigned_8); package Board.LCD.Generic_IO is procedure Initialize_Controller; + procedure Initialize_RGB_Interface; procedure Plot_24 (X, Y, R, G, B: Integer); end Board.LCD.Generic_IO; \ No newline at end of file diff --git a/examples/common/429disco/board-lcd-spi_io.adb b/examples/common/429disco/board-lcd-spi_io.adb index ecc5aa2..4f9d3ef 100644 --- a/examples/common/429disco/board-lcd-spi_io.adb +++ b/examples/common/429disco/board-lcd-spi_io.adb @@ -100,6 +100,7 @@ package body Board.LCD.SPI_IO is package IO is new LCD.Generic_IO(Command, Data); procedure Initialize_Controller renames IO.Initialize_Controller; + procedure Initialize_RGB_Interface renames IO.Initialize_RGB_Interface; procedure Plot_24 (X, Y, R, G, B: Integer) renames IO.Plot_24; begin Initialize_SPI; diff --git a/examples/common/429disco/board-lcd-spi_io.ads b/examples/common/429disco/board-lcd-spi_io.ads index 95fe1db..0a0a9e3 100644 --- a/examples/common/429disco/board-lcd-spi_io.ads +++ b/examples/common/429disco/board-lcd-spi_io.ads @@ -1,5 +1,6 @@ package Board.LCD.SPI_IO is + procedure Initialize_RGB_Interface; procedure Plot_24 (X, Y, R, G, B: Integer); end Board.LCD.SPI_IO; diff --git a/examples/lcd_demo/lcd_demo.adb b/examples/lcd_demo/lcd_demo.adb index 37c5bbe..c7a4fa4 100644 --- a/examples/lcd_demo/lcd_demo.adb +++ b/examples/lcd_demo/lcd_demo.adb @@ -3,7 +3,11 @@ with Board.LCD.Controller; with Board.UART.IO; with Board.Frequencies; use Board.Frequencies; +with Ada.Real_Time; +use Ada.Real_Time; procedure LCD_Demo is + Now : Time := Clock; + C : Integer := 0; 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); @@ -20,9 +24,15 @@ begin 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.Controller.Initialize; + Board.LCD.SPI_IO.Initialize_RGB_Interface; + + Now := Clock; loop - null; + 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; \ No newline at end of file diff --git a/source/f4/stm32-rcc-frequencies.adb b/source/f4/stm32-rcc-frequencies.adb index 92d004e..f4b8910 100644 --- a/source/f4/stm32-rcc-frequencies.adb +++ b/source/f4/stm32-rcc-frequencies.adb @@ -125,9 +125,10 @@ package body STM32.RCC.Frequencies is end; function PLLI2S_N (Frequency : Natural) return Natural is - F : Natural := Frequency * RCC.PLLCFGR.M; + F : Product := Product (Frequency) * Product (RCC.PLLCFGR.M); + P : Product := Product (PLL_Input_Frequency); begin - return (PLL_Input_Frequency + F / 2) / F; + return Natural ((F + P / 2) / P); end; function PLLSAI_N (Frequency : Natural) return Natural renames PLLI2S_N;