Line 22... |
Line 22... |
--
|
--
|
-- @note This file has been renamed and updated from the original.
|
-- @note This file has been renamed and updated from the original.
|
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
|
use work.util.common_generics;
|
|
|
package kbd_pkg is
|
package kbd_pkg is
|
|
|
component ps2_kbd_top is
|
component ps2_kbd_top is
|
generic(
|
generic(
|
clock_frequency: integer := 50000000; -- system clock frequency in hz
|
clock_frequency: integer := 50000000; -- system clock frequency in Hz
|
ps2_debounce_counter_size: integer := 8); -- set such that 2^size/clock_frequency = 5us (size = 8 for 50mhz)
|
ps2_debounce_counter_size: integer := 8); -- set such that 2^size/clock_frequency = 5us (size = 8 for 50MHz)
|
port(
|
port(
|
clk: in std_ulogic; -- system clock input
|
clk: in std_ulogic; -- system clock input
|
ps2_clk: in std_ulogic; -- clock signal from PS2 keyboard
|
ps2_clk: in std_ulogic; -- clock signal from PS2 keyboard
|
ps2_data: in std_ulogic; -- data signal from PS2 keyboard
|
ps2_data: in std_ulogic; -- data signal from PS2 keyboard
|
ascii_new: out std_ulogic := '0'; -- output flag indicating new ascii value
|
ascii_new: out std_ulogic := '0'; -- output flag indicating new ascii value
|
ascii_code: out std_ulogic_vector(6 downto 0)); -- ASCII value
|
ascii_code: out std_ulogic_vector(6 downto 0)); -- ASCII value
|
end component;
|
end component;
|
|
|
component ps2_kbd_core is
|
component ps2_kbd_core is
|
generic(
|
generic(
|
clock_frequency: integer := 50000000; -- system clock frequency in hz
|
clock_frequency: integer := 50000000; -- system clock frequency in Hz
|
debounce_counter_size: integer := 8); -- set such that (2^size)/clock_frequency = 5us (size = 8 for 50mhz)
|
debounce_counter_size: integer := 8); -- set such that (2^size)/clock_frequency = 5us (size = 8 for 50MHz)
|
port(
|
port(
|
clk: in std_ulogic; -- system clock
|
clk: in std_ulogic; -- system clock
|
ps2_clk: in std_ulogic; -- clock signal from PS/2 keyboard
|
ps2_clk: in std_ulogic; -- clock signal from PS/2 keyboard
|
ps2_data: in std_ulogic; -- data signal from PS/2 keyboard
|
ps2_data: in std_ulogic; -- data signal from PS/2 keyboard
|
ps2_code_new: out std_ulogic; -- flag that new PS/2 code is available on ps2_code bus
|
ps2_code_new: out std_ulogic; -- flag that new PS/2 code is available on ps2_code bus
|
ps2_code: out std_ulogic_vector(7 downto 0)); -- code received from PS/2
|
ps2_code: out std_ulogic_vector(7 downto 0)); -- code received from PS/2
|
end component;
|
end component;
|
|
|
component ps2_debounce is
|
component ps2_debounce is
|
generic(counter_size: integer := 19); --counter size (19 bits gives 10.5ms with 50mhz clock)
|
generic(counter_size: integer := 19); --counter size (19 bits gives 10.5ms with 50MHz clock)
|
port(
|
port(
|
clk: in std_ulogic;
|
clk: in std_ulogic;
|
button: in std_ulogic; --input signal to be debounced
|
button: in std_ulogic; --input signal to be debounced
|
result: out std_ulogic := '0'); --debounced signal
|
result: out std_ulogic := '0'); --debounced signal
|
end component;
|
end component;
|
|
|
component keyboard is
|
component keyboard is
|
generic(
|
generic(
|
clock_frequency: integer := 50000000; -- system clock frequency in hz
|
g: common_generics;
|
ps2_debounce_counter_size: integer := 8); -- set such that 2^size/clock_frequency = 5us (size = 8 for 50mhz)
|
ps2_debounce_counter_size: integer := 8); -- set such that 2^size/clock_frequency = 5us (size = 8 for 50MHz)
|
port(
|
port(
|
clk: in std_ulogic; -- system clock input
|
clk: in std_ulogic; -- system clock input
|
rst: in std_ulogic; -- system reset
|
rst: in std_ulogic; -- system reset
|
|
|
ps2_clk: in std_ulogic; -- clock signal from PS2 keyboard
|
ps2_clk: in std_ulogic; -- clock signal from PS2 keyboard
|
Line 75... |
Line 76... |
kbd_char_buf: out std_ulogic_vector(6 downto 0)); -- ASCII value
|
kbd_char_buf: out std_ulogic_vector(6 downto 0)); -- ASCII value
|
end component;
|
end component;
|
end package;
|
end package;
|
|
|
------ Keyboard ----------------------------------------------------------------
|
------ Keyboard ----------------------------------------------------------------
|
library ieee;
|
library ieee, work;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use work.kbd_pkg.all;
|
use work.kbd_pkg.all;
|
|
use work.util.common_generics;
|
|
|
entity keyboard is
|
entity keyboard is
|
generic(
|
generic(
|
clock_frequency: integer := 50000000; -- system clock frequency in hz
|
g: common_generics;
|
ps2_debounce_counter_size: integer := 8); -- set such that 2^size/clock_frequency = 5us (size = 8 for 50mhz)
|
ps2_debounce_counter_size: integer := 8); -- set such that 2^size/clock_frequency = 5us (size = 8 for 50MHz)
|
port(
|
port(
|
clk: in std_ulogic; -- system clock input
|
clk: in std_ulogic; -- system clock input
|
rst: in std_ulogic; -- system reset
|
rst: in std_ulogic; -- system reset
|
|
|
ps2_clk: in std_ulogic; -- clock signal from PS2 keyboard
|
ps2_clk: in std_ulogic; -- clock signal from PS2 keyboard
|
Line 100... |
Line 102... |
architecture rtl of keyboard is
|
architecture rtl of keyboard is
|
signal kbd_new_c, kbd_new_n: std_ulogic := '0';
|
signal kbd_new_c, kbd_new_n: std_ulogic := '0';
|
signal kbd_new_edge: std_ulogic := '0';
|
signal kbd_new_edge: std_ulogic := '0';
|
signal kbd_new: std_ulogic := '0'; -- new ASCII char available
|
signal kbd_new: std_ulogic := '0'; -- new ASCII char available
|
signal kbd_char: std_ulogic_vector(kbd_char_buf'range) := (others => '0'); -- ASCII char
|
signal kbd_char: std_ulogic_vector(kbd_char_buf'range) := (others => '0'); -- ASCII char
|
signal kbd_char_o: std_ulogic_vector(kbd_char_buf'range) := (others => '0'); -- ASCII char
|
|
begin
|
begin
|
kbd_char_buf_new <= kbd_new_c;
|
kbd_char_buf_new <= kbd_new_c after g.delay;
|
|
|
ps2_next: process(clk, rst)
|
ps2_next: process(clk, rst)
|
begin
|
begin
|
if rst = '1' then
|
if rst = '1' and g.asynchronous_reset then
|
kbd_new_c <= '0';
|
kbd_new_c <= '0' after g.delay;
|
elsif rising_edge(clk) then
|
elsif rising_edge(clk) then
|
kbd_new_c <= kbd_new_n;
|
if rst = '1' and not g.asynchronous_reset then
|
|
kbd_new_c <= '0' after g.delay;
|
|
else
|
|
kbd_new_c <= kbd_new_n after g.delay;
|
|
end if;
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|
new_char: entity work.reg
|
new_char: entity work.reg
|
generic map(N => kbd_char'high+1)
|
generic map(g => g, N => kbd_char'length)
|
port map(
|
port map(
|
clk => clk,
|
clk => clk,
|
rst => rst,
|
rst => rst,
|
di => kbd_char,
|
di => kbd_char,
|
we => kbd_new_edge,
|
we => kbd_new_edge,
|
do => kbd_char_o);
|
|
|
|
char_buf: entity work.reg
|
|
generic map(N => kbd_char'high+1)
|
|
port map(
|
|
clk => clk,
|
|
rst => rst,
|
|
di => kbd_char_o,
|
|
we => kbd_char_re,
|
|
do => kbd_char_buf);
|
do => kbd_char_buf);
|
|
|
ps2_proc: process(kbd_new_edge, kbd_new_c, kbd_char_re)
|
ps2_proc: process(kbd_new_edge, kbd_new_c, kbd_char_re)
|
begin
|
begin
|
if kbd_new_edge = '1' then
|
if kbd_new_edge = '1' then
|
kbd_new_n <= '1';
|
kbd_new_n <= '1' after g.delay;
|
elsif kbd_char_re = '1' then
|
elsif kbd_char_re = '1' then
|
kbd_new_n <= '0';
|
kbd_new_n <= '0' after g.delay;
|
else
|
else
|
kbd_new_n <= kbd_new_c;
|
kbd_new_n <= kbd_new_c after g.delay;
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|
-- Process a kbd_new into a single edge for the rest of the
|
-- Process a kbd_new into a single edge for the rest of the
|
-- system.
|
-- system.
|
ps2_edge_new_character_0: entity work.rising_edge_detector
|
ps2_edge_new_character_0: entity work.rising_edge_detector
|
|
generic map(g => g)
|
port map(
|
port map(
|
clk => clk,
|
clk => clk,
|
rst => rst,
|
rst => rst,
|
di => kbd_new,
|
di => kbd_new,
|
do => kbd_new_edge);
|
do => kbd_new_edge);
|
|
|
ps2_0: work.kbd_pkg.ps2_kbd_top
|
ps2_0: work.kbd_pkg.ps2_kbd_top
|
generic map(
|
generic map(
|
clock_frequency => clock_frequency,
|
clock_frequency => g.clock_frequency,
|
ps2_debounce_counter_size => ps2_debounce_counter_size)
|
ps2_debounce_counter_size => ps2_debounce_counter_size)
|
port map(
|
port map(
|
clk => clk,
|
clk => clk,
|
ps2_clk => ps2_clk,
|
ps2_clk => ps2_clk,
|
ps2_data => ps2_data,
|
ps2_data => ps2_data,
|
Line 172... |
Line 169... |
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use work.kbd_pkg.all;
|
use work.kbd_pkg.all;
|
|
|
entity ps2_kbd_top is
|
entity ps2_kbd_top is
|
generic(
|
generic(
|
clock_frequency: integer := 50000000; -- system clock frequency in hz
|
clock_frequency: integer := 50000000; -- system clock frequency in Hz
|
ps2_debounce_counter_size: integer := 8); -- set such that 2^size/clock_frequency = 5us (size = 8 for 50mhz)
|
ps2_debounce_counter_size: integer := 8); -- set such that 2^size/clock_frequency = 5us (size = 8 for 50MHz)
|
port(
|
port(
|
clk: in std_ulogic; -- system clock input
|
clk: in std_ulogic; -- system clock input
|
ps2_clk: in std_ulogic; -- clock signal from PS2 keyboard
|
ps2_clk: in std_ulogic; -- clock signal from PS2 keyboard
|
ps2_data: in std_ulogic; -- data signal from PS2 keyboard
|
ps2_data: in std_ulogic; -- data signal from PS2 keyboard
|
ascii_new: out std_ulogic := '0'; -- output flag indicating new ascii value
|
ascii_new: out std_ulogic := '0'; -- output flag indicating new ascii value
|
Line 485... |
Line 482... |
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
|
|
entity ps2_kbd_core is
|
entity ps2_kbd_core is
|
generic(
|
generic(
|
clock_frequency: integer := 50000000; -- system clock frequency in hz
|
clock_frequency: integer := 50000000; -- system clock frequency in Hz
|
debounce_counter_size: integer := 8); -- set such that (2^size)/clock_frequency = 5us (size = 8 for 50mhz)
|
debounce_counter_size: integer := 8); -- set such that (2^size)/clock_frequency = 5us (size = 8 for 50MHz)
|
port(
|
port(
|
clk: in std_ulogic; -- system clock
|
clk: in std_ulogic; -- system clock
|
ps2_clk: in std_ulogic; -- clock signal from PS/2 keyboard
|
ps2_clk: in std_ulogic; -- clock signal from PS/2 keyboard
|
ps2_data: in std_ulogic; -- data signal from PS/2 keyboard
|
ps2_data: in std_ulogic; -- data signal from PS/2 keyboard
|
ps2_code_new: out std_ulogic; -- flag that new PS/2 code is available on ps2_code bus
|
ps2_code_new: out std_ulogic; -- flag that new PS/2 code is available on ps2_code bus
|
Line 592... |
Line 589... |
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use ieee.numeric_std.all;
|
use ieee.numeric_std.all;
|
|
|
entity ps2_debounce is
|
entity ps2_debounce is
|
generic(counter_size: integer := 19); --counter size (19 bits gives 10.5ms with 50mhz clock)
|
generic(counter_size: integer := 19); --counter size (19 bits gives 10.5ms with 50MHz clock)
|
port(
|
port(
|
clk: in std_ulogic;
|
clk: in std_ulogic;
|
button: in std_ulogic; --input signal to be debounced
|
button: in std_ulogic; --input signal to be debounced
|
result: out std_ulogic := '0'); --debounced signal
|
result: out std_ulogic := '0'); --debounced signal
|
end entity;
|
end entity;
|
Line 604... |
Line 601... |
architecture rtl of ps2_debounce is
|
architecture rtl of ps2_debounce is
|
signal flipflops: std_ulogic_vector(1 downto 0); --input flip flops
|
signal flipflops: std_ulogic_vector(1 downto 0); --input flip flops
|
signal counter_set: std_ulogic; --sync reset to zero
|
signal counter_set: std_ulogic; --sync reset to zero
|
signal counter_out: unsigned(counter_size downto 0) := (others => '0'); --counter output
|
signal counter_out: unsigned(counter_size downto 0) := (others => '0'); --counter output
|
begin
|
begin
|
|
|
counter_set <= flipflops(0) xor flipflops(1); --determine when to start/reset counter
|
counter_set <= flipflops(0) xor flipflops(1); --determine when to start/reset counter
|
|
|
process(clk)
|
process(clk)
|
begin
|
begin
|
if rising_edge(clk) then
|
if rising_edge(clk) then
|
flipflops(0) <= button;
|
flipflops(0) <= button;
|
flipflops(1) <= flipflops(0);
|
flipflops(1) <= flipflops(0);
|
if(counter_set = '1') then --reset counter because input is changing
|
if counter_set = '1' then --reset counter because input is changing
|
counter_out <= (others => '0');
|
counter_out <= (others => '0');
|
elsif(counter_out(counter_size) = '0') then --stable input time is not yet met
|
elsif counter_out(counter_size) = '0' then --stable input time is not yet met
|
counter_out <= counter_out + 1;
|
counter_out <= counter_out + 1;
|
else --stable input time is met
|
else --stable input time is met
|
result <= flipflops(1);
|
result <= flipflops(1);
|
end if;
|
end if;
|
end if;
|
end if;
|