Various projects using Raspberry Pi
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
4.7 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. -- raspilcd, a simple tool to display bmp pictures & text on a ST7565 LCD
  2. -- Copyright (C) 2014 Torsten Meissner
  3. --
  4. -- This program is free software: you can redistribute it and/or modify
  5. -- it under the terms of the GNU General Public License as published by
  6. -- the Free Software Foundation, either version 3 of the License, or
  7. -- (at your option) any later version.
  8. --
  9. -- This program is distributed in the hope that it will be useful,
  10. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. -- GNU General Public License for more details.
  13. --
  14. -- You should have received a copy of the GNU General Public License
  15. -- along with this program. If not, see http://www.gnu.org/licenses/.
  16. with Ada.Text_IO;
  17. with bcm2835_h;
  18. with st7565lcd;
  19. with Interfaces; use Interfaces;
  20. with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Streams.Stream_IO;
  21. use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Streams.Stream_IO;
  22. with Ada.Command_Line; use Ada.Command_Line;
  23. procedure raspilcd is
  24. -- shorter names for packages
  25. package IO renames Ada.Text_IO;
  26. package LCD renames st7565lcd;
  27. package IOS renames Ada.Streams.Stream_IO;
  28. -- stream.io definitions
  29. My_File : IOS.FILE_TYPE;
  30. My_File_Access : IOS.STREAM_ACCESS;
  31. -- picture data
  32. picture_header : LCD.t_bmp_header;
  33. color_mask : LCD.t_color_mask;
  34. picture_data : LCD.t_bmp_array (0 .. 128 * 64 - 1);
  35. -- lcd pixel array
  36. lcd_data : LCD.t_lcd_array;
  37. -- exception handling
  38. tool_info : string := "raspi-lcd version 0.1, (c) 2014 by tmeissner";
  39. usage : string := "usage: ./raspitest BMP-FILE (as root)";
  40. bmp_error : string := "error: malformed BMP-FILE (valid: 128x64, no compression, 32bpp)";
  41. cli_exception : exception;
  42. bmp_exception : exception;
  43. begin
  44. -- no picture given
  45. if Argument_Count /= 1 then
  46. raise cli_exception;
  47. end if;
  48. -- open picture file
  49. declare
  50. filename : string := Argument (1);
  51. begin
  52. IOS.Open(My_File, In_File, filename);
  53. My_File_Access := IOS.Stream(My_File);
  54. end;
  55. -- read bmp header
  56. LCD.t_bmp_header'Read(My_File_Access, picture_header);
  57. --Put_Line("Width: " & Integer'Image(picture_header.biWidth));
  58. --Put_Line("Height: " & Integer'Image(picture_header.biHeight));
  59. --Put_Line("Color Depth: " & Integer'Image(Integer(picture_header.biBitCount)));
  60. --Put_Line("Compression: " & Integer'Image(Integer(picture_header.biCompression)));
  61. -- check for valid bmp format
  62. if (abs picture_header.biHeight /= 64 or picture_header.biWidth /= 128 or
  63. (picture_header.biCompression /= 0 and picture_header.biCompression /= 3) or
  64. picture_header.biBitCount /= 32) then
  65. raise bmp_exception;
  66. end if;
  67. -- get color map if existing
  68. if picture_header.biCompression = 3 then
  69. LCD.t_color_mask'Read(My_File_Access, color_mask);
  70. end if;
  71. -- read in image data
  72. if picture_header.biHeight < 0 then
  73. -- top-down pixel matrix
  74. for index in picture_data'range loop
  75. if not IOS.End_Of_File(My_File) then
  76. LCD.t_byte_array'Read(My_File_Access, picture_data(index));
  77. end if;
  78. end loop;
  79. else
  80. -- bottom-top pixel matrix
  81. for row in reverse 0 .. 63 loop
  82. for column in 0 .. 127 loop
  83. if not IOS.End_Of_File(My_File) then
  84. LCD.t_byte_array'Read(My_File_Access, picture_data(row * 128 + column));
  85. end if;
  86. end loop;
  87. end loop;
  88. end if;
  89. -- close picture file
  90. Ada.Streams.Stream_IO.Close(My_File);
  91. -- convert bmp to lcd matrix
  92. lcd_data := LCD.bmp_to_lcd(bmp => picture_data, color_mask => color_mask);
  93. -- load bcm2835 lib
  94. -- print picture and some text on lcd
  95. if integer(bcm2835_h.bcm2835_init) = 0 then
  96. IO.Put_Line("Error while initializing BCM2835 library");
  97. else
  98. LCD.io_init;
  99. LCD.lcd_init;
  100. LCD.lcd_picture(xpos => 0, ypos => 0, picture => lcd_data);
  101. bcm2835_h.bcm2835_delay(5000);
  102. LCD.lcd_clear;
  103. LCD.lcd_ascii57_string(xpos => 0, ypos => 0, data => "raspiFPGA 0.1");
  104. LCD.lcd_ascii57_string(xpos => 0, ypos => 1, data => "(c) raspiDEV 2013");
  105. -- close library
  106. if integer(bcm2835_h.bcm2835_close) = 0 then
  107. IO.Put_Line("Error while closing BCM2835 library");
  108. end if;
  109. end if;
  110. -- exception handling
  111. exception
  112. when e: cli_exception =>
  113. put_line(tool_info);
  114. put_line(usage);
  115. when e: bmp_exception =>
  116. put_line(tool_info);
  117. put_line(bmp_error);
  118. end raspilcd;