Skip to content
This repository was archived by the owner on May 22, 2023. It is now read-only.

Commit b1eb4b0

Browse files
author
Isabell Zorr
committed
Add Renderfunction and Rainbow
ref #147
1 parent 5a098fc commit b1eb4b0

File tree

3 files changed

+70
-48
lines changed

3 files changed

+70
-48
lines changed

src/core/nRF52832/main.adb

+30-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ is
1919
begin
2020
return S;
2121
end F;
22+
23+
procedure Rainbow (Color : Output.Pixel; Line : Natural);
24+
procedure Rainbow (Color : Output.Pixel; Line : Natural) is
25+
begin
26+
for I in Line .. Line + 39 loop
27+
Output.Render (I, 0, 1, 120, (1 .. 120 => Color));
28+
Output.Render (I, 120, 1, 120, (1 .. 120 => Color));
29+
end loop;
30+
end Rainbow;
31+
32+
Red : constant Output.Pixel := (255, 0, 24);
33+
Orange : constant Output.Pixel := (255, 165, 44);
34+
Yellow : constant Output.Pixel := (255, 255, 65);
35+
Green : constant Output.Pixel := (0, 128, 24);
36+
Blue : constant Output.Pixel := (0, 0, 249);
37+
Purple : constant Output.Pixel := (134, 0, 125);
38+
2239
begin
2340
Spi.Initialize;
2441
Output.Initialize;
@@ -31,14 +48,20 @@ begin
3148
Debug.Log_Debug ("Testing secondary stack...");
3249
Debug.Log_Debug (F (64));
3350
Debug.Log_Debug ("Finished.");
34-
for I in 0 .. 239 loop
35-
for J in 0 .. 239 loop
36-
Output.Draw_Pixel (I, J, (Output.Color (J), Output.Color (I), Output.Color (J)));
51+
for I in 0 .. 23 loop
52+
for J in 0 .. 23 loop
53+
Output.Render (I * 10, J * 10, 10, 10,
54+
(1 .. 100 => (Output.Color (J * 10),
55+
Output.Color ((I + J) * 5),
56+
Output.Color (I * 10))));
3757
end loop;
3858
end loop;
39-
-- Output.Draw_Pixel (0, 0, (255, 0, 0));
40-
-- Output.Draw_Pixel (0, 0, (0, 255, 0));
41-
-- Output.Draw_Pixel (0, 0, (0, 0, 255));
59+
Rainbow (Red, 0);
60+
Rainbow (Orange, 40);
61+
Rainbow (Yellow, 80);
62+
Rainbow (Green, 120);
63+
Rainbow (Blue, 160);
64+
Rainbow (Purple, 200);
4265
Debug.Log_Debug ("There should be a Pixel");
43-
Output.Turn_Off;
66+
-- Output.Turn_Off;
4467
end Main;

src/core/nRF52832/st7789.adb

+12-29
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ package body ST7789 is
4949
Write_CMD (SLPOUT);
5050
Write_Color_Mode (COLMOD, RGB565);
5151
Write_Data (MADCTL, MLRGB);
52-
Set_Window (0, 240, 0, 240);
52+
Set_Window (0, 239, 0, 239);
5353
Write_CMD (INVON);
5454
Write_CMD (NORON);
5555
Write_CMD (DISPON);
@@ -75,7 +75,8 @@ package body ST7789 is
7575
end if;
7676
end Write_CMD;
7777

78-
procedure Set_Window (X0 : Integer; Y0 : Integer; X1 : Integer; Y1 : Integer) is
78+
procedure Set_Window (X0 : Display_Index; Y0 : Display_Index;
79+
X1 : Display_Index; Y1 : Display_Index) is
7980
type Buf is array (Positive range <>) of Byte;
8081
procedure Send is new Spi.Send (Byte, Positive, Buf);
8182
Buffer : Buf (1 .. 4);
@@ -100,7 +101,7 @@ package body ST7789 is
100101
Write_CMD (RAMWR);
101102
end Set_Window;
102103

103-
function Color_To_Byte (A : Color_Buffer) return Data_Buffer is
104+
function Color_To_Byte (A : Frame) return Data_Buffer is
104105
use type Interfaces.Unsigned_8;
105106
Buf : Data_Buffer (1 .. A'Length * 2);
106107
I2 : Natural;
@@ -114,35 +115,17 @@ package body ST7789 is
114115
return Buf;
115116
end Color_To_Byte;
116117

117-
procedure Draw_Pixel (X : Integer; Y : Integer; C : Pixel) is
118-
procedure Send_Color is new Spi.Send (Byte, Positive, Data_Buffer);
119-
Buffer : Data_Buffer := Color_To_Byte ((1 => C));
118+
procedure Render (X : Natural; Y : Natural; Width : Positive;
119+
Height : Positive; Window : Frame) is
120+
Buffer : Data_Buffer := Color_To_Byte (Window);
121+
procedure Render_Send is new Spi.Send (Byte, Positive, Data_Buffer);
120122
begin
121-
-- Serial.Print ("Draw_Pixel" & ASCII.CR & ASCII.LF);
122-
Set_Window (X, Y, X, Y);
123+
Set_Window (Display_Index (X), Display_Index (Y),
124+
Display_Index (X + Width - 1), Display_Index (Y + Height - 1));
123125
GPIO.Write (DC_PIN, GPIO.High);
124126
GPIO.Write (CS_PIN, GPIO.Low);
125-
Send_Color (Buffer);
127+
Render_Send (Buffer);
126128
GPIO.Write (CS_PIN, GPIO.High);
127-
end Draw_Pixel;
128-
129-
-- procedure Fill_Color_Buffer (C : Color; L : Integer) is
130-
-- Buffer_Pixel : constant Integer := 128;
131-
-- Chunks : Integer := Length / Buffer_Pixel;
132-
-- Rest : Integer := Length mod Buffer_Pixel;
133-
-- begin
134-
-- null;
135-
-- end Fill_Color_Buffer;
136-
--
137-
-- procedure Fill_Rect (X : Integer; Y : Integer; C : Color) is
138-
-- W : Integer := Display.WIDTH;
139-
-- H : Integer := Display.HEIGHT;
140-
-- begin
141-
-- Set_Window (X, Y, (X + W - 1), (Y + H - 1));
142-
-- GPIO.Write (DC_PIN, GPIO.High);
143-
-- GPIO.Write (CS_PIN, GPIO.Low);
144-
-- Fill_Color_Buffer (C, (W * H));
145-
-- GPIO.Write (CS_PIN, GPIO.High);
146-
-- end Fill_Rect;
129+
end Render;
147130

148131
end ST7789;

src/core/nRF52832/st7789.ads

+28-12
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ is
2323
Blue : Color;
2424
end record;
2525

26-
procedure Draw_Pixel (X : Integer; Y : Integer; C : Pixel);
27-
2826
procedure Turn_Off;
2927

28+
type Frame is array (Positive range <>) of Pixel;
29+
30+
procedure Render (X : Natural; Y : Natural; Width : Positive; Height : Positive;
31+
Window : Frame) with
32+
Pre => X <= 240
33+
and then Y <= 240
34+
and then X + Width - 1 <= 240
35+
and then Y + Height - 1 <= 240
36+
and then Window'Length = Width * Height;
37+
3038
private
3139

3240
type Color_Mode is (RGB565) with
@@ -80,27 +88,35 @@ private
8088
type Data is private;
8189
procedure Write_Data_CMD (Cmd : Command; D : Data);
8290

83-
procedure Set_Window (X0 : Integer;
84-
Y0 : Integer;
85-
X1 : Integer;
86-
Y1 : Integer);
91+
type Display_Size is range 0 .. 240;
92+
subtype Display_Index is Display_Size range 0 .. 239;
93+
94+
procedure Set_Window (X0 : Display_Index;
95+
Y0 : Display_Index;
96+
X1 : Display_Index;
97+
Y1 : Display_Index) with
98+
Pre => X0 <= 240
99+
and then X1 <= 240
100+
and then X0 <= X1
101+
and then Y0 <= 240
102+
and then Y1 <= 240
103+
and then Y0 <= Y1;
87104

88105
procedure Hard_Reset;
89106

90107
procedure Soft_Reset;
91108

92109
type Display is record
93-
WIDTH : Integer;
94-
HEIGHT : Integer;
95-
XSTART : Integer;
96-
YSTART : Integer;
110+
WIDTH : Display_Size;
111+
HEIGHT : Display_Size;
112+
XSTART : Display_Index;
113+
YSTART : Display_Index;
97114
end record;
98115

99116
subtype Byte is Interfaces.Unsigned_8;
100117
type Data_Buffer is array (Positive range <>) of Byte;
101-
type Color_Buffer is array (Positive range <>) of Pixel;
102118

103-
function Color_To_Byte (A : Color_Buffer) return Data_Buffer;
119+
function Color_To_Byte (A : Frame) return Data_Buffer;
104120

105121
-- procedure Fill_Color_Buffer (C : Color;
106122
-- L : Integer);

0 commit comments

Comments
 (0)