1 |
11 |
rrred |
library IEEE;
|
2 |
|
|
use IEEE.std_logic_1164.all;
|
3 |
|
|
|
4 |
|
|
entity ps2kbd is
|
5 |
|
|
PORT (
|
6 |
|
|
keyboard_clk : inout std_logic;
|
7 |
|
|
keyboard_data : inout std_logic;
|
8 |
|
|
clock : in std_logic;
|
9 |
|
|
clkdelay : in std_logic;
|
10 |
|
|
reset : in std_logic;
|
11 |
|
|
read : in std_logic;
|
12 |
|
|
scan_ready : out std_logic;
|
13 |
|
|
ps2_ascii_code : out std_logic_vector(7 downto 0));
|
14 |
|
|
end ps2kbd;
|
15 |
|
|
|
16 |
|
|
architecture rtl of ps2kbd is
|
17 |
|
|
|
18 |
|
|
COMPONENT keyboard
|
19 |
|
|
PORT( keyboard_clk, keyboard_data, clock ,
|
20 |
|
|
reset, read : IN STD_LOGIC;
|
21 |
|
|
scan_code : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
|
22 |
|
|
scan_ready : OUT STD_LOGIC);
|
23 |
|
|
END COMPONENT;
|
24 |
|
|
|
25 |
|
|
signal scan_code_sig : std_logic_vector(7 downto 0);
|
26 |
|
|
signal scan_code : std_logic_vector(11 downto 0);
|
27 |
|
|
signal shift : std_logic_vector(1 downto 0);
|
28 |
|
|
signal caps : std_logic_vector(1 downto 0);
|
29 |
|
|
signal ctrlkey : std_logic_vector(3 downto 0);
|
30 |
|
|
|
31 |
|
|
begin
|
32 |
|
|
process (clkdelay)
|
33 |
|
|
begin
|
34 |
|
|
if clkdelay'event and clkdelay='1' then
|
35 |
|
|
if scan_code_sig = x"58" then
|
36 |
|
|
if caps = "00" then
|
37 |
|
|
caps <= "01";
|
38 |
|
|
elsif caps = "01" then
|
39 |
|
|
caps <= "11";
|
40 |
|
|
elsif caps = "11" then
|
41 |
|
|
caps <= "10";
|
42 |
|
|
else
|
43 |
|
|
caps <= "00";
|
44 |
|
|
end if;
|
45 |
|
|
end if;
|
46 |
|
|
end if;
|
47 |
|
|
|
48 |
|
|
scan_code <= "000" & caps(0) & scan_code_sig;
|
49 |
|
|
|
50 |
|
|
end process;
|
51 |
|
|
|
52 |
|
|
ps2_ascii_decode : process(scan_code)
|
53 |
|
|
begin
|
54 |
|
|
case scan_code is
|
55 |
|
|
when x"066" => ps2_ascii_code <= x"08"; -- Backspace ("backspace" key)
|
56 |
|
|
when x"00d" => ps2_ascii_code <= x"09"; -- Horizontal Tab
|
57 |
|
|
when x"05a" => ps2_ascii_code <= x"0d"; -- Carriage return ("enter" key)
|
58 |
|
|
when x"076" => ps2_ascii_code <= x"1b"; -- Escape ("esc" key)
|
59 |
|
|
when x"029" => ps2_ascii_code <= x"20"; -- Space
|
60 |
|
|
when x"116" => ps2_ascii_code <= x"21"; -- !
|
61 |
|
|
when x"152" => ps2_ascii_code <= x"22"; -- "
|
62 |
|
|
when x"126" => ps2_ascii_code <= x"23"; -- #
|
63 |
|
|
when x"125" => ps2_ascii_code <= x"24"; -- $
|
64 |
|
|
when x"12e" => ps2_ascii_code <= x"25"; --
|
65 |
|
|
when x"13d" => ps2_ascii_code <= x"26"; --
|
66 |
|
|
when x"052" => ps2_ascii_code <= x"27"; --
|
67 |
|
|
when x"146" => ps2_ascii_code <= x"28"; --
|
68 |
|
|
when x"145" => ps2_ascii_code <= x"29"; --
|
69 |
|
|
when x"13e" => ps2_ascii_code <= x"2a"; -- *
|
70 |
|
|
when x"155" => ps2_ascii_code <= x"2b"; -- +
|
71 |
|
|
when x"041" => ps2_ascii_code <= x"2c"; -- ,
|
72 |
|
|
when x"04e" => ps2_ascii_code <= x"2d"; -- -
|
73 |
|
|
when x"049" => ps2_ascii_code <= x"2e"; -- .
|
74 |
|
|
when x"04a" => ps2_ascii_code <= x"2f"; -- /
|
75 |
|
|
when x"045" => ps2_ascii_code <= x"30"; -- 0
|
76 |
|
|
when x"016" => ps2_ascii_code <= x"31"; -- 1
|
77 |
|
|
when x"01e" => ps2_ascii_code <= x"32"; -- 2
|
78 |
|
|
when x"026" => ps2_ascii_code <= x"33"; -- 3
|
79 |
|
|
when x"025" => ps2_ascii_code <= x"34"; -- 4
|
80 |
|
|
when x"02e" => ps2_ascii_code <= x"35"; -- 5
|
81 |
|
|
when x"036" => ps2_ascii_code <= x"36"; -- 6
|
82 |
|
|
when x"03d" => ps2_ascii_code <= x"37"; -- 7
|
83 |
|
|
when x"03e" => ps2_ascii_code <= x"38"; -- 8
|
84 |
|
|
when x"046" => ps2_ascii_code <= x"39"; -- 9
|
85 |
|
|
when x"14c" => ps2_ascii_code <= x"3a"; -- :
|
86 |
|
|
when x"04c" => ps2_ascii_code <= x"3b"; -- ;
|
87 |
|
|
when x"141" => ps2_ascii_code <= x"3c"; -- <
|
88 |
|
|
when x"055" => ps2_ascii_code <= x"3d"; -- =
|
89 |
|
|
when x"149" => ps2_ascii_code <= x"3e"; -- >
|
90 |
|
|
when x"14a" => ps2_ascii_code <= x"3f"; -- ?
|
91 |
|
|
when x"11e" => ps2_ascii_code <= x"40"; -- @
|
92 |
|
|
when x"11c" => ps2_ascii_code <= x"41"; -- A
|
93 |
|
|
when x"132" => ps2_ascii_code <= x"42"; -- B
|
94 |
|
|
when x"121" => ps2_ascii_code <= x"43"; -- C
|
95 |
|
|
when x"123" => ps2_ascii_code <= x"44"; -- D
|
96 |
|
|
when x"124" => ps2_ascii_code <= x"45"; -- E
|
97 |
|
|
when x"12b" => ps2_ascii_code <= x"46"; -- F
|
98 |
|
|
when x"134" => ps2_ascii_code <= x"47"; -- G
|
99 |
|
|
when x"133" => ps2_ascii_code <= x"48"; -- H
|
100 |
|
|
when x"143" => ps2_ascii_code <= x"49"; -- I
|
101 |
|
|
when x"13b" => ps2_ascii_code <= x"4a"; -- J
|
102 |
|
|
when x"142" => ps2_ascii_code <= x"4b"; -- K
|
103 |
|
|
when x"14b" => ps2_ascii_code <= x"4c"; -- L
|
104 |
|
|
when x"13a" => ps2_ascii_code <= x"4d"; -- M
|
105 |
|
|
when x"131" => ps2_ascii_code <= x"4e"; -- N
|
106 |
|
|
when x"144" => ps2_ascii_code <= x"4f"; -- O
|
107 |
|
|
when x"14d" => ps2_ascii_code <= x"50"; -- P
|
108 |
|
|
when x"115" => ps2_ascii_code <= x"51"; -- Q
|
109 |
|
|
when x"12d" => ps2_ascii_code <= x"52"; -- R
|
110 |
|
|
when x"11b" => ps2_ascii_code <= x"53"; -- S
|
111 |
|
|
when x"12c" => ps2_ascii_code <= x"54"; -- T
|
112 |
|
|
when x"13c" => ps2_ascii_code <= x"55"; -- U
|
113 |
|
|
when x"12a" => ps2_ascii_code <= x"56"; -- V
|
114 |
|
|
when x"11d" => ps2_ascii_code <= x"57"; -- W
|
115 |
|
|
when x"122" => ps2_ascii_code <= x"58"; -- X
|
116 |
|
|
when x"135" => ps2_ascii_code <= x"59"; -- Y
|
117 |
|
|
when x"11a" => ps2_ascii_code <= x"5a"; -- Z
|
118 |
|
|
when x"054" => ps2_ascii_code <= x"5b"; -- [
|
119 |
|
|
when x"05d" => ps2_ascii_code <= x"5c"; -- \
|
120 |
|
|
when x"05b" => ps2_ascii_code <= x"5d"; -- ]
|
121 |
|
|
when x"136" => ps2_ascii_code <= x"5e"; -- ^
|
122 |
|
|
when x"14e" => ps2_ascii_code <= x"5f"; -- _
|
123 |
|
|
when x"00e" => ps2_ascii_code <= x"60"; -- `
|
124 |
|
|
when x"01c" => ps2_ascii_code <= x"61"; -- a
|
125 |
|
|
when x"032" => ps2_ascii_code <= x"62"; -- b
|
126 |
|
|
when x"021" => ps2_ascii_code <= x"63"; -- c
|
127 |
|
|
when x"023" => ps2_ascii_code <= x"64"; -- d
|
128 |
|
|
when x"024" => ps2_ascii_code <= x"65"; -- e
|
129 |
|
|
when x"02b" => ps2_ascii_code <= x"66"; -- f
|
130 |
|
|
when x"034" => ps2_ascii_code <= x"67"; -- g
|
131 |
|
|
when x"033" => ps2_ascii_code <= x"68"; -- h
|
132 |
|
|
when x"043" => ps2_ascii_code <= x"69"; -- i
|
133 |
|
|
when x"03b" => ps2_ascii_code <= x"6a"; -- j
|
134 |
|
|
when x"042" => ps2_ascii_code <= x"6b"; -- k
|
135 |
|
|
when x"04b" => ps2_ascii_code <= x"6c"; -- l
|
136 |
|
|
when x"03a" => ps2_ascii_code <= x"6d"; -- m
|
137 |
|
|
when x"031" => ps2_ascii_code <= x"6e"; -- n
|
138 |
|
|
when x"044" => ps2_ascii_code <= x"6f"; -- o
|
139 |
|
|
when x"04d" => ps2_ascii_code <= x"70"; -- p
|
140 |
|
|
when x"015" => ps2_ascii_code <= x"71"; -- q
|
141 |
|
|
when x"02d" => ps2_ascii_code <= x"72"; -- r
|
142 |
|
|
when x"01b" => ps2_ascii_code <= x"73"; -- s
|
143 |
|
|
when x"02c" => ps2_ascii_code <= x"74"; -- t
|
144 |
|
|
when x"03c" => ps2_ascii_code <= x"75"; -- u
|
145 |
|
|
when x"02a" => ps2_ascii_code <= x"76"; -- v
|
146 |
|
|
when x"01d" => ps2_ascii_code <= x"77"; -- w
|
147 |
|
|
when x"022" => ps2_ascii_code <= x"78"; -- x
|
148 |
|
|
when x"035" => ps2_ascii_code <= x"79"; -- y
|
149 |
|
|
when x"01a" => ps2_ascii_code <= x"7a"; -- z
|
150 |
|
|
when x"154" => ps2_ascii_code <= x"7b"; -- {
|
151 |
|
|
when x"15d" => ps2_ascii_code <= x"7c"; -- |
|
152 |
|
|
when x"15b" => ps2_ascii_code <= x"7d"; -- }
|
153 |
|
|
when x"10e" => ps2_ascii_code <= x"7e"; -- ~
|
154 |
|
|
when x"071" => ps2_ascii_code <= x"7f"; -- (Delete OR DEL on numeric keypad)
|
155 |
|
|
when x"171" => ps2_ascii_code <= x"7f"; -- (Delete OR DEL on numeric keypad)
|
156 |
|
|
when others => ps2_ascii_code <= x"FF"; -- keys not mapped
|
157 |
|
|
end case;
|
158 |
|
|
end process;
|
159 |
|
|
|
160 |
|
|
kbd_inst: keyboard port map (
|
161 |
|
|
keyboard_clk => keyboard_clk,
|
162 |
|
|
keyboard_data => keyboard_data,
|
163 |
|
|
clock => clock,
|
164 |
|
|
reset => reset,
|
165 |
|
|
read => read,
|
166 |
|
|
scan_ready => scan_ready,
|
167 |
|
|
scan_code => scan_code_sig
|
168 |
|
|
);
|
169 |
|
|
|
170 |
|
|
end;
|
171 |
|
|
|