OpenCores
URL https://opencores.org/ocsvn/rtf68ksys/rtf68ksys/trunk

Subversion Repositories rtf68ksys

[/] [rtf68ksys/] [trunk/] [rtl/] [verilog/] [FF_PS2KbdToAscii.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 robfinch
// ============================================================================
2
//  Keyboard 
3
//  - Reads keys from PS2 style keyboard
4
//
5
//      2010-2011  Robert Finch
6
//      robfinch<remove>@FPGAfield.ca
7
//
8
//
9
//  This source code is available for evaluation and validation purposes
10
//  only. This copyright statement and disclaimer must remain present in
11
//  the file.
12
//
13
//
14
//      NO WARRANTY.
15
//  THIS Work, IS PROVIDEDED "AS IS" WITH NO WARRANTIES OF ANY KIND, WHETHER
16
//  EXPRESS OR IMPLIED. The user must assume the entire risk of using the
17
//  Work.
18
//
19
//  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
20
//  INCIDENTAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES WHATSOEVER RELATING TO
21
//  THE USE OF THIS WORK, OR YOUR RELATIONSHIP WITH THE AUTHOR.
22
//
23
//  IN ADDITION, IN NO EVENT DOES THE AUTHOR AUTHORIZE YOU TO USE THE WORK
24
//  IN APPLICATIONS OR SYSTEMS WHERE THE WORK'S FAILURE TO PERFORM CAN
25
//  REASONABLY BE EXPECTED TO RESULT IN A SIGNIFICANT PHYSICAL INJURY, OR IN
26
//  LOSS OF LIFE. ANY SUCH USE BY YOU IS ENTIRELY AT YOUR OWN RISK, AND YOU
27
//  AGREE TO HOLD THE AUTHOR AND CONTRIBUTORS HARMLESS FROM ANY CLAIMS OR
28
//  LOSSES RELATING TO SUCH UNAUTHORIZED USE.
29
//
30
//
31
//      Convert a PS2 keyboard to ascii
32
//
33
//      Reg
34
//      $00             ascii code - bit 15 = strobe
35
//      $01             access this address clears keyboard strobe
36
//      
37
//
38
//      Verilog 1995
39
//      Webpack 9.2i  xc3s1200-4fg320
40
//      64 slices / 118 LUTs / 175.009 MHz
41
//  72 ff's / 2 BRAM (2048x16)
42
//
43
// ============================================================================
44
 
45
// PS2 scan codes
46
`define SC_LSHIFT       8'h12
47
`define SC_RSHIFT       8'h59
48
`define SC_CTRL         8'h14
49
`define SC_ALT          8'h11
50
`define SC_DEL          8'h71   // extend
51
`define SC_LCTRL        8'h58
52
`define SC_EXTEND       8'hE0
53
`define SC_KEYUP        8'hF0
54
 
55
module FF_PS2KbdToAscii(rst_i, clk_i, cyc_i, stb_i, ack_o, adr_i, dat_o, kclk, kd, irq, rst_o);
56
input rst_i;                            // reset
57
input clk_i;                            // master clock
58
input cyc_i;
59
input stb_i;
60
output ack_o;                           // ready
61
input [43:0] adr_i;                      // address
62
output [15:0] dat_o;             // data output
63
inout kclk;                             // keyboard clock from keyboard
64
tri kclk;
65
inout kd;                               // keyboard data
66
tri kd;
67
output irq;                             // data available
68
output rst_o;                   // reset output CTRL-ALT-DEL was pressed
69
 
70
wire cs = cyc_i && stb_i && (adr_i[43:4]==40'hFFF_FFDC_000);
71
 
72
reg strobe;
73
wire ps2_irq;
74
reg ps2_irq1;
75
reg ps2_cs;
76
wire [15:0] ps2_o;
77
 
78
// keyboard state
79
reg keyup;
80
reg extend;                             // extended keycode active
81
reg shift;                              // shift status
82
reg ctrl;                               // control status
83
reg alt;                                // alt status
84
reg x;
85
 
86
reg [7:0] sc;
87
 
88
assign ack_o = cs;
89
 
90
wire ign;
91
wire [7:0] xlat_o;
92
PS2ScanToAscii u1
93
(
94
        .shift(shift),
95
        .ctrl(ctrl),
96
        .alt(1'b0),
97
        .sc(sc),
98
        .extend(x),
99
        .ascii(xlat_o)
100
);
101
assign irq = strobe;
102
assign dat_o = cs ? {strobe,7'b0,xlat_o} : 16'h0000;
103
 
104
 
105
FF_PS2kbd u2
106
(
107
        .rst_i(rst_i),
108
        .clk_i(clk_i),
109
        .cyc_i(ps2_cs),
110
        .stb_i(ps2_cs),
111
        .ack_o(),
112
        .we_i(1'b0),
113
        .adr_i(44'hFFF_FFDC_0000),
114
        .dat_i(16'h0000),
115
        .dat_o(ps2_o),
116
        .vol_o(),
117
        .irq(ps2_irq),
118
        .kclk(kclk),
119
        .kd(kd)
120
);
121
 
122
 
123
// This little machine takes care of issuing a read cycle to the ps2 keyboard
124
// when data is present.
125
always @(posedge clk_i)
126
        if (rst_i) begin
127
                ps2_cs <= 0;
128
                ps2_irq1 <= 0;
129
        end
130
        else begin
131
                // has an PS2 keyboard event happened ?
132
                // If so, read the ps2 port
133
                ps2_irq1 <= ps2_irq;
134
                if (ps2_irq & ~ps2_irq1)
135
                        ps2_cs <= 1;
136
                else
137
                        ps2_cs <= 0;
138
        end
139
 
140
 
141
// This machine
142
// 1) clears the strobe line on an access to the keyboard strobe clear address
143
// 2) activates the strobe on a keydown event, filtering out special keys
144
// like control and alt
145
// 3) captures the state of ctrl,alt and shift and filters these codes out
146
always @(posedge clk_i)
147
        if (rst_i) begin
148
                keyup <= 0;
149
                extend <= 0;
150
                shift <= 0;
151
                ctrl <= 0;
152
                alt <= 0;
153
                sc <= 0;
154
                x <= 1'b0;
155
                strobe <= 0;
156
        end
157
        else begin
158
                if (cs & adr_i[1])
159
                        strobe <= 0;
160
                if (ps2_cs) begin
161
                        case (ps2_o[7:0])
162
                        `SC_KEYUP:      keyup <= 1;
163
                        `SC_EXTEND:     extend <= 1;
164
                        default:
165
                                begin
166
                                case(ps2_o[7:0])
167
                                `SC_CTRL:       ctrl <= ~keyup;
168
                                `SC_ALT:        alt <= ~keyup;
169
                                `SC_LSHIFT,
170
                                `SC_RSHIFT:     shift <= ~keyup;
171
                                default:
172
                                        begin
173
                                        sc <= ps2_o;
174
                                        x <= extend;
175
                                        strobe <= keyup ? strobe : 1;
176
                                        end
177
                                endcase
178
                                keyup <= 0;
179
                                extend <= 0;
180
                                end
181
                        endcase
182
                end
183
        end
184
 
185
// CTRL-ALT-DEL
186
assign rst_o = ps2_o[7:0]==`SC_DEL && alt && ctrl;
187
 
188
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.