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

Subversion Repositories virtual_rs232_terminal_with_lvds_lcd

[/] [virtual_rs232_terminal_with_lvds_lcd/] [trunk/] [rtl/] [PS2.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 racerxdl
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// Company: 
4
// Engineer: Original Design by Joshua Wise 
5
// 
6
// http://joshuawise.com/
7
// http://git.joshuawise.com/vterm.git/
8
// Create Date:    21:54:03 02/16/2011 
9
// Design Name: 
10
// Module Name:    PS2 
11
// Project Name: 
12
// Target Devices: 
13
// Tool versions: 
14
// Description: 
15
//
16
// Dependencies: 
17
//
18
// Revision: 
19
// Revision 0.01 - Got Joshua Wise PS2 Controller Code
20
// Revision 0.02 - Modified to ABNT2 Keyboard
21
// Revision 0.03 - Correct a few bugs
22
// Additional Comments: 
23
//
24
//////////////////////////////////////////////////////////////////////////////////
25
module PS2(
26
                 input clk,
27
                 input ps2clk,
28
                 input ps2data,
29
                 output write,
30
                 output [7:0] dataout,
31
                 output mod_led
32
    );
33
                reg [3:0] bitcount = 0;
34
                reg [7:0] key = 0;
35
                reg keyarrow = 0, keyup = 0, parity = 0;
36
                reg wr = 0;
37
                reg [7:0] data = 0;
38
                /* Clock debouncing */
39
                reg lastinclk = 0;
40
                reg [6:0] debounce = 0;
41
                reg fixedclk = 0;
42
                reg [11:0] resetcountdown = 0;
43
 
44
                reg [6:0] unshiftedrom [127:0];   initial $readmemh("MemoryInit/scancodes_abnt2mi.list", unshiftedrom);
45
                reg [6:0] shiftedrom [127:0];     initial $readmemh("MemoryInit/scancodes_abnt2ma.list", shiftedrom);
46
 
47
                reg mod_lshift = 0;
48
                reg mod_rshift = 0;
49
                reg mod_capslock = 0;
50
                wire mod_shifted = (mod_lshift | mod_rshift) ^ mod_capslock;
51
 
52
                reg nd = 0;
53
                reg lastnd = 0;
54
 
55
                always @(posedge clk) begin
56
                        if (ps2clk != lastinclk) begin
57
                                        lastinclk               <= ps2clk;
58
                                        debounce                <= 1;
59
                                        resetcountdown <= 12'b111111111111;
60
                        end else if (debounce == 0) begin
61
                                        fixedclk                <= ps2clk;
62
                                        resetcountdown <= resetcountdown - 1;
63
                        end else
64
                                        debounce                <= debounce + 1;
65
 
66
                        if (nd ^ lastnd) begin
67
                                        lastnd                  <= nd;
68
                                        wr                              <= 1;
69
                        end else
70
                                        wr                              <= 0;
71
                end
72
 
73
                always @(negedge fixedclk) begin
74
                        if (resetcountdown == 0)
75
                                        bitcount                <= 0;
76
                        else if (bitcount == 10) begin
77
                                        bitcount                <= 0;
78
                                if(parity != (^ key)) begin
79
                                                if(keyarrow) begin
80
                                                                casex(key)
81
                                                                        8'hF0: keyup <= 1;
82
                                                                        8'hxx: keyarrow <= 0;
83
                                                                endcase
84
                                                end
85
                                        else begin
86
                                                if(keyup) begin
87
                                                                keyup                   <= 0;
88
                                                                keyarrow                <= 0;
89
                                                                casex (key)
90
                                                                                                8'h12: mod_lshift <= 0;
91
                                                                                                8'h59: mod_rshift <= 0;
92
                                                                endcase
93
                                                                // handle this? I don't fucking know
94
                                                end
95
                                                else begin
96
                                                        casex(key)
97
                                                                                        8'hE0: keyarrow                         <= 1;   // handle these? I don't fucking know
98
                                                                                        8'hF0: keyup                            <= 1;
99
                                                                                        8'h12: mod_lshift               <= 1;
100
                                                                                        8'h59: mod_rshift               <= 1;
101
                                                                                        8'h58: mod_capslock             <= ~mod_capslock;
102
                                                                                        8'b0xxxxxxx: begin nd   <= ~nd; data <= mod_shifted ? shiftedrom[key] : unshiftedrom[key]; end
103
                                                                                        //8'b0xxxxxxx: begin nd <= ~nd; data <= key; end // Use isso para mostrar os ScanCodes
104
                                                                                        8'b1xxxxxxx: begin /* Nada */ end
105
                                                        endcase
106
                                                end
107
                                        end
108
                                end
109
                                else begin
110
                                                keyarrow        <= 0;
111
                                                keyup           <= 0;
112
                                end
113
                        end else
114
                                        bitcount        <= bitcount + 1;
115
 
116
                        case(bitcount)
117
                                                                1: key[0] <= ps2data;
118
                                                                2: key[1] <= ps2data;
119
                                                                3: key[2] <= ps2data;
120
                                                                4: key[3] <= ps2data;
121
                                                                5: key[4] <= ps2data;
122
                                                                6: key[5] <= ps2data;
123
                                                                7: key[6] <= ps2data;
124
                                                                8: key[7] <= ps2data;
125
                                                                9: parity <= ps2data;
126
                        endcase
127
                end
128
 
129
        assign write    = wr;
130
        assign dataout = data;
131
        assign mod_led = mod_shifted;
132
endmodule

powered by: WebSVN 2.1.0

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