-
Notifications
You must be signed in to change notification settings - Fork 0
/
mist_keyboard.sv
64 lines (53 loc) · 1.3 KB
/
mist_keyboard.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// simple MiST PS2 keyboard interface
module mist_keyboard (
input clk,
input reset,
// ps2 interface
input ps2_clk,
input ps2_data,
output valid,
output [15:0] key,
output status
);
wire [7:0] kdata; // keyboard data byte, 0xE0 = extended key, 0xF0 release key
wire error; // not used here
reg key_extended;
reg key_status;
assign key = { (key_extended ? 8'he0 : 8'h00) , kdata };
assign status = key_status;
always @(posedge clk or posedge reset) begin
if(reset) begin
key_status <= 1'b0;
key_extended <= 1'b0;
end
else begin
// ps2 decoder has received a valid byte
if(valid) begin
if(kdata == 8'he0)
// extended key code
key_extended <= 1'b1;
else if(kdata == 8'hf0)
// release code
key_status <= 1'b0;
else begin
// key press
key_extended <= 1'b0;
key_status <= 1'b1;
end
end
end
end
// the ps2 decoder has been taken from the zx spectrum core
ps2_intf ps2_keyboard (
.CLK ( clk ),
.nRESET ( !reset ),
// PS/2 interface
.PS2_CLK ( ps2_clk ),
.PS2_DATA ( ps2_data ),
// Byte-wide data interface - only valid for one clock
// so must be latched externally if required
.DATA ( kdata ),
.VALID ( valid ),
.ERROR ( error )
);
endmodule