From 586b006e88c7c75b2fcbd4d436479a473879dc73 Mon Sep 17 00:00:00 2001 From: Niels Moseley Date: Mon, 29 Jan 2018 00:39:24 +0100 Subject: [PATCH] PS/2 keyboard seems to be working including the shift key. It needs debouncing, however --- rtl/apple1.v | 21 +++++++++++++++++++++ rtl/boards/terasic_de0/apple1_de0_top.v | 15 ++------------- rtl/ps2keyboard/ps2keyboard.v | 2 +- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/rtl/apple1.v b/rtl/apple1.v index 741834b..b0de29b 100644 --- a/rtl/apple1.v +++ b/rtl/apple1.v @@ -6,6 +6,9 @@ module apple1( output uart_tx, output uart_cts, + input ps2_clk, // PS/2 keyboard serial clock input + input ps2_din, // PS/2 keyboard serial data input + output [15:0] pc_monitor // spy for program counter / debugging ); parameter RAM_FILENAME = "../../roms/ram.hex"; @@ -109,6 +112,9 @@ module apple1( wire ram_cs = (ab[15:13] == 3'b000); // 0x0000 -> 0x1FFF wire uart_cs = (ab[15:2] == 14'b11010000000100); // 0xD010 -> 0xD013 + wire ps2kb_cs = 1'b0; + //wire uart_cs = (ab[15:1] == 15'b110100000001001); // 0xD012 -> 0xD013 + //wire ps2kb_cs = (ab[15:1] == 15'b110100000001000); // 0xD010 -> 0xD011 wire basic_cs = (ab[15:12] == 4'b1110); // 0xE000 -> 0xEFFF wire rom_cs = (ab[15:8] == 8'b11111111); // 0xFF00 -> 0xFFFF @@ -155,16 +161,31 @@ module apple1( .uart_cts(uart_cts), .enable(uart_cs & cpu_clken), + //.address({1'b1, ab[0]}), // for ps/2 .address(ab[1:0]), .w_en(we & uart_cs), .din(dbo), .dout(uart_dout) ); + // PS/2 keyboard interface + wire [7:0] ps2_dout; + ps2keyboard keyboard + ( + .clk25(clk25), + .reset(reset), + .key_clk(ps2_clk), + .key_din(ps2_din), + .cs(ps2kb_cs), + .address(ab[0]), + .dout(ps2_dout) + ); + // link up chip selected device to cpu input assign dbi = ram_cs ? ram_dout : rom_cs ? rom_dout : basic_cs ? basic_dout : uart_cs ? uart_dout : + ps2kb_cs ? ps2_dout : 8'hFF; endmodule diff --git a/rtl/boards/terasic_de0/apple1_de0_top.v b/rtl/boards/terasic_de0/apple1_de0_top.v index a5f653f..8fa067d 100644 --- a/rtl/boards/terasic_de0/apple1_de0_top.v +++ b/rtl/boards/terasic_de0/apple1_de0_top.v @@ -59,6 +59,8 @@ module apple1_de0_top( .uart_rx(UART_RXD), .uart_tx(UART_TXD), .uart_cts(UART_CTS), + .ps2_clk(PS2_KBCLK), + .ps2_din(PS2_KBDAT), .pc_monitor(pc_monitor) ); @@ -92,18 +94,5 @@ module apple1_de0_top( .hexdigit_in(pc_monitor[15:12]), .display_out(HEX3_D) ); - - ////////////////////////////////////////////////////////////////////////// - // Experimental PS/2 interface - - ps2keyboard keys( - .clk25(clk25), - .reset(~BUTTON[0]), - .key_clk(PS2_KBCLK), - .key_din(PS2_KBDAT), - .cs(1'b1), - .address(1'b0), - .dout(LEDG[7:0]) - ); endmodule diff --git a/rtl/ps2keyboard/ps2keyboard.v b/rtl/ps2keyboard/ps2keyboard.v index 529b10a..06d0ebf 100644 --- a/rtl/ps2keyboard/ps2keyboard.v +++ b/rtl/ps2keyboard/ps2keyboard.v @@ -142,7 +142,7 @@ begin if (address == 1'b0) begin // RX buffer address - dout <= ascii; + dout <= {1'b1, ascii[6:0]}; ascii_rdy <= 1'b0; end else