83 lines
2.3 KiB
VHDL
83 lines
2.3 KiB
VHDL
library ieee;
|
|
|
|
use ieee.std_logic_1164.all;
|
|
use ieee.std_logic_unsigned.all;
|
|
use ieee.numeric_std.all;
|
|
|
|
entity image_generator is
|
|
generic (
|
|
input_clk: integer
|
|
);
|
|
port (
|
|
clk: in std_logic;
|
|
x, y: in std_logic_vector(9 downto 0);
|
|
ctrl_up: in std_logic;
|
|
ctrl_down: in std_logic;
|
|
|
|
rgb: out std_logic_vector(23 downto 0)
|
|
);
|
|
end image_generator;
|
|
|
|
|
|
architecture logic of image_generator is
|
|
type glyph is array(0 to 7) of std_logic_vector(7 downto 0);
|
|
constant emoji_grin: glyph := (
|
|
"00111100",
|
|
"01000010",
|
|
"10101001",
|
|
"10101001",
|
|
"10000101",
|
|
"10111001",
|
|
"01000010",
|
|
"00111100"
|
|
);
|
|
|
|
signal glyph_x: integer range 0 to 7;
|
|
signal glyph_y: integer range 0 to 7;
|
|
|
|
signal color: std_logic_vector(23 downto 0);
|
|
signal color_index: integer range 0 to 2;
|
|
begin
|
|
glyph_x <= to_integer(unsigned(x(4 downto 1)));
|
|
glyph_y <= to_integer(unsigned(y(4 downto 1)));
|
|
|
|
process(clk) is
|
|
variable last_up: std_logic;
|
|
variable last_down: std_logic;
|
|
constant debounce_max: integer := input_clk / 50; -- 20ms
|
|
variable debounce: integer range 0 to debounce_max := 0;
|
|
begin
|
|
if rising_edge(clk) then
|
|
if debounce = 0 then
|
|
if ctrl_up = '1' and last_up = '0' then
|
|
if color_index /= 2 then
|
|
color_index <= color_index + 1;
|
|
end if;
|
|
debounce := debounce_max;
|
|
end if;
|
|
last_up := ctrl_up;
|
|
|
|
if ctrl_down = '1' and last_down = '0' then
|
|
if color_index /= 0 then
|
|
color_index <= color_index - 1;
|
|
end if;
|
|
debounce := debounce_max;
|
|
end if;
|
|
last_down := ctrl_down;
|
|
else
|
|
debounce := debounce - 1;
|
|
end if;
|
|
end if;
|
|
end process;
|
|
|
|
with color_index select color <=
|
|
"111111111111111111111111" when 0,
|
|
"000000000000000011111111" when 1,
|
|
"000101001111111110110100" when 2;
|
|
|
|
-- actually currently BRG
|
|
rgb <=
|
|
color when x(4) = y(4) and emoji_grin(glyph_y)(glyph_x) = '1' else
|
|
"000000000000000000000000";
|
|
end logic;
|