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

Subversion Repositories vg_z80_sbc

[/] [vg_z80_sbc/] [trunk/] [rtl/] [ps2.v] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 hharte
//-------------------------------------------------------------------------------------
2
//
3
// Author: John Clayton
4
// Date  : April 30, 2001
5
// Update: 4/30/01 copied this file from lcd_2.v (pared down).
6
// Update: 5/24/01 changed the first module from "ps2_keyboard_receiver"
7
//                 to "ps2_keyboard_interface"
8
// Update: 5/29/01 Added input synchronizing flip-flops.  Changed state
9
//                 encoding (m1) for good operation after part config.
10
// Update: 5/31/01 Added low drive strength and slow transitions to ps2_clk
11
//                 and ps2_data in the constraints file.  Added the signal
12
//                 "tx_shifting_done" as distinguished from "rx_shifting_done."
13
//                 Debugged the transmitter portion in the lab.
14
// Update: 6/01/01 Added horizontal tab to the ascii output.
15
// Update: 6/01/01 Added parameter TRAP_SHIFT_KEYS.
16
//
17
//
18
//
19
//
20
//
21
// Description
22
//-------------------------------------------------------------------------------------
23
// This is a state-machine driven serial-to-parallel and parallel-to-serial
24
// interface to the ps2 style keyboard interface.  The details of the operation
25
// of the keyboard interface were obtained from the following website:
26
//
27
//   http://www.beyondlogic.org/keyboard/keybrd.htm
28
//
29
// Some aspects of the keyboard interface are not implemented (e.g, parity
30
// checking for the receive side, and recognition of the various commands
31
// which the keyboard sends out, such as "power on selt test passed," "Error"
32
// and "Resend.")  However, if the user wishes to recognize these reply
33
// messages, the scan code output can always be used to extend functionality
34
// as desired.
35
//
36
// Note that the "Extended" (0xE0) and "Released" (0xF0) codes are recognized.
37
// The rx interface provides separate indicator flags for these two conditions
38
// with every valid character scan code which it provides.  The shift keys are
39
// also trapped by the interface, in order to provide correct uppercase ASCII
40
// characters at the ascii output, although the scan codes for the shift keys
41
// are still provided at the scan code output.  So, the left/right ALT keys
42
// can be differentiated by the presence of the rx_entended signal, while the
43
// left/right shift keys are differentiable by the different scan codes
44
// received.
45
//
46
// The interface to the ps2 keyboard uses ps2_clk clock rates of
47
// 30-40 kHz, dependent upon the keyboard itself.  The rate at which the state
48
// machine runs should be at least twice the rate of the ps2_clk, so that the
49
// states can accurately follow the clock signal itself.  Four times 
50
// oversampling is better.  Say 200kHz at least.  The upper limit for clocking
51
// the state machine will undoubtedly be determined by delays in the logic 
52
// which decodes the scan codes into ASCII equivalents.  The maximum speed
53
// will be most likely many megahertz, depending upon target technology.
54
// In order to run the state machine extremely fast, synchronizing flip-flops
55
// have been added to the ps2_clk and ps2_data inputs of the state machine.
56
// This avoids poor performance related to slow transitions of the inputs.
57
// 
58
// Because this is a bi-directional interface, while reading from the keyboard
59
// the ps2_clk and ps2_data lines are used as inputs.  While writing to the
60
// keyboard, however (which may be done at any time.  If writing interrupts a
61
// read from the keyboard, the keyboard will buffer up its data, and send
62
// it later) both the ps2_clk and ps2_data lines are occasionally pulled low,
63
// and pullup resistors are used to bring the lines high again, by setting
64
// the drivers to high impedance state.
65
//
66
// The tx interface, for writing to the keyboard, does not provide any special
67
// pre-processing.  It simply transmits the 8-bit command value to the
68
// keyboard.
69
//
70
// Pullups MUST BE USED on the ps2_clk and ps2_data lines for this design,
71
// whether they be internal to an FPGA I/O pad, or externally placed.
72
// If internal pullups are used, they may be fairly weak, causing bounces
73
// due to crosstalk, etc.  There is a "debounce timer" implemented in order
74
// to eliminate erroneous state transitions which would occur based on bounce.
75
// 
76
// Parameters are provided in order to configure and appropriately size the
77
// counter of a 60 microsecond timer used in the transmitter, depending on
78
// the clock frequency used.  The 60 microsecond period is guaranteed to be
79
// more than one period of the ps2_clk_s signal.
80
//
81
// Also, a smaller 5 microsecond timer has been included for "debounce".
82
// This is used because, with internal pullups on the ps2_clk and ps2_data
83
// lines, there is some bouncing around which occurs
84
//
85
// A parameter TRAP_SHIFT_KEYS allows the user to eliminate shift keypresses
86
// from producing scan codes (along with their "undefined" ASCII equivalents)
87
// at the output of the interface.  If TRAP_SHIFT_KEYS is non-zero, the shift
88
// key status will only be reported by rx_shift_key_on.  No ascii or scan
89
// codes will be reported for the shift keys.  This is useful for those who
90
// wish to use the ASCII data stream, and who don't want to have to "filter
91
// out" the shift key codes.
92
//
93
//-------------------------------------------------------------------------------------
94
 
95
 
96
`resetall
97
`timescale 1ns/100ps
98
 
99
`define TOTAL_BITS   11
100
`define EXTEND_CODE  16'hE0
101
`define RELEASE_CODE 16'hF0
102
`define LEFT_SHIFT   16'h12
103 23 hharte
`define RIGHT_SHIFT  16'h59
104
`define CTRL_KEY     16'h1D
105 3 hharte
 
106
 
107
module ps2_keyboard_interface (
108
  clk,
109
  reset,
110
  ps2_clk,
111
  ps2_data,
112
  rx_extended,
113
  rx_released,
114 23 hharte
  rx_shift_key_on,
115
  rx_ctrl_key_on,
116 3 hharte
  rx_scan_code,
117
  rx_ascii,
118
  rx_data_ready,       // rx_read_o
119
  rx_read,             // rx_read_ack_i
120
  tx_data,
121
  tx_write,
122
  tx_write_ack_o,
123
  tx_error_no_keyboard_ack
124
  );
125
 
126
// Parameters
127
 
128
// The timer value can be up to (2^bits) inclusive.
129
parameter TIMER_60USEC_VALUE_PP = 1920; // Number of sys_clks for 60usec.
130
parameter TIMER_60USEC_BITS_PP  = 11;   // Number of bits needed for timer
131
parameter TIMER_5USEC_VALUE_PP = 186;   // Number of sys_clks for debounce
132
parameter TIMER_5USEC_BITS_PP  = 8;     // Number of bits needed for timer
133
parameter TRAP_SHIFT_KEYS_PP = 0;       // Default: No shift key trap.
134
 
135
// State encodings, provided as parameters
136
// for flexibility to the one instantiating the module.
137
// In general, the default values need not be changed.
138
 
139
// State "m1_rx_clk_l" has been chosen on purpose.  Since the input
140
// synchronizing flip-flops initially contain zero, it takes one clk
141
// for them to update to reflect the actual (idle = high) status of
142
// the I/O lines from the keyboard.  Therefore, choosing 0 for m1_rx_clk_l
143
// allows the state machine to transition to m1_rx_clk_h when the true
144
// values of the input signals become present at the outputs of the
145
// synchronizing flip-flops.  This initial transition is harmless, and it
146
// eliminates the need for a "reset" pulse before the interface can operate.
147
 
148
parameter m1_rx_clk_h = 1;
149
parameter m1_rx_clk_l = 0;
150
parameter m1_rx_falling_edge_marker = 13;
151
parameter m1_rx_rising_edge_marker = 14;
152
parameter m1_tx_force_clk_l = 3;
153
parameter m1_tx_first_wait_clk_h = 10;
154
parameter m1_tx_first_wait_clk_l = 11;
155
parameter m1_tx_reset_timer = 12;
156
parameter m1_tx_wait_clk_h = 2;
157
parameter m1_tx_clk_h = 4;
158
parameter m1_tx_clk_l = 5;
159
parameter m1_tx_wait_keyboard_ack = 6;
160
parameter m1_tx_done_recovery = 7;
161
parameter m1_tx_error_no_keyboard_ack = 8;
162
parameter m1_tx_rising_edge_marker = 9;
163
parameter m2_rx_data_ready = 1;
164
parameter m2_rx_data_ready_ack = 0;
165
 
166
 
167
// I/O declarations
168
input clk;
169
input reset;
170
inout ps2_clk;
171
inout ps2_data;
172
output rx_extended;
173
output rx_released;
174 23 hharte
output rx_shift_key_on;
175
output rx_ctrl_key_on;
176 3 hharte
output [7:0] rx_scan_code;
177
output [7:0] rx_ascii;
178
output rx_data_ready;
179
input rx_read;
180
input [7:0] tx_data;
181
input tx_write;
182
output tx_write_ack_o;
183
output tx_error_no_keyboard_ack;
184
 
185
reg rx_extended;
186
reg rx_released;
187
reg [7:0] rx_scan_code;
188
reg [7:0] rx_ascii;
189
reg rx_data_ready;
190
reg tx_error_no_keyboard_ack;
191
 
192
// Internal signal declarations
193
wire timer_60usec_done;
194
wire timer_5usec_done;
195
wire extended;
196
wire released;
197
wire shift_key_on;
198
 
199
                         // NOTE: These two signals used to be one.  They
200
                         //       were split into two signals because of
201
                         //       shift key trapping.  With shift key
202
                         //       trapping, no event is generated externally,
203
                         //       but the "hold" data must still be cleared
204
                         //       anyway regardless, in preparation for the
205
                         //       next scan codes.
206
wire rx_output_event;    // Used only to clear: hold_released, hold_extended
207
wire rx_output_strobe;   // Used to produce the actual output.
208
 
209
wire tx_parity_bit;
210
wire rx_shifting_done;
211
wire tx_shifting_done;
212
wire [11:0] shift_key_plus_code;
213
 
214
reg [`TOTAL_BITS-1:0] q;
215
reg [3:0] m1_state;
216
reg [3:0] m1_next_state;
217
reg m2_state;
218
reg m2_next_state;
219
reg [3:0] bit_count;
220
reg enable_timer_60usec;
221
reg enable_timer_5usec;
222
reg [TIMER_60USEC_BITS_PP-1:0] timer_60usec_count;
223
reg [7:0] timer_5usec_count;
224
reg [7:0] ascii;      // "REG" type only because a case statement is used.
225
reg left_shift_key;
226
reg right_shift_key;
227 23 hharte
reg ctrl_key;
228 3 hharte
reg hold_extended;    // Holds prior value, cleared at rx_output_strobe
229
reg hold_released;    // Holds prior value, cleared at rx_output_strobe
230
reg ps2_clk_s;        // Synchronous version of this input
231
reg ps2_data_s;       // Synchronous version of this input
232
reg ps2_clk_hi_z;     // Without keyboard, high Z equals 1 due to pullups.
233
reg ps2_data_hi_z;    // Without keyboard, high Z equals 1 due to pullups.
234
 
235
//--------------------------------------------------------------------------
236
// Module code
237
 
238
assign ps2_clk = ps2_clk_hi_z?1'bZ:1'b0;
239
assign ps2_data = ps2_data_hi_z?1'bZ:1'b0;
240
 
241
// Input "synchronizing" logic -- synchronizes the inputs to the state
242
// machine clock, thus avoiding errors related to
243
// spurious state machine transitions.
244
//
245
// Since the initial state of registers is zero, and the idle state
246
// of the ps2_clk and ps2_data lines is "1" (due to pullups), the
247
// "sense" of the ps2_clk_s signal is inverted from the true signal.
248
// This allows the state machine to "come up" in the correct
249
always @(posedge clk)
250
begin
251
  ps2_clk_s <= ps2_clk;
252
  ps2_data_s <= ps2_data;
253
end
254
 
255
// State register
256
always @(posedge clk)
257
begin : m1_state_register
258
  if (reset) m1_state <= m1_rx_clk_h;
259
  else m1_state <= m1_next_state;
260
end
261
 
262
// State transition logic
263
always @(m1_state
264
         or q
265
         or tx_shifting_done
266
         or tx_write
267
         or ps2_clk_s
268
         or ps2_data_s
269
         or timer_60usec_done
270
         or timer_5usec_done
271
         )
272
begin : m1_state_logic
273
 
274
  // Output signals default to this value, unless changed in a state condition.
275
  ps2_clk_hi_z <= 1;
276
  ps2_data_hi_z <= 1;
277
  tx_error_no_keyboard_ack <= 0;
278
  enable_timer_60usec <= 0;
279
  enable_timer_5usec <= 0;
280
 
281
  case (m1_state)
282
 
283
    m1_rx_clk_h :
284
      begin
285
        enable_timer_60usec <= 1;
286
        if (tx_write) m1_next_state <= m1_tx_reset_timer;
287
        else if (~ps2_clk_s) m1_next_state <= m1_rx_falling_edge_marker;
288
        else m1_next_state <= m1_rx_clk_h;
289
      end
290
 
291
    m1_rx_falling_edge_marker :
292
      begin
293
        enable_timer_60usec <= 0;
294
        m1_next_state <= m1_rx_clk_l;
295
      end
296
 
297
    m1_rx_rising_edge_marker :
298
      begin
299
        enable_timer_60usec <= 0;
300
        m1_next_state <= m1_rx_clk_h;
301
      end
302
 
303
 
304
    m1_rx_clk_l :
305
      begin
306
        enable_timer_60usec <= 1;
307
        if (tx_write) m1_next_state <= m1_tx_reset_timer;
308
        else if (ps2_clk_s) m1_next_state <= m1_rx_rising_edge_marker;
309
        else m1_next_state <= m1_rx_clk_l;
310
      end
311
 
312
    m1_tx_reset_timer:
313
      begin
314
        enable_timer_60usec <= 0;
315
        m1_next_state <= m1_tx_force_clk_l;
316
      end
317
 
318
    m1_tx_force_clk_l :
319
      begin
320
        enable_timer_60usec <= 1;
321
        ps2_clk_hi_z <= 0;  // Force the ps2_clk line low.
322
        if (timer_60usec_done) m1_next_state <= m1_tx_first_wait_clk_h;
323
        else m1_next_state <= m1_tx_force_clk_l;
324
      end
325
 
326
    m1_tx_first_wait_clk_h :
327
      begin
328
        enable_timer_5usec <= 1;
329
        ps2_data_hi_z <= 0;        // Start bit.
330
        if (~ps2_clk_s && timer_5usec_done)
331
          m1_next_state <= m1_tx_clk_l;
332
        else
333
          m1_next_state <= m1_tx_first_wait_clk_h;
334
      end
335
 
336
    // This state must be included because the device might possibly
337
    // delay for up to 10 milliseconds before beginning its clock pulses.
338
    // During that waiting time, we cannot drive the data (q[0]) because it
339
    // is possibly 1, which would cause the keyboard to abort its receive
340
    // and the expected clocks would then never be generated.
341
    m1_tx_first_wait_clk_l :
342
      begin
343
        ps2_data_hi_z <= 0;
344
        if (~ps2_clk_s) m1_next_state <= m1_tx_clk_l;
345
        else m1_next_state <= m1_tx_first_wait_clk_l;
346
      end
347
 
348
    m1_tx_wait_clk_h :
349
      begin
350
        enable_timer_5usec <= 1;
351
        ps2_data_hi_z <= q[0];
352
        if (ps2_clk_s && timer_5usec_done)
353
          m1_next_state <= m1_tx_rising_edge_marker;
354
        else
355
          m1_next_state <= m1_tx_wait_clk_h;
356
      end
357
 
358
    m1_tx_rising_edge_marker :
359
      begin
360
        ps2_data_hi_z <= q[0];
361
        m1_next_state <= m1_tx_clk_h;
362
      end
363
 
364
    m1_tx_clk_h :
365
      begin
366
        ps2_data_hi_z <= q[0];
367
        if (tx_shifting_done) m1_next_state <= m1_tx_wait_keyboard_ack;
368
        else if (~ps2_clk_s) m1_next_state <= m1_tx_clk_l;
369
        else m1_next_state <= m1_tx_clk_h;
370
      end
371
 
372
    m1_tx_clk_l :
373
      begin
374
        ps2_data_hi_z <= q[0];
375
        if (ps2_clk_s) m1_next_state <= m1_tx_wait_clk_h;
376
        else m1_next_state <= m1_tx_clk_l;
377
      end
378
 
379
    m1_tx_wait_keyboard_ack :
380
      begin
381
        if (~ps2_clk_s && ps2_data_s)
382
          m1_next_state <= m1_tx_error_no_keyboard_ack;
383
        else if (~ps2_clk_s && ~ps2_data_s)
384
          m1_next_state <= m1_tx_done_recovery;
385
        else m1_next_state <= m1_tx_wait_keyboard_ack;
386
      end
387
 
388
    m1_tx_done_recovery :
389
      begin
390
        if (ps2_clk_s && ps2_data_s) m1_next_state <= m1_rx_clk_h;
391
        else m1_next_state <= m1_tx_done_recovery;
392
      end
393
 
394
    m1_tx_error_no_keyboard_ack :
395
      begin
396
        tx_error_no_keyboard_ack <= 1;
397
        if (ps2_clk_s && ps2_data_s) m1_next_state <= m1_rx_clk_h;
398
        else m1_next_state <= m1_tx_error_no_keyboard_ack;
399
      end
400
 
401
    default : m1_next_state <= m1_rx_clk_h;
402
  endcase
403
end
404
 
405
// State register
406
always @(posedge clk)
407
begin : m2_state_register
408
  if (reset) m2_state <= m2_rx_data_ready_ack;
409
  else m2_state <= m2_next_state;
410
end
411
 
412
// State transition logic
413
always @(m2_state or rx_output_strobe or rx_read)
414
begin : m2_state_logic
415
  case (m2_state)
416
    m2_rx_data_ready_ack:
417
          begin
418
            rx_data_ready <= 1'b0;
419
            if (rx_output_strobe) m2_next_state <= m2_rx_data_ready;
420
            else m2_next_state <= m2_rx_data_ready_ack;
421
          end
422
    m2_rx_data_ready:
423
          begin
424
            rx_data_ready <= 1'b1;
425
            if (rx_read) m2_next_state <= m2_rx_data_ready_ack;
426
            else m2_next_state <= m2_rx_data_ready;
427
          end
428
    default : m2_next_state <= m2_rx_data_ready_ack;
429
  endcase
430
end
431
 
432
// This is the bit counter
433
always @(posedge clk)
434
begin
435
  if (   reset
436
      || rx_shifting_done
437
      || (m1_state == m1_tx_wait_keyboard_ack)        // After tx is done.
438
      ) bit_count <= 0;  // normal reset
439
  else if (timer_60usec_done
440
           && (m1_state == m1_rx_clk_h)
441
           && (ps2_clk_s)
442
      ) bit_count <= 0;  // rx watchdog timer reset
443
//  else if (((m1_state == m1_rx_clk_h) && ~ps2_clk_s)  // increment for rx
444
  else if ( (m1_state == m1_rx_falling_edge_marker)   // increment for rx
445
           ||(m1_state == m1_tx_rising_edge_marker)   // increment for tx
446
           )
447
    bit_count <= bit_count + 1;
448
end
449
// This signal is high for one clock at the end of the timer count.
450
assign rx_shifting_done = (bit_count == `TOTAL_BITS);
451
assign tx_shifting_done = (bit_count == `TOTAL_BITS-1);
452
 
453
// This is the signal which enables loading of the shift register.
454
// It also indicates "ack" to the device writing to the transmitter.
455
assign tx_write_ack_o = (  (tx_write && (m1_state == m1_rx_clk_h))
456
                         ||(tx_write && (m1_state == m1_rx_clk_l))
457
                         );
458
 
459
// This is the ODD parity bit for the transmitted word.
460
assign tx_parity_bit = ~^tx_data;
461
 
462
// This is the shift register
463
always @(posedge clk)
464
begin
465
  if (reset) q <= 0;
466
  else if (tx_write_ack_o) q <= {1'b1,tx_parity_bit,tx_data,1'b0};
467
//  else if (((m1_state == m1_rx_clk_h) && ~ps2_clk_s)
468
  else if ( (m1_state == m1_rx_falling_edge_marker)
469
           ||(m1_state == m1_tx_rising_edge_marker) )
470
    q <= {ps2_data_s,q[`TOTAL_BITS-1:1]};
471
end
472
 
473
// This is the 60usec timer counter
474
always @(posedge clk)
475
begin
476
  if (~enable_timer_60usec) timer_60usec_count <= 0;
477
  else if (~timer_60usec_done) timer_60usec_count <= timer_60usec_count + 1;
478
end
479
assign timer_60usec_done = (timer_60usec_count == (TIMER_60USEC_VALUE_PP - 1));
480
 
481
// This is the 5usec timer counter
482
always @(posedge clk)
483
begin
484
  if (~enable_timer_5usec) timer_5usec_count <= 0;
485
  else if (~timer_5usec_done) timer_5usec_count <= timer_5usec_count + 1;
486
end
487
assign timer_5usec_done = (timer_5usec_count == TIMER_5USEC_VALUE_PP - 1);
488
 
489
 
490
// Create the signals which indicate special scan codes received.
491
// These are the "unlatched versions."
492
assign extended = (q[8:1] == `EXTEND_CODE) && rx_shifting_done;
493
assign released = (q[8:1] == `RELEASE_CODE) && rx_shifting_done;
494
 
495
// Store the special scan code status bits
496
// Not the final output, but an intermediate storage place,
497
// until the entire set of output data can be assembled.
498
always @(posedge clk)
499
begin
500
  if (reset || rx_output_event)
501
  begin
502
    hold_extended <= 0;
503
    hold_released <= 0;
504
  end
505
  else
506
  begin
507
    if (rx_shifting_done && extended) hold_extended <= 1;
508
    if (rx_shifting_done && released) hold_released <= 1;
509
  end
510
end
511
 
512
 
513
// These bits contain the status of the two shift keys
514
always @(posedge clk)
515
begin
516
  if (reset) left_shift_key <= 0;
517
  else if ((q[8:1] == `LEFT_SHIFT) && rx_shifting_done && ~hold_released)
518
    left_shift_key <= 1;
519
  else if ((q[8:1] == `LEFT_SHIFT) && rx_shifting_done && hold_released)
520
    left_shift_key <= 0;
521
end
522
 
523
always @(posedge clk)
524
begin
525
  if (reset) right_shift_key <= 0;
526
  else if ((q[8:1] == `RIGHT_SHIFT) && rx_shifting_done && ~hold_released)
527
    right_shift_key <= 1;
528
  else if ((q[8:1] == `RIGHT_SHIFT) && rx_shifting_done && hold_released)
529
    right_shift_key <= 0;
530
end
531
 
532
assign rx_shift_key_on = left_shift_key || right_shift_key;
533 23 hharte
 
534
// This bit contains the status of the CTRL key
535
always @(posedge clk)
536
begin
537
  if (reset) ctrl_key <= 0;
538
  else if ((q[8:1] == `CTRL_KEY) && rx_shifting_done && ~hold_released)
539
    ctrl_key <= 1;
540
  else if ((q[8:1] == `CTRL_KEY) && rx_shifting_done && hold_released)
541
    ctrl_key <= 0;
542
end
543
 
544
assign rx_ctrl_key_on = ctrl_key;
545
 
546 3 hharte
 
547
// Output the special scan code flags, the scan code and the ascii
548
always @(posedge clk)
549
begin
550
  if (reset)
551
  begin
552
    rx_extended <= 0;
553
    rx_released <= 0;
554
    rx_scan_code <= 0;
555
    rx_ascii <= 0;
556
  end
557
  else if (rx_output_strobe && q[8:1])
558
  begin
559
    rx_extended <= hold_extended;
560
    rx_released <= hold_released;
561
    rx_scan_code <= q[8:1];
562
    rx_ascii <= ascii;
563
  end
564
end
565
 
566
// Store the final rx output data only when all extend and release codes
567
// are received and the next (actual key) scan code is also ready.
568
// (the presence of rx_extended or rx_released refers to the
569
// the current latest scan code received, not the previously latched flags.)
570
assign rx_output_event  = (rx_shifting_done
571
                          && ~extended
572
                          && ~released
573
                          );
574
 
575
assign rx_output_strobe = (rx_shifting_done
576
                          && ~extended
577
                          && ~released
578
                          && ( (TRAP_SHIFT_KEYS_PP == 0)
579
                               || ( (q[8:1] != `RIGHT_SHIFT)
580
                                    &&(q[8:1] != `LEFT_SHIFT)
581
                                  )
582
                             )
583
                          );
584
 
585
// This part translates the scan code into an ASCII value...
586
// Only the ASCII codes which I considered important have been included.
587
// if you want more, just add the appropriate case statement lines...
588
// (You will need to know the keyboard scan codes you wish to assign.)
589
// The entries are listed in ascending order of ASCII value.
590
assign shift_key_plus_code = {3'b0,rx_shift_key_on,q[8:1]};
591
always @(shift_key_plus_code)
592
begin
593
  casez (shift_key_plus_code)
594
    12'h?66 : ascii <= 8'h08;  // Backspace ("backspace" key)
595
    12'h?0d : ascii <= 8'h09;  // Horizontal Tab
596
    12'h?5a : ascii <= 8'h0d;  // Carriage return ("enter" key)
597
    12'h?76 : ascii <= 8'h1b;  // Escape ("esc" key)
598
    12'h?29 : ascii <= 8'h20;  // Space
599
    12'h116 : ascii <= 8'h21;  // !
600
    12'h152 : ascii <= 8'h22;  // "
601
    12'h126 : ascii <= 8'h23;  // #
602
    12'h125 : ascii <= 8'h24;  // $
603
    12'h12e : ascii <= 8'h25;  // %
604
    12'h13d : ascii <= 8'h26;  // &
605
    12'h052 : ascii <= 8'h27;  // '
606
    12'h146 : ascii <= 8'h28;  // (
607
    12'h145 : ascii <= 8'h29;  // )
608
    12'h13e : ascii <= 8'h2a;  // *
609
    12'h155 : ascii <= 8'h2b;  // +
610
    12'h041 : ascii <= 8'h2c;  // ,
611
    12'h04e : ascii <= 8'h2d;  // -
612
    12'h049 : ascii <= 8'h2e;  // .
613
    12'h04a : ascii <= 8'h2f;  // /
614
    12'h045 : ascii <= 8'h30;  // 0
615
    12'h016 : ascii <= 8'h31;  // 1
616
    12'h01e : ascii <= 8'h32;  // 2
617
    12'h026 : ascii <= 8'h33;  // 3
618
    12'h025 : ascii <= 8'h34;  // 4
619
    12'h02e : ascii <= 8'h35;  // 5
620
    12'h036 : ascii <= 8'h36;  // 6
621
    12'h03d : ascii <= 8'h37;  // 7
622
    12'h03e : ascii <= 8'h38;  // 8
623
    12'h046 : ascii <= 8'h39;  // 9
624
    12'h14c : ascii <= 8'h3a;  // :
625
    12'h04c : ascii <= 8'h3b;  // ;
626
    12'h141 : ascii <= 8'h3c;  // <
627
    12'h055 : ascii <= 8'h3d;  // =
628
    12'h149 : ascii <= 8'h3e;  // >
629
    12'h14a : ascii <= 8'h3f;  // ?
630
    12'h11e : ascii <= 8'h40;  // @
631
    12'h11c : ascii <= 8'h41;  // A
632
    12'h132 : ascii <= 8'h42;  // B
633
    12'h121 : ascii <= 8'h43;  // C
634
    12'h123 : ascii <= 8'h44;  // D
635
    12'h124 : ascii <= 8'h45;  // E
636
    12'h12b : ascii <= 8'h46;  // F
637
    12'h134 : ascii <= 8'h47;  // G
638
    12'h133 : ascii <= 8'h48;  // H
639
    12'h143 : ascii <= 8'h49;  // I
640
    12'h13b : ascii <= 8'h4a;  // J
641
    12'h142 : ascii <= 8'h4b;  // K
642
    12'h14b : ascii <= 8'h4c;  // L
643
    12'h13a : ascii <= 8'h4d;  // M
644
    12'h131 : ascii <= 8'h4e;  // N
645
    12'h144 : ascii <= 8'h4f;  // O
646
    12'h14d : ascii <= 8'h50;  // P
647
    12'h115 : ascii <= 8'h51;  // Q
648
    12'h12d : ascii <= 8'h52;  // R
649
    12'h11b : ascii <= 8'h53;  // S
650
    12'h12c : ascii <= 8'h54;  // T
651
    12'h13c : ascii <= 8'h55;  // U
652
    12'h12a : ascii <= 8'h56;  // V
653
    12'h11d : ascii <= 8'h57;  // W
654
    12'h122 : ascii <= 8'h58;  // X
655
    12'h135 : ascii <= 8'h59;  // Y
656
    12'h11a : ascii <= 8'h5a;  // Z
657
    12'h054 : ascii <= 8'h5b;  // [
658
    12'h05d : ascii <= 8'h5c;  // \
659
    12'h05b : ascii <= 8'h5d;  // ]
660
    12'h136 : ascii <= 8'h5e;  // ^
661
    12'h14e : ascii <= 8'h5f;  // _    
662
    12'h00e : ascii <= 8'h60;  // `
663
    12'h01c : ascii <= 8'h61;  // a
664
    12'h032 : ascii <= 8'h62;  // b
665
    12'h021 : ascii <= 8'h63;  // c
666
    12'h023 : ascii <= 8'h64;  // d
667
    12'h024 : ascii <= 8'h65;  // e
668
    12'h02b : ascii <= 8'h66;  // f
669
    12'h034 : ascii <= 8'h67;  // g
670
    12'h033 : ascii <= 8'h68;  // h
671
    12'h043 : ascii <= 8'h69;  // i
672
    12'h03b : ascii <= 8'h6a;  // j
673
    12'h042 : ascii <= 8'h6b;  // k
674
    12'h04b : ascii <= 8'h6c;  // l
675
    12'h03a : ascii <= 8'h6d;  // m
676
    12'h031 : ascii <= 8'h6e;  // n
677
    12'h044 : ascii <= 8'h6f;  // o
678
    12'h04d : ascii <= 8'h70;  // p
679
    12'h015 : ascii <= 8'h71;  // q
680
    12'h02d : ascii <= 8'h72;  // r
681
    12'h01b : ascii <= 8'h73;  // s
682
    12'h02c : ascii <= 8'h74;  // t
683
    12'h03c : ascii <= 8'h75;  // u
684
    12'h02a : ascii <= 8'h76;  // v
685
    12'h01d : ascii <= 8'h77;  // w
686
    12'h022 : ascii <= 8'h78;  // x
687
    12'h035 : ascii <= 8'h79;  // y
688
    12'h01a : ascii <= 8'h7a;  // z
689
    12'h154 : ascii <= 8'h7b;  // {
690
    12'h15d : ascii <= 8'h7c;  // |
691
    12'h15b : ascii <= 8'h7d;  // }
692
    12'h10e : ascii <= 8'h7e;  // ~
693
    12'h?71 : ascii <= 8'h7f;  // (Delete OR DEL on numeric keypad)
694
    default : ascii <= 8'h2e;  // '.' used for unlisted characters.
695
  endcase
696
end
697
 
698
 
699
endmodule
700
 
701
//`undefine TOTAL_BITS
702
//`undefine EXTEND_CODE
703
//`undefine RELEASE_CODE
704
//`undefine LEFT_SHIFT
705
//`undefine RIGHT_SHIFT
706
 

powered by: WebSVN 2.1.0

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