diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-12-19 18:39:32 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-12-19 18:39:32 +0100 |
commit | bfb6b4cf92747d5a6457ff1a1d6a85cbef7b019b (patch) | |
tree | a4c4534e5b1102ea0e36250c7c27c86554ceab8e /src | |
parent | 3f01179d64959276062284ab17239844c02d952c (diff) |
bouncing ball beginsel
Diffstat (limited to 'src')
-rw-r--r-- | src/.gitignore | 3 | ||||
-rw-r--r-- | src/ball.png | bin | 0 -> 538 bytes | |||
-rwxr-xr-x | src/bitmap-ball.py | 30 | ||||
-rw-r--r-- | src/main-bouncing-ball.vhd | 67 | ||||
-rw-r--r-- | src/makefile | 6 | ||||
-rw-r--r-- | src/pixeldata-ball-bottom.vhd | 27 | ||||
-rw-r--r-- | src/pixeldata-ball-top.vhd | 13 |
7 files changed, 146 insertions, 0 deletions
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 Binary files differnew file mode 100644 index 0000000..fef186d --- /dev/null +++ b/src/ball.png 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 |