From bfb6b4cf92747d5a6457ff1a1d6a85cbef7b019b Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 19 Dec 2022 18:39:32 +0100 Subject: bouncing ball beginsel --- .../bouncing-ball.srcs/constrs_1/main.xdc | 35 +++ .../bouncing-ball.srcs/sources_1/bitmap-ball.vhd | 1 + .../bouncing-ball.srcs/sources_1/bounce.vhd | 1 + .../bouncing-ball.srcs/sources_1/main.vhd | 1 + .../bouncing-ball.srcs/sources_1/new/test.mem | 0 .../sources_1/pixeldata-ball.vhd | 1 + bouncing-ball/bouncing-ball.srcs/sources_1/vga.vhd | 1 + bouncing-ball/bouncing-ball.xpr | 253 +++++++++++++++++++++ src/.gitignore | 3 + src/ball.png | Bin 0 -> 538 bytes src/bitmap-ball.py | 30 +++ src/main-bouncing-ball.vhd | 67 ++++++ src/makefile | 6 + src/pixeldata-ball-bottom.vhd | 27 +++ src/pixeldata-ball-top.vhd | 13 ++ 15 files changed, 439 insertions(+) create mode 100644 bouncing-ball/bouncing-ball.srcs/constrs_1/main.xdc create mode 120000 bouncing-ball/bouncing-ball.srcs/sources_1/bitmap-ball.vhd create mode 120000 bouncing-ball/bouncing-ball.srcs/sources_1/bounce.vhd create mode 120000 bouncing-ball/bouncing-ball.srcs/sources_1/main.vhd create mode 100644 bouncing-ball/bouncing-ball.srcs/sources_1/new/test.mem create mode 120000 bouncing-ball/bouncing-ball.srcs/sources_1/pixeldata-ball.vhd create mode 120000 bouncing-ball/bouncing-ball.srcs/sources_1/vga.vhd create mode 100644 bouncing-ball/bouncing-ball.xpr create mode 100644 src/.gitignore create mode 100644 src/ball.png create mode 100755 src/bitmap-ball.py create mode 100644 src/main-bouncing-ball.vhd create mode 100644 src/makefile create mode 100644 src/pixeldata-ball-bottom.vhd create mode 100644 src/pixeldata-ball-top.vhd diff --git a/bouncing-ball/bouncing-ball.srcs/constrs_1/main.xdc b/bouncing-ball/bouncing-ball.srcs/constrs_1/main.xdc new file mode 100644 index 0000000..6415f3a --- /dev/null +++ b/bouncing-ball/bouncing-ball.srcs/constrs_1/main.xdc @@ -0,0 +1,35 @@ +set_property IOSTANDARD LVCMOS33 [get_ports {blue[3]}] +set_property IOSTANDARD LVCMOS33 [get_ports {blue[2]}] +set_property IOSTANDARD LVCMOS33 [get_ports {blue[1]}] +set_property IOSTANDARD LVCMOS33 [get_ports {blue[0]}] +set_property IOSTANDARD LVCMOS33 [get_ports clk] +set_property IOSTANDARD LVCMOS33 [get_ports {green[3]}] +set_property IOSTANDARD LVCMOS33 [get_ports {green[2]}] +set_property IOSTANDARD LVCMOS33 [get_ports {green[1]}] +set_property IOSTANDARD LVCMOS33 [get_ports {green[0]}] +set_property IOSTANDARD LVCMOS33 [get_ports hsync] +set_property IOSTANDARD LVCMOS33 [get_ports {red[3]}] +set_property IOSTANDARD LVCMOS33 [get_ports {red[2]}] +set_property IOSTANDARD LVCMOS33 [get_ports {red[1]}] +set_property IOSTANDARD LVCMOS33 [get_ports {red[0]}] +set_property IOSTANDARD LVCMOS33 [get_ports vsync] +set_property PACKAGE_PIN W5 [get_ports clk] +set_property PACKAGE_PIN P19 [get_ports hsync] +set_property PACKAGE_PIN R19 [get_ports vsync] + + +set_property PACKAGE_PIN J18 [get_ports {blue[3]}] +set_property PACKAGE_PIN K18 [get_ports {blue[2]}] +set_property PACKAGE_PIN L18 [get_ports {blue[1]}] +set_property PACKAGE_PIN N18 [get_ports {blue[0]}] +set_property PACKAGE_PIN D17 [get_ports {green[3]}] +set_property PACKAGE_PIN G17 [get_ports {green[2]}] +set_property PACKAGE_PIN H17 [get_ports {green[1]}] +set_property PACKAGE_PIN J17 [get_ports {green[0]}] +set_property PACKAGE_PIN N19 [get_ports {red[3]}] +set_property PACKAGE_PIN J19 [get_ports {red[2]}] +set_property PACKAGE_PIN H19 [get_ports {red[1]}] +set_property PACKAGE_PIN G19 [get_ports {red[0]}] + +set_property PACKAGE_PIN T18 [get_ports reset] +set_property IOSTANDARD LVCMOS33 [get_ports reset] diff --git a/bouncing-ball/bouncing-ball.srcs/sources_1/bitmap-ball.vhd b/bouncing-ball/bouncing-ball.srcs/sources_1/bitmap-ball.vhd new file mode 120000 index 0000000..3631200 --- /dev/null +++ b/bouncing-ball/bouncing-ball.srcs/sources_1/bitmap-ball.vhd @@ -0,0 +1 @@ +../../../src/bitmap-ball.vhd \ No newline at end of file diff --git a/bouncing-ball/bouncing-ball.srcs/sources_1/bounce.vhd b/bouncing-ball/bouncing-ball.srcs/sources_1/bounce.vhd new file mode 120000 index 0000000..4419d8d --- /dev/null +++ b/bouncing-ball/bouncing-ball.srcs/sources_1/bounce.vhd @@ -0,0 +1 @@ +../../../src/bounce.vhd \ No newline at end of file diff --git a/bouncing-ball/bouncing-ball.srcs/sources_1/main.vhd b/bouncing-ball/bouncing-ball.srcs/sources_1/main.vhd new file mode 120000 index 0000000..9270930 --- /dev/null +++ b/bouncing-ball/bouncing-ball.srcs/sources_1/main.vhd @@ -0,0 +1 @@ +../../../src/main-bouncing-ball.vhd \ No newline at end of file diff --git a/bouncing-ball/bouncing-ball.srcs/sources_1/new/test.mem b/bouncing-ball/bouncing-ball.srcs/sources_1/new/test.mem new file mode 100644 index 0000000..e69de29 diff --git a/bouncing-ball/bouncing-ball.srcs/sources_1/pixeldata-ball.vhd b/bouncing-ball/bouncing-ball.srcs/sources_1/pixeldata-ball.vhd new file mode 120000 index 0000000..1dde575 --- /dev/null +++ b/bouncing-ball/bouncing-ball.srcs/sources_1/pixeldata-ball.vhd @@ -0,0 +1 @@ +../../../src/pixeldata-ball.vhd \ No newline at end of file diff --git a/bouncing-ball/bouncing-ball.srcs/sources_1/vga.vhd b/bouncing-ball/bouncing-ball.srcs/sources_1/vga.vhd new file mode 120000 index 0000000..19e49f9 --- /dev/null +++ b/bouncing-ball/bouncing-ball.srcs/sources_1/vga.vhd @@ -0,0 +1 @@ +../../../src/vga.vhd \ No newline at end of file diff --git a/bouncing-ball/bouncing-ball.xpr b/bouncing-ball/bouncing-ball.xpr new file mode 100644 index 0000000..79c6b38 --- /dev/null +++ b/bouncing-ball/bouncing-ball.xpr @@ -0,0 +1,253 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Vivado Synthesis Defaults + + + + + + + + + + + + Default settings for Implementation. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + default_dashboard + + + diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..d830ccc --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,3 @@ +pixeldata-ball.vhd +bitmap-ball.vhd + diff --git a/src/ball.png b/src/ball.png new file mode 100644 index 0000000..fef186d Binary files /dev/null and b/src/ball.png differ diff --git a/src/bitmap-ball.py b/src/bitmap-ball.py new file mode 100755 index 0000000..d28609c --- /dev/null +++ b/src/bitmap-ball.py @@ -0,0 +1,30 @@ +#!/bin/python3 + +from PIL import Image +import os + +WIDTH = 10 +HEIGHT = 10 + +# return array of 12-bit color values (0bRRRGGGBBB) +def pixeldata(): + image = Image.open("./ball.png") + pixels = image.load() + pixarr = [] + for x in range(WIDTH): + for y in range(HEIGHT): + color = pixels[x, y] + crushed_color = ((color[0] >> 4) << 8 | (color[1] >> 4) << 4 | (color[2] >> 4) << 0) + pixarr.append(crushed_color) + return pixarr + +if __name__ == "__main__": + # get array of 12-bit pixels + pixels = pixeldata() + # declare rom_t as array with size len(pixels) and word width of 12 bits + print(f"type rom_t is array (0 to {len(pixels) - 1}) of std_logic_vector(11 downto 0);") + # format pixel value as x"rgb" (12-bit hexadecimal with padding) + formatted_pixels = [f"x\"{hex(c)[2:].zfill(3)}\"" for c in pixels] + # print constant bitmap_ball + print(f"constant bitmap_ball: rom_t := ({', '.join(formatted_pixels)});") + diff --git a/src/main-bouncing-ball.vhd b/src/main-bouncing-ball.vhd new file mode 100644 index 0000000..521a0c0 --- /dev/null +++ b/src/main-bouncing-ball.vhd @@ -0,0 +1,67 @@ +library ieee; +use ieee.std_logic_1164.all; +use ieee.std_logic_arith.all; +use ieee.std_logic_unsigned.all; + +entity main is + port ( + clk, reset: in std_logic; + red, green, blue: out std_logic_vector(3 downto 0); + hsync, vsync: out std_logic); +end main; + +architecture Behavioral of main is + component vga port ( + clk25, reset: in std_logic; + x, y: out std_logic_vector(9 downto 0); + rgb: in std_logic_vector(11 downto 0); + red, green, blue: out std_logic_vector(3 downto 0); + hsync, vsync: out std_logic); + end component; + component pixeldata port ( + pixel_clk, bounce_clk, reset: in std_logic; + x, y: in std_logic_vector(9 downto 0); + rgb: out std_logic_vector(11 downto 0)); + end component; + signal clk25: std_logic_vector(1 downto 0); -- clock divider (100_000_000/4) + signal vsync_temp: std_logic; -- vsync signal + signal vsync_inv: std_logic; -- inverted vsync (frame clock) + signal x, y: std_logic_vector(9 downto 0); -- current pixel xy + signal rgb: std_logic_vector(11 downto 0); -- pixel rgb out -> vga in +begin + -- clock divider + process(clk) + begin + if rising_edge(clk) then + clk25 <= (clk25 + 1); + end if; + end process; + + -- get current pixel color + pixel: component pixeldata + port map ( + pixel_clk => clk25(1), + bounce_clk => vsync_inv, + reset => reset, + x => x, + y => y, + rgb => rgb); + + -- display on vga monitor + display: component vga + port map( + reset => reset, + clk25 => clk25(1), + rgb => rgb, + x => x, + y => y, + hsync => hsync, + vsync => vsync_temp, + red => red, + green => green, + blue => blue); + vsync <= vsync_temp; -- vsync output + vsync_inv <= not vsync_temp; -- frame clock output + + +end Behavioral; diff --git a/src/makefile b/src/makefile new file mode 100644 index 0000000..2906e87 --- /dev/null +++ b/src/makefile @@ -0,0 +1,6 @@ +pixeldata-ball.vhd: pixeldata-ball-top.vhd bitmap-ball.vhd pixeldata-ball-bottom.vhd + cat $^ > $@ + +bitmap-ball.vhd: bitmap-ball.py + python3 $< > $@ + diff --git a/src/pixeldata-ball-bottom.vhd b/src/pixeldata-ball-bottom.vhd new file mode 100644 index 0000000..966af41 --- /dev/null +++ b/src/pixeldata-ball-bottom.vhd @@ -0,0 +1,27 @@ + component bounce + port ( + clk, reset: in std_logic; + x, y: out std_logic_vector(9 downto 0)); + end component; + signal sx, sy: std_logic_vector(9 downto 0); -- square x and y + signal pixel_index: integer; +begin + bounce_pos: component bounce + port map ( + reset => reset, + clk => bounce_clk, + x => sx, + y => sy); + process(pixel_clk, sx, sy) + begin + if rising_edge(pixel_clk) then + if (x >= sx) and (x < sx + 10) and (y >= sy) and (y < sy + 10) then + -- draw 10x10 pixel box in white + rgb <= bitmap_ball(to_integer(unsigned(x - sx)) + to_integer(unsigned(y - sy)) * 10); + else + -- blue background + rgb <= x"00f"; + end if; + end if; + end process; +end Behavioral; diff --git a/src/pixeldata-ball-top.vhd b/src/pixeldata-ball-top.vhd new file mode 100644 index 0000000..77ef000 --- /dev/null +++ b/src/pixeldata-ball-top.vhd @@ -0,0 +1,13 @@ +library ieee; +use ieee.std_logic_1164.all; +use ieee.std_logic_unsigned.all; +use ieee.numeric_std.all; + +entity pixeldata is + port ( + pixel_clk, bounce_clk, reset: in std_logic; + x, y: in std_logic_vector(9 downto 0); + rgb: out std_logic_vector(11 downto 0)); +end pixeldata; + +architecture Behavioral of pixeldata is -- cgit v1.2.3