Skip to content

Commit

Permalink
Merge branch 'master' into CDAP_Protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
masonticehurst authored Feb 11, 2024
2 parents 36c7808 + 337ed15 commit 10d188e
Show file tree
Hide file tree
Showing 10 changed files with 798 additions and 122 deletions.
88 changes: 88 additions & 0 deletions eRINA_STM32F7/src/rina/debug.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
with Bitmapped_Drawing;
with STM32.Board;
with GUI;

package body Debug is

-- Probably a cleaner way to do this
procedure Print (Debug_Level : in Debug; Msg : in String) is
currentLine : constant Natural :=
(CURRENT_CONSOLE_POSITION.Y - 100) / FONT_HEIGHT; -- zero indexed
Foreground : HAL.Bitmap.Bitmap_Color;
Background : HAL.Bitmap.Bitmap_Color;
begin

Foreground :=
(case Debug_Level is when Info | Error => HAL.Bitmap.White,
when Warning => HAL.Bitmap.Black);

Background :=
(case Debug_Level is when Info => HAL.Bitmap.Blue,
when Warning => HAL.Bitmap.Yellow, when Error => HAL.Bitmap.Red);

if currentLine > MAX_LINES then
-- Shift console lines up
for I in 1 .. MAX_LINES loop
CopyLine (I, I - 1, I = MAX_LINES);
end loop;

-- Adjust Y position to overwrite the last line
CURRENT_CONSOLE_POSITION.Y :=
CURRENT_CONSOLE_POSITION.Y - FONT_HEIGHT - LINE_PADDING;
end if;

-- Draw debug prefix
Bitmapped_Drawing.Draw_String
(Buffer => GUI.ScreenBuffer.all,
Start =>
GUI.Scale
((CURRENT_CONSOLE_POSITION.X, CURRENT_CONSOLE_POSITION.Y)),
Msg => Debug_Level'Image, Font => BMP_Fonts.Font8x8,
Foreground => Foreground, Background => Background);

-- Draw actual message text
Bitmapped_Drawing.Draw_String
(Buffer => GUI.ScreenBuffer.all,
Start =>
GUI.Scale
((CURRENT_CONSOLE_POSITION.X +
GUI.MeasureText (Debug_Level'Image, BMP_Fonts.Font8x8).Width +
LINE_PADDING,
CURRENT_CONSOLE_POSITION.Y)),
Msg => Msg, Font => BMP_Fonts.Font8x8, Foreground => HAL.Bitmap.White,
Background => HAL.Bitmap.Black);

-- Move the Y position down for the next message
CURRENT_CONSOLE_POSITION.Y :=
CURRENT_CONSOLE_POSITION.Y + FONT_HEIGHT + LINE_PADDING;

STM32.Board.Display.Update_Layer (1, True);
end Print;

procedure CopyLine
(SrcLineNumber : in Natural; DstLineNumer : in Natural;
DeleteSrc : in Boolean)
is
-- TODO: Cleanup later...
srcToPoint : constant HAL.Bitmap.Point :=
(0, (CONSOLE_STARTING_POINT.Y + (FONT_HEIGHT * SrcLineNumber)));
dstToPoint : constant HAL.Bitmap.Point :=
(0, (CONSOLE_STARTING_POINT.Y + (FONT_HEIGHT * DstLineNumer)));
srcRect : constant HAL.Bitmap.Rect :=
(Position => srcToPoint, Width => GUI.Board_Resolution.Width,
Height => FONT_HEIGHT);
begin
HAL.Bitmap.Copy_Rect
(Src_Buffer => GUI.ScreenBuffer.all,
Src_Pt => srcToPoint,
Dst_Buffer => GUI.ScreenBuffer.all,
Dst_Pt => dstToPoint, Width => GUI.Board_Resolution.Width,
Height => FONT_HEIGHT, Synchronous => True);
if DeleteSrc then
HAL.Bitmap.Fill_Rect
(Buffer => GUI.ScreenBuffer.all,
Area => srcRect);
end if;
STM32.Board.Display.Update_Layer (1, True);
end CopyLine;
end Debug;
18 changes: 18 additions & 0 deletions eRINA_STM32F7/src/rina/debug.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
with HAL.Bitmap;
with BMP_Fonts;

package Debug is
type Debug is (Error, Warning, Info);

CONSOLE_STARTING_POINT : HAL.Bitmap.Point := (0, 100);
CURRENT_CONSOLE_POSITION : HAL.Bitmap.Point := (0, 100);
FONT_HEIGHT : constant Natural :=
BMP_Fonts.Char_Height (Font => BMP_Fonts.Font8x8);
MAX_LINES : constant Natural := 20;
LINE_PADDING : constant Natural := 2;

procedure Print (Debug_Level : in Debug; Msg : in String);
procedure CopyLine
(SrcLineNumber : in Natural; DstLineNumer : in Natural;
DeleteSrc : in Boolean);
end Debug;
29 changes: 16 additions & 13 deletions eRINA_STM32F7/src/rina/demo.adb
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
with Demos;
-- with CDAP;
-- with EFCP;
with IPCP_Manager; use IPCP_Manager;
with GUI;
with Debug;
with Textures;
with Textures.PSU;

procedure Demo is

procedure Header is
begin
Demos.Put (0, 0, "eRINA Debug");
end Header;

procedure Initialize is new Demos.Initialize_Blank (Header);
Counter : Natural := 0;
begin
Initialize;
GUI.Initialize ("eRINA Debug");

Textures.Print (Textures.PSU.Bitmap, (5, 10));
-- Keep board from immediately terminating
loop
null;
Debug.Print (Debug.Info, "Message " & Counter'Image);
Counter := Counter + 1;
delay 0.5;
Debug.Print (Debug.Warning, "Message " & Counter'Image);
Counter := Counter + 1;
delay 0.5;
Debug.Print (Debug.Error, "Message " & Counter'Image);
Counter := Counter + 1;
delay 0.5;
end loop;
end Demo;
121 changes: 44 additions & 77 deletions eRINA_STM32F7/src/rina/gui.adb
Original file line number Diff line number Diff line change
@@ -1,84 +1,51 @@
with Bitmapped_Drawing;
with HAL.Bitmap;
with STM32.Board;
with STM32.RNG.Interrupts;


package body GUI is
pragma Warnings (Off);

CONSOLE_STARTING_POINT : HAL.Bitmap.Point := (0, 100);
CURRENT_CONSOLE_POSITION : HAL.Bitmap.Point := (0, 100);
FONT_HEIGHT : Natural := BMP_Fonts.Char_Height(Font => Large_Font);


function Scale (Point : in HAL.Bitmap.Point) return HAL.Bitmap.Point;

function Scale (Point : in HAL.Bitmap.Point) return HAL.Bitmap.Point is
begin
if STM32.Board.LCD_Natural_Width > 480 then
return (Point.X * 800 / 480, Point.Y * 480 / 272);
else
return Point;
function ScreenBuffer return HAL.Bitmap.Any_Bitmap_Buffer is
begin
return STM32.Board.Display.Hidden_Buffer (1);
end ScreenBuffer;

function Scale (Point : in HAL.Bitmap.Point) return HAL.Bitmap.Point is
begin
if STM32.Board.LCD_Natural_Width > Board_Resolution.Width then
return (Point.X * 800 / Board_Resolution.Width, Point.Y * Board_Resolution.Width / Board_Resolution.Width);
else
return Point;
end if;
end Scale;

procedure Print (X : in Natural; Y : in Natural; Msg : in String) is
begin
Bitmapped_Drawing.Draw_String (Buffer => STM32.Board.Display.Hidden_Buffer (1).all,
Start => Scale ((X,Y)),
Msg => Msg,
Font => Large_Font,
Foreground => Foreground,
Background => Background);
end Print;

procedure Initialize (Title : in String) is
begin
STM32.RNG.Interrupts.Initialize_RNG;
STM32.Board.Display.Initialize;
STM32.Board.Display.Initialize_Layer (1, HAL.Bitmap.ARGB_1555);
Print(0, 0, Title);
end Initialize;

-- Probably a cleaner way to do this
procedure PrintToConsole(Msg : in String) is
currentLine : Natural := (CURRENT_CONSOLE_POSITION.Y - 100) / FONT_HEIGHT; -- zero indexed
begin
if currentLine = 14 then --make dynamic
declare
iterator : Integer := 1;
begin
while iterator < 13 loop --make dynamic
CopyLine(iterator, iterator - 1, false);
iterator := iterator + 1;
end loop;
CopyLine(13, 12, True); --make dynamic
end;
CURRENT_CONSOLE_POSITION.Y := CURRENT_CONSOLE_POSITION.Y - FONT_HEIGHT;
Print(CURRENT_CONSOLE_POSITION.X, CURRENT_CONSOLE_POSITION.Y, Msg);
CURRENT_CONSOLE_POSITION.Y := CURRENT_CONSOLE_POSITION.Y + FONT_HEIGHT;

else
Print(CURRENT_CONSOLE_POSITION.X, CURRENT_CONSOLE_POSITION.Y, Msg);
CURRENT_CONSOLE_POSITION.Y := CURRENT_CONSOLE_POSITION.Y + FONT_HEIGHT;
end if;

STM32.Board.Display.Update_Layer(1, True);
end PrintToConsole;


procedure CopyLine(SrcLineNumber : in Natural; DstLineNumer : in Natural; DeleteSrc : in Boolean) is
srcToPoint : HAL.Bitmap.Point := (0, (CONSOLE_STARTING_POINT.Y + (FONT_HEIGHT * SrcLineNumber)));
dstToPoint : HAL.Bitmap.Point := (0, (CONSOLE_STARTING_POINT.Y + (FONT_HEIGHT * DstLineNumer)));
srcRect : HAL.Bitmap.Rect := (Position => srcToPoint, Width => 480, Height => FONT_HEIGHT); -- dont hardcode 480
begin
HAL.Bitmap.Copy_Rect(Src_Buffer => STM32.Board.Display.Hidden_Buffer (1).all, Src_Pt => srcToPoint, Dst_Buffer => STM32.Board.Display.Hidden_Buffer (1).all, Dst_Pt => dstToPoint, Width => 480, Height => FONT_HEIGHT, Synchronous => True);
if DeleteSrc then
HAL.Bitmap.Fill_Rect(Buffer => STM32.Board.Display.Hidden_Buffer (1).all, Area => srcRect);
end if;
STM32.Board.Display.Update_Layer(1, True);
end CopyLine;


end GUI;
end Scale;

procedure Print (Msg : in String; Pos : in HAL.Bitmap.Point) is
begin
Bitmapped_Drawing.Draw_String
(Buffer => ScreenBuffer.all,
Start => Scale ((Pos.X, Pos.Y)),
Msg => Msg,
Font => BMP_Fonts.Font8x8,
Foreground => Foreground,
Background => Background);

STM32.Board.Display.Update_Layer (1, True);
end Print;

procedure Initialize (Title : in String) is
Title_Location : constant HAL.Bitmap.Point := (80, 10);
begin
STM32.RNG.Interrupts.Initialize_RNG;
STM32.Board.Display.Initialize;
STM32.Board.Display.Initialize_Layer (1, HAL.Bitmap.ARGB_1555);
Print (Title, Title_Location);
end Initialize;

function MeasureText
(Text : in String; Font : in BMP_Fonts.BMP_Font) return Size
is
begin
return
(Text'Length * BMP_Fonts.Char_Width (Font),
BMP_Fonts.Char_Height (Font));
end MeasureText;
end GUI;
26 changes: 17 additions & 9 deletions eRINA_STM32F7/src/rina/gui.ads
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
with BMP_Fonts;
with HAL.Bitmap;
package GUI is
pragma Warnings(Off);

Large_Font : BMP_Fonts.BMP_Font := BMP_Fonts.Font12x12;
Foreground : HAL.Bitmap.Bitmap_Color := HAL.Bitmap.White;
Background : HAL.Bitmap.Bitmap_Color := HAL.Bitmap.Black;
package GUI is
pragma Warnings (Off);

procedure Print (X : in Natural; Y : in Natural; Msg : in String);
Large_Font : BMP_Fonts.BMP_Font := BMP_Fonts.Font12x12;
Foreground : HAL.Bitmap.Bitmap_Color := HAL.Bitmap.White;
Background : HAL.Bitmap.Bitmap_Color := HAL.Bitmap.Black;

procedure Initialize (Title : in String);
type Size is record
Width : Natural;
Height : Natural;
end record;

procedure PrintToConsole(Msg : in String);
Board_Resolution : Size := (480, 272);

procedure CopyLine(SrcLineNumber : in Natural; DstLineNumer : in Natural; DeleteSrc : in Boolean);
function ScreenBuffer return HAL.Bitmap.Any_Bitmap_Buffer;
procedure Initialize (Title : in String);
procedure Print (Msg : in String; Pos : in HAL.Bitmap.Point);

function MeasureText
(Text : in String; Font : in BMP_Fonts.BMP_Font) return Size;
function Scale (Point : in HAL.Bitmap.Point) return HAL.Bitmap.Point;
end GUI;
Loading

0 comments on commit 10d188e

Please sign in to comment.