stm32-ada/examples/spi_lcd/spi_lcd.adb

80 lines
1.7 KiB
Ada

with Interfaces;
with Ada.Real_Time; use Ada.Real_Time;
with Chip.Units; use Chip.Units;
with Board.LCD.IO;
use Board;
with ILI9341;
with STM32.RCC; use STM32.RCC;
with STM32.SPI;
with STM32.GPIO.Ports; use STM32.GPIO.Ports;
procedure SPI_LCD is
package LED is new GPIO_Port_Boolean(LED_Port, LED_Bit);
package LED_2 is new GPIO_Port_Boolean(LED_2_Port, LED_2_Bit);
Period : constant Time_Span := Milliseconds(2000);
Now : Time := Clock;
--X, Y : Integer := 0;
--Colour : Integer := 0;
Scale : Float := 1.0/60.0;
CRe, CIm : Float;
ZRe, ZIm, T : Float;
N : Integer;
begin
-- LED to see what's happen
LED_RCC_EN := True;
LED.Set_MODER (STM32.GPIO.Output_Mode);
LED.Set_OTYPER (STM32.GPIO.Push_Pull_Type);
LED.Set_OSPEEDR (STM32.GPIO.Very_High_Speed);
LED.Set_PUPDR (STM32.GPIO.No_Pull);
LED.Set (not LED_On);
LED_2_RCC_EN := True;
LED_2.Set_MODER (STM32.GPIO.Output_Mode);
LED_2.Set_OTYPER (STM32.GPIO.Push_Pull_Type);
LED_2.Set_OSPEEDR (STM32.GPIO.Very_High_Speed);
LED_2.Set_PUPDR (STM32.GPIO.No_Pull);
LED_2.Set (not LED_2_On);
loop
for Y in Integer range 0 .. 319 loop
for X in Integer range 0 .. 239 loop
CRe := Float(- Y + 160) * Scale - 1.403;
CIm := Float(X - 120) * Scale;
N := 0;
ZRe := CRe;
ZIm := CIm;
while ZRe * ZRe + ZIm * ZIm < 4.0 and N < 256 loop
T := ZRe * ZRe - ZIm * ZIm + CRe;
ZIm := 2.0 * ZRe * ZIm + CIm;
ZRe := T;
N := N + 1;
end loop;
if N = 256 then
LCD.IO.Plot_24 (X, Y, 0, 0, 0);
else
LCD.IO.Plot_24 (X, Y, 255 - N, N, 255 - N);
end if;
end loop;
end loop;
Scale := Scale * 0.63;
Now := Clock + Period;
delay until Now;
--LED.Set (not LED_On);
end loop;
end SPI_LCD;