diff options
| author | lonkaars <loek@pipeframe.xyz> | 2022-12-20 12:44:12 +0100 | 
|---|---|---|
| committer | lonkaars <loek@pipeframe.xyz> | 2022-12-20 12:44:12 +0100 | 
| commit | 9366676ed5074cf1efee95382cf99728bc3707e7 (patch) | |
| tree | 5492233830cf37681a3a8bbba82b21e6d107947f /src | |
| parent | da810896f4c249d61f00e9e413d82dad2ad2058e (diff) | |
ball pixeldata in memory IP core
Diffstat (limited to 'src')
| -rw-r--r-- | src/.gitignore | 3 | ||||
| -rwxr-xr-x | src/bitmap-ball.py | 12 | ||||
| -rw-r--r-- | src/makefile | 7 | ||||
| -rw-r--r-- | src/pixeldata-ball-bottom.vhd | 27 | ||||
| -rw-r--r-- | src/pixeldata-ball-top.vhd | 13 | ||||
| -rw-r--r-- | src/pixeldata-ball.vhd | 51 | 
6 files changed, 62 insertions, 51 deletions
diff --git a/src/.gitignore b/src/.gitignore index d830ccc..e23e341 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,3 +1,2 @@ -pixeldata-ball.vhd -bitmap-ball.vhd +bitmap-ball.coe diff --git a/src/bitmap-ball.py b/src/bitmap-ball.py index 4d5be0c..25b7fd3 100755 --- a/src/bitmap-ball.py +++ b/src/bitmap-ball.py @@ -21,10 +21,10 @@ def pixeldata():  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)});") +  # coe file header +  print("memory_initialization_radix=16;\nmemory_initialization_vector=", end='') +  # format pixel value as 12-bit hexadecimal with padding seperated by comma and space +  formatted_pixels = ','.join([f"{hex(c)[2:].zfill(3)}" for c in pixels]) +  print(f"{formatted_pixels};") + diff --git a/src/makefile b/src/makefile index 5dff86d..8ecc8f2 100644 --- a/src/makefile +++ b/src/makefile @@ -1,6 +1,7 @@ -pixeldata-ball.vhd: pixeldata-ball-top.vhd bitmap-ball.vhd pixeldata-ball-bottom.vhd -	cat $^ > $@ +.PHONY: clean -bitmap-ball.vhd: ball.png +bitmap-ball.coe: ball.png  	python3 bitmap-ball.py $< > $@ +clean: +	$(RM) bitmap-ball.coe diff --git a/src/pixeldata-ball-bottom.vhd b/src/pixeldata-ball-bottom.vhd deleted file mode 100644 index 966af41..0000000 --- a/src/pixeldata-ball-bottom.vhd +++ /dev/null @@ -1,27 +0,0 @@ -	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 deleted file mode 100644 index 77ef000..0000000 --- a/src/pixeldata-ball-top.vhd +++ /dev/null @@ -1,13 +0,0 @@ -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 diff --git a/src/pixeldata-ball.vhd b/src/pixeldata-ball.vhd new file mode 100644 index 0000000..4690241 --- /dev/null +++ b/src/pixeldata-ball.vhd @@ -0,0 +1,51 @@ +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 +	component bounce +		port ( +			clk, reset: in std_logic; +			x, y: out std_logic_vector(9 downto 0)); +	end component; +	component ball_rom +		port ( +			a: in std_logic_vector(6 downto 0); +			spo: out std_logic_vector(11 downto 0)); +	end component; +	signal sx, sy: std_logic_vector(9 downto 0); -- square x and y +	signal bitmap_idx: std_logic_vector(6 downto 0); +	signal bitmap_out: std_logic_vector(11 downto 0); +begin +	bounce_pos: component bounce +		port map ( +			reset => reset, +			clk => bounce_clk, +			x => sx, +			y => sy); +	bitmap_lookup: component ball_rom +		port map ( +			a => bitmap_idx, +			spo => bitmap_out); +	process(pixel_clk) +	begin +		if rising_edge(pixel_clk) then +			if (x >= sx) and (x < sx + 10) and (y >= sy) and (y < sy + 10) then +				-- draw ball +				bitmap_idx <= std_logic_vector(resize(unsigned(y - sy) + unsigned(y - sy) * 10, bitmap_idx'length)); +				rgb <= bitmap_out; +			else +				-- blue background +				rgb <= x"00f"; +			end if; +		end if; +	end process; +end Behavioral;  |