Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolving Tang Nano 20K warnings from Gowin_V1.9.10_x64 #11

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
e4f4a8a
change Tang Nano 20K file paths in project file from absolute to rela…
hu-ict-ti-patzke-hagen Aug 9, 2024
20e3114
Step 1 - add .gitignore for generated files
hu-ict-ti-patzke-hagen Aug 9, 2024
e06e51c
Step 2 - Fix EX0206 invalid parameter value for DEVICE
hu-ict-ti-patzke-hagen Aug 9, 2024
4272be9
Step 3 - fix top.v warnings for gowin_pll_usb (pll_usb instance)
hu-ict-ti-patzke-hagen Aug 9, 2024
24b3361
Step 4 - fix top.v unused input s1 warning, re-organize physical cont…
hu-ict-ti-patzke-hagen Aug 9, 2024
3d32b4c
Step 5 - fix UART warnings
hu-ict-ti-patzke-hagen Aug 9, 2024
a5c80af
Step 6 - fix EXPRESSION SIZE warnings caused by increment or computation
hu-ict-ti-patzke-hagen Aug 9, 2024
b4f2886
Step 7 - fix EXPRESSION SIZE warnings for mouse x/y positions
hu-ict-ti-patzke-hagen Aug 9, 2024
db5b000
Step 8 - fix clock relationship warning
hu-ict-ti-patzke-hagen Aug 9, 2024
284f4ad
Manual commit for process config file
hu-ict-ti-patzke-hagen Aug 9, 2024
ed53b72
Add synthesis-hagen-git.md to project
hu-ict-ti-patzke-hagen Aug 9, 2024
a6e9851
Cleanup, refactoring, comments
hu-ict-ti-patzke-hagen Aug 10, 2024
e48824e
Remove unused UART_RXD, add s1 and LED for it, show UART-TXD state on…
hu-ict-ti-patzke-hagen Aug 10, 2024
6da2a40
Add logic for CTRL-A..Z processing, change ENTER key to CR (\x0d) and…
hu-ict-ti-patzke-hagen Aug 10, 2024
dc27d17
add HID device descriptor overview and setup photo
hu-ict-ti-patzke-hagen Aug 12, 2024
ee13d2c
add Steam Controller (dongle) USB descriptors
hu-ict-ti-patzke-hagen Aug 12, 2024
197339c
typofix in file name
hu-ict-ti-patzke-hagen Aug 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 58 additions & 48 deletions boards/common/hid_printer.v
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

module hid_printer (
output uart_tx,
input clk,
input resetn,
input uart_tx,
input [1:0] usb_type,
input usb_report,
input [7:0] key_modifiers,
Expand All @@ -11,24 +11,24 @@ module hid_printer (
input signed [7:0] mouse_dx,
input signed [7:0] mouse_dy,
input game_l, game_r, game_u, game_d,
input game_a, game_b, game_x, game_y, game_sel, game_sta
input game_a, game_b, game_x, game_y,
input game_sel, game_sta

// , input [63:0] hid_report
);

reg [22:0] cnt;
always @(posedge clk) cnt <= cnt + 1;

`include "print.vh"
defparam tx.uart_freq=115200;
defparam tx.clk_freq=12000000;

assign print_clk = clk;
assign uart_tx = uart_txp;

`include "utils.vh" // scancode2ascii()

reg [19:0] timer;
reg signed [10:0] mouse_x, mouse_y; // 0-1023
wire [7:0] mouse_x2 = mouse_x + mouse_dx;
wire [7:0] mouse_y2 = mouse_y + mouse_dy;
reg signed [10:0] mouse_x, mouse_y; // 0-1023 and negative(!) to detect overflow
wire signed [10:0] mouse_x2 = mouse_x + mouse_dx;
wire signed [10:0] mouse_y2 = mouse_y + mouse_dy;
reg [7:0] last_dx, last_dy;

reg start_print;
Expand All @@ -40,21 +40,26 @@ reg [9:0] game_btns_r;
wire [9:0] game_btns = {game_l, game_r, game_u, game_d, game_a, game_b,
game_x, game_y, game_sel, game_sta};

//reg [22:0] cnt; // print raw reports

always @(posedge clk) begin
if(~resetn) begin
`print("usb_hid_host demo. Connect keyboard, mouse or gamepad.\n",STR);
if (~resetn) begin
`print("usb_hid_host demo. Connect keyboard, mouse or gamepad.\x0d\x0a",STR); // "\r\n" does not work
end else begin
// Sequence timer for print delay
if (timer == 20'hfffff) begin
if (start_print) begin
timer <= 0;
start_print <= 0;
end
end else
timer <= timer + 1;
timer <= ((timer + 1) & 20'hfffff);

// print raw reports
// cnt <= ((cnt + 1) & 23'h7fffff);

// Simple ways to handle HID inputs
if (usb_report) begin

case (usb_type)
1: begin // keyboard
// just catch all keydown events. no auto-repeat. no capslock.
Expand Down Expand Up @@ -82,8 +87,8 @@ always @(posedge clk) begin
start_print <= 1;
game_btns_r <= game_btns;
end
endcase
end
endcase // usb_type
end // if usb_report

// print result to UART
case (usb_type)
Expand All @@ -92,41 +97,46 @@ always @(posedge clk) begin
keyascii <= 0;
start_print <= 0;
end

2: case (timer) // print mouse position
20'h00000: `print("\x0dMouse: x=", STR); // there's no \r ...
20'h10000: `print({6'b0, mouse_x[9:0]}, 2);
20'h20000: `print(", y=", STR);
20'h30000: `print({6'b0, mouse_y[9:0]}, 2);
20'h40000: `print(mouse_btn[0] ? " L" : " _", STR);
20'h50000: `print(mouse_btn[1] ? " R" : " _", STR);
20'h60000: `print(mouse_btn[2] ? " M " : " _ ", STR);
endcase
2: case (timer) // print mouse position
20'h00000: `print("\x0dMouse: x=", STR); // Print CR (\r) to start at line
20'h10000: `print({6'b0, mouse_x[9:0]}, 2);
20'h20000: `print(", y=", STR);
20'h30000: `print({6'b0, mouse_y[9:0]}, 2);
20'h40000: `print(mouse_btn[0] ? " L" : " _", STR);
20'h50000: `print(mouse_btn[1] ? " R" : " _", STR);
20'h60000: `print(mouse_btn[2] ? " M" : " _", STR);
20'h70000: `print("\x0d\x0a", STR); // CRLF (\r\n)
endcase
3: case(timer) // print gamepad status
20'h00000: `print("\x0dGamepad:", STR);
20'h10000: `print(game_l ? " L" : " _", STR);
20'h20000: `print(game_u ? " U" : " _", STR);
20'h30000: `print(game_r ? " R" : " _", STR);
20'h40000: `print(game_d ? " D" : " _", STR);
20'h50000: `print(game_a ? " A" : " _", STR);
20'h60000: `print(game_b ? " B" : " _", STR);
20'h70000: `print(game_x ? " X" : " _", STR);
20'h80000: `print(game_y ? " Y" : " _", STR);
20'h90000: `print(game_sel ? " SE" : " __", STR);
20'ha0000: `print(game_sta ? " ST" : " __", STR);
20'hb0000: `print(" ", STR);
endcase
endcase
end

// print raw reports
// case (cnt[19:0])
// 20'h00000: `print(hid_report, 8);
// 20'h10000: `print(", type=", STR);
// 20'h20000: `print({6'b0, usb_type}, 1);
// 20'hf0000: `print("\n", STR);
// endcase
20'h00000: `print("\x0dGamepad:", STR);
20'h10000: `print(game_l ? " L" : " _", STR);
20'h20000: `print(game_u ? " U" : " _", STR);
20'h30000: `print(game_r ? " R" : " _", STR);
20'h40000: `print(game_d ? " D" : " _", STR);
20'h50000: `print(game_a ? " A" : " _", STR);
20'h60000: `print(game_b ? " B" : " _", STR);
20'h70000: `print(game_x ? " X" : " _", STR);
20'h80000: `print(game_y ? " Y" : " _", STR);
20'h90000: `print(game_sel ? " SE" : " __", STR);
20'ha0000: `print(game_sta ? " ST" : " __", STR);
20'hb0000: `print("\x0d\x0a", STR);
endcase
endcase // usb_type

// print raw reports
// if (cnt[22:20] == 3'b100) begin
// case (cnt[19:0])
// 20'h00000: `print("Last USB HID report: ", STR);
// 20'h10000: `print(hid_report, 8);
// 20'h20000: `print(", type=", STR);
// 20'h30000: `print({6'b0, usb_type}, HEX);
// 20'h40000: `print("\x0d\x0a", STR);
// endcase
// end

end // resetn not active
end



endmodule
16 changes: 8 additions & 8 deletions boards/common/print.vh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameter STR = 0;
parameter HEX = 1;
localparam STR = 1'b0;
localparam HEX = 1'b1;

wire print_clk;

Expand All @@ -15,11 +15,11 @@ reg spin_state=0;
reg[6:0] print_length;
reg print_type;

parameter PRINT_IDLE_STATE = 0;
parameter PRINT_WAIT_STATE = 1;
parameter PRINT_WORK_STATE = 2;
parameter PRINT_CONV_STATE = 3;
reg[1:0] print_state=PRINT_IDLE_STATE;
localparam PRINT_IDLE_STATE = 2'b00;
localparam PRINT_WAIT_STATE = 2'b01;
localparam PRINT_WORK_STATE = 2'b10;
localparam PRINT_CONV_STATE = 2'b11;
reg[1:0] print_state = PRINT_IDLE_STATE;

wire[7:0] hex_lib[15:0];
assign hex_lib[4'h0] = 8'h30;
Expand Down Expand Up @@ -108,7 +108,7 @@ always @(posedge print_clk) begin
seq_head <= seq_head + 8'd1;
if (seq_head!=seq_tail && !uart_bz) begin
uart_en <= 1'b1;
total <= total + 1;
total <= ((total + 1) & 8'hff);
end
end

Expand Down
33 changes: 16 additions & 17 deletions boards/common/uart_tx_V2.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,40 @@ module uart_tx_V2(
input wire [7:0] din,
input wire wr_en,
output wire tx_busy,

output reg tx_p
);

initial begin
tx_p = 1'b1;
end

parameter clk_freq = 12000000;
parameter clk_freq = 12000000;
parameter uart_freq = 115200;

localparam STATE_IDLE = 2'b00;
localparam STATE_START = 2'b01;
localparam STATE_DATA = 2'b10;
localparam STATE_STOP = 2'b11;
localparam TX_CLK_MAX = (clk_freq / uart_freq) - 1;
localparam TX_CLK_WID = $clog2(TX_CLK_MAX);

localparam STATE_IDLE = 2'd0;
localparam STATE_START = 2'd1;
localparam STATE_DATA = 2'd2;
localparam STATE_STOP = 2'd3;

reg[7:0] localdin;
reg localwr_en;

//always@(posedge clk)begin
always@(*)begin
//always @(*) begin
always @(posedge clk) begin
localdin<=din;
localwr_en<=wr_en;
end

reg [7:0] data= 8'h00;
reg [2:0] bitpos= 3'h0;
reg [1:0] state= STATE_IDLE;
reg [7:0] data = 8'h00;
reg [2:0] bitpos = 3'h0;
reg [1:0] state = STATE_IDLE;

wire tx_clk;

localparam TX_CLK_MAX = (clk_freq / uart_freq)-1;

reg[$clog2(TX_CLK_MAX+1)+1:0] tx_clkcnt;
reg[TX_CLK_WID-1:0] tx_clkcnt; // 7 bits is enough for 12000000/115200=104.1666 -> 105

wire tx_clk;
assign tx_clk = (tx_clkcnt == 0);

initial tx_clkcnt=0;
Expand All @@ -46,7 +45,7 @@ always @(posedge clk) begin
if (tx_clkcnt >= TX_CLK_MAX)
tx_clkcnt <= 0;
else
tx_clkcnt <= tx_clkcnt + 1;
tx_clkcnt <= ((tx_clkcnt + 1) & {TX_CLK_WID{1'b1}});
end


Expand Down
25 changes: 15 additions & 10 deletions boards/common/utils.vh
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@

localparam [7:0] SHIFT_MASK = 8'b00100010;
// Bits in modifier byte:
// 0=LEFT CTRL, 1=LEFT SHIFT, 2=LEFT ALT, 3=LEFT GUI
// 4=RIGHT CTRL, 5=RIGHT SHIFT, 6=RIGHT ALT, 7=RIGHT GUI
localparam [7:0] SHIFT_MASK = 8'b00100010; // right and left SHIFT
localparam [7:0] CTRL_MASK = 8'b00010001; // richt and left CTRL
function [7:0] scancode2char(input [7:0] scancode, input [7:0] modifiers);
reg [7:0] a;
if (scancode >= 4 && scancode <= 29) begin // a-z
if (modifiers == 0)
a = scancode - 4 + 97; // a: 97, A: 65
a = ((scancode - 4 + 97) & 8'hff); // a: 97
else if ((modifiers & SHIFT_MASK) && (modifiers & ~SHIFT_MASK) == 0)
a = scancode - 4 + 65;
a = ((scancode - 4 + 65) & 8'hff); // A: 65
else if ((modifiers & CTRL_MASK) && (modifiers & ~CTRL_MASK) == 0)
a = ((scancode - 4 + 1) & 8'hff); // CTRL-A until CTRL-Z
end else if (modifiers == 0) begin
case (scancode)
30: a = "1";
Expand All @@ -19,10 +25,10 @@ function [7:0] scancode2char(input [7:0] scancode, input [7:0] modifiers);
37: a = "8";
38: a = "9";
39: a = "0";
40: a = "\n"; // enter
40: a = 13; // enter (CR, CTRL-M)
41: a = 27; // esc
42: a = 8; // backspace
43: a = 9; // tab
42: a = 8; // backspace (CTRL-H)
43: a = 9; // tab (CTRL-I)
44: a = 32; // space
45: a = "-"; // -
46: a = "="; // =
Expand Down Expand Up @@ -51,11 +57,10 @@ function [7:0] scancode2char(input [7:0] scancode, input [7:0] modifiers);
37: a = "*";
38: a = "(";
39: a = ")";
40: a = "\n";
40: a = "\n"; // enter
40: a = 10; // shift-enter (LF, CTRL-J)
41: a = 27; // esc
42: a = 8; // backspace
43: a = 9; // tab
42: a = 8; // backspace (CTRL-H)
43: a = 9; // tab (CTRL-I)
44: a = 32; // space
45: a = "_";
46: a = "+";
Expand Down
4 changes: 4 additions & 0 deletions boards/tang-nano20k-primer25k/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# GOWIN Generated sythesis files
/impl/
# GOWIN Report files
*.gprj.user
Loading